‪TYPO3CMS  11.5
BytesViewHelperTest.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 
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22 
23 class ‪BytesViewHelperTest extends FunctionalTestCase
24 {
28  protected ‪$initializeDatabase = false;
29 
30  public function ‪renderConvertsAValueDataProvider(): array
31  {
32  return [
33  // invalid values
34  [
35  '<f:format.bytes value="invalid" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
36  '0 B',
37  ],
38  [
39  '<f:format.bytes value="" decimals="2" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
40  '0.00 B',
41  ],
42  [
43  '<f:format.bytes value="{}" decimals="2" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
44  '0.00 B',
45  ],
46  // valid values
47  [
48  '<f:format.bytes value="123" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
49  '123 B',
50  ],
51  [
52  '<f:format.bytes value="43008" decimals="1" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
53  '42.0 KB',
54  ],
55  [
56  '<f:format.bytes value="1024" decimals="1" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
57  '1.0 KB',
58  ],
59  [
60  '<f:format.bytes value="1023" decimals="2" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
61  '1,023.00 B',
62  ],
63  [
64  '<f:format.bytes value="1073741823" decimals="1" thousandsSeparator="." units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
65  '1.024.0 MB',
66  ],
67  [
68  '<f:format.bytes value="{1024 ^ 5}" decimals="1" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
69  '1.0 PB',
70  ],
71  [
72  '<f:format.bytes value="{1024 ^ 8}" decimals="1" units="B,KB,MB,GB,TB,PB,EB,ZB,YB" />',
73  '1.0 YB',
74  ],
75  [
76  '<f:format.bytes units="B,KB,MB,GB,TB,PB,EB,ZB,YB">12345</f:format.bytes>',
77  '12 KB',
78  ],
79  ];
80  }
81 
86  public function ‪renderConvertsAValue(string $src, string $expected): void
87  {
88  $view = new ‪StandaloneView();
89  $view->setTemplateSource($src);
90  self::assertSame($expected, $view->render());
91  }
92 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\BytesViewHelperTest
Definition: BytesViewHelperTest.php:24
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\BytesViewHelperTest\renderConvertsAValue
‪renderConvertsAValue(string $src, string $expected)
Definition: BytesViewHelperTest.php:85
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\BytesViewHelperTest\$initializeDatabase
‪bool $initializeDatabase
Definition: BytesViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format
Definition: BytesViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Format\BytesViewHelperTest\renderConvertsAValueDataProvider
‪renderConvertsAValueDataProvider()
Definition: BytesViewHelperTest.php:29
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:31