TYPO3 CMS  TYPO3_6-2
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 
28 
32  protected $viewHelper;
33 
37  protected $mockContentObject;
38 
43 
44  public function setUp() {
45  parent::setUp();
46  $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array(), array(), '', FALSE);
47  $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
48  $this->mockConfigurationManager->expects($this->any())->method('getContentObject')->will($this->returnValue($this->mockContentObject));
49  $this->viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CropViewHelper', array('renderChildren'));
50  $this->viewHelper->injectConfigurationManager($this->mockConfigurationManager);
51  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Some Content'));
52  }
53 
58  $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
59  $actualResult = $this->viewHelper->render(123);
60  $this->assertEquals('Cropped Content', $actualResult);
61  }
62 
67  $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '-321|custom suffix|1')->will($this->returnValue('Cropped Content'));
68  $actualResult = $this->viewHelper->render(-321, 'custom suffix');
69  $this->assertEquals('Cropped Content', $actualResult);
70  }
71 
76  $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|')->will($this->returnValue('Cropped Content'));
77  $actualResult = $this->viewHelper->render(123, '...', FALSE);
78  $this->assertEquals('Cropped Content', $actualResult);
79  }
80 
84  public function respectHtmlCanBeDisabled() {
85  $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
86  $actualResult = $this->viewHelper->render(123, '...', TRUE, FALSE);
87  $this->assertEquals('Cropped Content', $actualResult);
88  }
89 }