‪TYPO3CMS  10.4
TitleTagRenderingTest.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 Symfony\Component\Yaml\Yaml;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
29 class ‪TitleTagRenderingTest extends FunctionalTestCase
30 {
34  protected ‪$coreExtensionsToLoad = [
35  'core', 'frontend', 'seo'
36  ];
37 
41  protected ‪$pathsToLinkInTestInstance = [
42  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
43  ];
44 
48  protected $configurationToUseInTestInstance = [
49  'FE' => [
50  'cacheHash' => [
51  'enforceValidation' => false,
52  ],
53  ],
54  ];
55 
56  protected function setUp(): void
57  {
58  parent::setUp();
59  $this->‪importDataSet('EXT:frontend/Tests/Functional/Fixtures/pages-title-tag.xml');
60  $this->setUpFrontendRootPage(
61  1,
62  ['EXT:frontend/Tests/Functional/Rendering/Fixtures/TitleTagRenderingTest.typoscript']
63  );
64  $this->‪setUpFrontendSite(1);
66  1,
67  'Site Title'
68  );
69  }
70 
77  protected function ‪setUpFrontendSite(int $pageId)
78  {
79  $configuration = [
80  'rootPageId' => $pageId,
81  'base' => '/',
82  'websiteTitle' => '',
83  'languages' => [
84  [
85  'title' => 'English',
86  'enabled' => true,
87  'languageId' => '0',
88  'base' => '/',
89  'typo3Language' => 'default',
90  'locale' => 'en_US.UTF-8',
91  'iso-639-1' => 'en',
92  'websiteTitle' => 'Site EN',
93  'navigationTitle' => '',
94  'hreflang' => '',
95  'direction' => '',
96  'flag' => 'us',
97  ]
98  ],
99  'errorHandling' => [],
100  'routes' => [],
101  ];
102  ‪GeneralUtility::mkdir_deep($this->instancePath . '/typo3conf/sites/testing/');
103  $yamlFileContents = Yaml::dump($configuration, 99, 2);
104  $fileName = $this->instancePath . '/typo3conf/sites/testing/config.yaml';
105  ‪GeneralUtility::writeFile($fileName, $yamlFileContents);
106  }
107 
108  public function ‪titleTagDataProvider(): array
109  {
110  return [
111  [
112  [
113  'pageId' => 1000,
114  ],
115  [
116  'assertRegExp' => '#<title>Site EN: Root 1000</title>#',
117  'assertNotRegExp' => '',
118  ]
119  ],
120  [
121  [
122  'pageId' => 1001,
123  ],
124  [
125  'assertRegExp' => '#<title>Site EN: SEO Root 1001</title>#',
126  'assertNotRegExp' => '',
127  ]
128  ],
129  [
130  [
131  'pageId' => 1000,
132  'noPageTitle' => 1,
133  ],
134  [
135  'assertRegExp' => '#<title>Site EN</title>#',
136  'assertNotRegExp' => '',
137  ]
138  ],
139  [
140  [
141  'pageId' => 1001,
142  'noPageTitle' => 1,
143  ],
144  [
145  'assertRegExp' => '#<title>Site EN</title>#',
146  'assertNotRegExp' => '',
147  ]
148  ],
149  [
150  [
151  'pageId' => 1000,
152  'noPageTitle' => 2,
153  ],
154  [
155  'assertRegExp' => '',
156  'assertNotRegExp' => '#<title>.*</title>#',
157  ]
158  ],
159  [
160  [
161  'pageId' => 1001,
162  'noPageTitle' => 2,
163  ],
164  [
165  'assertRegExp' => '',
166  'assertNotRegExp' => '#<title>.*</title>#',
167  ]
168  ],
169  [
170  [
171  'pageId' => 1000,
172  'noPageTitle' => 2,
173  'headerData' => 1
174  ],
175  [
176  'assertRegExp' => '#<title>Header Data Title</title>#',
177  'assertNotRegExp' => '',
178  ]
179  ],
180  [
181  [
182  'pageId' => 1001,
183  'noPageTitle' => 2,
184  'headerData' => 1
185  ],
186  [
187  'assertRegExp' => '#<title>Header Data Title</title>#',
188  'assertNotRegExp' => '',
189  ]
190  ],
191  [
192  [
193  'pageId' => 1000,
194  'pageTitleTS' => 1
195  ],
196  [
197  'assertRegExp' => '#<title>SITE EN: ROOT 1000</title>#',
198  'assertNotRegExp' => '',
199  ]
200  ],
201  [
202  [
203  'pageId' => 1000,
204  'pageTitleFirst' => 1
205  ],
206  [
207  'assertRegExp' => '#<title>Root 1000: Site EN</title>#',
208  'assertNotRegExp' => '',
209  ]
210  ],
211  [
212  [
213  'pageId' => 1000,
214  'pageTitleSeparator' => 'typoscriptText'
215  ],
216  [
217  'assertRegExp' => '#<title>Site EN| Root 1000</title>#',
218  'assertNotRegExp' => '',
219  ]
220  ],
221  [
222  [
223  'pageId' => 1000,
224  'pageTitleSeparator' => 'typoscriptStdwrap'
225  ],
226  [
227  'assertRegExp' => '#<title>Site EN - Root 1000</title>#',
228  'assertNotRegExp' => '',
229  ]
230  ],
231  ];
232  }
233 
240  public function ‪checkIfCorrectTitleTagIsRendered($pageConfig, $expectations): void
241  {
242  $response = $this->executeFrontendRequest(
243  (new InternalRequest())->withQueryParameters([
244  'id' => (int)$pageConfig['pageId'],
245  'noPageTitle' => (int)$pageConfig['noPageTitle'],
246  'headerData' => (int)$pageConfig['headerData'],
247  'pageTitleTS' => (int)$pageConfig['pageTitleTS'],
248  'pageTitleFirst' => (int)$pageConfig['pageTitleFirst'],
249  'pageTitleSeparator' => $pageConfig['pageTitleSeparator']
250  ])
251  );
252  $content = (string)$response->getBody();
253  if ($expectations['assertRegExp']) {
254  self::assertRegExp($expectations['assertRegExp'], $content);
255  }
256  if ($expectations['assertNotRegExp']) {
257  self::assertNotRegExp($expectations['assertNotRegExp'], $content);
258  }
259  }
260 
267  protected function ‪setSiteTitleToTemplateRecord(int $pageId, string $siteTitle): void
268  {
269  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
270 
271  $template = $connection->select(['uid', 'sitetitle'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetch();
272  if (empty($template)) {
273  self::fail('Cannot find root template on page with id: "' . $pageId . '"');
274  }
275  $updateFields = [];
276  $updateFields['sitetitle'] = $siteTitle;
277  $connection->update(
278  'sys_template',
279  $updateFields,
280  ['uid' => $template['uid']]
281  );
282  }
283 }
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\$coreExtensionsToLoad
‪string[] $coreExtensionsToLoad
Definition: TitleTagRenderingTest.php:33
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\setSiteTitleToTemplateRecord
‪setSiteTitleToTemplateRecord(int $pageId, string $siteTitle)
Definition: TitleTagRenderingTest.php:264
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\importDataSet
‪array< string, $configurationToUseInTestInstance=array('FE'=>['cacheHash'=>['enforceValidation'=> false,],],);protected setUp():void { parent::setUp();$this-> importDataSet('EXT:frontend/Tests/Functional/Fixtures/pages-title-tag.xml')
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\titleTagDataProvider
‪titleTagDataProvider()
Definition: TitleTagRenderingTest.php:105
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir_deep
‪static mkdir_deep($directory)
Definition: GeneralUtility.php:2022
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\checkIfCorrectTitleTagIsRendered
‪checkIfCorrectTitleTagIsRendered($pageConfig, $expectations)
Definition: TitleTagRenderingTest.php:237
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\setUpFrontendSite
‪setUpFrontendSite(int $pageId)
Definition: TitleTagRenderingTest.php:74
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\$pathsToLinkInTestInstance
‪string[] $pathsToLinkInTestInstance
Definition: TitleTagRenderingTest.php:39
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering
Definition: LocalizedSiteContentRenderingTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility\writeFile
‪static bool writeFile($file, $content, $changePermissions=false)
Definition: GeneralUtility.php:1836
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest
Definition: TitleTagRenderingTest.php:30