TYPO3 CMS  TYPO3_6-2
BytesViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU General Public License, either version 3 of the *
9  * License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 
22  protected $viewHelper;
23 
24  public function setUp() {
25  $this->viewHelper = $this->getMock('TYPO3\CMS\Fluid\ViewHelpers\Format\BytesViewHelper', array('renderChildren'));
26  }
27 
31  public function valueDataProvider() {
32  return array(
33 
34  // invalid values
35  array(
36  'value' => 'invalid',
37  'decimals' => NULL,
38  'decimalSeparator' => NULL,
39  'thousandsSeparator' => NULL,
40  'expected' => '0 B'
41  ),
42  array(
43  'value' => '',
44  'decimals' => 2,
45  'decimalSeparator' => NULL,
46  'thousandsSeparator' => NULL,
47  'expected' => '0.00 B'
48  ),
49  array(
50  'value' => array(),
51  'decimals' => 2,
52  'decimalSeparator' => ',',
53  'thousandsSeparator' => NULL,
54  'expected' => '0,00 B'
55  ),
56  // valid values
57  array(
58  'value' => 123,
59  'decimals' => NULL,
60  'decimalSeparator' => NULL,
61  'thousandsSeparator' => NULL,
62  'expected' => '123 B'
63  ),
64  array(
65  'value' => '43008',
66  'decimals' => 1,
67  'decimalSeparator' => NULL,
68  'thousandsSeparator' => NULL,
69  'expected' => '42.0 KB'
70  ),
71  array(
72  'value' => 1024,
73  'decimals' => 1,
74  'decimalSeparator' => NULL,
75  'thousandsSeparator' => NULL,
76  'expected' => '1.0 KB'
77  ),
78  array(
79  'value' => 1023,
80  'decimals' => 2,
81  'decimalSeparator' => NULL,
82  'thousandsSeparator' => NULL,
83  'expected' => '1,023.00 B'
84  ),
85  array(
86  'value' => 1073741823,
87  'decimals' => 1,
88  'decimalSeparator' => NULL,
89  'thousandsSeparator' => '.',
90  'expected' => '1.024.0 MB'
91  ),
92  array(
93  'value' => pow(1024, 5),
94  'decimals' => 1,
95  'decimalSeparator' => NULL,
96  'thousandsSeparator' => NULL,
97  'expected' => '1.0 PB'
98  ),
99  array(
100  'value' => pow(1024, 8),
101  'decimals' => 1,
102  'decimalSeparator' => NULL,
103  'thousandsSeparator' => NULL,
104  'expected' => '1.0 YB'
105  )
106  );
107  }
108 
118  public function renderCorrectlyConvertsAValue($value, $decimals, $decimalSeparator, $thousandsSeparator, $expected) {
119  $actualResult = $this->viewHelper->render($value, $decimals, $decimalSeparator, $thousandsSeparator);
120  $this->assertEquals($expected, $actualResult);
121  }
122 
127  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(12345));
128  $actualResult = $this->viewHelper->render();
129  $this->assertEquals('12 KB', $actualResult);
130  }
131 }
renderCorrectlyConvertsAValue($value, $decimals, $decimalSeparator, $thousandsSeparator, $expected)