public function ExtensionViewsFieldTest::testFileExtensionTarOption in Drupal 8
Same name and namespace in other branches
- 9 core/modules/file/tests/src/Kernel/Views/ExtensionViewsFieldTest.php \Drupal\Tests\file\Kernel\Views\ExtensionViewsFieldTest::testFileExtensionTarOption()
- 10 core/modules/file/tests/src/Kernel/Views/ExtensionViewsFieldTest.php \Drupal\Tests\file\Kernel\Views\ExtensionViewsFieldTest::testFileExtensionTarOption()
Tests file extension views field handler extension_detect_tar option.
File
- core/
modules/ file/ tests/ src/ Kernel/ Views/ ExtensionViewsFieldTest.php, line 67
Class
- ExtensionViewsFieldTest
- Tests the core Drupal\file\Plugin\views\field\Extension handler.
Namespace
Drupal\Tests\file\Kernel\ViewsCode
public function testFileExtensionTarOption() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('file_extension_view');
$view
->setDisplay();
$this
->executeView($view);
// Test without the tar option.
$renderer
->executeInRenderContext(new RenderContext(), function () use ($view) {
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[0]), 'png');
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[1]), 'tar');
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[2]), 'gz');
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[3]), '');
});
// Test with the tar option.
$view = Views::getView('file_extension_view');
$view
->setDisplay();
$view
->initHandlers();
$view->field['extension']->options['settings']['extension_detect_tar'] = TRUE;
$this
->executeView($view);
$renderer
->executeInRenderContext(new RenderContext(), function () use ($view) {
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[0]), 'png');
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[1]), 'tar');
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[2]), 'tar.gz');
$this
->assertEqual($view->field['extension']
->advancedRender($view->result[3]), '');
});
}