‪TYPO3CMS  9.5
CropViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
21 
25 class ‪CropViewHelperTest extends ViewHelperBaseTestcase
26 {
30  protected ‪$viewHelper;
31 
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 
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 
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 
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 
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 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\$viewHelper
‪CropViewHelper $viewHelper
Definition: CropViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\respectWordBoundariesCanBeDisabled
‪respectWordBoundariesCanBeDisabled()
Definition: CropViewHelperTest.php:86
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\viewHelperCallsCropHtmlByDefault
‪viewHelperCallsCropHtmlByDefault()
Definition: CropViewHelperTest.php:51
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: BytesViewHelperTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\setUp
‪setUp()
Definition: CropViewHelperTest.php:35
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\$mockContentObject
‪ContentObjectRenderer PHPUnit_Framework_MockObject_MockObject $mockContentObject
Definition: CropViewHelperTest.php:33
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\respectHtmlCanBeDisabled
‪respectHtmlCanBeDisabled()
Definition: CropViewHelperTest.php:105
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper
Definition: CropViewHelper.php:85
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest
Definition: CropViewHelperTest.php:26
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\viewHelperCallsCropHtmlByDefault2
‪viewHelperCallsCropHtmlByDefault2()
Definition: CropViewHelperTest.php:68