function FieldBooleanTest::testFieldBoolean
Same name in other branches
- 9 core/modules/views/tests/src/Kernel/Handler/FieldBooleanTest.php \Drupal\Tests\views\Kernel\Handler\FieldBooleanTest::testFieldBoolean()
- 8.9.x core/modules/views/tests/src/Kernel/Handler/FieldBooleanTest.php \Drupal\Tests\views\Kernel\Handler\FieldBooleanTest::testFieldBoolean()
- 11.x core/modules/views/tests/src/Kernel/Handler/FieldBooleanTest.php \Drupal\Tests\views\Kernel\Handler\FieldBooleanTest::testFieldBoolean()
File
-
core/
modules/ views/ tests/ src/ Kernel/ Handler/ FieldBooleanTest.php, line 38
Class
- FieldBooleanTest
- Tests the core Drupal\views\Plugin\views\field\Boolean handler.
Namespace
Drupal\Tests\views\Kernel\HandlerCode
public function testFieldBoolean() : void {
$view = Views::getView('test_view');
$view->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('fields', [
'age' => [
'id' => 'age',
'table' => 'views_test_data',
'field' => 'age',
'relationship' => 'none',
],
]);
$this->executeView($view);
// This is john, which has no age, there are no custom formats defined, yet.
$this->assertEquals('No', $view->field['age']
->advancedRender($view->result[0]));
$this->assertEquals('Yes', $view->field['age']
->advancedRender($view->result[1]));
// Reverse the output.
$view->field['age']->options['not'] = TRUE;
$this->assertEquals('Yes', $view->field['age']
->advancedRender($view->result[0]));
$this->assertEquals('No', $view->field['age']
->advancedRender($view->result[1]));
unset($view->field['age']->options['not']);
// Use another output format.
$view->field['age']->options['type'] = 'true-false';
$this->assertEquals('False', $view->field['age']
->advancedRender($view->result[0]));
$this->assertEquals('True', $view->field['age']
->advancedRender($view->result[1]));
// Test awesome unicode.
$view->field['age']->options['type'] = 'unicode-yes-no';
$this->assertEquals('✖', $view->field['age']
->advancedRender($view->result[0]));
$this->assertEquals('✔', $view->field['age']
->advancedRender($view->result[1]));
// Set a custom output format.
$view->field['age']->formats['test'] = [
'Test-True',
'Test-False',
];
$view->field['age']->options['type'] = 'test';
$this->assertEquals('Test-False', $view->field['age']
->advancedRender($view->result[0]));
$this->assertEquals('Test-True', $view->field['age']
->advancedRender($view->result[1]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.