コード例 #1
0
 /**
  * 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);
     }
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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');
     }
 }