public function ViewsHandlerManyToOneTest::testTermIdExposedGroupedOptions in Views (for Drupal 7) 7.3
Tests exposed filter on term ID with grouped options.
File
- tests/
handlers/ views_handler_manytoone.test, line 453
Class
- ViewsHandlerManyToOneTest
- Tests the many to one helper handler class.
Code
public function testTermIdExposedGroupedOptions() {
// 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.');
// 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 option 1, 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.');
// Default option: Any.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
$this
->assertEqual($result_count, 3, 'Default option: View has three results.');
$nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
$result1 = $nid === (int) $this->nodes[0]->nid;
$nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0;
$result2 = $nid === (int) $this->nodes[1]->nid;
$nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0;
$result3 = $nid === (int) $this->nodes[2]->nid;
$this
->assertTrue($result1 && $result2 && $result3, 'Default option: View result has correct node ID.');
// Option 1: Is none of 2.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$view
->set_exposed_input(array(
'field_tags_tid' => '1',
));
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
$this
->assertEqual($result_count, 1, 'Option 1: View has one result.');
$nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
$this
->assertIdentical($nid, (int) $this->nodes[1]->nid, 'Option 1: View result has correct node ID.');
// Option 2: Is none of 1 or 2.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$view
->set_exposed_input(array(
'field_tags_tid' => '2',
));
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 1;
$this
->assertEqual($result_count, 0, 'Option 2: View has empty result.');
// Option 3: Is one of 1.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$view
->set_exposed_input(array(
'field_tags_tid' => '3',
));
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
$this
->assertEqual($result_count, 2, 'Option 3: 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, 'Option 3: View result has correct node ID.');
// Option 4: Is one of 1 or 2.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$view
->set_exposed_input(array(
'field_tags_tid' => '4',
));
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
$nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
$result1 = $nid === (int) $this->nodes[0]->nid;
$nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0;
$result2 = $nid === (int) $this->nodes[1]->nid;
$nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0;
$result3 = $nid === (int) $this->nodes[2]->nid;
$nid = isset($view->result[3]->nid) ? (int) $view->result[3]->nid : 0;
$result4 = $nid === (int) $this->nodes[2]->nid;
$this
->assertTrue($result1 && $result2 && $result3 && $result4, 'Option 4: View result has correct node ID.');
$this
->verbose($view->result);
$this
->assertEqual($result_count, 4, 'Option 4: View has four results.');
/* @todo: Fix and uncomment in issue #3045168.
* // Option 5: Is all of 1 and 2.
* $view = $this->getTermIdExposedGroupedOptionsTestView();
* $view->set_exposed_input(array(
* 'field_tags_tid' => '5',
* ));
* $this->executeView($view);
*
* // Assert correct result set.
* $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
* $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
* $this->assertIdentical($nid, (int) $this->nodes[2]->nid, 'Option 5: View result has correct node ID.');
* $this->assertIdentical($result_count, 1, 'Option 5: View has one result.');
*/
// Option 6: Is empty.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$view
->set_exposed_input(array(
'field_tags_tid' => '6',
));
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 1;
$this
->assertIdentical($result_count, 0, 'Option 6: View has empty result.');
// Option 7: Is not empty.
$view = $this
->getTermIdExposedGroupedOptionsTestView();
$view
->set_exposed_input(array(
'field_tags_tid' => '7',
));
$this
->executeView($view);
// Assert correct result set.
$result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
$nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
$result1 = $nid === (int) $this->nodes[0]->nid;
$nid = isset($view->result[1]->nid) ? (int) $view->result[1]->nid : 0;
$result2 = $nid === (int) $this->nodes[1]->nid;
$nid = isset($view->result[2]->nid) ? (int) $view->result[2]->nid : 0;
$result3 = $nid === (int) $this->nodes[2]->nid;
$nid = isset($view->result[3]->nid) ? (int) $view->result[3]->nid : 0;
$result4 = $nid === (int) $this->nodes[2]->nid;
$this
->assertTrue($result1 && $result2 && $result3 && $result4, 'Option 7: View result has correct node ID.');
$this
->verbose($view->result);
$this
->assertIdentical($result_count, 4, 'Option 7: View has four results.');
}