[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 file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * Test case
21 */
22 class CropViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper
26 */
27 protected $viewHelper;
28
29 /**
30 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
31 */
32 protected $mockContentObject;
33
34 /**
35 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
36 */
37 protected $mockConfigurationManager;
38
39 public function setUp() {
40 parent::setUp();
41 $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array(), array(), '', FALSE);
42 $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
43 $this->mockConfigurationManager->expects($this->any())->method('getContentObject')->will($this->returnValue($this->mockContentObject));
44 $this->viewHelper = $this->getMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Format\\CropViewHelper', array('renderChildren'));
45 $this->viewHelper->injectConfigurationManager($this->mockConfigurationManager);
46 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Some Content'));
47 }
48
49 /**
50 * @test
51 */
52 public function viewHelperCallsCropHtmlByDefault() {
53 $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
54 $actualResult = $this->viewHelper->render(123);
55 $this->assertEquals('Cropped Content', $actualResult);
56 }
57
58 /**
59 * @test
60 */
61 public function viewHelperCallsCropHtmlByDefault2() {
62 $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '-321|custom suffix|1')->will($this->returnValue('Cropped Content'));
63 $actualResult = $this->viewHelper->render(-321, 'custom suffix');
64 $this->assertEquals('Cropped Content', $actualResult);
65 }
66
67 /**
68 * @test
69 */
70 public function respectWordBoundariesCanBeDisabled() {
71 $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|')->will($this->returnValue('Cropped Content'));
72 $actualResult = $this->viewHelper->render(123, '...', FALSE);
73 $this->assertEquals('Cropped Content', $actualResult);
74 }
75
76 /**
77 * @test
78 */
79 public function respectHtmlCanBeDisabled() {
80 $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
81 $actualResult = $this->viewHelper->render(123, '...', TRUE, FALSE);
82 $this->assertEquals('Cropped Content', $actualResult);
83 }
84 }