[TASK] use horizontal ellipsis instead of 3 dots
[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 free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper;
19 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
21
22 /**
23 * Test case.
24 */
25 class CropViewHelperTest extends ViewHelperBaseTestcase
26 {
27 /**
28 * @var CropViewHelper
29 */
30 protected $viewHelper;
31
32 /**
33 * @var ContentObjectRenderer|\PHPUnit_Framework_MockObject_MockObject
34 */
35 protected $mockContentObject;
36
37 protected function setUp()
38 {
39 parent::setUp();
40 $this->mockContentObject = $this->createMock(ContentObjectRenderer::class);
41 $this->viewHelper = new CropViewHelper();
42 $this->injectDependenciesIntoViewHelper($this->viewHelper);
43 $this->viewHelper->setRenderChildrenClosure(
44 function () {
45 return 'Some Content';
46 }
47 );
48 }
49
50 /**
51 * @test
52 */
53 public function viewHelperCallsCropHtmlByDefault()
54 {
55 $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|&hellip;|1')->will($this->returnValue('Cropped Content'));
56 GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
57 $this->setArgumentsUnderTest(
58 $this->viewHelper,
59 [
60 'maxCharacters' => '123',
61 ]
62 );
63 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
64 $this->assertEquals('Cropped Content', $actualResult);
65 }
66
67 /**
68 * @test
69 */
70 public function viewHelperCallsCropHtmlByDefault2()
71 {
72 $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '-321|custom suffix|1')->will($this->returnValue('Cropped Content'));
73 GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
74 $this->setArgumentsUnderTest(
75 $this->viewHelper,
76 [
77 'maxCharacters' => '-321',
78 'append' => 'custom suffix',
79 ]
80 );
81 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
82 $this->assertEquals('Cropped Content', $actualResult);
83 }
84
85 /**
86 * @test
87 */
88 public function respectWordBoundariesCanBeDisabled()
89 {
90 $this->mockContentObject->expects($this->once())->method('cropHTML')->with('Some Content', '123|...|')->will($this->returnValue('Cropped Content'));
91 GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
92 $this->setArgumentsUnderTest(
93 $this->viewHelper,
94 [
95 'maxCharacters' => '123',
96 'append' => '...',
97 'respectWordBoundaries' => false,
98 ]
99 );
100 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
101 $this->assertEquals('Cropped Content', $actualResult);
102 }
103
104 /**
105 * @test
106 */
107 public function respectHtmlCanBeDisabled()
108 {
109 $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content'));
110 GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
111 $this->setArgumentsUnderTest(
112 $this->viewHelper,
113 [
114 'maxCharacters' => '123',
115 'append' => '...',
116 'respectWordBoundaries' => true,
117 'respectHtml' => false,
118 ]
119 );
120 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
121 $this->assertEquals('Cropped Content', $actualResult);
122 }
123 }