public static function setUpBeforeClass() { self::$kernel->resetDatabase(); $site = new Site(); $site->setLabel('foobar'); self::$em->persist($site); self::$em->flush($site); $layout = self::$kernel->createLayout('foobar'); self::$em->persist($layout); self::$em->flush($layout); }
public function test_serializeSite() { $controller = $this->getController(); $serialized = $controller->formatItem($this->site); $content = json_decode($serialized, true); $this->assertInternalType('string', $content['label']); $this->assertEquals($this->site->getLayouts()->count(), count($content['layouts'])); foreach ($this->site->getLayouts() as $key => $layout) { $this->assertSame(json_decode($controller->formatItem($layout), true), $content['layouts'][$key]); } }
/** * @covers ::getLayoutsAction */ public function test_getSiteController() { $user = $this->createAuthUser('super_admin', array('ROLE_API_USER')); $aclManager = $this->getBBApp()->getContainer()->get('security.acl_manager'); $aclManager->insertOrUpdateObjectAce(new ObjectIdentity($this->site->getObjectIdentifier(), get_class($this->site)), new UserSecurityIdentity($user->getGroups()[0]->getId(), 'BackBee\\Security\\Group'), MaskBuilder::MASK_VIEW); // authenticate a user with super admin authority $controller = $this->getController(); $response = $controller->getCollectionAction(new Request()); $this->assertEquals(200, $response->getStatusCode()); $content = json_decode($response->getContent(), true); $this->assertInternalType('array', $content); $this->assertCount(1, $content); }
/** * Removes stored site-content indexes for a content in a site. * * @param Site $site * @param AbstractClassContent $content * * @return IndexationRepository */ public function removeIdxSiteContent(Site $site, AbstractClassContent $content) { $query = 'DELETE FROM idx_site_content WHERE site_uid = :site AND (content_uid IN ' . '(SELECT content_uid FROM content_has_subcontent WHERE parent_uid = :content)' . 'OR content_uid = :content)'; $params = array('site' => $site->getUid(), 'content' => $content->getUid()); return $this->_executeQuery($query, $params); }
/** * Returns uri from pathinfo according to site to be reached. * * @param \Symfony\Component\HttpFoundation\Request $request * @param string $pathinfo * @param \BackBee\Site\Site $site * * @return string */ private function getUriForSite(Request $request, $pathinfo, Site $site) { return $request->getScheme() . '://' . $site->getServerName() . $pathinfo; }
/** * Create new home layout * * @param \BackBee\Site\Site $site Site object * * @return \BackBee\Site\Layout */ private function createHomeLayout($site) { $layout = new \BackBee\Site\Layout(md5('defaultlayout-' . $site->getLabel())); $layout->setData('{"templateLayouts":[{"title":"Top column","layoutSize":{"height":300,"width":false},"gridSizeInfos":{"colWidth":60,"gutterWidth":20},"id":"Layout__1332943638139_1","layoutClass":"bb4ResizableLayout","animateResize":false,"showTitle":false,"target":"#bb5-mainLayoutRow","resizable":true,"useGridSize":true,"gridSize":5,"gridStep":100,"gridClassPrefix":"span","selectedClass":"bb5-layout-selected","position":"none","height":800,"defaultContainer":"#bb5-mainLayoutRow","layoutManager":[],"mainZone":true,"accept":[],"maxentry":"0","defaultClassContent":null},{"title":"Main column","layoutSize":{"height":800,"width":false},"gridSizeInfos":{"colWidth":60,"gutterWidth":20},"id":"Layout__1383430750637_1","layoutClass":"bb5-resizableLayout","animateResize":false,"showTitle":false,"target":"#bb5-mainLayoutRow","resizable":true,"useGridSize":true,"gridSize":2,"gridStep":100,"gridClassPrefix":"span","selectedClass":"bb5-layout-selected","alphaClass":"alpha","omegaClass":"omega","typeClass":"hChild","clearAfter":1,"height":800,"defaultContainer":"#bb5-mainLayoutRow","layoutManager":[],"mainZone":false,"accept":[],"maxentry":0,"defaultClassContent":null},{"title": "Nouvelle zone","layoutSize": {"height": 800,"width": false},"gridSizeInfos": {"colWidth": 60,"gutterWidth": 20},"id": "Layout__1383430750640_1","layoutClass": "bb5-resizableLayout","animateResize": false,"showTitle": false,"target": "#bb5-mainLayoutRow","resizable": true,"useGridSize": true,"gridSize": 2,"gridStep": 100,"gridClassPrefix": "span","selectedClass": "bb5-layout-selected","alphaClass": "alpha","omegaClass": "omega","typeClass": "hChild","clearAfter": 1,"height": 800,"defaultContainer": "#bb5-mainLayoutRow","layoutManager": [],"mainZone": false,"accept": [],"maxentry": 0,"defaultClassContent": null}]}')->setLabel('Home')->setPath('Home.twig')->setPicPath($layout->getUid() . '.png')->setSite($site); $this->entyMgr->persist($layout); return $layout; }
/** * Returns the theme registry or null if not found. * * @param Site|null $site * @return Registry|null */ protected function getThemeRegistry(Site $site = null) { $registry = null; $criteria = ['type' => 'selected_theme', 'scope' => 'THEME_CONFIG']; if (null !== $site) { $criteria['key'] = $site->getLabel(); $registry = $this->app->getEntityManager()->getRepository(Registry::class)->findOneBy($criteria); } if (null === $registry) { $criteria['key'] = 'default'; $registry = $this->app->getEntityManager()->getRepository(Registry::class)->findOneBy($criteria); } return $registry; }
/** * @covers ::persist * @covers ::loadPersistors * @covers ::doPersist * @covers ::updateConfigOverridedSectionsForSite */ public function test_persistWithConfigPerSite() { $this->application->setIs_Started(true); $this->application->getConfig()->setSection('config', array('persistor' => 'BackBee\\Config\\Tests\\Persistor\\FakePersistor')); $this->application->getConfig()->setSection('parameters', array('hello' => 'foo')); $this->application->setContainer(new Container()); $this->application->getContainer()->set('container.builder', new FakeContainerBuilder()); $current_config = $this->application->getConfig()->getAllRawSections(); $this->application->setSite($site = new Site()); $this->persistor->persist($this->application->getConfig(), true); $this->assertTrue($this->application->getConfig()->getSection('override_site') !== null); $updated_override_section = array('override_site' => array($site->getUid() => array('parameters' => array('hello' => 'foo'), 'config' => array('persistor' => 'BackBee\\Config\\Tests\\Persistor\\FakePersistor')))); $this->assertEquals(array_merge($current_config, $updated_override_section), $this->application->getConfig()->getAllRawSections()); $this->assertEquals(array_merge($this->configurator->getConfigDefaultSections($this->application->getConfig()), $updated_override_section), $this->application->getContainer()->getParameter('config_to_persist')); }
/** * @Serializer\VirtualProperty * @Serializer\SerializedName("site_label") */ public function getSiteLabel() { return null !== $this->_site ? $this->_site->getLabel() : null; }
/** * Retrieves root nodes for $site * * @param Site $site The site we are looking for root nodes * @param string $classname * * @return array The root nodes found */ private function getPageRoot(Site $site, $classname) { $query = sprintf('SELECT %s FROM %s WHERE %s = ? AND %s IS NULL', $this->requiredFields['uid'], $this->em->getClassMetadata($classname)->getTableName(), $this->requiredFields['site_uid'], $this->requiredFields['parent_uid']); return $this->em->getConnection()->executeQuery($query, array($site->getUid()), array(Type::STRING))->fetchAll(\PDO::FETCH_COLUMN); }
/** * @Serializer\VirtualProperty * @Serializer\SerializedName("site_uid") * * @return string|null */ public function getSiteUid() { if (null === $this->_site) { return; } return $this->_site->getUid(); }
public function testGetUriRequested() { // Starting with a site without servername and simulate an HTTPS request $site = new Site(); self::$app->getContainer()->set('site', $site); unset($GLOBALS['argv']); self::$app->setIsStarted(true); $request = self::$app->getRequest(); $request->server->add(['SCRIPT_URL' => '/public/fake/fake.html', 'SCRIPT_URI' => 'https://www.fakeserver.com/public/fake/fake.html', 'HTTP_HOST' => 'www.fakeserver.com', 'SERVER_NAME' => 'www.fakeserver.com', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '443', 'HTTPS' => 'on', 'DOCUMENT_ROOT' => '/home/web/fakeroot', 'SCRIPT_FILENAME' => '/home/web/fakeroot/public/index.php', 'REQUEST_URI' => '/public/fake/fake.html', 'SCRIPT_NAME' => '/public/index.php']); // No site provided, the request is used $routeCollection = new RouteCollection(self::$app); $this->assertEquals('http://www.backbee.com', $routeCollection->getUri('http://www.backbee.com')); $this->assertEquals('https://www.fakeserver.com/public/', $routeCollection->getUri()); $this->assertEquals('https://www.fakeserver.com/public/images/', $routeCollection->getUri(null, null, null, RouteCollection::IMAGE_URL)); $this->assertEquals('https://www.fakeserver.com/public/', $routeCollection->getUri(null, '.html')); $this->assertEquals('https://www.fakeserver.com/public/fake.html', $routeCollection->getUri('/fake')); $this->assertEquals('https://www.fakeserver.com/public/fake.htm', $routeCollection->getUri('fake.htm', '.html')); $this->assertEquals('https://www.fakeserver.com/public/fake.html', $routeCollection->getUri('fake', '.html')); // A site is provided, the base URL and the protocol can't be predicted $otherSite = new Site(); $otherSite->setServerName('other.fakeserver.com'); $this->assertEquals('http://www.backbee.com', $routeCollection->getUri('http://www.backbee.com', null, $otherSite)); $this->assertEquals('http://other.fakeserver.com/', $routeCollection->getUri(null, null, $otherSite)); $this->assertEquals('http://other.fakeserver.com/images/', $routeCollection->getUri(null, null, $otherSite, RouteCollection::IMAGE_URL)); $this->assertEquals('http://other.fakeserver.com/', $routeCollection->getUri(null, '.html', $otherSite)); $this->assertEquals('http://other.fakeserver.com/fake.html', $routeCollection->getUri('/fake', null, $otherSite)); $this->assertEquals('http://other.fakeserver.com/fake.htm', $routeCollection->getUri('fake.htm', '.html', $otherSite)); $this->assertEquals('http://other.fakeserver.com/fake.html', $routeCollection->getUri('fake', '.html', $otherSite)); }
public function __construct() { $faker = Factory::create(); $faker->seed(1337); parent::__construct($faker->md5); }
/** * @covers ::getCollectionAction */ public function testGetCollectionAction() { $controller = $this->getController(); // no filters $response = $this->getBBApp()->getController()->handle(new Request(array(), array(), array('id' => $this->groupEditor->getId(), '_action' => 'getCollectionAction', '_controller' => 'BackBee\\Rest\\Controller\\GroupController'), array(), array(), array('REQUEST_URI' => '/rest/1/test/'))); $res = json_decode($response->getContent(), true); $this->assertInternalType('array', $res); $this->assertCount(1, $res); // filter by site $response = $this->getBBApp()->getController()->handle(new Request(array(), array('site_uid' => $this->site->getUid()), array('id' => $this->groupEditor->getId(), '_action' => 'getCollectionAction', '_controller' => 'BackBee\\Rest\\Controller\\GroupController'), array(), array(), array('REQUEST_URI' => '/rest/1/test/'))); $this->assertEquals(200, $response->getStatusCode()); $res = json_decode($response->getContent(), true); $this->assertInternalType('array', $res); $this->assertCount(1, $res); $this->assertEquals($this->site->getUid(), $res[0]['site_uid']); // filter by site that has no $siteWithNoGroups = new Site(); $siteWithNoGroups->setLabel('SiteWithNoGroups'); $this->getBBApp()->getEntityManager()->persist($siteWithNoGroups); $this->getBBApp()->getEntityManager()->flush(); $response = $this->getBBApp()->getController()->handle(new Request([], ['site_uid' => $siteWithNoGroups->getUid()], ['id' => $this->groupEditor->getId(), '_action' => 'getCollectionAction', '_controller' => 'BackBee\\Rest\\Controller\\GroupController'], [], [], ['REQUEST_URI' => '/rest/1/test/'])); $this->assertEquals(200, $response->getStatusCode()); $res = json_decode($response->getContent(), true); $this->assertInternalType('array', $res); $this->assertCount(0, $res); }
/** * Generates an uid for layout * * @param string $filename The filename of the definition * @param array $data The parsed data of the definition * @param Site $site Optional, the site for which layout will add * * @return string The generated uid */ public function generateUid($filename, array $data, Site $site = null) { $baseUid = $site !== null ? $site->getUid() : ''; return md5($baseUid . basename($filename)); }