function ExtensionViewsFieldTest::testFileExtensionTarOption

Same name in other branches
  1. 9 core/modules/file/tests/src/Kernel/Views/ExtensionViewsFieldTest.php \Drupal\Tests\file\Kernel\Views\ExtensionViewsFieldTest::testFileExtensionTarOption()
  2. 8.9.x core/modules/file/tests/src/Kernel/Views/ExtensionViewsFieldTest.php \Drupal\Tests\file\Kernel\Views\ExtensionViewsFieldTest::testFileExtensionTarOption()
  3. 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 69

Class

ExtensionViewsFieldTest
Tests the core Drupal\file\Plugin\views\field\Extension handler.

Namespace

Drupal\Tests\file\Kernel\Views

Code

public function testFileExtensionTarOption() : void {
    
    /** @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]));
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.