‪TYPO3CMS  10.4
CropViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
22 
26 class ‪CropViewHelperTest extends ViewHelperBaseTestcase
27 {
31  protected ‪$viewHelper;
32 
37 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  $this->mockContentObject = $this->createMock(ContentObjectRenderer::class);
42  $this->viewHelper = new ‪CropViewHelper();
43  $this->injectDependenciesIntoViewHelper($this->viewHelper);
44  $this->viewHelper->setRenderChildrenClosure(
45  function () {
46  return 'Some Content';
47  }
48  );
49  }
50 
54  public function ‪viewHelperCallsCropHtmlByDefault()
55  {
56  $this->mockContentObject->expects(self::once())->method('cropHTML')->with('Some Content', '123|&hellip;|1')->willReturn('Cropped Content');
57  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
58  $this->setArgumentsUnderTest(
59  $this->viewHelper,
60  [
61  'maxCharacters' => '123',
62  ]
63  );
64  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
65  self::assertEquals('Cropped Content', $actualResult);
66  }
67 
71  public function ‪viewHelperCallsCropHtmlByDefault2()
72  {
73  $this->mockContentObject->expects(self::once())->method('cropHTML')->with('Some Content', '-321|custom suffix|1')->willReturn('Cropped Content');
74  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
75  $this->setArgumentsUnderTest(
76  $this->viewHelper,
77  [
78  'maxCharacters' => '-321',
79  'append' => 'custom suffix',
80  ]
81  );
82  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
83  self::assertEquals('Cropped Content', $actualResult);
84  }
85 
90  {
91  $this->mockContentObject->expects(self::once())->method('cropHTML')->with('Some Content', '123|...|')->willReturn('Cropped Content');
92  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
93  $this->setArgumentsUnderTest(
94  $this->viewHelper,
95  [
96  'maxCharacters' => '123',
97  'append' => '...',
98  'respectWordBoundaries' => false,
99  ]
100  );
101  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
102  self::assertEquals('Cropped Content', $actualResult);
103  }
104 
108  public function ‪respectHtmlCanBeDisabled()
109  {
110  $this->mockContentObject->expects(self::once())->method('crop')->with('Some Content', '123|...|1')->willReturn('Cropped Content');
111  GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject);
112  $this->setArgumentsUnderTest(
113  $this->viewHelper,
114  [
115  'maxCharacters' => '123',
116  'append' => '...',
117  'respectWordBoundaries' => true,
118  'respectHtml' => false,
119  ]
120  );
121  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
122  self::assertEquals('Cropped Content', $actualResult);
123  }
124 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\$viewHelper
‪CropViewHelper $viewHelper
Definition: CropViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\respectWordBoundariesCanBeDisabled
‪respectWordBoundariesCanBeDisabled()
Definition: CropViewHelperTest.php:87
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\viewHelperCallsCropHtmlByDefault
‪viewHelperCallsCropHtmlByDefault()
Definition: CropViewHelperTest.php:52
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: ScriptViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\setUp
‪setUp()
Definition: CropViewHelperTest.php:36
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\respectHtmlCanBeDisabled
‪respectHtmlCanBeDisabled()
Definition: CropViewHelperTest.php:106
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CropViewHelper
Definition: CropViewHelper.php:90
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\$mockContentObject
‪ContentObjectRenderer PHPUnit Framework MockObject MockObject $mockContentObject
Definition: CropViewHelperTest.php:34
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest
Definition: CropViewHelperTest.php:27
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CropViewHelperTest\viewHelperCallsCropHtmlByDefault2
‪viewHelperCallsCropHtmlByDefault2()
Definition: CropViewHelperTest.php:69