‪TYPO3CMS  9.5
TitleTagRenderingTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
21 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
27 class ‪TitleTagRenderingTest extends FunctionalTestCase
28 {
32  protected ‪$coreExtensionsToLoad = [
33  'core', 'frontend', 'seo'
34  ];
35 
39  protected ‪$pathsToLinkInTestInstance = [
40  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
41  ];
42 
43  protected function ‪setUp()
44  {
45  parent::setUp();
46  $this->importDataSet('EXT:frontend/Tests/Functional/Fixtures/pages-title-tag.xml');
47  $this->setUpFrontendRootPage(
48  1,
49  ['EXT:frontend/Tests/Functional/Rendering/Fixtures/TitleTagRenderingTest.typoscript']
50  );
52  1,
53  'Site Title'
54  );
55  }
56 
57  public function ‪titleTagDataProvider(): array
58  {
59  return [
60  [
61  [
62  'pageId' => 1000,
63  ],
64  [
65  'assertRegExp' => '#<title>Site Title: Root 1000</title>#',
66  'assertNotRegExp' => '',
67  ]
68  ],
69  [
70  [
71  'pageId' => 1001,
72  ],
73  [
74  'assertRegExp' => '#<title>Site Title: SEO Root 1001</title>#',
75  'assertNotRegExp' => '',
76  ]
77  ],
78  [
79  [
80  'pageId' => 1000,
81  'noPageTitle' => 1,
82  ],
83  [
84  'assertRegExp' => '#<title>Site Title</title>#',
85  'assertNotRegExp' => '',
86  ]
87  ],
88  [
89  [
90  'pageId' => 1001,
91  'noPageTitle' => 1,
92  ],
93  [
94  'assertRegExp' => '#<title>Site Title</title>#',
95  'assertNotRegExp' => '',
96  ]
97  ],
98  [
99  [
100  'pageId' => 1000,
101  'noPageTitle' => 2,
102  ],
103  [
104  'assertRegExp' => '',
105  'assertNotRegExp' => '#<title>.*</title>#',
106  ]
107  ],
108  [
109  [
110  'pageId' => 1001,
111  'noPageTitle' => 2,
112  ],
113  [
114  'assertRegExp' => '',
115  'assertNotRegExp' => '#<title>.*</title>#',
116  ]
117  ],
118  [
119  [
120  'pageId' => 1000,
121  'noPageTitle' => 2,
122  'headerData' => 1
123  ],
124  [
125  'assertRegExp' => '#<title>Header Data Title</title>#',
126  'assertNotRegExp' => '',
127  ]
128  ],
129  [
130  [
131  'pageId' => 1001,
132  'noPageTitle' => 2,
133  'headerData' => 1
134  ],
135  [
136  'assertRegExp' => '#<title>Header Data Title</title>#',
137  'assertNotRegExp' => '',
138  ]
139  ],
140  [
141  [
142  'pageId' => 1000,
143  'pageTitleTS' => 1
144  ],
145  [
146  'assertRegExp' => '#<title>SITE TITLE: ROOT 1000</title>#',
147  'assertNotRegExp' => '',
148  ]
149  ],
150  ];
151  }
152 
159  public function ‪checkIfCorrectTitleTagIsRendered($pageConfig, $expectations): void
160  {
161  $response = $this->executeFrontendRequest(
162  (new InternalRequest())->withQueryParameters([
163  'id' => (int)$pageConfig['pageId'],
164  'noPageTitle' => (int)$pageConfig['noPageTitle'],
165  'headerData' => (int)$pageConfig['headerData'],
166  'pageTitleTS' => (int)$pageConfig['pageTitleTS']
167  ])
168  );
169  $content = (string)$response->getBody();
170  if ($expectations['assertRegExp']) {
171  $this->assertRegExp($expectations['assertRegExp'], $content);
172  }
173  if ($expectations['assertNotRegExp']) {
174  $this->assertNotRegExp($expectations['assertNotRegExp'], $content);
175  }
176  }
177 
184  protected function ‪setSiteTitleToTemplateRecord(int $pageId, string $siteTitle): void
185  {
186  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template');
187 
188  $template = $connection->select(['uid', 'sitetitle'], 'sys_template', ['pid' => $pageId, 'root' => 1])->fetch();
189  if (empty($template)) {
190  $this->fail('Cannot find root template on page with id: "' . $pageId . '"');
191  }
192  $updateFields['sitetitle'] = $siteTitle;
193  $connection->update(
194  'sys_template',
195  $updateFields,
196  ['uid' => $template['uid']]
197  );
198  }
199 }
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\$coreExtensionsToLoad
‪string[] $coreExtensionsToLoad
Definition: TitleTagRenderingTest.php:31
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\setSiteTitleToTemplateRecord
‪setSiteTitleToTemplateRecord(int $pageId, string $siteTitle)
Definition: TitleTagRenderingTest.php:182
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\titleTagDataProvider
‪titleTagDataProvider()
Definition: TitleTagRenderingTest.php:55
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\setUp
‪setUp()
Definition: TitleTagRenderingTest.php:41
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\checkIfCorrectTitleTagIsRendered
‪checkIfCorrectTitleTagIsRendered($pageConfig, $expectations)
Definition: TitleTagRenderingTest.php:157
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest\$pathsToLinkInTestInstance
‪string[] $pathsToLinkInTestInstance
Definition: TitleTagRenderingTest.php:37
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering
Definition: LocalizedContentRenderingTest.php:4
‪TYPO3\CMS\Frontend\Tests\Functional\Rendering\TitleTagRenderingTest
Definition: TitleTagRenderingTest.php:28