FieldBooleanTest.php in Zircon Profile 8
File
core/modules/views/src/Tests/Handler/FieldBooleanTest.php
View source
<?php
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Views;
class FieldBooleanTest extends ViewKernelTestBase {
public static $testViews = array(
'test_view',
);
function dataSet() {
$data = parent::dataSet();
$data[0]['age'] = 0;
$data[3]['age'] = 0;
return $data;
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['age']['field']['id'] = 'boolean';
return $data;
}
public function testFieldBoolean() {
$view = Views::getView('test_view');
$view
->setDisplay();
$view->displayHandlers
->get('default')
->overrideOption('fields', array(
'age' => array(
'id' => 'age',
'table' => 'views_test_data',
'field' => 'age',
'relationship' => 'none',
),
));
$this
->executeView($view);
$this
->assertEqual(t('No'), $view->field['age']
->advancedRender($view->result[0]));
$this
->assertEqual(t('Yes'), $view->field['age']
->advancedRender($view->result[1]));
$view->field['age']->options['not'] = TRUE;
$this
->assertEqual(t('Yes'), $view->field['age']
->advancedRender($view->result[0]));
$this
->assertEqual(t('No'), $view->field['age']
->advancedRender($view->result[1]));
unset($view->field['age']->options['not']);
$view->field['age']->options['type'] = 'true-false';
$this
->assertEqual(t('False'), $view->field['age']
->advancedRender($view->result[0]));
$this
->assertEqual(t('True'), $view->field['age']
->advancedRender($view->result[1]));
$view->field['age']->options['type'] = 'unicode-yes-no';
$this
->assertEqual('✖', $view->field['age']
->advancedRender($view->result[0]));
$this
->assertEqual('✔', $view->field['age']
->advancedRender($view->result[1]));
$view->field['age']->formats['test'] = array(
t('Test-True'),
t('Test-False'),
);
$view->field['age']->options['type'] = 'test';
$this
->assertEqual(t('Test-False'), $view->field['age']
->advancedRender($view->result[0]));
$this
->assertEqual(t('Test-True'), $view->field['age']
->advancedRender($view->result[1]));
}
}