public function installDemoData() { \Jarves\Model\DomainQuery::create()->deleteAll(); \Jarves\Model\NodeQuery::create()->deleteAll(); \Jarves\Model\ContentQuery::create()->deleteAll(); \Jarves\Model\AppLockQuery::create()->deleteAll(); \Jarves\Model\AclQuery::create()->deleteAll(); $domainName = $this->getDomain(); $domainName = explode(':', $domainName)[0]; $domain = new Domain(); $domain->setDomain($domainName); $path = $this->getPath(); $domain->setPath($path); $domain->setTitleFormat('%title% | Node title - My Website - change me under domain settings.'); $domain->setMaster(1); $domain->setLang('en'); $domain->setResourceCompression(0); $domain->setTheme('jarvesDemoTheme'); $domain->setSearchIndexKey(md5(time() . '-' . rand())); $domain->save(); $root = new Node(); $root->setDomainId($domain->getId()); $root->makeRoot(); $root->setTitle('root'); $root->setUrn(''); $root->save(); //setup live workspace WorkspaceQuery::create()->deleteAll(); $workspace = new Workspace(); $workspace->setTitle('LIVE'); $workspace->setCreated(time()); $workspace->save(); $id = $workspace->getId(); if ($id != 1) { WorkspaceQuery::create()->filterById($id)->update(array('Id' => 1)); } $defaultLayout = 'default'; $defaultContentTemplate = 'JarvesBundle:Default:content.html.twig'; $Nodes = array(array(0, 'Blog', $defaultLayout, 'home', '', array('1' => array(array('text', 'Jarves cms has been installed!', $defaultContentTemplate, '<p>Jarves cms has been installed correctly.</p><p> </p><p><a href="http://www.jarves.io">Jarves cms Website</a></p><p> </p><p> </p><p>Go to <a href="jarves">administration</a> to manage your new website.</p><p> </p><p><strong>Default login:</strong></p><p><strong><br /></strong></p><p style="padding-left: 10px;">Username: admin</p><p style="padding-left: 10px;">Password: admin</p>'), array('plugin', '', $defaultContentTemplate, '{"bundle":"JarvesPublicationBundle","plugin":"listing","options":{"itemsPerPage":10,"maxPages":10,"detailPage":"","template":"default.html.twig","categoryId":[],"enableRss":false}}')), '2' => array(array('plugin', '» CATEGORIES', $defaultContentTemplate, '{"bundle":"JarvesPublicationBundle","plugin":"categoryList","options":{"listNode":"1","template":"default.html.twig","category_rsn":[]}}'))), array(array(1, 'Article', $defaultLayout, 'article', '', array(), array(), 0))), array(0, 'Links', $defaultLayout, 'links', '', array('1' => array(array('text', 'Links', $defaultContentTemplate, 'Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.')), '2' => array(array('text', '» About', $defaultContentTemplate, 'hoho'))), array(array(1, 'Jarves cms Official Website', $defaultLayout, 'www-jarves-org', 'http://www.jarves.io/'), array(1, 'Jarves cms Documentation', $defaultLayout, 'docu-jarves-org', 'http://docu.jarves.io/'), array(1, 'Jarves cms Extensions', $defaultLayout, 'www-jarves-org-extensions', 'http://www.jarves.io/extensions'))), array(0, 'About me', $defaultLayout, 'about-me', '', array('1' => array(array('text', 'About me', $defaultContentTemplate, 'Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.')), '2' => array(array('text', 'Hi, my Name is', $defaultContentTemplate, 'John Doe and I\'m a creative dude living in Springfield. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt...'))), array(array(0, 'Sublink 1', $defaultLayout, 'sublink-1', '', array('1' => array(array('text', 'Sublink 1', $defaultContentTemplate, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')))), array(0, 'Sublink 2', $defaultLayout, 'sublink-2', '', array('1' => array(array('text', 'Sublink 1', $defaultContentTemplate, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.<br/><br/><h3>Lorem ...</h3>ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')))))), array(2, 'Footer Navigation', '', '', '', array(), array(array(0, 'Sitemap', $defaultLayout, 'sitemap', '', array('1' => array(array('plugin', 'Sitemap', $defaultContentTemplate, 'todo')))), array(0, 'Contact', $defaultLayout, 'contact', '', array('1' => array(array('plugin', 'Contact form', $defaultContentTemplate, 'todo')))), array(0, 'Impress', $defaultLayout, 'impress', '', array('1' => array(array('text', 'Impress', $defaultContentTemplate, 'Owner: <b>Name</b><br/>Street, Nr<br/>Country<br/>')))))), array(3, 'Footer text', '', '', '', array('1' => array(array('text', '', $defaultContentTemplate, '<p>© my Node | <a href="http://www.jarves.io/">CMS</a> powered by Jarves cms - simply different</p>'))), array())); /* * 0: type * 1: Title * 2: layout * 3: url * 4: link target * 5: contents * 6: children * 7: visible */ foreach ($Nodes as $Node) { $oNode = new Node(); $oNode->setDomainId($domain->getId()); $oNode->setType($Node[0]); $oNode->setTitle($Node[1]); $oNode->setLayout($Node[2]); $oNode->setUrn($Node[3]); $oNode->insertAsLastChildOf($root); if (isset($Node[7])) { $oNode->setVisible($Node[7]); } else { $oNode->setVisible(1); } $oNode->save(); if ($Node[4]) { $oNode->setLink($Node[4]); } if ($Node[5]) { $this->installContents($oNode, $Node[5]); } if ($Node[6]) { $this->installNodes($oNode, $Node[6]); } } $startNode = NodeQuery::create()->filterByDomainId($domain->getId())->findOneByLft(2); $domain->setStartnodeId($startNode->getId()); $domain->save(); LanguageQuery::create()->deleteAll(); $h = fopen(__DIR__ . '/Resources/package/ISO_639-1_codes.csv', 'r'); if ($h) { while (($data = fgetcsv($h, 1000, ",")) !== false) { $lang = new Language(); $lang->setCode($data[0]); $lang->setTitle($data[1]); $lang->setLangtitle($data[2]); $lang->save(); } } LanguageQuery::create()->filterByCode('en')->update(array('Visible' => 1)); //search footer id $footerNavi = NodeQuery::create()->findOneByTitle('Footer Navigation'); $footerText = NodeQuery::create()->findOneByTitle('Footer text'); $domainThemeProperties = ['footerNavigation' => $footerNavi->getId(), 'footerTray' => $footerText->getId()]; $domain->setThemeOptions($domainThemeProperties); $domain->save(); SessionQuery::create()->deleteAll(); UserGroupQuery::create()->deleteAll(); UserQuery::create()->deleteAll(); GroupQuery::create()->deleteAll(); AclQuery::create()->deleteAll(); $groupGuest = new Group(); $groupGuest->setName('Guest'); $groupGuest->setDescription('All anonymous user'); $groupGuest->save(); $id = $groupGuest->getId(); GroupQuery::create()->filterById($id)->update(array('Id' => 0)); $groupAdmin = new Group(); $groupAdmin->setName('Admin'); $groupAdmin->setDescription('Super user'); $groupAdmin->save(); $id = $groupAdmin->getId(); GroupQuery::create()->filterById($id)->update(array('Id' => 1)); $groupAdmin->setId(1); $groupUsers = new Group(); $groupUsers->setName('Users'); $groupUsers->setDescription('Registered user'); $groupUsers->save(); $admin = new User(); $admin->setUsername('admin'); $admin->setFirstName('Admini'); $admin->setLastName('strator'); $admin->setEmail('admin@localhost'); $admin->setActivate(1); $encoderFactory = $this->container->get('security.encoder_factory'); $encoder = $encoderFactory->getEncoder($admin); $admin->setPassword($encoder->encodePassword('admin', null)); $liveWorkspace = WorkspaceQuery::create()->findOneById(1); $admin->addWorkspace($liveWorkspace); $settings = new \Jarves\Properties(array('userBg' => '/admin/images/userBgs/defaultImages/color-blue.jpg', 'adminLanguage' => 'en')); $admin->setSettings($settings); $admin->save(); $id = $admin->getId(); UserQuery::create()->filterById($id)->update(array('Id' => 1)); $admin->setId(1); $admin->addGroup($groupAdmin); $admin->save(); }
public function testObjectGeneral() { ItemQuery::create()->deleteAll(); TestQuery::create()->deleteAll(); $this->getACL()->removeObjectRules('test/item'); $this->getACL()->setCaching(false); $user = new User(); $user->setUsername('TestUser'); $user->save(); $group = new Group(); $group->setName('ACL Test group'); $group->addUser($user); $group->save(); $item1 = new Item(); $item1->setTitle('Item 1'); $item1->save(); $item2 = new Item(); $item2->setTitle('Item 2'); $item2->save(); $test1 = new Test(); $test1->setName('Test 1'); $test1->save(); $aclRequestItem1OnlyListing = ACLRequest::create('test/item', $item1->getId())->onlyListingMode(); $this->assertFalse($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup($group->getId())), 'we have no rules, so everyone except admin user and admin group has no access.'); $this->assertTrue($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup(1)), 'we have no rules, so only group admin has access.'); $this->assertTrue($this->getACL()->check($aclRequestItem1OnlyListing->targetUser(1)), 'we have no rules, so only user admin has access.'); $this->getACL()->removeObjectRules('test/item'); $this->getACL()->setObjectList('test/item', \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), true); $this->assertTrue($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup($group->getId())), 'testGroup got list access to all test/item objects.'); $this->getACL()->setObjectListExact('test/item', $item1->getId(), \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), false); $this->assertFalse($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup($group->getId())), 'testGroup got list access-denied to item 1.'); $aclRequestItem2OnlyListing = ACLRequest::create('test/item', $item2->getId())->onlyListingMode(); $this->assertTrue($this->getACL()->check($aclRequestItem2OnlyListing->targetGroup($group->getId())), 'testGroup still have access to item2.'); $this->getACL()->setObjectListExact('test/item', $item2->getId(), \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), false); $this->assertFalse($this->getACL()->check($aclRequestItem2OnlyListing->targetGroup($group->getId())), 'testGroup does not have access to item2 anymore.'); $acl = $this->getACL()->setObjectListExact('test/item', $item2->getId(), \Jarves\ACL::TARGET_TYPE_USER, $user->getId(), true); $this->assertTrue($this->getACL()->check($aclRequestItem2OnlyListing->targetUser($user->getId())), 'testUser got access through a rule for only him.'); $acl->setAccess(false); $acl->save(); $this->assertFalse($this->getACL()->check($aclRequestItem2OnlyListing->targetUser($user->getId())), 'testUser got no-access through a rule for only him.'); //access to every item $acl = $this->getACL()->setObjectList('test/item', \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), true); $this->assertTrue($this->getACL()->check($aclRequestItem2OnlyListing->targetUser($user->getId())), 'testUser has now access to all items through his group.'); $this->assertTrue($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup($group->getId())), 'testGroup has now access to all items.'); $this->assertTrue($this->getACL()->check($aclRequestItem2OnlyListing->targetGroup($group->getId())), 'testGroup has now access to all items.'); //remove the acl item that gives access to anything. $acl->delete(); $this->assertFalse($this->getACL()->check($aclRequestItem2OnlyListing->targetUser($user->getId())), 'testUser has no access anymore, since we deleted the access-for-all rule.'); $this->assertFalse($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup($group->getId())), 'testGroup has no access anymore to all items (item1).'); $this->assertFalse($this->getACL()->check($aclRequestItem2OnlyListing->targetGroup($group->getId())), 'testGroup has no access anymore to all items (item2).'); //check checkListCondition $this->getACL()->setObjectListCondition('test/item', array(array('id', '>', $item1->getId())), \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), true); $this->assertTrue($this->getACL()->check($aclRequestItem2OnlyListing->targetGroup($group->getId())), 'testGroup has access to all items after item1'); $this->assertFalse($this->getACL()->check($aclRequestItem1OnlyListing->targetGroup($group->getId())), 'testGroup has access to all items after item1, but only > , so not item1 itself.'); //revoke anything to object 'test\item' $this->getACL()->setObjectList('test/item', \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), false); $this->assertFalse($this->getACL()->check($aclRequestItem2OnlyListing->targetGroup($group->getId())), 'testGroup has no access to all items after item1'); //check against object test $aclRequestTest1OnlyListing = ACLRequest::create('test/test', $test1->getId())->onlyListingMode(); $this->getACL()->setObjectListExact('test/test', $test1->getId(), \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), true); $this->assertTrue($this->getACL()->check($aclRequestTest1OnlyListing->targetGroup($group->getId())), 'testGroup has access test1.'); $this->getACL()->setObjectList('test/test', \Jarves\ACL::TARGET_TYPE_GROUP, $group->getId(), false); $this->assertFalse($this->getACL()->check($aclRequestTest1OnlyListing->targetGroup($group->getId())), 'testGroup has no access test1.'); $this->getACL()->setCaching(true); $this->getACL()->removeObjectRules('test/item'); }