‪TYPO3CMS  ‪main
CropViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 use TYPO3Fluid\Fluid\View\TemplateView;
25 
26 final class ‪CropViewHelperTest extends FunctionalTestCase
27 {
28  protected bool ‪$initializeDatabase = false;
29 
30  public static function ‪renderConvertsAValueDataProvider(): array
31  {
32  return [
33  'simple html crop' => [
34  '<f:format.crop maxCharacters="10">Crop this content</f:format.crop>',
35  'Crop this&hellip;',
36  ],
37  'simple html crop with html' => [
38  '<f:format.crop maxCharacters="10"><p>Crop</p> this content</f:format.crop>',
39  '<p>Crop</p> this&hellip;',
40  ],
41  'custom suffix' => [
42  '<f:format.crop maxCharacters="10" append="custom suffix">Crop this content</f:format.crop>',
43  'Crop thiscustom suffix',
44  ],
45  'disabled respectWordBoundaries' => [
46  '<f:format.crop maxCharacters="7" respectWordBoundaries="false">Crop this content</f:format.crop>',
47  'Crop th&hellip;',
48  ],
49  'do not respect html' => [
50  '<f:format.crop maxCharacters="7" respectHtml="false" append="..."><p>Crop</p> this content</f:format.crop>',
51  '<p>Crop...',
52  ],
53  ];
54  }
55 
56  #[DataProvider('renderConvertsAValueDataProvider')]
57  #[Test]
58  public function ‪renderConvertsAValue(string $src, string $expected): void
59  {
60  $context = $this->get(RenderingContextFactory::class)->create();
61  $context->getTemplatePaths()->setTemplateSource($src);
62  self::assertSame($expected, (new TemplateView($context))->render());
63  }
64 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format
Definition: BytesViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CropViewHelperTest\renderConvertsAValue
‪renderConvertsAValue(string $src, string $expected)
Definition: CropViewHelperTest.php:58
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CropViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: CropViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CropViewHelperTest
Definition: CropViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory
Definition: RenderingContextFactory.php:51
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\CropViewHelperTest\renderConvertsAValueDataProvider
‪static renderConvertsAValueDataProvider()
Definition: CropViewHelperTest.php:30