Revert "[CLEANUP] Rework/simplify copyright header and remove @package"
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Format / CropViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
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
24 /**
25 * Test case
26 */
27 class CropViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
28
29 /**
30 * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper
31 */
32 protected $viewHelper;
33
34 /**
35 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
36 */
37 protected $mockContentObject;
38
39 /**
40 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
41 */
42 protected $mockConfigurationManager;
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
54 /**
55 * @test
56 */
57 public function viewHelperCallsCropHtmlByDefault() {
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
63 /**
64 * @test
65 */
66 public function viewHelperCallsCropHtmlByDefault2() {
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
72 /**
73 * @test
74 */
75 public function respectWordBoundariesCanBeDisabled() {
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
81 /**
82 * @test
83 */
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 }