[TASK] Remove @author lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / Tests / Unit / IndexerTest.php
1 <?php
2 namespace TYPO3\CMS\IndexedSearch\Tests\Unit;
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
17 /**
18 * This class contains unit tests for the indexer
19 */
20 class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * Indexer instance
24 *
25 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\IndexedSearch\Indexer
26 */
27 protected $subject = NULL;
28
29 /**
30 * Sets up the test
31 */
32 protected function setUp() {
33 $this->subject = $this->getMock(\TYPO3\CMS\IndexedSearch\Indexer::class, array('dummy'));
34 }
35
36 /**
37 * @test
38 */
39 public function extractHyperLinksDoesNotReturnNonExistingLocalPath() {
40 $html = 'test <a href="' . $this->getUniqueId() . '">test</a> test';
41 $result = $this->subject->extractHyperLinks($html);
42 $this->assertEquals(1, count($result));
43 $this->assertEquals('', $result[0]['localPath']);
44 }
45
46 /**
47 * @test
48 */
49 public function extractHyperLinksReturnsCorrectFileUsingT3Vars() {
50 $temporaryFileName = tempnam(PATH_site . 'typo3temp/', 't3unit-');
51 $this->testFilesToDelete[] = $temporaryFileName;
52 $html = 'test <a href="testfile">test</a> test';
53 $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = array(
54 \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $temporaryFileName,
55 );
56 $result = $this->subject->extractHyperLinks($html);
57 $this->assertEquals(1, count($result));
58 $this->assertEquals($temporaryFileName, $result[0]['localPath']);
59 }
60
61 /**
62 * @test
63 */
64 public function extractHyperLinksRecurnsCorrectPathWithBaseUrl() {
65 $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
66 $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
67 $result = $this->subject->extractHyperLinks($html);
68 $this->assertEquals(1, count($result));
69 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
70 }
71
72 /**
73 * @test
74 */
75 public function extractHyperLinksFindsCorrectPathWithAbsolutePath() {
76 $html = 'test <a href="index.php">test</a> test';
77 $result = $this->subject->extractHyperLinks($html);
78 $this->assertEquals(1, count($result));
79 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
80 }
81
82 /**
83 * @test
84 */
85 public function extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory() {
86 $path = substr(PATH_typo3, strlen(PATH_site) - 1);
87 $html = 'test <a href="' . $path . 'index.php">test</a> test';
88 $result = $this->subject->extractHyperLinks($html);
89 $this->assertEquals(1, count($result));
90 $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
91 }
92
93 /**
94 * @test
95 */
96 public function extractHyperLinksFindsCorrectPathUsingAbsRefPrefix() {
97 $absRefPrefix = '/' . $this->getUniqueId();
98 $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
99 $GLOBALS['TSFE'] = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array(), '', FALSE);
100 $GLOBALS['TSFE']->config['config']['absRefPrefix'] = $absRefPrefix;
101 $result = $this->subject->extractHyperLinks($html);
102 $this->assertEquals(1, count($result));
103 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
104 }
105
106 /**
107 * @test
108 */
109 public function extractBaseHrefExtractsBaseHref() {
110 $baseHref = 'http://example.com/';
111 $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
112 $result = $this->subject->extractBaseHref($html);
113 $this->assertEquals($baseHref, $result);
114 }
115
116 }