/** * Set up services for tests. */ protected function setUp() { $this->attributesToDocumentsService = new AttributesToDocumentsService(); $this->modifier = new CategoryModifier($this->attributesToDocumentsService); /** @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])); $this->modifier->setSeoFinderService($seoFinder); }
/** * 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); } }
/** * Set up services for tests. */ protected function setUp() { /** @var AttributesToDocumentsService|MockObject attrToDocService */ $this->attrToDocService = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Service\\AttributesToDocumentsService'); // Mocks for CategoryModifier. /** @var Seo|\PHPUnit_Framework_MockObject_MockObject $seo */ $seo = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Seo'); $seo->setSeoUrl('test/category'); /** @var SeoFinder|\PHPUnit_Framework_MockObject_MockObject $seoFinder */ $seoFinder = $this->getMockBuilder('ONGR\\OXIDConnectorBundle\\Service\\SeoFinder')->disableOriginalConstructor()->getMock(); $seoFinder->expects($this->any())->method('getEntitySeo')->willReturn(new \ArrayIterator([$seo])); $this->catModifierListener = new CategoryModifier($this->attrToDocService); $this->catModifierListener->setSeoFinderService($seoFinder); $this->catEntity = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Category'); $this->catDocument = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Document\\CategoryDocument'); // Mocks for ContentModifier. /** @var Seo|\PHPUnit_Framework_MockObject_MockObject $seo */ $seo = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Seo'); $seo->setSeoUrl('test/content'); /** @var SeoFinder|\PHPUnit_Framework_MockObject_MockObject $seoFinder */ $seoFinder = $this->getMockBuilder('ONGR\\OXIDConnectorBundle\\Service\\SeoFinder')->disableOriginalConstructor()->getMock(); $seoFinder->expects($this->any())->method('getEntitySeo')->willReturn(new \ArrayIterator([$seo])); $this->contModifierListener = new ContentModifier(); $this->contModifierListener->setSeoFinderService($seoFinder); $this->contEntity = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Content'); $this->contDocument = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Document\\ContentDocument'); // Mocks for ProductModifier. /** @var Seo|\PHPUnit_Framework_MockObject_MockObject $seo */ $seo = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Seo'); $seo->setSeoUrl('test/product'); /** @var SeoFinder|\PHPUnit_Framework_MockObject_MockObject $seoFinder */ $seoFinder = $this->getMockBuilder('ONGR\\OXIDConnectorBundle\\Service\\SeoFinder')->disableOriginalConstructor()->getMock(); $seoFinder->expects($this->any())->method('getEntitySeo')->willReturn(new \ArrayIterator([$seo])); $this->prodModifierListener = new ProductModifier($this->attrToDocService); $this->prodModifierListener->setSeoFinderService($seoFinder); $this->prodEntity = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Article'); $this->prodDocument = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Document\\ProductDocument'); }