/** * Test for modify(). */ public function testModify() { $modifier = new ContentModifier(); /** @var Content $content */ $content = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Content'); $content->setId('testId')->setActive(true)->setPosition(4)->setContent('testContent')->setTitle('testTitle')->setFolder('testFolder')->setLoadId('testSlug')->setSnippet(false)->setType(5)->setFolder('testFolder'); /** @var Seo|\PHPUnit_Framework_MockObject_MockObject $seo */ $seo = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Seo'); $seo->setSeoUrl('test'); /** @var SeoFinder|\PHPUnit_Framework_MockObject_MockObject $seoFinder */ $seoFinder = $this->getMockBuilder('ONGR\\OXIDConnectorBundle\\Service\\SeoFinder')->disableOriginalConstructor()->getMock(); $seoFinder->expects($this->once())->method('getEntitySeo')->willReturn(new \ArrayIterator([$seo])); $modifier->setSeoFinderService($seoFinder); $expectedDocument = new ContentDocument(); $expectedDocument->setId('testId'); $expectedDocument->setActive(true); $expectedDocument->setPosition(4); $expectedDocument->setContent('testContent'); $expectedDocument->setTitle('testTitle'); $expectedDocument->setFolder('testFolder'); $expectedDocument->setSlug('testSlug'); $expectedDocument->setSnippet(false); $expectedDocument->setType(5); $expectedDocument->setFolder('testFolder'); $url = new UrlNested(); $url->setUrl('test'); $expectedDocument->setUrls(new \ArrayIterator([$url])); $expectedDocument->setExpiredUrls([]); $document = new ContentDocument(); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); $modifier->modify(new ImportItem($content, $document), $event); $this->assertEquals($expectedDocument, $document); }
/** * Test modification. */ public function testModify() { $expectedCategory1 = new CategoryDocument(); $expectedCategory1->setId('fada9485f003c731b7fad08b873214e0'); $expectedCategory1->setActive(true); $expectedCategory1->setHidden(true); $expectedCategory1->setLeft(4); $expectedCategory1->setRight(5); $expectedCategory1->setParentId('fad2d80baf7aca6ac54e819e066f24aa'); $expectedCategory1->setRootId('30e44ab83fdee7564.23264141'); $expectedCategory1->setSort(3010101); $expectedCategory1->setTitle('BestCategory'); $expectedCategory1->setDescription('Description 1'); $attribute = new AttributeObject(); $attribute->setPos(9999); $attribute->setTitle('testAttribute'); $expectedCategory1->setAttributes([$attribute]); $url = new UrlNested(); $url->setUrl('Test/Category/1'); $expectedCategory1->setUrls(new \ArrayIterator([$url])); $expectedCategory1->setExpiredUrls([]); $expectedCategory2 = new CategoryDocument(); $expectedCategory2->setId('0f41a4463b227c437f6e6bf57b1697c4'); $expectedCategory2->setActive(false); $expectedCategory2->setHidden(false); $expectedCategory2->setLeft(6); $expectedCategory2->setRight(7); $expectedCategory2->setParentId('fada9485f003c731b7fad08b873214e0'); $expectedCategory2->setRootId('943a9ba3050e78b443c16e043ae60ef3'); $expectedCategory2->setSort(103); $expectedCategory2->setTitle('Trapeze'); $expectedCategory2->setDescription('Description 2'); $expectedCategory2->setAttributes([]); $url = new UrlNested(); $url->setUrl('Test/Category/2'); $expectedCategory2->setUrls(new \ArrayIterator([$url])); $expectedCategory2->setExpiredUrls([]); $expectedCategories = [$expectedCategory1, $expectedCategory2]; /** @var Category[] $categoryItems */ $categoryItems = $this->getTestElements(['fada9485f003c731b7fad08b873214e0', '0f41a4463b227c437f6e6bf57b1697c4'], 'ONGROXIDConnectorBundleTest:Category'); $this->assertCount(2, $categoryItems); // Test if we have the correct attribute. /** @var CategoryToAttribute[] $categoryToAttribute */ $categoryToAttribute = $categoryItems[0]->getAttributes(); $this->assertEquals($attribute->getTitle(), $categoryToAttribute[0]->getAttribute()->getTitle()); $seoFinder = new SeoFinder(); $seoFinder->setEntityManager($this->getEntityManager()); $seoFinder->setShopId(0); $seoFinder->setRepository('ONGROXIDConnectorBundleTest:Seo'); $modifier = new CategoryModifier(new AttributesToDocumentsService()); $modifier->setSeoFinderService($seoFinder); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); foreach ($expectedCategories as $key => $expectedCategory) { $actualCategory = new CategoryDocument(); $modifier->modify(new ImportItem($categoryItems[$key], $actualCategory), $event); $this->assertEquals($expectedCategory, $actualCategory); } }
/** * 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); } }
/** * Extract content seo urls. * * @param Content $content * @param ContentDocument $document */ private function extractUrls(Content $content, $document) { $urls = []; $seoUrls = $this->getSeoFinderService()->getEntitySeo($content, $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 modification. */ public function testModify() { $expectedContent1 = new ContentDocument(); $expectedContent1->setId('8709e45f31a86909e9f999222e80b1d0'); $expectedContent1->setContent('CONTENT ONE'); $expectedContent1->setTitle('TITLE OF CONTENT ONE'); $expectedContent1->setFolder('CMSFOLDER_STANDARD'); $expectedContent1->setSlug('oxstdfooter'); $expectedContent1->setSnippet(true); $expectedContent1->setType(2); $expectedContent1->setActive(false); $expectedContent1->setPosition('position1'); $url = new UrlNested(); $url->setUrl('Test/Content/1'); $expectedContent1->setUrls(new \ArrayIterator([$url])); $expectedContent1->setExpiredUrls([]); $expectedContent2 = new ContentDocument(); $expectedContent2->setId('ad542e49bff479009.64538090'); $expectedContent2->setContent('<div>Content two</div>'); $expectedContent2->setTitle('Title of content two'); $expectedContent2->setFolder('CMSFOLDER_EMAILS'); $expectedContent2->setSlug('oxadminorderemail'); $expectedContent2->setSnippet(false); $expectedContent2->setType(1); $expectedContent2->setActive(true); $expectedContent2->setPosition('position2'); $url = new UrlNested(); $url->setUrl('Test/Content/2'); $expectedContent2->setUrls(new \ArrayIterator([$url])); $expectedContent2->setExpiredUrls([]); $expectedEntities = [$expectedContent1, $expectedContent2]; $contentItems = $this->getTestElements(['8709e45f31a86909e9f999222e80b1d0', 'ad542e49bff479009.64538090'], 'ONGROXIDConnectorBundleTest:Content'); $this->assertCount(2, $contentItems); $seoFinder = new SeoFinder(); $seoFinder->setEntityManager($this->getEntityManager()); $seoFinder->setShopId(0); $seoFinder->setRepository('ONGROXIDConnectorBundleTest:Seo'); $modifier = new ContentModifier(); $modifier->setSeoFinderService($seoFinder); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); foreach ($expectedEntities as $key => $expectedContent) { $actualContent = new ContentDocument(); $modifier->modify(new ImportItem($contentItems[$key], $actualContent), $event); $this->assertEquals($expectedContent, $actualContent); } }
/** * Test for modify(). */ public function testModify() { /** @var Category $root */ $root = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category'); $root->setId('testIdRoot'); /** @var Category $category */ $category = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category'); // Attribute to be added to Category. $attribute = new Attribute(); $attribute->setId(123); $attribute->setPos(1); $attribute->setTitle('testAttributeTitle'); $catToAttr = new CategoryToAttribute(); $catToAttr->setId(321); $catToAttr->setSort(1); $catToAttr->setCategory($category); $catToAttr->setAttribute($attribute); $category->setId('testId')->setActive(true)->setHidden(false)->setTitle('testTitle')->setDesc('testDescription')->setLongDesc('testLongDescription')->setSort(3)->setRoot($root)->setRight(501)->setLeft(102)->addAttribute($catToAttr); /** @var CategoryDocument $expectedDocument */ $expectedDocument = new CategoryDocument(); $expectedDocument->setId('testId'); $expectedDocument->setActive(true); $expectedDocument->setHidden(false); $expectedDocument->setTitle('testTitle'); $expectedDocument->setDescription('testDescription'); $expectedDocument->setLongDescription('testLongDescription'); $expectedDocument->setSort(3); $expectedDocument->setRootId('testIdRoot'); $expectedDocument->setParentId('oxrootid'); $expectedDocument->setLeft(102); $expectedDocument->setRight(501); $url = new UrlNested(); $url->setUrl('test'); $expectedDocument->setUrls(new \ArrayIterator([$url])); $expectedDocument->setExpiredUrls([]); $attrObj = new AttributeObject(); $attrObj->setPos(1); $attrObj->setTitle('testAttributeTitle'); $expectedDocument->setAttributes([$attrObj]); $document = new CategoryDocument(); /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false); $this->modifier->modify(new ImportItem($category, $document), $event); $this->assertEquals($expectedDocument, $document); }
/** * Extract category seo urls. * * @param Category $category * @param CategoryDocument $document */ private function extractUrls(Category $category, $document) { $urls = []; $seoUrls = $category->getSeoUrls(); if (count($seoUrls) > 0) { foreach ($seoUrls as $seo) { if ($seo->getLang() === $this->languageId) { /** @var Seo $seo */ $urlObject = new UrlNested(); $urlObject->setUrl($seo->getSeoUrl()); $urls[] = $urlObject; } } } $document->setUrls(new \ArrayIterator($urls)); $document->setExpiredUrls([]); }
/** * 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()); $url = new UrlNested(); $url->setUrl('test'); $expectedDocument->setUrls(new \ArrayIterator([$url])); $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); }