/** * 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); } }
/** * Tests if correct urls are collected. * * @param string $repository * @param string[] $expectedUrls * @param int|null $language * * @dataProvider urlsTestProvider */ public function testUrls($repository, $expectedUrls, $language) { $repository = $this->getEntityManager()->getRepository($repository); /** @var Category|Article|Content $entity */ foreach ($repository->findAll() as $entity) { $seos = $this->seoFinder->getEntitySeo($entity, $language); $urls = []; foreach ($seos as $seo) { $urls[] = $seo->getSeoUrl(); } sort($urls); sort($expectedUrls[$entity->getId()]); $this->assertSame($expectedUrls[$entity->getId()], $urls); } }
/** * 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); } }
/** * Tests getting manager before it is set. */ public function testException2() { $instance = new SeoFinder(); $this->setExpectedException('LogicException', 'setEntityManager must be called before getEntityManager'); $instance->getEntityManager(); }