/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); $locator = $this->container->get('file_locator'); $filePath = $locator->locate('@OroB2BCMSBundle/Migrations/Data/Demo/ORM/data/pages.csv'); if (is_array($filePath)) { $filePath = current($filePath); } $handler = fopen($filePath, 'r'); $headers = fgetcsv($handler, 5000, ','); while (($data = fgetcsv($handler, 5000, ',')) !== false) { $row = array_combine($headers, array_values($data)); $page = new Page(); $page->setTitle($row['title']); $page->setContent($row['content']); $page->setOrganization($organization); $page->setCurrentSlugUrl($row['slug']); if ($row['parentId'] > 0 && array_key_exists($row['parentId'], $this->pages)) { /** @var Page $parent */ $parent = $this->pages[$row['parentId']]; $parent->addChildPage($page); } $manager->persist($page); $this->pages[$row['id']] = $page; } fclose($handler); $manager->flush(); }
public function testViewBySlug() { $registry = $this->getContainer()->get('doctrine'); $pageEntityManager = $registry->getManagerForClass('OroB2BCMSBundle:Page'); $organization = $registry->getManagerForClass('OroOrganizationBundle:Organization')->getRepository('OroOrganizationBundle:Organization')->getFirst(); $slug = '/test-slug'; $title = 'Test Page'; $content = '<p>Test content</p>'; $page = new Page(); $page->setCurrentSlugUrl($slug)->setTitle($title)->setContent($content)->setOrganization($organization); $pageEntityManager->persist($page); $pageEntityManager->flush(); $crawler = $this->client->request('GET', $slug); $this->assertHtmlResponseStatusCodeEquals($this->client->getResponse(), 200); $pageHtml = $crawler->html(); $this->assertContains($title, $pageHtml); $this->assertContains($content, $pageHtml); }
public function testSetCurrentSlugUrl() { $rootSlug = new Slug(); $rootSlug->setUrl('/root'); $rootPage = new Page(); $rootPage->setCurrentSlug($rootSlug); $childSlug = new Slug(); $childSlug->setUrl('/first'); $childPage = new Page(); $childPage->setCurrentSlug($childSlug); $rootPage->addChildPage($childPage); $childPage->setCurrentSlugUrl('first-altered'); $this->assertEquals('/root', $rootPage->getCurrentSlugUrl()); $this->assertEquals('/root/first-altered', $childPage->getCurrentSlugUrl()); $rootPage->setCurrentSlugUrl('root-altered'); $this->assertEquals('/root-altered', $rootPage->getCurrentSlugUrl()); $this->assertEquals('/root-altered/first-altered', $childPage->getCurrentSlugUrl()); }