TYPO3 CMS  TYPO3_7-6
CountViewHelperTest.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 Lesser General Public License, either version 3 *
9  * of the 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  protected function setUp()
25  {
26  parent::setUp();
27  $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\CountViewHelper::class, ['renderChildren']);
28  $this->injectDependenciesIntoViewHelper($this->viewHelper);
29  $this->viewHelper->initializeArguments();
30  }
31 
36  {
37  $expectedResult = 3;
38  $actualResult = $this->viewHelper->render(['foo', 'bar', 'Baz']);
39  $this->assertSame($expectedResult, $actualResult);
40  }
41 
46  {
47  $expectedResult = 2;
48  $actualResult = $this->viewHelper->render(new \ArrayObject(['foo', 'bar']));
49  $this->assertSame($expectedResult, $actualResult);
50  }
51 
56  {
57  $expectedResult = 0;
58  $actualResult = $this->viewHelper->render([]);
59  $this->assertSame($expectedResult, $actualResult);
60  }
61 
66  {
67  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(['foo', 'bar', 'baz']));
68  $expectedResult = 3;
69  $actualResult = $this->viewHelper->render(null);
70  $this->assertSame($expectedResult, $actualResult);
71  }
72 
77  {
78  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue(null));
79  $expectedResult = 0;
80  $actualResult = $this->viewHelper->render(null);
81  $this->assertSame($expectedResult, $actualResult);
82  }
83 
89  {
90  $object = new \stdClass();
91  $this->viewHelper->render($object);
92  }
93 }
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)