[TASK] Remove @package and @subpackage annotations
[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 class contains unit tests for the indexer
6 *
7 * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
8 * @author Christian Kuhn <lolli@schwarzbu.ch>
9 */
10 class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
11
12 /**
13 * Enable backup of global and system variables
14 *
15 * @var boolean
16 */
17 protected $backupGlobals = TRUE;
18
19 /**
20 * Indexer instance
21 *
22 * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\IndexedSearch\Indexer
23 */
24 protected $fixture = NULL;
25
26 /**
27 * A name of the temporary file
28 *
29 * @var string
30 */
31 protected $temporaryFileName = '';
32
33 /**
34 * Sets up the test
35 */
36 public function setUp() {
37 $this->fixture = $this->getMock('TYPO3\CMS\IndexedSearch\Indexer', array('dummy'));
38 }
39
40 /**
41 * Explicitly clean up the indexer object to prevent any memory leaks
42 */
43 public function tearDown() {
44 $this->fixture = NULL;
45 if ($this->temporaryFileName) {
46 @unlink($this->temporaryFileName);
47 }
48 }
49
50 /**
51 * @test
52 */
53 public function extractHyperLinksDoesNotReturnNonExistingLocalPath() {
54 $html = 'test <a href="' . md5(uniqid('')) . '">test</a> test';
55 $result = $this->fixture->extractHyperLinks($html);
56 $this->assertEquals(1, count($result));
57 $this->assertEquals('', $result[0]['localPath']);
58 }
59
60 /**
61 * @test
62 */
63 public function extractHyperLinksReturnsCorrectFileUsingT3Vars() {
64 $this->temporaryFileName = tempnam(sys_get_temp_dir(), 't3unit-');
65 $html = 'test <a href="testfile">test</a> test';
66 $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = array(
67 \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $this->temporaryFileName,
68 );
69 $result = $this->fixture->extractHyperLinks($html);
70 $this->assertEquals(1, count($result));
71 $this->assertEquals($this->temporaryFileName, $result[0]['localPath']);
72 }
73
74 /**
75 * @test
76 */
77 public function extractHyperLinksRecurnsCorrectPathWithBaseUrl() {
78 $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
79 $html = 'test <a href="' . $baseURL . '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 extractHyperLinksFindsCorrectPathWithAbsolutePath() {
89 $html = 'test <a href="index.php">test</a> test';
90 $result = $this->fixture->extractHyperLinks($html);
91 $this->assertEquals(1, count($result));
92 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
93 }
94
95 /**
96 * @test
97 */
98 public function extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory() {
99 $path = substr(PATH_typo3, strlen(PATH_site) - 1);
100 $html = 'test <a href="' . $path . 'index.php">test</a> test';
101 $result = $this->fixture->extractHyperLinks($html);
102 $this->assertEquals(1, count($result));
103 $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
104 }
105
106 /**
107 * @test
108 */
109 public function extractHyperLinksFindsCorrectPathUsingAbsRefPrefix() {
110 $absRefPrefix = '/' . md5(uniqid(''));
111 $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
112 $GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
113 $GLOBALS['TSFE']->config['config']['absRefPrefix'] = $absRefPrefix;
114 $result = $this->fixture->extractHyperLinks($html);
115 $this->assertEquals(1, count($result));
116 $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
117 }
118
119 /**
120 * @test
121 */
122 public function extractBaseHrefExtractsBaseHref() {
123 $baseHref = 'http://example.com/';
124 $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
125 $result = $this->fixture->extractBaseHref($html);
126 $this->assertEquals($baseHref, $result);
127 }
128
129 }
130
131
132 ?>