/** * Test method for categories. */ public function testTransformCategoryToDocument() { $attributes = new ArrayCollection(); $expected = []; /** @var Category|MockObject $mockCategory */ $mockCategory = $this->getMockForAbstractClass('\\ONGR\\OXIDConnectorBundle\\Entity\\Category'); for ($i = 1; $i <= 10; $i++) { $catToAttr = new CategoryToAttribute(); $catToAttr->setId($i); $catToAttr->setSort($i); $catToAttr->setCategory($mockCategory); $attr = new Attribute(); $attr->setPos($i); $attr->setTitle('Some title ' . $i); $catToAttr->setAttribute($attr); $attributes->add($catToAttr); $expected[] = $catToAttr; } $result = $this->service->transform($attributes); foreach ($result as $idx => $actual) { $this->assertInstanceOf('\\ONGR\\OXIDConnectorBundle\\Document\\AttributeObject', $actual); $this->assertEquals('Some title ' . ($idx + 1), $actual->getTitle()); $this->assertEquals($idx + 1, $actual->getPos()); } }
/** * 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); }