/** * 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); $url = new UrlNested(); $url->setUrl('test'); $expectedDocument->setUrls(new \ArrayIterator([$url])); $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); }
/** * 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'); } }