[CLEANUP] Move test file deletion into UnitTestCase class
[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 * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
21 * @author Christian Kuhn <lolli@schwarzbu.ch>
22 */
23 class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
24
25 /**
26 * Indexer instance
27 *
28 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\IndexedSearch\Indexer
29 */
30 protected $fixture = NULL;
31
32 /**
33 * Sets up the test
34 */
35 public function setUp() {
36 $this->fixture = $this->getMock('TYPO3\CMS\IndexedSearch\Indexer', array('dummy'));
37 }
38
39 /**
40 * @test
41 */
42 public function extractHyperLinksDoesNotReturnNonExistingLocalPath() {
43 $html = 'test <a href="' . md5(uniqid('')) . '">test</a> test';
44 $result = $this->fixture->extractHyperLinks($html);
45 $this->assertEquals(1, count($result));
46 $this->assertEquals('', $result[0]['localPath']);
47 }
48
49 /**
50 * @test
51 */
52 public function extractHyperLinksReturnsCorrectFileUsingT3Vars() {
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'] = array(
57 \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $temporaryFileName,
58 );
59 $result = $this->fixture->extractHyperLinks($html);
60 $this->assertEquals(1, count($result));
61 $this->assertEquals($temporaryFileName, $result[0]['localPath']);
62 }
63
64 /**
65 * @test
66 */
67 public function extractHyperLinksRecurnsCorrectPathWithBaseUrl() {
68 $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
69 $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
70 $result = $this->fixture->extractHyperLinks($html);
71 $this->assertEquals(1, count($result));
72 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
73 }
74
75 /**
76 * @test
77 */
78 public function extractHyperLinksFindsCorrectPathWithAbsolutePath() {
79 $html = 'test <a href="index.php">test</a> test';
80 $result = $this->fixture->extractHyperLinks($html);
81 $this->assertEquals(1, count($result));
82 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
83 }
84
85 /**
86 * @test
87 */
88 public function extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory() {
89 $path = substr(PATH_typo3, strlen(PATH_site) - 1);
90 $html = 'test <a href="' . $path . 'index.php">test</a> test';
91 $result = $this->fixture->extractHyperLinks($html);
92 $this->assertEquals(1, count($result));
93 $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
94 }
95
96 /**
97 * @test
98 */
99 public function extractHyperLinksFindsCorrectPathUsingAbsRefPrefix() {
100 $absRefPrefix = '/' . md5(uniqid(''));
101 $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
102 $GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
103 $GLOBALS['TSFE']->config['config']['absRefPrefix'] = $absRefPrefix;
104 $result = $this->fixture->extractHyperLinks($html);
105 $this->assertEquals(1, count($result));
106 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
107 }
108
109 /**
110 * @test
111 */
112 public function extractBaseHrefExtractsBaseHref() {
113 $baseHref = 'http://example.com/';
114 $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
115 $result = $this->fixture->extractBaseHref($html);
116 $this->assertEquals($baseHref, $result);
117 }
118
119 }