[!!!][TASK] Remove last usages of $GLOBALS[T3_VAR]
[Packages/TYPO3.CMS.git] / typo3 / sysext / indexed_search / Tests / Unit / IndexerTest.php
index 5bcad4e..0e25159 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\IndexedSearch\Tests\Unit;
 
 /*
@@ -14,25 +15,20 @@ namespace TYPO3\CMS\IndexedSearch\Tests\Unit;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
+use TYPO3\CMS\IndexedSearch\Indexer;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
 /**
- * This class contains unit tests for the indexer
+ * Test case
  */
-class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+class IndexerTest extends UnitTestCase
 {
     /**
-     * Indexer instance
-     *
-     * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\IndexedSearch\Indexer
+     * @var bool Reset singletons created by subject
      */
-    protected $subject = null;
-
-    /**
-     * Sets up the test
-     */
-    protected function setUp()
-    {
-        $this->subject = $this->getMock(\TYPO3\CMS\IndexedSearch\Indexer::class, array('dummy'));
-    }
+    protected $resetSingletonInstances = true;
 
     /**
      * @test
@@ -40,7 +36,8 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     public function extractHyperLinksDoesNotReturnNonExistingLocalPath()
     {
         $html = 'test <a href="' . $this->getUniqueId() . '">test</a> test';
-        $result = $this->subject->extractHyperLinks($html);
+        $subject = new Indexer();
+        $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
         $this->assertEquals('', $result[0]['localPath']);
     }
@@ -48,29 +45,14 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     /**
      * @test
      */
-    public function extractHyperLinksReturnsCorrectFileUsingT3Vars()
-    {
-        $temporaryFileName = tempnam(PATH_site . 'typo3temp/var/tests/', 't3unit-');
-        $this->testFilesToDelete[] = $temporaryFileName;
-        $html = 'test <a href="testfile">test</a> test';
-        $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = array(
-            \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $temporaryFileName,
-        );
-        $result = $this->subject->extractHyperLinks($html);
-        $this->assertEquals(1, count($result));
-        $this->assertEquals($temporaryFileName, $result[0]['localPath']);
-    }
-
-    /**
-     * @test
-     */
-    public function extractHyperLinksRecurnsCorrectPathWithBaseUrl()
+    public function extractHyperLinksReturnsCorrectPathWithBaseUrl()
     {
         $baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
         $html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
-        $result = $this->subject->extractHyperLinks($html);
+        $subject = new Indexer();
+        $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -79,9 +61,10 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     public function extractHyperLinksFindsCorrectPathWithAbsolutePath()
     {
         $html = 'test <a href="index.php">test</a> test';
-        $result = $this->subject->extractHyperLinks($html);
+        $subject = new Indexer();
+        $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -89,11 +72,11 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory()
     {
-        $path = substr(PATH_typo3, strlen(PATH_site) - 1);
-        $html = 'test <a href="' . $path . 'index.php">test</a> test';
-        $result = $this->subject->extractHyperLinks($html);
+        $html = 'test <a href="typo3/index.php">test</a> test';
+        $subject = new Indexer();
+        $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/typo3/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -103,11 +86,17 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $absRefPrefix = '/' . $this->getUniqueId();
         $html = 'test <a href="' . $absRefPrefix . 'index.php">test</a> test';
-        $GLOBALS['TSFE'] = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array(), '', false);
-        $GLOBALS['TSFE']->config['config']['absRefPrefix'] = $absRefPrefix;
-        $result = $this->subject->extractHyperLinks($html);
+        $GLOBALS['TSFE'] = $this->createMock(TypoScriptFrontendController::class);
+        $config = [
+            'config' => [
+                'absRefPrefix' => $absRefPrefix,
+            ],
+        ];
+        $GLOBALS['TSFE']->config = $config;
+        $subject = new Indexer();
+        $result = $subject->extractHyperLinks($html);
         $this->assertEquals(1, count($result));
-        $this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
+        $this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
     }
 
     /**
@@ -117,7 +106,8 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $baseHref = 'http://example.com/';
         $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>';
-        $result = $this->subject->extractBaseHref($html);
+        $subject = new Indexer();
+        $result = $subject->extractBaseHref($html);
         $this->assertEquals($baseHref, $result);
     }
 
@@ -159,7 +149,8 @@ EOT;
 
 EOT;
 
-        $result = $this->subject->typoSearchTags($body);
+        $subject = new Indexer();
+        $result = $subject->typoSearchTags($body);
         $this->assertTrue($result);
         $this->assertEquals($expected, $body);
     }
@@ -214,7 +205,8 @@ EOT;
 
 EOT;
 
-        $result = $this->subject->typoSearchTags($body);
+        $subject = new Indexer();
+        $result = $subject->typoSearchTags($body);
         $this->assertTrue($result);
         $this->assertEquals($expected, $body);
     }