public function testDuplicateImages() { $user = $this->em->getRepository('Aisel\\UserBundle\\Entity\\User')->findOneBy(['email' => '*****@*****.**']); $this->setExpectedException('Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException'); $image = new Media(); $image->setType(Media::MEDIA_IMAGE); $image->setFilename($this->faker->numberBetween(0, 10000)); $image->setMainImage(false); $this->em->persist($image); $this->em->flush(); $this->assertNotNull($image->getId()); $product = new Product(); $product->setUser($user); $product->setLocale('en'); $product->setName($this->faker->sentence(1)); $product->setContentShort($this->faker->sentence(10)); $product->setContent($this->faker->sentence(10)); $product->setStatus(true); $product->setSku($this->faker->numberBetween()); $product->setCommentStatus(true); $product->setMetaUrl('url_' . time()); $product->addMedia($image); $product->addMedia($image); $this->em->persist($product); $this->em->flush(); }
/** * {@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) { $product = new Product(); $product->setLocale($table->column[1]); $product->setName($table->column[2]); $product->setSku($table->column[3]); $product->setPrice((double) $table->column[4]); $product->setQty((int) $table->column[11]); $product->setDescriptionShort($table->column[14]); $product->setDescription($table->column[15]); $product->setStatus((int) $table->column[16]); $product->setHidden((int) $table->column[17]); $product->setCommentStatus((int) $table->column[18]); $product->setMetaUrl($table->column[19]); $categories = explode(",", $table->column[20]); foreach ($categories as $c) { $category = $this->getReference('product_category_' . $c); $product->addCategory($category); } $manager->persist($product); $manager->flush(); $this->addReference('product_' . $table->column[0], $product); $this->setProductImage($manager, $product); } } } }
/** * newProduct * * @return Product $product */ public function newProduct() { $product = new Product(); $product->setLocale('en'); $product->setName($this->faker->sentence()); $product->setSku($this->faker->randomDigit); $product->setPrice($this->faker->randomDigit); $product->setQty($this->faker->randomDigit); $product->setContentShort($this->faker->sentence()); $product->setContent($this->faker->text()); $product->setStatus(true); $product->setHidden(false); $product->setCommentStatus(false); $product->setMetaUrl($this->faker->numberBetween(100000000, 9999999999)); $this->em->persist($product); $this->em->flush(); return $product; }
/** * newProduct * * @return Product $product */ public function newProduct() { $user = $this->em->getRepository('Aisel\\UserBundle\\Entity\\User')->findOneBy(['email' => '*****@*****.**']); $product = new Product(); $product->setUser($user); $product->setLocale('en'); $product->setName($this->faker->sentence()); $product->setSku($this->faker->randomDigit); $product->setPrice($this->faker->randomDigit); $product->setQty($this->faker->randomDigit); $product->setContentShort($this->faker->sentence()); $product->setContent($this->faker->text()); $product->setStatus(true); $product->setHidden(false); $product->setCommentStatus(false); $product->setMetaUrl($this->faker->numberBetween(100000000, 9999999999)); $this->em->persist($product); $this->em->flush(); return $product; }
public function testDuplicatedUrlThrowsError() { $urlText = 'product-test-meta-url'; $this->setExpectedException('LogicException', 'Given URL already exists'); $user = $this->em->getRepository('Aisel\\UserBundle\\Entity\\User')->findOneBy(['email' => '*****@*****.**']); // Create Product 1 $product1 = new Product(); $product1->setUser($user); $product1->setLocale('en'); $product1->setContent('...'); $product1->setContentShort('...'); $product1->setInStock(false); $product1->setName('...'); $product1->setSku('test-1'); $product1->setStatus(true); $product1->setMetaUrl($urlText); $product1->setMetaTitle('...'); $product1->setCommentStatus(true); $this->em->persist($product1); $this->em->flush(); // Create Product 2 $product2 = new Product(); $product2->setUser($user); $product2->setLocale('en'); $product2->setContent('...'); $product2->setContentShort('...'); $product2->setInStock(false); $product2->setName('...'); $product2->setSku('test-2'); $product2->setStatus(true); $product2->setMetaUrl($urlText); $product2->setMetaTitle('...'); $product2->setCommentStatus(true); $this->em->persist($product2); $this->em->flush(); // Delete Product 1 $product1 = $this->em->getRepository('Aisel\\ProductBundle\\Entity\\Product')->findOneBy(['metaUrl' => $urlText]); $this->em->remove($product1); $this->em->flush(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { // Delete all files and directories $this->cleanMediaDir(); 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) { $user = $this->getReference('user_' . $table->column[1]); $product = new Product(); $product->setUser($user); $product->setLocale($table->column[2]); $product->setName($table->column[3]); $product->setSku($table->column[4]); $product->setPrice((int) $table->column[5]); $product->setQty((int) $table->column[12]); $product->setContentShort($table->column[15]); $product->setContent($table->column[16]); $product->setStatus((int) $table->column[17]); $product->setHidden((int) $table->column[18]); $product->setCommentStatus((int) $table->column[19]); $product->setMetaUrl($table->column[20]); $nodes = explode(",", $table->column[21]); foreach ($nodes as $c) { $node = $this->getReference('product_node_' . $c); $product->addNode($node); } $manager->persist($product); $manager->flush(); $this->addReference('product_' . $table->column[0], $product); $images = $this->setProductImage($manager, $product); $product->setMedias($images); $manager->persist($product); $manager->flush(); } } } }