TYPO3 CMS  TYPO3_7-6
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  * */
15 
20 {
24  protected $subject;
25 
26  protected function setUp()
27  {
28  $this->subject = $this->getAccessibleMock(CurrencyViewHelper::class, ['renderChildren']);
30  $renderingContext = $this->getMock(RenderingContext::class);
31  $this->subject->_set('renderingContext', $renderingContext);
32  }
33 
38  {
39  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(123.456));
40  $actualResult = $this->subject->render();
41  $this->assertEquals('123,46', $actualResult);
42  }
43 
48  {
49  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
50  $actualResult = $this->subject->render('foo');
51  $this->assertEquals('123,00 foo', $actualResult);
52  }
53 
58  {
59  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
60  $actualResult = $this->subject->render('foo', ',', '.', true);
61  $this->assertEquals('foo 123,00', $actualResult);
62  }
63 
68  {
69  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(123));
70  $actualResult = $this->subject->render('foo', ',', '.', true, false);
71  $this->assertEquals('foo123,00', $actualResult);
72  }
73 
78  {
79  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(12345));
80  $actualResult = $this->subject->render('', '|');
81  $this->assertEquals('12.345|00', $actualResult);
82  }
83 
88  {
89  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(12345));
90  $actualResult = $this->subject->render('', ',', '|');
91  $this->assertEquals('12|345,00', $actualResult);
92  }
93 
97  public function viewHelperRendersNullValues()
98  {
99  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(null));
100  $actualResult = $this->subject->render();
101  $this->assertEquals('0,00', $actualResult);
102  }
103 
108  {
109  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(''));
110  $actualResult = $this->subject->render();
111  $this->assertEquals('0,00', $actualResult);
112  }
113 
117  public function viewHelperRendersZeroValues()
118  {
119  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(0));
120  $actualResult = $this->subject->render();
121  $this->assertEquals('0,00', $actualResult);
122  }
123 
128  {
129  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue(-123.456));
130  $actualResult = $this->subject->render();
131  $this->assertEquals('-123,46', $actualResult);
132  }
133 
138  {
139  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue('TYPO3'));
140  $actualResult = $this->subject->render();
141  $this->assertEquals('0,00', $actualResult);
142  }
143 
148  {
149  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue('12,34.00'));
150  $actualResult = $this->subject->render();
151  $this->assertEquals('12,00', $actualResult);
152  }
153 
158  {
159  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue('54321'));
160  $actualResult = $this->subject->render('', ',', '.', false, true, 0);
161  $this->assertEquals('54.321', $actualResult);
162  }
163 
168  {
169  $this->subject->expects($this->once())->method('renderChildren')->will($this->returnValue('54321'));
170  $actualResult = $this->subject->render('', ',', '.', false, true, 3);
171  $this->assertEquals('54.321,000', $actualResult);
172  }
173 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)