function ViewsHandlerManyToOneTest::testGroupedOneOf
Tests duplicate grouped "one of" filters on taxonomy term field.
File
-
tests/
handlers/ views_handler_manytoone.test, line 289
Class
- ViewsHandlerManyToOneTest
- Tests the many to one helper handler class.
Code
public function testGroupedOneOf() {
$view = $this->getGroupedOneOfTestView();
$this->executeView($view);
// Assert that nodes have been created and have expected field values.
$value = field_get_items('node', $this->nodes[0], 'field_tags', LANGUAGE_NONE);
$value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0;
$this->assertIdentical($value, 2, 'First node has been created and tags field references term 2.');
$value = field_get_items('node', $this->nodes[1], 'field_tags', LANGUAGE_NONE);
$value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0;
$this->assertIdentical($value, 1, 'Second node has been created and tags field references term 1.');
$value = field_get_items('node', $this->nodes[2], 'field_tags', LANGUAGE_NONE);
$value = !empty($value[0]['tid']) && !empty($value[1]['tid']);
$this->assertTrue($value, 'Third node has been created and tags field references both terms 1 and 2.');
// Assert that user has been created and has expected field values.
$value = field_get_items('user', $this->accounts[0], 'field_tags', LANGUAGE_NONE);
$value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0;
$this->assertIdentical($value, 1, 'User has been created and tags field references term 1.');
// Assert that node ID with empty field value matches user ID so that the
// node would be excluded from the result, if the joins are missing extras.
$this->assertIdentical((int) $this->accounts[0]->uid, (int) $this->nodes[1]->nid, 'Node ID of second node matches UID of first user.');
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
$this->assertEqual($result_count, 2, 'View has two results.');
$nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
$result1 = $nid === (int) $this->nodes[1]->nid;
$nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0;
$result2 = $nid === (int) $this->nodes[2]->nid;
$this->assertTrue($result1 && $result2, 'View result has correct node IDs.');
}