‪TYPO3CMS  10.4
IndexerTest.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 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪IndexerTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
41  {
42  $html = 'test <a href="' . ‪StringUtility::getUniqueId() . '">test</a> test';
43  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
44  $result = $subject->extractHyperLinks($html);
45  self::assertEquals(1, count($result));
46  self::assertEquals('', $result[0]['localPath']);
47  }
48 
53  {
54  $baseURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
55  $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
56  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
57  $result = $subject->extractHyperLinks($html);
58  self::assertEquals(1, count($result));
59  self::assertEquals(‪Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
60  }
61 
66  {
67  $html = 'test <a href="index.php">test</a> test';
68  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
69  $result = $subject->extractHyperLinks($html);
70  self::assertEquals(1, count($result));
71  self::assertEquals(‪Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
72  }
73 
78  {
79  $html = 'test <a href="typo3/index.php">test</a> test';
80  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
81  $result = $subject->extractHyperLinks($html);
82  self::assertEquals(1, count($result));
83  self::assertEquals(‪Environment::getPublicPath() . '/typo3/index.php', $result[0]['localPath']);
84  }
85 
90  {
91  $absRefPrefix = '/' . ‪StringUtility::getUniqueId();
92  $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
93  ‪$GLOBALS['TSFE'] = $this->createMock(TypoScriptFrontendController::class);
94  $config = [
95  'config' => [
96  'absRefPrefix' => $absRefPrefix,
97  ],
98  ];
99  ‪$GLOBALS['TSFE']->config = $config;
100  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
101  $result = $subject->extractHyperLinks($html);
102  self::assertEquals(1, count($result));
103  self::assertEquals(‪Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
104  }
105 
109  public function ‪extractBaseHrefExtractsBaseHref()
110  {
111  $baseHref = 'http://example.com/';
112  $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
113  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
114  $result = $subject->extractBaseHref($html);
115  self::assertEquals($baseHref, $result);
116  }
117 
124  {
125  $body = <<<EOT
126 <html>
127 <head>
128 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
129 <title>Some Title</title>
130 <link href='css/normalize.css' rel='stylesheet' type='text/css'/>
131 </head>
132 <body>
133 <div>
134 <div class="non_searchable">
135  not searchable content
136 </div>
137 <!--TYPO3SEARCH_begin-->
138 <div class="searchable">
139  lorem ipsum
140 </div>
141 <!--TYPO3SEARCH_end-->
142 <div class="non_searchable">
143  not searchable content
144 </div>
145 </body>
146 </html>
147 EOT;
148  $expected = <<<EOT
149 
150 <div class="searchable">
151  lorem ipsum
152 </div>
153 
154 EOT;
155 
156  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
157  $result = $subject->typoSearchTags($body);
158  self::assertTrue($result);
159  self::assertEquals($expected, $body);
160  }
161 
168  {
169  $body = <<<EOT
170 <html>
171 <head>
172 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
173 <title>Some Title</title>
174 <link href='css/normalize.css' rel='stylesheet' type='text/css'/>
175 </head>
176 <body>
177 <div>
178 <div class="non_searchable">
179  not searchable content
180 </div>
181 <!--TYPO3SEARCH_begin-->
182 <div class="searchable">
183  lorem ipsum
184 </div>
185 <!--TYPO3SEARCH_end-->
186 <div class="non_searchable">
187  not searchable content
188 </div>
189 <!--TYPO3SEARCH_begin-->
190 <div class="searchable">
191  lorem ipsum2
192 </div>
193 <!--TYPO3SEARCH_end-->
194 <div class="non_searchable">
195  not searchable content
196 </div>
197 </body>
198 </html>
199 EOT;
200  $expected = <<<EOT
201 
202 <div class="searchable">
203  lorem ipsum
204 </div>
205 
206 <div class="searchable">
207  lorem ipsum2
208 </div>
209 
210 EOT;
211 
212  $subject = $this->getMockBuilder(Indexer::class)->disableOriginalConstructor()->addMethods(['dummy'])->getMock();
213  $result = $subject->typoSearchTags($body);
214  self::assertTrue($result);
215  self::assertEquals($expected, $body);
216  }
217 }
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\extractHyperLinksFindsCorrectPathUsingAbsRefPrefix
‪extractHyperLinksFindsCorrectPathUsingAbsRefPrefix()
Definition: IndexerTest.php:88
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\extractHyperLinksDoesNotReturnNonExistingLocalPath
‪extractHyperLinksDoesNotReturnNonExistingLocalPath()
Definition: IndexerTest.php:39
‪TYPO3\CMS\IndexedSearch\Tests\Unit
Definition: IndexerTest.php:18
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\extractHyperLinksReturnsCorrectPathWithBaseUrl
‪extractHyperLinksReturnsCorrectPathWithBaseUrl()
Definition: IndexerTest.php:51
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\typoSearchTagsRemovesBodyContentOutsideMarkers
‪typoSearchTagsRemovesBodyContentOutsideMarkers()
Definition: IndexerTest.php:122
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\extractHyperLinksFindsCorrectPathWithAbsolutePath
‪extractHyperLinksFindsCorrectPathWithAbsolutePath()
Definition: IndexerTest.php:64
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\extractBaseHrefExtractsBaseHref
‪extractBaseHrefExtractsBaseHref()
Definition: IndexerTest.php:108
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory
‪extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory()
Definition: IndexerTest.php:76
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\typoSearchTagsHandlesMultipleMarkerPairs
‪typoSearchTagsHandlesMultipleMarkerPairs()
Definition: IndexerTest.php:166
‪TYPO3\CMS\IndexedSearch\Indexer
Definition: Indexer.php:37
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest
Definition: IndexerTest.php:31
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\IndexedSearch\Tests\Unit\IndexerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: IndexerTest.php:34