/** * 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); } }
/** * @return VariantObject[] */ private function getExpectedVariants() { $variant1 = new VariantObject(); $attObj = new AttributeObject(); $attObj->setPos(1); $attObj->setTitle('testAttributeTitle'); $variant1->setId('id1235')->setActive(true)->setOldPrice(44.21)->setStock(5)->setAttributes([$attObj])->setTitle('Any title')->setDescription('Short description')->setLongDescription('Long description')->setSku('abc123')->setPrice(13.34); $variant2 = new VariantObject(); $attObj = new AttributeObject(); $attObj->setPos(1); $attObj->setTitle('testAttributeTitle2'); $variant2->setId('id1234')->setActive(false)->setOldPrice(44.21)->setStock(6)->setAttributes([$attObj])->setTitle('Any title2')->setDescription('Short description2')->setLongDescription('Long description2')->setSku('abc1234')->setPrice(13.34); return [$variant1, $variant2]; }
/** * Adds product variant to document. * * @param ProductDocument $document * @param Article $variant */ protected function modifyVariant($document, $variant) { $variantObject = new VariantObject(); $variantObject->setId($variant->getId()); $variantObject->setActive($variant->isActive()); $variantObject->setSku($variant->getArtNum()); $variantObject->setTitle($variant->getTitle()); $variantObject->setDescription($variant->getShortDesc()); $variantObject->setPrice($variant->getPrice()); $variantObject->setOldPrice($variant->getTPrice()); $variantObject->setStock($variant->getStock()); $variantObject->setAttributes($this->attrToDocService->transform($variant->getAttributes())); $this->extractExtensionData($variant, $variantObject); $document->addVariant($variantObject); }
/** * Test getters and setters. */ public function testGettersAndSetters() { $variant = new VariantObject(); $attribute = new AttributeObject(); $variant->setId('id')->setActive(false)->setPrice(1.0)->setAttributes([$attribute])->setDescription('Description.')->setLongDescription('Long description.')->setOldPrice(2.1)->setSku('sku')->setStock(5)->setTitle('Title'); $this->assertEquals('id', $variant->getId()); $this->assertEquals(false, $variant->isActive()); $this->assertEquals(1.0, $variant->getPrice()); $this->assertSame([$attribute], $variant->getAttributes()); $this->assertEquals('Description.', $variant->getDescription()); $this->assertEquals('Long description.', $variant->getLongDescription()); $this->assertEquals(2.1, $variant->getOldPrice()); $this->assertEquals('sku', $variant->getSku()); $this->assertEquals(5, $variant->getStock()); $this->assertEquals('Title', $variant->getTitle()); }