public function testRemovePage()
 {
     $page = new Page();
     $page->setTitle('Test')->setContent('<p>test</p>')->setCurrentSlugUrl('/remove');
     $this->entityManager->persist($page);
     $childPage1 = new Page();
     $childPage1->setTitle('Test child Page 1')->setContent('<p>test child page</p>')->setCurrentSlugUrl('/child1');
     $this->entityManager->persist($childPage1);
     $childPage2 = new Page();
     $childPage2->setTitle('Test child Page 2')->setContent('<p>test child page</p>')->setCurrentSlugUrl('/child2');
     $this->entityManager->persist($childPage2);
     $page->addChildPage($childPage1);
     $page->addChildPage($childPage2);
     $this->entityManager->flush($page);
     $pageSlugId = $page->getCurrentSlug()->getId();
     $childPage1SlugId = $childPage1->getCurrentSlug()->getId();
     $childPage2SlugId = $childPage2->getCurrentSlug()->getId();
     $this->entityManager->remove($page);
     $this->entityManager->flush();
     // make sure data updated correctly
     $this->entityManager->clear();
     $this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $pageSlugId));
     $this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $childPage1SlugId));
     $this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $childPage2SlugId));
 }
Exemplo n.º 2
0
 /**
  * @param  EntityManager $em
  * @param  Page $page
  */
 protected function removePageSlugs(EntityManager $em, Page $page)
 {
     foreach ($page->getSlugs() as $slug) {
         $page->removeSlug($slug);
         $em->remove($slug);
     }
     foreach ($page->getChildPages() as $childPage) {
         $this->removePageSlugs($em, $childPage);
     }
 }
Exemplo n.º 3
0
 /**
  * @Route("/create/{id}", name="orob2b_cms_page_create", requirements={"id"="\d+"}, defaults={"id"=null})
  * @Template("OroB2BCMSBundle:Page:update.html.twig")
  * @Acl(
  *      id="orob2b_cms_page_create",
  *      type="entity",
  *      class="OroB2BCMSBundle:Page",
  *      permission="CREATE"
  * )
  *
  * @param int|null $id
  * @return array|RedirectResponse
  */
 public function createAction($id)
 {
     $page = new Page();
     if ($id) {
         $parentPage = $this->getDoctrine()->getRepository('OroB2BCMSBundle:Page')->find($id);
         if (!$parentPage) {
             throw new \LogicException(sprintf('Page with identifier %s does not exist', $id));
         }
         $page->setParentPage($parentPage);
     }
     return $this->update($page);
 }
 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);
 }
Exemplo n.º 5
0
 /**
  * {@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();
 }
Exemplo n.º 6
0
 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());
 }
Exemplo n.º 7
0
 /**
  * Returns an array formatted as:
  * array(
  *     'id'     => int,    // tree item id
  *     'parent' => int,    // tree item parent id
  *     'text'   => string  // tree item label
  * )
  *
  * @param Page $entity
  * @return array
  */
 protected function formatEntity($entity)
 {
     return ['id' => $entity->getId(), 'parent' => $entity->getParentPage() ? $entity->getParentPage()->getId() : '#', 'text' => $entity->getTitle(), 'state' => ['opened' => $entity->getParentPage() === null]];
 }