You are here

public function FieldFileSizeTest::testFieldFileSize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/FieldFileSizeTest.php \Drupal\views\Tests\Handler\FieldFileSizeTest::testFieldFileSize()

File

core/modules/views/src/Tests/Handler/FieldFileSizeTest.php, line 45
Contains \Drupal\views\Tests\Handler\FieldFileSizeTest.

Class

FieldFileSizeTest
Tests the core Drupal\views\Plugin\views\field\FileSize handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testFieldFileSize() {
  $view = Views::getView('test_view');
  $view
    ->setDisplay();
  $view->displayHandlers
    ->get('default')
    ->overrideOption('fields', array(
    'age' => array(
      'id' => 'age',
      'table' => 'views_test_data',
      'field' => 'age',
    ),
  ));
  $this
    ->executeView($view);

  // Test with the formatted option.
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[0]), '');
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[1]), '10 bytes');
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[2]), '1000 bytes');
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[3]), '9.77 KB');

  // Test with the bytes option.
  $view->field['age']->options['file_size_display'] = 'bytes';
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[0]), '');
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[1]), '10');
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[2]), '1000');
  $this
    ->assertEqual($view->field['age']
    ->advancedRender($view->result[3]), '10000');
}