/**
  * 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);
     }
 }
 /**
  * Worker method.
  *
  * @param array $attributes
  *
  * @return AttributeObject[]
  */
 public function transform($attributes)
 {
     $result = [];
     if (!$attributes instanceof \Traversable) {
         return $result;
     }
     /** @var ObjectToAttribute|CategoryToAttribute $attr */
     foreach ($attributes as $attr) {
         /** @var Attribute $attrEntity */
         $attrEntity = $attr->getAttribute();
         $attrObj = new AttributeObject();
         $attrObj->setTitle($attrEntity->getTitle());
         $attrObj->setPos($attrEntity->getPos());
         $result[] = $attrObj;
     }
     return $result;
 }
 /**
  * Test for modify().
  */
 public function testModify()
 {
     /** @var Category $root */
     $root = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category');
     $root->setId('testIdRoot');
     /** @var Category $category */
     $category = $this->getMockForAbstractClass('ONGR\\OXIDConnectorBundle\\Entity\\Category');
     // Attribute to be added to Category.
     $attribute = new Attribute();
     $attribute->setId(123);
     $attribute->setPos(1);
     $attribute->setTitle('testAttributeTitle');
     $catToAttr = new CategoryToAttribute();
     $catToAttr->setId(321);
     $catToAttr->setSort(1);
     $catToAttr->setCategory($category);
     $catToAttr->setAttribute($attribute);
     $category->setId('testId')->setActive(true)->setHidden(false)->setTitle('testTitle')->setDesc('testDescription')->setLongDesc('testLongDescription')->setSort(3)->setRoot($root)->setRight(501)->setLeft(102)->addAttribute($catToAttr);
     /** @var CategoryDocument $expectedDocument */
     $expectedDocument = new CategoryDocument();
     $expectedDocument->setId('testId');
     $expectedDocument->setActive(true);
     $expectedDocument->setHidden(false);
     $expectedDocument->setTitle('testTitle');
     $expectedDocument->setDescription('testDescription');
     $expectedDocument->setLongDescription('testLongDescription');
     $expectedDocument->setSort(3);
     $expectedDocument->setRootId('testIdRoot');
     $expectedDocument->setParentId('oxrootid');
     $expectedDocument->setLeft(102);
     $expectedDocument->setRight(501);
     $expectedDocument->setUrls(new \ArrayIterator());
     $expectedDocument->setExpiredUrls([]);
     $attrObj = new AttributeObject();
     $attrObj->setPos(1);
     $attrObj->setTitle('testAttributeTitle');
     $expectedDocument->setAttributes([$attrObj]);
     $document = new CategoryDocument();
     /** @var ItemPipelineEvent|\PHPUnit_Framework_MockObject_MockObject $event */
     $event = $this->getMock('ONGR\\ConnectionsBundle\\Pipeline\\Event\\ItemPipelineEvent', [], [], '', false);
     $this->modifier->modify(new ImportItem($category, $document), $event);
     $this->assertEquals($expectedDocument, $document);
 }
 /**
  * @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];
 }