TYPO3 CMS  TYPO3_6-2
CurrencyViewHelperTest.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  public function viewHelperRoundsFloatCorrectly() {
23  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
24  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(123.456));
25  $actualResult = $viewHelper->render();
26  $this->assertEquals('123,46', $actualResult);
27  }
28 
32  public function viewHelperRendersCurrencySign() {
33  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
34  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
35  $actualResult = $viewHelper->render('foo');
36  $this->assertEquals('123,00 foo', $actualResult);
37  }
38 
43  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
44  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
45  $actualResult = $viewHelper->render('foo', ',', '.', TRUE);
46  $this->assertEquals('foo 123,00', $actualResult);
47  }
48 
53  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
54  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
55  $actualResult = $viewHelper->render('foo', ',', '.', TRUE, FALSE);
56  $this->assertEquals('foo123,00', $actualResult);
57  }
58 
63  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
64  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(12345));
65  $actualResult = $viewHelper->render('', '|');
66  $this->assertEquals('12.345|00', $actualResult);
67  }
68 
73  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
74  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(12345));
75  $actualResult = $viewHelper->render('', ',', '|');
76  $this->assertEquals('12|345,00', $actualResult);
77  }
78 
82  public function viewHelperRendersNullValues() {
83  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
84  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(NULL));
85  $actualResult = $viewHelper->render();
86  $this->assertEquals('0,00', $actualResult);
87  }
88 
92  public function viewHelperRendersEmptyString() {
93  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
94  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(''));
95  $actualResult = $viewHelper->render();
96  $this->assertEquals('0,00', $actualResult);
97  }
98 
102  public function viewHelperRendersZeroValues() {
103  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
104  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(0));
105  $actualResult = $viewHelper->render();
106  $this->assertEquals('0,00', $actualResult);
107  }
108 
113  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
114  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(-123.456));
115  $actualResult = $viewHelper->render();
116  $this->assertEquals('-123,46', $actualResult);
117  }
118 
123  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
124  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('TYPO3'));
125  $actualResult = $viewHelper->render();
126  $this->assertEquals('0,00', $actualResult);
127  }
128 
133  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
134  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('12,34.00'));
135  $actualResult = $viewHelper->render();
136  $this->assertEquals('12,00', $actualResult);
137  }
138 
143  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
144  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('54321'));
145  $actualResult = $viewHelper->render('', ',', '.', FALSE, TRUE, 0);
146  $this->assertEquals('54.321', $actualResult);
147  }
148 
152  public function viewHelperRendersThreeDecimals() {
153  $viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CurrencyViewHelper', array('renderChildren'));
154  $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('54321'));
155  $actualResult = $viewHelper->render('', ',', '.', FALSE, TRUE, 3);
156  $this->assertEquals('54.321,000', $actualResult);
157  }
158 }