You are here

public function ViewsHandlerManyToOneTest::testGroupedNoneOf in Views (for Drupal 7) 7.3

Tests duplicate grouped "none of" filters on boolean field.

File

tests/handlers/views_handler_manytoone.test, line 252

Class

ViewsHandlerManyToOneTest
Tests the many to one helper handler class.

Code

public function testGroupedNoneOf() {
  $view = $this
    ->getGroupedNoneOfTestView();
  $this
    ->executeView($view);

  // Assert that nodes have been created and have expected field values.
  $value = field_get_items('node', $this->nodes[0], $this->fields[0]['field_name'], LANGUAGE_NONE);
  $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0;
  $this
    ->assertIdentical($value, 1, 'First node has been created and boolean field is checked.');
  $value = field_get_items('node', $this->nodes[1], $this->fields[0]['field_name'], LANGUAGE_NONE);
  $this
    ->assertFalse($value, 'Second node has been created and boolean field is not checked.');
  $value = field_get_items('node', $this->nodes[2], $this->fields[0]['field_name'], LANGUAGE_NONE);
  $this
    ->assertFalse($value, 'Third node has been created and boolean field is not checked.');

  // Assert that user has been created and has expected field values.
  $value = field_get_items('user', $this->accounts[0], $this->fields[0]['field_name'], LANGUAGE_NONE);
  $value = isset($value[0]['value']) ? (int) $value[0]['value'] : 0;
  $this
    ->assertIdentical($value, 1, 'User has been created and boolean field is checked.');

  // 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.');
}