public function ExtensionViewsFieldTest::testFileExtensionTarOption in Drupal 10
Same name and namespace in other branches
- 8 core/modules/file/tests/src/Kernel/Views/ExtensionViewsFieldTest.php \Drupal\Tests\file\Kernel\Views\ExtensionViewsFieldTest::testFileExtensionTarOption()
- 9 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
->assertEquals('png', $view->field['extension']
->advancedRender($view->result[0]));
$this
->assertEquals('tar', $view->field['extension']
->advancedRender($view->result[1]));
$this
->assertEquals('gz', $view->field['extension']
->advancedRender($view->result[2]));
$this
->assertEquals('', $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
->assertEquals('png', $view->field['extension']
->advancedRender($view->result[0]));
$this
->assertEquals('tar', $view->field['extension']
->advancedRender($view->result[1]));
$this
->assertEquals('tar.gz', $view->field['extension']
->advancedRender($view->result[2]));
$this
->assertEquals('', $view->field['extension']
->advancedRender($view->result[3]));
});
}