TYPO3  7.6
PageGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Page;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
23 class PageGeneratorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
24 {
29 
34 
38  protected function setUp()
39  {
40  $this->pageGeneratorFixture = new PageGeneratorFixture();
41  $this->contentObjectRenderer = new ContentObjectRenderer();
42  }
43 
48  {
49  return array(
50  'simple meta' => array(
51  array(
52  'author' => 'Markus Klein',
53  ),
54  false,
55  array(
56  '<meta name="generator" content="TYPO3 CMS">',
57  '<meta name="author" content="Markus Klein">',
58  )
59  ),
60  'simple meta xhtml' => array(
61  array(
62  'author' => 'Markus Klein',
63  ),
64  true,
65  array(
66  '<meta name="generator" content="TYPO3 CMS" />',
67  '<meta name="author" content="Markus Klein" />',
68  )
69  ),
70  'meta with nested stdWrap' => array(
71  array(
72  'author' => 'Markus ',
73  'author.' => array('stdWrap.' => array('wrap' => '|Klein'))
74  ),
75  false,
76  array(
77  '<meta name="generator" content="TYPO3 CMS">',
78  '<meta name="author" content="Markus Klein">',
79  )
80  ),
81  'httpEquivalent meta' => array(
82  array(
83  'X-UA-Compatible' => 'IE=edge,chrome=1',
84  'X-UA-Compatible.' => array('httpEquivalent' => 1)
85  ),
86  false,
87  array(
88  '<meta name="generator" content="TYPO3 CMS">',
89  '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">'
90  )
91  ),
92  'httpEquivalent meta xhtml' => array(
93  array(
94  'X-UA-Compatible' => 'IE=edge,chrome=1',
95  'X-UA-Compatible.' => array('httpEquivalent' => 1)
96  ),
97  true,
98  array(
99  '<meta name="generator" content="TYPO3 CMS" />',
100  '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />'
101  )
102  ),
103  'httpEquivalent meta xhtml new notation' => array(
104  array(
105  'X-UA-Compatible' => 'IE=edge,chrome=1',
106  'X-UA-Compatible.' => array('attribute' => 'http-equiv')
107  ),
108  true,
109  array(
110  '<meta name="generator" content="TYPO3 CMS" />',
111  '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />'
112  )
113  ),
114  'refresh meta' => array(
115  array(
116  'refresh' => '10',
117  ),
118  false,
119  array(
120  '<meta name="generator" content="TYPO3 CMS">',
121  '<meta http-equiv="refresh" content="10">',
122  )
123  ),
124  'refresh meta new notation' => array(
125  array(
126  'refresh' => '10',
127  'refresh.' => array('attribute' => 'http-equiv')
128  ),
129  false,
130  array(
131  '<meta name="generator" content="TYPO3 CMS">',
132  '<meta http-equiv="refresh" content="10">',
133  )
134  ),
135  'refresh meta new notation wins form old' => array(
136  array(
137  'refresh' => '10',
138  'refresh.' => array('attribute' => 'http-equiv-new')
139  ),
140  false,
141  array(
142  '<meta name="generator" content="TYPO3 CMS">',
143  '<meta http-equiv-new="refresh" content="10">',
144  )
145  ),
146  'meta with dot' => array(
147  array(
148  'DC.author' => 'Markus Klein',
149  ),
150  false,
151  array(
152  '<meta name="generator" content="TYPO3 CMS">',
153  '<meta name="DC.author" content="Markus Klein">',
154  )
155  ),
156  'meta with colon' => array(
157  array(
158  'OG:title' => 'Magic Tests',
159  ),
160  false,
161  array(
162  '<meta name="generator" content="TYPO3 CMS">',
163  '<meta name="OG:title" content="Magic Tests">',
164  )
165  ),
166  'different attribute name' => array(
167  array(
168  'og:site_title' => 'My TYPO3 site',
169  'og:site_title.' => array('attribute' => 'property'),
170  ),
171  false,
172  array(
173  '<meta name="generator" content="TYPO3 CMS">',
174  '<meta property="og:site_title" content="My TYPO3 site">',
175  )
176  ),
177  'multi value attribute name' => array(
178  array(
179  'og:locale:alternate.' => array(
180  'attribute' => 'property',
181  'value' => array(
182  10 => 'nl_NL',
183  20 => 'de_DE',
184  )
185  ),
186  ),
187  false,
188  array(
189  '<meta name="generator" content="TYPO3 CMS">',
190  '<meta property="og:locale:alternate" content="nl_NL">',
191  '<meta property="og:locale:alternate" content="de_DE">',
192  )
193  ),
194  'multi value attribute name (empty values are skipped)' => array(
195  array(
196  'og:locale:alternate.' => array(
197  'attribute' => 'property',
198  'value' => array(
199  10 => 'nl_NL',
200  20 => '',
201  30 => 'de_DE',
202  )
203  ),
204  ),
205  false,
206  array(
207  '<meta name="generator" content="TYPO3 CMS">',
208  '<meta property="og:locale:alternate" content="nl_NL">',
209  '<meta property="og:locale:alternate" content="de_DE">',
210  )
211  ),
212  'meta with empty string value' => array(
213  array(
214  'custom:key' => '',
215  ),
216  false,
217  array(
218  '<meta name="generator" content="TYPO3 CMS">',
219  )
220  ),
221  'meta with 0 value' => array(
222  array(
223  'custom:key' => '0',
224  ),
225  false,
226  array(
227  '<meta name="generator" content="TYPO3 CMS">',
228  '<meta name="custom:key" content="0">',
229  )
230  ),
231  );
232  }
233 
242  public function generateMetaTagHtmlGeneratesCorrectTags(array $typoScript, $xhtml, array $expectedTags)
243  {
244  $result = $this->pageGeneratorFixture->callGenerateMetaTagHtml($typoScript, $xhtml, $this->contentObjectRenderer);
245  $this->assertSame($expectedTags, $result);
246  }
247 
252  {
253  return array(
254  'one simple search word' => array(
255  array('test'),
256  false,
257  'test',
258  ),
259  'one simple search word with standalone words' => array(
260  array('test'),
261  true,
262  '[[:space:]]test[[:space:]]',
263  ),
264  'two simple search words' => array(
265  array('test', 'test2'),
266  false,
267  'test|test2',
268  ),
269  'two simple search words with standalone words' => array(
270  array('test', 'test2'),
271  true,
272  '[[:space:]]test[[:space:]]|[[:space:]]test2[[:space:]]',
273  ),
274  'word with regex chars' => array(
275  array('A \\ word with / a bunch of [] regex () chars .*'),
276  false,
277  'A \\\\ word with \\/ a bunch of \\[\\] regex \\(\\) chars \\.\\*',
278  ),
279  );
280  }
281 
290  public function initializeSearchWordDataInTsfeBuildsCorrectRegex(array $searchWordGetParameters, $enableStandaloneSearchWords, $expectedRegex)
291  {
292  $_GET['sword_list'] = $searchWordGetParameters;
293 
294  $GLOBALS['TSFE'] = new \stdClass();
295  if ($enableStandaloneSearchWords) {
296  $GLOBALS['TSFE']->config = array('config' => array('sword_standAlone' => 1));
297  }
298 
299  $this->pageGeneratorFixture->callInitializeSearchWordDataInTsfe();
300  $this->assertEquals($GLOBALS['TSFE']->sWordRegEx, $expectedRegex);
301  }
302 }