/** * Unit test for eZContentFunctionCollection::fetchKeyword */ public function testFetchKeyword() { $class1Identifier = __FUNCTION__ . '_1'; // First create two content classes with a keyword attribute $class1 = new ezpClass($class1Identifier, $class1Identifier, '<title>'); $class1->add('Title', 'title', 'ezstring'); $class1->add('Keywords', 'keywords', 'ezkeyword'); $class1->store(); $class1ID = $class1->class->attribute('id'); // Create an instance of each of these classes with attributes $object = new ezpObject($class1Identifier, 2); $object->title = __FUNCTION__; $object->keywords = "keyword1, keyword2, keyword3"; $object->publish(); // Fetch keywords for class 1 $keywords = eZContentFunctionCollection::fetchKeyword('k', $class1ID, 0, 20); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(3, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } }
/** * Unit test for eZContentFunctionCollection::fetchKeyword */ public function testFetchKeyword() { $class1Identifier = __FUNCTION__ . '_1'; // First create two content classes with a keyword attribute $class1 = new ezpClass($class1Identifier, $class1Identifier, '<title>'); $class1->add('Title', 'title', 'ezstring'); $class1->add('Keywords', 'keywords', 'ezkeyword'); $class1->store(); $class1ID = $class1->class->attribute('id'); // Create placeholder folders for objects $folder1 = new ezpObject('folder', 2); $folder1->title = __FUNCTION__ . ' A'; $folder1->publish(); $folder2 = new ezpObject('folder', 2); $folder2->title = __FUNCTION__ . ' B'; $folder2->publish(); $folder3 = new ezpObject('folder', $folder1->mainNode->node_id); $folder3->title = __FUNCTION__ . ' A'; $folder3->publish(); // Create an objects to test function $object0 = new ezpObject($class1Identifier, 2); $object0->title = __FUNCTION__ . ' A '; $object0->keywords = "keyword1, keyword2, keyword3"; $object0->publish(); $object1 = new ezpObject($class1Identifier, $folder1->mainNode->node_id); $object1->title = __FUNCTION__ . ' A '; $object1->keywords = "keyword1, keyword2, keyword3"; $object1->publish(); $object2 = new ezpObject($class1Identifier, $folder2->mainNode->node_id); $object2->title = __FUNCTION__ . ' C '; $object2->keywords = "keyword1, keyword2, keyword3"; $object2->publish(); $object3 = new ezpObject($class1Identifier, $folder3->mainNode->node_id); $object3->title = __FUNCTION__ . ' D '; $object3->keywords = "keyword1, keyword2, keyword3"; $object3->publish(); // Fetch keywords for class 1, on all scope $keywords = eZContentFunctionCollection::fetchKeyword('k', $class1ID, 0, 20); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(12, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keyword1 for class 1, not specifying parent node $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(4, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keyword1 for class 1, directly below parentNodeId (rootNode) $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), 2); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(1, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keywords for class 1, directly below parentNodeId (specific folder) $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), $folder1->mainNode->node_id); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(1, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keywords for class 1, from root folder, with depth equal to 2 $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), 2, true, false, 2); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(3, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keywords for class 1, from sepecific node, with depth equal to 2 $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), $folder1->mainNode->node_id, true, false, 2); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(2, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keywords for class 1, from root folder, with depth equal to 0 (unlimited) $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), 2, true, false, 0); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(4, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } // Fetch keywords for class 1, from specific folder, with depth equal to 0 (unlimited) $keywords = eZContentFunctionCollection::fetchKeyword('keyword1', $class1ID, 0, 20, false, array(), $folder1->mainNode->node_id, true, false, 0); $this->assertInternalType('array', $keywords); $this->assertArrayHasKey('result', $keywords); $this->assertInternalType('array', $keywords['result']); $this->assertEquals(2, count($keywords['result'])); foreach ($keywords['result'] as $result) { $this->assertInternalType('array', $result); $this->assertArrayHasKey('keyword', $result); $this->assertArrayHasKey('link_object', $result); $this->assertInstanceOf('eZContentObjectTreeNode', $result['link_object']); } }