/**
  * 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);
     }
 }
Пример #2
0
 /**
  * Retrieves manufacturer title.
  *
  * @param Article         $entity
  * @param ProductDocument $document
  */
 protected function extractManufacturer(Article $entity, ProductDocument $document)
 {
     try {
         $document->setManufacturer($entity->getManufacturer()->getTitle());
     } catch (EntityNotFoundException $exception) {
         // No manufacturer. Just ignore.
     }
 }
 /**
  * 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());
     $expectedDocument->setUrls(new \ArrayIterator());
     $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);
 }