1 views_handler_manytoone.test public ViewsHandlerManyToOneTest::testReducedExposedGroupedOptions()

Tests exposed filter with "Reduce duplicates." and grouped options.

File

core/modules/views/tests/handlers/views_handler_manytoone.test, line 245
Definition of ViewsHandlerManyToOneTest.

Class

ViewsHandlerManyToOneTest
Tests the many to one helper handler class.

Code

public function testReducedExposedGroupedOptions() {
  // Assert that nodes have been created and have expected field values.
  $value = field_get_items('node', $this->nodes[0], 'field_list', LANGUAGE_NONE);
  $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0;
  $this->assertIdentical($value, 1, 'First node has been created and list field has value 1.');

  $value = field_get_items('node', $this->nodes[1], 'field_list', LANGUAGE_NONE);
  $value = isset($value[0]['tid']) ? (int) $value[0]['tid'] : 0;
  $this->assertFalse($value, 'Second node has been created and list is empty.');

  // Assert that user has been created and has expected field values.
  $last_account = end($this->accounts);
  $value = field_get_items('user', $last_account, 'field_list', LANGUAGE_NONE);
  $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0;
  $this->assertIdentical($value, 1, 'User has been created and list field has value 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) $last_account->uid, (int) $this->nodes[1]->nid, 'Node ID of our second node matches UID of the latest user.');

  /* Default option: Any. */
  $view = $this->getReducedExposedGroupedOptionsTestView();
  $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, 'Default option: View has two results.');

  /* Option 1: Is none of 1 or 2. */
  $view = $this->getReducedExposedGroupedOptionsTestView();
  $view->set_exposed_input(array(
    'field_list_value' => '1',
  ));
  $this->executeView($view);

  // @todo get this test passing.
  // Assert correct result set.
  // $result_count = isset($view->result) && is_array($view->result) ? count($view->result) : 0;
  // debug('should be 1:' . $result_count);
  // $this->assertEqual($result_count, 1, 'Option 1: View has one result.');
  // $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
  // debug('nid should be ' . $this->nodes[1]->nid . ': ' . $nid);
  // $this->assertIdentical($nid, (int) $this->nodes[1]->nid, 'Option 1: View result has correct node id.');

  /* Option 2: Is one of 1. */
  $view = $this->getReducedExposedGroupedOptionsTestView();
  $view->set_exposed_input(array(
    'field_list_value' => '2',
  ));
  $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 2: View has one result.');
  $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
  $this->assertIdentical($nid, (int) $this->nodes[0]->nid, 'Option 2: View result has correct node id.');

  // @todo: Add test for Option 3: Is one of 1 or 2.
  // @todo: Add test for Option 4: Is all of 1 and 2.

  /* Option 5: Is empty. */
  $view = $this->getReducedExposedGroupedOptionsTestView();
  $view->set_exposed_input(array(
    'field_list_value' => '5',
  ));
  $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 5: 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 5: View result has correct node id.');

  /* Option 6: Is not empty. */
  $view = $this->getReducedExposedGroupedOptionsTestView();
  $view->set_exposed_input(array(
    'field_list_value' => '6',
  ));
  $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 6: View has one result.');
  $nid = isset($view->result[0]->nid) ? (int) $view->result[0]->nid : 0;
  $this->assertIdentical($nid, (int) $this->nodes[0]->nid, 'Option 6: View result has correct node id.');
}