public function ModuleTest::testViewsGetHandler in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/src/Tests/ModuleTest.php \Drupal\views\Tests\ModuleTest::testViewsGetHandler()
Tests the views_get_handler method.
See also
File
- core/
modules/ views/ src/ Tests/ ModuleTest.php, line 49 - Contains \Drupal\views\Tests\ModuleTest.
Class
Namespace
Drupal\views\TestsCode
public function testViewsGetHandler() {
$types = array(
'field',
'area',
'filter',
);
foreach ($types as $type) {
$item = array(
'table' => $this
->randomMachineName(),
'field' => $this
->randomMachineName(),
);
$handler = $this->container
->get('plugin.manager.views.' . $type)
->getHandler($item);
$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 = $this->container
->get('plugin.manager.views.' . $id)
->getHandler($item);
$this
->assertInstanceHandler($handler, $table, $field, $id);
}
}
}
}
// Test the override handler feature.
$item = array(
'table' => 'views_test_data',
'field' => 'job',
);
$handler = $this->container
->get('plugin.manager.views.filter')
->getHandler($item, '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',
);
$this->container
->get('plugin.manager.views.field')
->getHandler($item);
$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',
);
$this->container
->get('plugin.manager.views.filter')
->getHandler($item);
$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',
);
$this->container
->get('plugin.manager.views.filter')
->getHandler($item);
$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);
restore_error_handler();
}