public function testDuplicateNodes() { $node = new Node(); $node->setStatus(true); $node->setDescription($this->faker->sentence(10)); $node->setMetaUrl('url_' . time()); $node->setLocale('en'); $this->dm->persist($node); $this->dm->flush(); $this->assertNotNull($node->getId()); $page = new Page(); $page->setLocale('en'); $page->setTitle($this->faker->sentence(1)); $page->setContent($this->faker->sentence(10)); $page->setStatus(true); $page->setCommentStatus(true); $page->setMetaUrl('url_' . time()); $page->addNode($node); $page->addNode($node); $this->dm->persist($page); $this->dm->flush(); $this->assertNotNull($page->getId()); $this->assertEquals(count($page->getNodes()), 1); $this->dm->remove($node); $this->dm->flush(); $this->dm->remove($page); $this->dm->flush(); }
public function testDuplicatedUrlThrowsError() { $urlText = 'page-test-meta-url'; $this->setExpectedException('LogicException', 'Given URL already exists'); // Create Page 1 $page1 = new Page(); $page1->setLocale('en'); $page1->setContent('...'); $page1->setTitle('...'); $page1->setStatus(true); $page1->setMetaUrl($urlText); $page1->setMetaTitle('...'); $page1->setCommentStatus(true); $this->dm->persist($page1); $this->dm->flush(); $this->dm->clear(); // Create Page 2 $page2 = new Page(); $page2->setLocale('en'); $page2->setContent('...'); $page2->setTitle('...'); $page2->setStatus(true); $page2->setMetaUrl($urlText); $page2->setMetaTitle('...'); $page2->setCommentStatus(true); $this->dm->persist($page2); $this->dm->flush(); // Delete Page 1 $page1 = $this->dm->getRepository('Aisel\\PageBundle\\Document\\Page')->findOneBy(['metaUrl' => $urlText]); $this->dm->remove($page1); $this->dm->flush(); $this->dm->clear(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { foreach ($this->fixtureFiles as $file) { if (file_exists($file)) { $contents = file_get_contents($file); $XML = simplexml_load_string($contents); foreach ($XML->database->table as $table) { $page = new Page(); $page->setLocale($table->column[1]); $page->setTitle($table->column[2]); $page->setContent($table->column[3]); $page->setStatus($table->column[4]); $page->setCommentStatus($table->column[6]); $page->setMetaUrl($table->column[7]); $nodes = explode(",", $table->column[8]); foreach ($nodes as $c) { $node = $this->getReference('page_node_' . $c); $page->addNode($node); } $manager->persist($page); $manager->flush(); $this->addReference('page_' . $table->column[0], $page); } } } }