TYPO3 CMS  TYPO3_7-6
CropViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the FLOW3 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 as published by the Free *
9  * Software Foundation, either version 3 of the License, or (at your *
10  * *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
15  * Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with the script. *
19  * If not, see http://www.gnu.org/licenses/gpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
27 
32 {
36  protected $viewHelper;
37 
41  protected $mockContentObject;
42 
43  protected function setUp()
44  {
45  parent::setUp();
46  $this->mockContentObject = $this->getMock(ContentObjectRenderer::class, [], [], '', false);
47  $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper::class, ['renderChildren']);
48 
49  $renderingContext = $this->getMock(RenderingContext::class);
50  $this->viewHelper->setRenderingContext($renderingContext);
51  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Some Content'));
52  }
53 
58  {
59  $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
60  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
61  $actualResult = $this->viewHelper->render(123);
62  $this->assertEquals('Cropped Content', $actualResult);
63  }
64 
69  {
70  $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '-321|custom suffix|1')->will($this->returnValue('Cropped Content'));
71  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
72  $actualResult = $this->viewHelper->render(-321, 'custom suffix');
73  $this->assertEquals('Cropped Content', $actualResult);
74  }
75 
80  {
81  $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|')->will($this->returnValue('Cropped Content'));
82  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
83  $actualResult = $this->viewHelper->render(123, '...', false);
84  $this->assertEquals('Cropped Content', $actualResult);
85  }
86 
90  public function respectHtmlCanBeDisabled()
91  {
92  $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
93  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
94  $actualResult = $this->viewHelper->render(123, '...', true, false);
95  $this->assertEquals('Cropped Content', $actualResult);
96  }
97 }
static addInstance($className, $instance)