/** * Test modification. */ public function testModify() { // Non-existant product in db. $expectedProduct1 = new ProductDocument(); $expectedProduct1->setId('6b698c33118caee4ca0882c33f513d2f'); $expectedProduct1->setActive(true); $expectedProduct1->setSku('85-8573-846-1-4-3'); $expectedProduct1->setTitle('PRODUCT NO. 1'); $expectedProduct1->setDescription('Product number one for testing'); $expectedProduct1->setPrice(25.5); $expectedProduct1->setOldPrice(36.7); $expectedProduct1->setManufacturer(null); $expectedProduct1->setLongDescription(null); $expectedProduct1->setVendor(null); $expectedProduct1->setStock(5); $expectedProduct1->setAttributes([]); $url = new UrlNested(); $url->setUrl('Test/Product/1'); $expectedProduct1->setUrls(new \ArrayIterator([$url])); $expectedProduct1->setExpiredUrls([]); $expectedProduct2 = new VariantObject(); $expectedProduct2->setId('6b6a6aedca3e438e98d51f0a5d586c0b'); $expectedProduct2->setActive(false); $expectedProduct2->setSku('0702-85-853-9-2'); $expectedProduct2->setTitle('PRODUCT NO. 2'); $expectedProduct2->setDescription('Product number two for testing'); $expectedProduct2->setPrice(46.6); $expectedProduct2->setOldPrice(35.7); $expectedProduct2->setLongDescription('Product number two description for testing from extension'); $expectedProduct2->setStock(2); $expectedProduct2->setAttributes([]); $expectedProduct1->setVariants([$expectedProduct2]); $expectedEntities = [$expectedProduct1]; $productItems = $this->getTestElements(['6b698c33118caee4ca0882c33f513d2f', '6b6a6aedca3e438e98d51f0a5d586c0b'], 'ONGROXIDConnectorBundleTest:Article'); $this->assertCount(2, $productItems); $seoFinder = new SeoFinder(); $seoFinder->setEntityManager($this->getEntityManager()); $seoFinder->setShopId(0); $seoFinder->setRepository('ONGROXIDConnectorBundleTest:Seo'); $modifier = new ProductModifier(new AttributesToDocumentsService()); $modifier->setSeoFinderService($seoFinder); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); foreach ($expectedEntities as $key => $expectedProduct) { $actualProduct = new ProductDocument(); $modifier->modify(new ImportItem($productItems[$key], $actualProduct), $event); $this->assertEquals($expectedProduct, $actualProduct); } }
/** * Test for modify(). */ public function testModify() { /** @var Article $parent */ $parent = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Article'); $parent->setId('parentId'); /** @var Category $category */ $category = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category'); $category->setId('inactiveCategoryId'); $category->setActive(false); /** @var Category $activeCategory */ $activeCategory = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category'); $activeCategory->setId('activeCategoryId'); $activeCategory->setActive(true); /** @var ArticleToCategory $objToCat */ $objToCat = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\ArticleToCategory'); $objToCat->setCategory($category); /** @var ArticleToCategory $activeObjToCat */ $activeObjToCat = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\ArticleToCategory'); $activeObjToCat->setCategory($activeCategory); /** @var ArticleExtension $extension */ $extension = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\ArticleExtension'); $extension->setLongDesc('Long description'); /** @var Vendor $vendor */ $vendor = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Vendor'); $vendor->setTitle('Vendor A'); /** @var Manufacturer $manufacturer */ $manufacturer = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Manufacturer'); $manufacturer->setTitle('Manufacturer A'); /** @var Article $entity */ $entity = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Article'); // Attribute to be added to Category. $attribute = new Attribute(); $attribute->setId(123); $attribute->setPos(1); $attribute->setTitle('testAttributeTitle'); $artToAttr = new ArticleToAttribute(); $artToAttr->setId(321); $artToAttr->setPos(1); $artToAttr->setArticle($entity); $artToAttr->setAttribute($attribute); $entity->setId('id123')->setActive(true)->setArtNum('abc123')->setTitle('Any title')->setShortDesc('Short description')->setPrice(12.34)->setTPrice(43.21)->setExtension($extension)->addCategory($objToCat)->addCategory($activeObjToCat)->setStock(5)->setStockFlag(1)->setVendor($vendor)->setManufacturer($manufacturer)->addAttribute($artToAttr); $entity->setVariants($this->getVariants($entity)); $expectedDocument = new ProductDocument(); $expectedDocument->setId('id123'); $expectedDocument->setActive(true); $expectedDocument->setSku('abc123'); $expectedDocument->setTitle('Any title'); $expectedDocument->setDescription('Short description'); $expectedDocument->setPrice(12.34); $expectedDocument->setOldPrice(43.21); $expectedDocument->setLongDescription('Long description'); $expectedDocument->setCategories(['activeCategoryId']); $expectedDocument->setStock(5); $expectedDocument->setVendor('Vendor A'); $expectedDocument->setManufacturer('Manufacturer A'); $expectedDocument->setVariants($this->getExpectedVariants()); $expectedDocument->setUrls(new \ArrayIterator()); $expectedDocument->setExpiredUrls([]); $attObj = new AttributeObject(); $attObj->setPos(1); $attObj->setTitle('testAttributeTitle'); $expectedDocument->setAttributes([$attObj]); $document = new ProductDocument(); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); $this->modifier->modify(new ImportItem($entity, $document), $event); $this->assertEquals($expectedDocument, $document); }
/** * Extract article seo urls. * * @param Article $article * @param ProductDocument $document */ private function extractUrls(Article $article, $document) { $urls = []; $seoUrls = $this->getSeoFinderService()->getEntitySeo($article, $this->languageId); if (count($seoUrls) > 0) { foreach ($seoUrls as $seo) { /** @var Seo $seo */ $urlObject = new UrlNested(); $urlObject->setUrl($seo->getSeoUrl()); $urls[] = $urlObject; } } $document->setUrls(new \ArrayIterator($urls)); $document->setExpiredUrls([]); }
/** * Test getters and setters. */ public function testGettersAndSetters() { $variant = new VariantObject(); $this->document->setActive(true)->setOldPrice(20.5)->setStock(10)->setVendor('testVendor')->setManufacturer('testManufacturer')->setCategories([1, 3, 2])->setVariants([$variant]); $expectedAttributes = []; $expectedAttributes[0] = new AttributeObject(); $expectedAttributes[0]->setPos(1); $expectedAttributes[0]->setTitle('testTitle1'); $this->document->setAttributes($expectedAttributes); $this->assertEquals(true, $this->document->isActive()); $this->assertEquals(true, $this->document->getActive()); $this->assertEquals(20.5, $this->document->getOldPrice()); $this->assertEquals(10, $this->document->getStock()); $this->assertEquals('testVendor', $this->document->getVendor()); $this->assertEquals('testManufacturer', $this->document->getManufacturer()); $this->assertEquals([1, 3, 2], $this->document->getCategories()); $this->assertSame([$variant], $this->document->getVariants()); $actualAttributes = $this->document->getAttributes(); foreach ($actualAttributes as $idx => $actualAttribute) { $this->assertSame($expectedAttributes[$idx], $actualAttribute); } $this->document->setAttributes(null)->setCategories(null); $this->assertEquals(null, $this->document->getAttributes()); $this->assertEquals(null, $this->document->getCategories()); }