TYPO3 CMS  TYPO3_7-6
IndexerTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
27  protected $subject = null;
28 
32  protected function setUp()
33  {
34  $this->subject = $this->getMock(\TYPO3\CMS\IndexedSearch\Indexer::class, ['dummy']);
35  }
36 
41  {
42  $html = 'test <a href="' . $this->getUniqueId() . '">test</a> test';
43  $result = $this->subject->extractHyperLinks($html);
44  $this->assertEquals(1, count($result));
45  $this->assertEquals('', $result[0]['localPath']);
46  }
47 
52  {
53  $temporaryFileName = tempnam(PATH_site . 'typo3temp/', 't3unit-');
54  $this->testFilesToDelete[] = $temporaryFileName;
55  $html = 'test <a href="testfile">test</a> test';
56  $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = [
57  \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $temporaryFileName,
58  ];
59  $result = $this->subject->extractHyperLinks($html);
60  $this->assertEquals(1, count($result));
61  $this->assertEquals($temporaryFileName, $result[0]['localPath']);
62  }
63 
68  {
69  $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
70  $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
71  $result = $this->subject->extractHyperLinks($html);
72  $this->assertEquals(1, count($result));
73  $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
74  }
75 
80  {
81  $html = 'test <a href="index.php">test</a> test';
82  $result = $this->subject->extractHyperLinks($html);
83  $this->assertEquals(1, count($result));
84  $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
85  }
86 
91  {
92  $path = substr(PATH_typo3, strlen(PATH_site) - 1);
93  $html = 'test <a href="' . $path . 'index.php">test</a> test';
94  $result = $this->subject->extractHyperLinks($html);
95  $this->assertEquals(1, count($result));
96  $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
97  }
98 
103  {
104  $absRefPrefix = '/' . $this->getUniqueId();
105  $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
106  $GLOBALS['TSFE'] = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, [], [], '', false);
107  $config = [
108  'config' => [
109  'absRefPrefix' => $absRefPrefix,
110  ],
111  ];
112  $GLOBALS['TSFE']->config = $config;
113  $result = $this->subject->extractHyperLinks($html);
114  $this->assertEquals(1, count($result));
115  $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
116  }
117 
122  {
123  $baseHref = 'http://example.com/';
124  $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
125  $result = $this->subject->extractBaseHref($html);
126  $this->assertEquals($baseHref, $result);
127  }
128 
135  {
136  $body = <<<EOT
137 <html>
138 <head>
139 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
140 <title>Some Title</title>
141 <link href='css/normalize.css' rel='stylesheet' type='text/css'/>
142 </head>
143 <body>
144 <div>
145 <div class="non_searchable">
146  not searchable content
147 </div>
148 <!--TYPO3SEARCH_begin-->
149 <div class="searchable">
150  lorem ipsum
151 </div>
152 <!--TYPO3SEARCH_end-->
153 <div class="non_searchable">
154  not searchable content
155 </div>
156 </body>
157 </html>
158 EOT;
159  $expected = <<<EOT
160 
161 <div class="searchable">
162  lorem ipsum
163 </div>
164 
165 EOT;
166 
167  $result = $this->subject->typoSearchTags($body);
168  $this->assertTrue($result);
169  $this->assertEquals($expected, $body);
170  }
171 
178  {
179  $body = <<<EOT
180 <html>
181 <head>
182 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
183 <title>Some Title</title>
184 <link href='css/normalize.css' rel='stylesheet' type='text/css'/>
185 </head>
186 <body>
187 <div>
188 <div class="non_searchable">
189  not searchable content
190 </div>
191 <!--TYPO3SEARCH_begin-->
192 <div class="searchable">
193  lorem ipsum
194 </div>
195 <!--TYPO3SEARCH_end-->
196 <div class="non_searchable">
197  not searchable content
198 </div>
199 <!--TYPO3SEARCH_begin-->
200 <div class="searchable">
201  lorem ipsum2
202 </div>
203 <!--TYPO3SEARCH_end-->
204 <div class="non_searchable">
205  not searchable content
206 </div>
207 </body>
208 </html>
209 EOT;
210  $expected = <<<EOT
211 
212 <div class="searchable">
213  lorem ipsum
214 </div>
215 
216 <div class="searchable">
217  lorem ipsum2
218 </div>
219 
220 EOT;
221 
222  $result = $this->subject->typoSearchTags($body);
223  $this->assertTrue($result);
224  $this->assertEquals($expected, $body);
225  }
226 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']