You are here

public function ExtensionViewsFieldTest::testFileExtensionTarOption in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/file/src/Tests/Views/ExtensionViewsFieldTest.php \Drupal\file\Tests\Views\ExtensionViewsFieldTest::testFileExtensionTarOption()

Tests file extension views field handler extension_detect_tar option.

File

core/modules/file/src/Tests/Views/ExtensionViewsFieldTest.php, line 72
Contains \Drupal\file\Tests\Views\ExtensionViewsFieldTest.

Class

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

Namespace

Drupal\file\Tests\Views

Code

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]), '');
  });
}