/** * Set up services for tests. */ protected function setUp() { $this->attrToDocService = new AttributesToDocumentsService(); $this->modifier = new ProductModifier($this->attrToDocService); /** @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->any())->method('getEntitySeo')->willReturn(new \ArrayIterator([$seo])); $this->modifier->setSeoFinderService($seoFinder); }
/** * 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); } }
/** * 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'); }