‪TYPO3CMS  ‪main
TableListTest.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;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪TableListTest extends UnitTestCase
30 {
31  public static function ‪renderResolvesEntryPointDataProvider(): \Generator
32  {
33  yield 'Wildcard' => [
34  [
35  'allowed' => '*',
36  'elementBrowserEntryPoints' => [
37  '_default' => 123,
38  ],
39  ],
40  [],
41  ];
42  yield 'One table' => [
43  [
44  'allowed' => 'pages',
45  'elementBrowserEntryPoints' => [
46  'pages' => 123,
47  ],
48  ],
49  [
50  'data-params="|||pages" data-entry-point="123"',
51  ],
52  ];
53  yield 'One table with default' => [
54  [
55  'allowed' => 'pages',
56  'elementBrowserEntryPoints' => [
57  '_default' => 123,
58  ],
59  ],
60  [
61  'data-params="|||pages" data-entry-point="123"',
62  ],
63  ];
64  yield 'One table with default and table definition' => [
65  [
66  'allowed' => 'pages',
67  'elementBrowserEntryPoints' => [
68  '_default' => 123,
69  'pages' => 124,
70  ],
71  ],
72  [
73  'data-params="|||pages" data-entry-point="124"',
74  ],
75  ];
76  yield 'One table with invalid configuration' => [
77  [
78  'allowed' => 'pages',
79  'elementBrowserEntryPoints' => [
80  'some_table' => 123,
81  ],
82  ],
83  [],
84  ];
85  yield 'One table without entry point configuration' => [
86  [
87  'allowed' => 'pages',
88  ],
89  [],
90  ];
91  yield 'Two tables without _default' => [
92  [
93  'allowed' => 'pages,some_table',
94  'elementBrowserEntryPoints' => [
95  'pages' => 123,
96  'some_table' => 124,
97  ],
98  ],
99  [
100  'data-params="|||pages" data-entry-point="123"',
101  'data-params="|||some_table" data-entry-point="124"',
102  ],
103  ];
104  yield 'Two tables with just _default' => [
105  [
106  'allowed' => 'pages,some_table',
107  'elementBrowserEntryPoints' => [
108  '_default' => 123,
109  ],
110  ],
111  [
112  'data-params="|||pages" data-entry-point="123"',
113  'data-params="|||some_table" data-entry-point="123"',
114  ],
115  ];
116  yield 'Two tables with _default' => [
117  [
118  'allowed' => 'pages,some_table',
119  'elementBrowserEntryPoints' => [
120  '_default' => 123,
121  'pages' => 124,
122  'some_table' => 125,
123  ],
124  ],
125  [
126  'data-params="|||pages" data-entry-point="124"',
127  'data-params="|||some_table" data-entry-point="125"',
128  ],
129  ];
130  yield 'Entry point is escaped' => [
131  [
132  'allowed' => 'pages',
133  'elementBrowserEntryPoints' => [
134  'pages' => '<script>alert(1)</script>',
135  ],
136  ], [
137  'data-params="|||pages" data-entry-point="&lt;script&gt;alert(1)&lt;/script&gt;"',
138  ],
139  ];
140  yield 'Pid placeholder is resolved' => [
141  [
142  'allowed' => 'pages',
143  'elementBrowserEntryPoints' => [
144  '_default' => '###CURRENT_PID###',
145  ],
146  ],
147  [
148  'data-params="|||pages" data-entry-point="123"',
149  ],
150  ];
151  yield 'Site placeholder is resolved' => [
152  [
153  'allowed' => 'pages',
154  'elementBrowserEntryPoints' => [
155  '_default' => '###SITEROOT###',
156  ],
157  ],
158  [
159  'data-params="|||pages" data-entry-point="123"',
160  ],
161  ];
162  }
163 
164  #[DataProvider('renderResolvesEntryPointDataProvider')]
165  #[Test]
166  public function ‪renderResolvesEntryPoint(array $config, array $expected): void
167  {
168  ‪$GLOBALS['TCA'] = [];
169  ‪$GLOBALS['LANG'] = $this->createMock(LanguageService::class);
170 
171  $iconMock = $this->createMock(Icon::class);
172  $iconMock->method('render')->with(self::anything())->willReturn('icon html');
173  $iconFactoryMock = $this->createMock(IconFactory::class);
174  $iconFactoryMock->method('getIconForRecord')->with(self::anything())->willReturn($iconMock);
175 
176  $tableList = new ‪TableList($iconFactoryMock);
177  $tableList->setData([
178  'fieldName' => 'somefield',
179  'isInlineChild' => false,
180  'effectivePid' => 123,
181  'site' => new ‪Site('some-site', 123, []),
182  'tableName' => 'tt_content',
183  'inlineStructure' => [],
184  'parameterArray' => [
185  'itemFormElName' => '',
186  'fieldConf' => [
187  'config' => $config,
188  ],
189  ],
190  ]);
191  $result = $tableList->render();
192 
193  if ($expected === []) {
194  self::assertStringNotContainsString('data-entry-point', $result['html']);
195  }
196 
197  foreach ($expected as $value) {
198  self::assertStringContainsString($value, $result['html']);
199  }
200  }
201 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FieldWizard\TableListTest\renderResolvesEntryPointDataProvider
‪static renderResolvesEntryPointDataProvider()
Definition: TableListTest.php:31
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FieldWizard\TableListTest\renderResolvesEntryPoint
‪renderResolvesEntryPoint(array $config, array $expected)
Definition: TableListTest.php:166
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Backend\Form\FieldWizard\TableList
Definition: TableList.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Form\FieldWizard\TableListTest
Definition: TableListTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FieldWizard
Definition: TableListTest.php:18