1.20.x views_module.test ViewsModuleTest::testviews_get_handler()

Tests the views_get_handler method.

File

modules/views/tests/views_module.test, line 100
Definition of ViewsModuleTest.

Class

ViewsModuleTest
Tests basic functions from the Views module.

Code

function testviews_get_handler() {
  $types = array('field', 'area', 'filter');
  foreach ($types as $type) {
    $handler = views_get_handler($this->randomName(), $this->randomName(), $type);
    $this->assertEqual('views_handler_' . $type . '_broken', get_class($handler), t('Make sure that a broken handler of type: @type are created', array('@type' => $type)));
  }

  $views_data = $this->viewsData();
  $test_tables = array('views_test' => array('id', 'name'));
  foreach ($test_tables as $table => $fields) {
    foreach ($fields as $field) {
      $data = $views_data[$table][$field];
      foreach ($data as $id => $field_data) {
        if (!in_array($id, array('title', 'help'))) {
          $handler = views_get_handler($table, $field, $id);
          $this->assertInstanceHandler($handler, $table, $field, $id);
        }
      }
    }
  }

  // Test the automatic conversion feature.

  // Test the automatic table renaming.
  $handler = views_get_handler('views_test_previous', 'id', 'field');
  $this->assertInstanceHandler($handler, 'views_test', 'id', 'field');
  $handler = views_get_handler('views_test_previous', 'id', 'filter');
  $this->assertInstanceHandler($handler, 'views_test', 'id', 'filter');

  // Test the automatic field renaming.
  $handler = views_get_handler('views_test', 'age_previous', 'field');
  $this->assertInstanceHandler($handler, 'views_test', 'age', 'field');
  $handler = views_get_handler('views_test', 'age_previous', 'sort');
  $this->assertInstanceHandler($handler, 'views_test', 'age', 'sort');

  // Test the automatic table and field renaming.
  $handler = views_get_handler('views_test_previous', 'name_previous', 'field');
  $this->assertInstanceHandler($handler, 'views_test', 'name', 'field');
  $handler = views_get_handler('views_test_previous', 'name_previous', 'argument');
  $this->assertInstanceHandler($handler, 'views_test', 'name', 'argument');

  // Test the override handler feature.
  $handler = views_get_handler('views_test', 'job', 'filter', 'views_handler_filter');
  $this->assertEqual('views_handler_filter', get_class($handler));
}