You are here

function viewsFieldApiDataTest::testViewsData in Views (for Drupal 7) 7.3

Unit testing the views data structure.

We check data structure for both node and node revision tables.

File

tests/field/views_fieldapi.test, line 189
Tests the fieldapi integration of viewsdata.

Class

viewsFieldApiDataTest
Test the produced views_data.

Code

function testViewsData() {
  $data = views_fetch_data();

  // Check the table and the joins of the first field.
  // Attached to node only.
  $field = $this->fields[0];
  $current_table = _field_sql_storage_tablename($field);
  $revision_table = _field_sql_storage_revision_tablename($field);
  $this
    ->assertTrue(isset($data[$current_table]));
  $this
    ->assertTrue(isset($data[$revision_table]));

  // The node field should join against node.
  $this
    ->assertTrue(isset($data[$current_table]['table']['join']['node']));
  $this
    ->assertTrue(isset($data[$revision_table]['table']['join']['node_revision']));
  $expected_join = array(
    'left_field' => 'nid',
    'field' => 'entity_id',
    'extra' => array(
      array(
        'field' => 'entity_type',
        'value' => 'node',
      ),
      array(
        'field' => 'deleted',
        'value' => 0,
        'numeric' => TRUE,
      ),
    ),
  );
  $this
    ->assertEqual($expected_join, $data[$current_table]['table']['join']['node']);
  $expected_join = array(
    'left_field' => 'vid',
    'field' => 'revision_id',
    'extra' => array(
      array(
        'field' => 'entity_type',
        'value' => 'node',
      ),
      array(
        'field' => 'deleted',
        'value' => 0,
        'numeric' => TRUE,
      ),
    ),
  );
  $this
    ->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_revision']);

  // Check the table and the joins of the second field.
  // Attached to both node and user.
  $field_2 = $this->fields[2];
  $current_table_2 = _field_sql_storage_tablename($field_2);
  $revision_table_2 = _field_sql_storage_revision_tablename($field_2);
  $this
    ->assertTrue(isset($data[$current_table_2]));
  $this
    ->assertTrue(isset($data[$revision_table_2]));

  // The second field should join against both node and users.
  $this
    ->assertTrue(isset($data[$current_table_2]['table']['join']['node']));
  $this
    ->assertTrue(isset($data[$revision_table_2]['table']['join']['node_revision']));
  $this
    ->assertTrue(isset($data[$current_table_2]['table']['join']['users']));
  $expected_join = array(
    'left_field' => 'nid',
    'field' => 'entity_id',
    'extra' => array(
      array(
        'field' => 'entity_type',
        'value' => 'node',
      ),
      array(
        'field' => 'deleted',
        'value' => 0,
        'numeric' => TRUE,
      ),
    ),
  );
  $this
    ->assertEqual($expected_join, $data[$current_table_2]['table']['join']['node']);
  $expected_join = array(
    'left_field' => 'vid',
    'field' => 'revision_id',
    'extra' => array(
      array(
        'field' => 'entity_type',
        'value' => 'node',
      ),
      array(
        'field' => 'deleted',
        'value' => 0,
        'numeric' => TRUE,
      ),
    ),
  );
  $this
    ->assertEqual($expected_join, $data[$revision_table_2]['table']['join']['node_revision']);
  $expected_join = array(
    'left_field' => 'uid',
    'field' => 'entity_id',
    'extra' => array(
      array(
        'field' => 'entity_type',
        'value' => 'user',
      ),
      array(
        'field' => 'deleted',
        'value' => 0,
        'numeric' => TRUE,
      ),
    ),
  );
  $this
    ->assertEqual($expected_join, $data[$current_table_2]['table']['join']['users']);

  // @todo Check the fields.
  // @todo Check the arguments.
  // @todo Check the sort criterias.
  // @todo Check the relationships.
}