summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/views/tests/handlers/views_handler_field_file_size.test
blob: 8652754fea11df8c59acb16467c62bb6c40e3937 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

/**
 * @file
 * Definition of ViewsHandlerTestFileSize.
 */

/**
 * Tests the core views_handler_field_file_size handler.
 *
 * @see CommonXssUnitTest
 */
class ViewsHandlerTestFileSize extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Field: file_size',
      'description' => 'Test the core views_handler_field_file_size handler.',
      'group' => 'Views Handlers',
    );
  }

  function dataSet() {
    $data = parent::dataSet();
    $data[0]['age'] = 0;
    $data[1]['age'] = 10;
    $data[2]['age'] = 1000;
    $data[3]['age'] = 10000;

    return $data;
  }

  function viewsData() {
    $data = parent::viewsData();
    $data['views_test']['age']['field']['handler'] = 'views_handler_field_file_size';

    return $data;
  }

  public function testFieldFileSize() {
    $view = $this->getBasicView();

    $view->display['default']->handler->override_option('fields', array(
      'age' => array(
        'id' => 'age',
        'table' => 'views_test',
        'field' => 'age',
      ),
    ));

    $this->executeView($view);

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