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); }
protected function setUp() { $this->initAutoload(); $this->bbapp = $this->getBBApp(); $this->initDb($this->bbapp); $this->initAcl(); $this->bbapp->start(); // craete site $this->site = new Site(); $this->site->setLabel('sitelabel'); $this->site->setServerName('www.example.org'); // craete layout $this->layout = new Layout(); $this->layout->setSite($this->site); $this->layout->setLabel('defaultLayoutLabel'); $this->layout->setPath($this->bbapp->getBBDir() . '/Rest/Tests/Fixtures/Controller/defaultLayout.html.twig'); $this->layout->setData(json_encode(array('templateLayouts' => array('title' => 'zone_1234567')))); $this->site->addLayout($this->layout); $this->getEntityManager()->persist($this->layout); $this->getEntityManager()->persist($this->site); $this->getEntityManager()->flush(); }
/** * @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); }