Tests the views_get_handler method.
public function testViewsGetHandler() {
$types = array(
'field',
'area',
'filter',
);
foreach ($types as $type) {
$item = array(
'table' => $this
->randomName(),
'field' => $this
->randomName(),
);
$handler = views_get_handler($item, $type);
$this
->assertEqual('Drupal\\views\\Plugin\\views\\' . $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_data' => array(
'id',
'name',
),
);
foreach ($test_tables as $table => $fields) {
foreach ($fields as $field) {
$data = $views_data[$table][$field];
$item = array(
'table' => $table,
'field' => $field,
);
foreach ($data as $id => $field_data) {
if (!in_array($id, array(
'title',
'help',
))) {
$handler = views_get_handler($item, $id);
$this
->assertInstanceHandler($handler, $table, $field, $id);
}
}
}
}
// Test the override handler feature.
$item = array(
'table' => 'views_test_data',
'field' => 'job',
);
$handler = views_get_handler($item, 'filter', 'standard');
$this
->assertTrue($handler instanceof Standard);
// @todo Reinstate these tests when the debug() in views_get_handler() is
// restored.
return;
// Test non-existent tables/fields.
set_error_handler(array(
$this,
'customErrorHandler',
));
$item = array(
'table' => 'views_test_data',
'field' => 'field_invalid',
);
views_get_handler($item, 'field');
$this
->assertTrue(strpos($this->lastErrorMessage, format_string("Missing handler: @table @field @type", array(
'@table' => 'views_test_data',
'@field' => 'field_invalid',
'@type' => 'field',
))) !== FALSE, 'An invalid field name throws a debug message.');
unset($this->lastErrorMessage);
$item = array(
'table' => 'table_invalid',
'field' => 'id',
);
views_get_handler($item, 'filter');
$this
->assertEqual(strpos($this->lastErrorMessage, format_string("Missing handler: @table @field @type", array(
'@table' => 'table_invalid',
'@field' => 'id',
'@type' => 'filter',
))) !== FALSE, 'An invalid table name throws a debug message.');
unset($this->lastErrorMessage);
$item = array(
'table' => 'table_invalid',
'field' => 'id',
'optional' => FALSE,
);
views_get_handler($item, 'filter');
$this
->assertEqual(strpos($this->lastErrorMessage, format_string("Missing handler: @table @field @type", array(
'@table' => 'table_invalid',
'@field' => 'id',
'@type' => 'filter',
))) !== FALSE, 'An invalid table name throws a debug message.');
unset($this->lastErrorMessage);
$item = array(
'table' => 'table_invalid',
'field' => 'id',
'optional' => TRUE,
);
views_get_handler($item, 'filter');
$this
->assertFalse($this->lastErrorMessage, "An optional handler does not throw a debug message.");
unset($this->lastErrorMessage);
restore_error_handler();
}