/** * Test CategoryService#getItemCategories */ public function testGetItemCategories() { $fooClass = new RdfClass('foo'); $eligibleProp1 = $this->prophesize('\\core_kernel_classes_Property'); $eligibleProp1->getWidget()->willReturn(new RdfResource(CategoryService::$supportedWidgetUris[0])); $eligibleProp1->getUri()->willReturn('p1'); $eligibleProp2 = $this->prophesize('\\core_kernel_classes_Property'); $eligibleProp2->getWidget()->willReturn(new RdfResource(CategoryService::$supportedWidgetUris[2])); $eligibleProp2->getUri()->willReturn('p2'); $p2Value = $this->prophesize('\\core_kernel_classes_Resource'); $p2Value->getLabel()->willReturn('Yeah Moo'); $item = $this->prophesize('\\core_kernel_classes_Resource'); $item->getPropertiesValues(Argument::any())->willReturn(['p1' => ['Foo', 'Yo _Bar '], 'p2' => [$p2Value->reveal()]]); $item->getTypes()->willReturn([$fooClass]); $itemService = $this->prophesize('\\taoItems_models_classes_ItemsService'); $itemService->getClazzProperties($fooClass, Argument::any())->willReturn(['p1' => $eligibleProp1->reveal(), 'p2' => $eligibleProp2->reveal()]); $categoryService = new CategoryService(); $categoryService->setItemService($itemService->reveal()); $categories = $categoryService->getItemCategories($item->reveal()); $this->assertEquals(3, count($categories), "We have 3 categories"); $this->assertEquals('foo', $categories[0], "The category matches"); $this->assertEquals('yo-bar', $categories[1], "The category matches"); $this->assertEquals('yeah-moo', $categories[2], "The category matches"); }