TYPO3 CMS  TYPO3_6-2
IndexerTest.php
Go to the documentation of this file.
1 <?php
3 
24 
30  protected $fixture = NULL;
31 
37  protected $temporaryFileName = '';
38 
42  public function setUp() {
43  $this->fixture = $this->getMock('TYPO3\CMS\IndexedSearch\Indexer', array('dummy'));
44  }
45 
49  public function tearDown() {
50  if ($this->temporaryFileName) {
51  @unlink($this->temporaryFileName);
52  }
53  parent::tearDown();
54  }
55 
60  $html = 'test <a href="' . $this->getUniqueId() . '">test</a> test';
61  $result = $this->fixture->extractHyperLinks($html);
62  $this->assertEquals(1, count($result));
63  $this->assertEquals('', $result[0]['localPath']);
64  }
65 
70  $this->temporaryFileName = tempnam(sys_get_temp_dir(), 't3unit-');
71  $html = 'test <a href="testfile">test</a> test';
72  $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = array(
73  \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $this->temporaryFileName,
74  );
75  $result = $this->fixture->extractHyperLinks($html);
76  $this->assertEquals(1, count($result));
77  $this->assertEquals($this->temporaryFileName, $result[0]['localPath']);
78  }
79 
84  $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
85  $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
86  $result = $this->fixture->extractHyperLinks($html);
87  $this->assertEquals(1, count($result));
88  $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
89  }
90 
95  $html = 'test <a href="index.php">test</a> test';
96  $result = $this->fixture->extractHyperLinks($html);
97  $this->assertEquals(1, count($result));
98  $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
99  }
100 
105  $path = substr(PATH_typo3, strlen(PATH_site) - 1);
106  $html = 'test <a href="' . $path . 'index.php">test</a> test';
107  $result = $this->fixture->extractHyperLinks($html);
108  $this->assertEquals(1, count($result));
109  $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
110  }
111 
116  $absRefPrefix = '/' . $this->getUniqueId();
117  $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
118  $GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
119  $GLOBALS['TSFE']->config['config']['absRefPrefix'] = $absRefPrefix;
120  $result = $this->fixture->extractHyperLinks($html);
121  $this->assertEquals(1, count($result));
122  $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
123  }
124 
129  $baseHref = 'http://example.com/';
130  $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
131  $result = $this->fixture->extractBaseHref($html);
132  $this->assertEquals($baseHref, $result);
133  }
134 
141  $body = <<<EOT
142 <html>
143 <head>
144 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
145 <title>Some Title</title>
146 <link href='css/normalize.css' rel='stylesheet' type='text/css'/>
147 </head>
148 <body>
149 <div>
150 <div class="non_searchable">
151  not searchable content
152 </div>
153 <!--TYPO3SEARCH_begin-->
154 <div class="searchable">
155  lorem ipsum
156 </div>
157 <!--TYPO3SEARCH_end-->
158 <div class="non_searchable">
159  not searchable content
160 </div>
161 </body>
162 </html>
163 EOT;
164  $expected = <<<EOT
165 
166 <div class="searchable">
167  lorem ipsum
168 </div>
169 
170 EOT;
171 
172  $result = $this->fixture->typoSearchTags($body);
173  $this->assertTrue($result);
174  $this->assertEquals($expected, $body);
175  }
176 
183  $body = <<<EOT
184 <html>
185 <head>
186 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
187 <title>Some Title</title>
188 <link href='css/normalize.css' rel='stylesheet' type='text/css'/>
189 </head>
190 <body>
191 <div>
192 <div class="non_searchable">
193  not searchable content
194 </div>
195 <!--TYPO3SEARCH_begin-->
196 <div class="searchable">
197  lorem ipsum
198 </div>
199 <!--TYPO3SEARCH_end-->
200 <div class="non_searchable">
201  not searchable content
202 </div>
203 <!--TYPO3SEARCH_begin-->
204 <div class="searchable">
205  lorem ipsum2
206 </div>
207 <!--TYPO3SEARCH_end-->
208 <div class="non_searchable">
209  not searchable content
210 </div>
211 </body>
212 </html>
213 EOT;
214  $expected = <<<EOT
215 
216 <div class="searchable">
217  lorem ipsum
218 </div>
219 
220 <div class="searchable">
221  lorem ipsum2
222 </div>
223 
224 EOT;
225 
226  $result = $this->fixture->typoSearchTags($body);
227  $this->assertTrue($result);
228  $this->assertEquals($expected, $body);
229  }
230 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]