Project

General

Profile

Paste
Download (1.89 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views / tests / handlers / views_handler_field_file_size.test @ 4003efde

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of ViewsHandlerTestFileSize.
6
 */
7

    
8
/**
9
 * Tests the core views_handler_field_file_size handler.
10
 *
11
 * @see CommonXssUnitTest
12
 */
13
class ViewsHandlerTestFileSize extends ViewsSqlTest {
14
  public static function getInfo() {
15
    return array(
16
      'name' => 'Field: file_size',
17
      'description' => 'Test the core views_handler_field_file_size handler.',
18
      'group' => 'Views Handlers',
19
    );
20
  }
21

    
22
  function dataSet() {
23
    $data = parent::dataSet();
24
    $data[0]['age'] = 0;
25
    $data[1]['age'] = 10;
26
    $data[2]['age'] = 1000;
27
    $data[3]['age'] = 10000;
28

    
29
    return $data;
30
  }
31

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

    
36
    return $data;
37
  }
38

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

    
42
    $view->display['default']->handler->override_option('fields', array(
43
      'age' => array(
44
        'id' => 'age',
45
        'table' => 'views_test',
46
        'field' => 'age',
47
      ),
48
    ));
49

    
50
    $this->executeView($view);
51

    
52
    // Test with the formatted option.
53
    $this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
54
    $this->assertEqual($view->field['age']->advanced_render($view->result[1]), '10 bytes');
55
    $this->assertEqual($view->field['age']->advanced_render($view->result[2]), '1000 bytes');
56
    $this->assertEqual($view->field['age']->advanced_render($view->result[3]), '9.77 KB');
57
    // Test with the bytes option.
58
    $view->field['age']->options['file_size_display'] = 'bytes';
59
    $this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
60
    $this->assertEqual($view->field['age']->advanced_render($view->result[1]), 10);
61
    $this->assertEqual($view->field['age']->advanced_render($view->result[2]), 1000);
62
    $this->assertEqual($view->field['age']->advanced_render($view->result[3]), 10000);
63
  }
64

    
65
}