/**
  * Test product modifier listener.
  */
 public function testProductModifierListener()
 {
     $articleExtension = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\ArticleExtension');
     $articleExtension->expects($this->once())->method('getLongDesc')->will($this->returnValue('testLongDescription'));
     $vendor = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Vendor');
     $vendor->expects($this->once())->method('getTitle')->will($this->returnValue('testVendorTitle'));
     $manufacturer = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Manufacturer');
     $manufacturer->expects($this->once())->method('getTitle')->will($this->returnValue('testManufacturerTitle'));
     $objectToCategories = [];
     $objectToCategories[0] = new ObjectToCategory();
     $category1 = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Category');
     $category1->expects($this->once())->method('isActive')->will($this->returnValue(true));
     $category1->expects($this->once())->method('getId')->will($this->returnValue(123));
     $objectToCategories[0]->setCategory($category1);
     // The following category should be skipped because of isActive=false.
     $objectToCategories[1] = new ObjectToCategory();
     $category2 = $this->getMock('\\ONGR\\OXIDConnectorBundle\\Tests\\Functional\\Entity\\Category');
     $category2->expects($this->once())->method('isActive')->will($this->returnValue(false));
     $category2->expects($this->never())->method('getId');
     $objectToCategories[1]->setCategory($category2);
     $this->mockExpectsMethods($this->prodEntity, [['getId', 1, 123], ['isActive', 1, true], ['getArtNum', 1, 'testArtNum'], ['getTitle', 1, 'testTitle'], ['getShortDesc', 1, 'testShortDescription'], ['getPrice', 1, 20.2], ['getTPrice', 1, 25.0], ['getParent', 1, null], ['getStock', 1, 50], ['getAttributes', 1, [1, 2, 3]], ['getExtension', 1, $articleExtension], ['getVendor', 1, $vendor], ['getManufacturer', 1, $manufacturer], ['getCategories', 1, $objectToCategories]]);
     $this->mockExpectsMethods($this->prodDocument, [['setId', 1, null, 123], ['setActive', 1, null, true], ['setSku', 1, null, 'testArtNum'], ['setTitle', 1, null, 'testTitle'], ['setDescription', 1, null, 'testShortDescription'], ['setPrice', 1, null, 20.2], ['setOldPrice', 1, null, 25.0], ['setStock', 1, null, 50], ['setAttributes', 1, null, [11, 22, 33]], ['setLongDescription', 1, null, 'testLongDescription'], ['setVendor', 1, null, 'testVendorTitle'], ['setManufacturer', 1, null, 'testManufacturerTitle'], ['setCategories', 1, null, [123]]]);
     $this->attrToDocService->expects($this->once())->method('transform')->with([1, 2, 3])->will($this->returnValue([11, 22, 33]));
     /** @var ImportItem|MockObject $importItem */
     $importItem = $this->getMockBuilder('ONGR\\ConnectionsBundle\\Pipeline\\Item\\ImportItem')->disableOriginalConstructor()->getMock();
     $importItem->expects($this->once())->method('getEntity')->will($this->returnValue($this->prodEntity));
     $importItem->expects($this->once())->method('getDocument')->will($this->returnValue($this->prodDocument));
     /** @var ItemPipelineEvent|MockObject $itemPipelineEvent */
     $itemPipelineEvent = $this->getMockBuilder('\\ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent')->disableOriginalConstructor()->getMock();
     $itemPipelineEvent->expects($this->once())->method('getItem')->will($this->returnValue($importItem));
     $this->prodModifierListener->onModify($itemPipelineEvent);
 }
 /**
  * Transforms Category entity into ES document.
  *
  * @param Category         $category
  * @param CategoryDocument $document
  */
 public function transformCategoryToDocument(Category $category, CategoryDocument $document)
 {
     $document->setId($category->getId());
     $document->setActive($category->isActive());
     $document->setHidden($category->isHidden());
     $document->setLeft($category->getLeft());
     $document->setRight($category->getRight());
     $document->setRootId($category->getRoot()->getId());
     $document->setSort($category->getSort());
     $document->setTitle($category->getTitle());
     $document->setDescription($category->getDesc());
     $document->setLongDescription($category->getLongDesc());
     $document->setAttributes($this->attrToDocService->transform($category->getAttributes()));
     $this->extractUrls($category, $document);
     $parent = $category->getParent();
     $parentId = $parent ? $parent->getId() : null;
     if (empty($parentId) === false) {
         $document->setParentId($parentId);
     } else {
         $document->setParentId('oxrootid');
     }
 }
 /**
  * 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 transform with non-traversable entity.
  */
 public function testTransformNonTraversable()
 {
     $entity = new Attribute();
     $this->assertEquals([], $this->service->transform($entity));
 }