[TASK] Use Environment API instead of PATH_site in EXT:backend 29/57229/5
authorBenni Mack <benni@typo3.org>
Fri, 15 Jun 2018 13:31:30 +0000 (15:31 +0200)
committerJan Helke <typo3@helke.de>
Fri, 15 Jun 2018 15:26:51 +0000 (17:26 +0200)
Several places of the PATH_site constant in EXT:backend are replaced
by the new Environment API.

Resolves: #85272
Releases: master
Change-Id: I992b07a5bde377f9a65798eaf9ec797433eb9ce4
Reviewed-on: https://review.typo3.org/57229
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/backend/Classes/Backend/Avatar/Image.php
typo3/sysext/backend/Classes/Controller/LoginController.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php
typo3/sysext/backend/Tests/Unit/Tree/TreeNodeTest.php

index 48cb595..5e18721 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Backend\Backend\Avatar;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 
@@ -62,7 +63,7 @@ class Image
     {
         $url = $this->url;
         if ($relativeToCurrentScript && !GeneralUtility::isValidUrl($url)) {
-            $url = PathUtility::getAbsoluteWebPath(PATH_site . $url);
+            $url = PathUtility::getAbsoluteWebPath(Environment::getPublicPath() . '/' . $url);
         }
         return $url;
     }
index 43d4611..08387e4 100644 (file)
@@ -451,7 +451,7 @@ class LoginController implements LoggerAwareInterface
     /**
      * Returns the uri of a relative reference, resolves the "EXT:" prefix
      * (way of referring to files inside extensions) and checks that the file is inside
-     * the PATH_site of the TYPO3 installation
+     * the project root of the TYPO3 installation
      *
      * @param string $filename The input filename/filepath to evaluate
      * @return string Returns the filename of $filename if valid, otherwise blank string.
index a048a89..eb22471 100644 (file)
@@ -945,7 +945,7 @@ function jumpToUrl(URL) {
     /**
      * Returns the uri of a relative reference, resolves the "EXT:" prefix
      * (way of referring to files inside extensions) and checks that the file is inside
-     * the PATH_site of the TYPO3 installation
+     * the project root of the TYPO3 installation
      *
      * @param string $filename The input filename/filepath to evaluate
      * @return string Returns the filename of $filename if valid, otherwise blank string.
index f521cdb..7a4b0ce 100644 (file)
@@ -1297,7 +1297,7 @@ class BackendUtility
      * @param string $field Field is pointing to the list of image files
      * @param string $backPath Back path prefix for image tag src="" field
      * @param string $thumbScript UNUSED since FAL
-     * @param string $uploaddir Optional: $uploaddir is the directory relative to PATH_site where the image files from the $field value is found (Is by default set to the entry in $GLOBALS['TCA'] for that field! so you don't have to!)
+     * @param string $uploaddir Optional: $uploaddir is the directory relative to Environment::getPublicPath() where the image files from the $field value is found (Is by default set to the entry in $GLOBALS['TCA'] for that field! so you don't have to!)
      * @param int $abs UNUSED
      * @param string $tparams Optional: $tparams is additional attributes for the image tags
      * @param int|string $size Optional: $size is [w]x[h] of the thumbnail. 64 is default.
@@ -3686,7 +3686,7 @@ class BackendUtility
      * Counting references to a record/file
      *
      * @param string $table Table name (or "_FILE" if its a file)
-     * @param string $ref Reference: If table, then int-uid, if _FILE, then file reference (relative to PATH_site)
+     * @param string $ref Reference: If table, then int-uid, if _FILE, then file reference (relative to Environment::getPublicPath())
      * @param string $msg Message with %s, eg. "There were %s records pointing to this file!
      * @param string|null $count Reference count
      * @return string Output string (or int count value if no msg string specified)
@@ -3707,7 +3707,7 @@ class BackendUtility
 
             // Look up the path:
             if ($table === '_FILE') {
-                if (!GeneralUtility::isFirstPartOfStr($ref, PATH_site)) {
+                if (!GeneralUtility::isFirstPartOfStr($ref, Environment::getPublicPath())) {
                     return '';
                 }
 
index e5e916f..d86b933 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Module\ModuleLoader;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
@@ -1229,24 +1230,24 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
         ];
 
-        mkdir(PATH_site . $directory);
-        $this->testFilesToDelete[] = PATH_site . $directory;
-        touch(PATH_site . $directory . 'anImage.gif');
-        touch(PATH_site . $directory . 'aFile.txt');
-        mkdir(PATH_site . $directory . '/subdir');
-        touch(PATH_site . $directory . '/subdir/anotherImage.gif');
+        mkdir(Environment::getPublicPath() . '/' . $directory);
+        $this->testFilesToDelete[] = Environment::getPublicPath() . '/' . $directory;
+        touch(Environment::getPublicPath() . '/' . $directory . 'anImage.gif');
+        touch(Environment::getPublicPath() . '/' . $directory . 'aFile.txt');
+        mkdir(Environment::getPublicPath() . '/' . $directory . '/subdir');
+        touch(Environment::getPublicPath() . '/' . $directory . '/subdir/anotherImage.gif');
 
         $expectedItems = [
             0 => [
                 0 => 'anImage.gif',
                 1 => 'anImage.gif',
-                2 => PATH_site . $directory . 'anImage.gif',
+                2 => Environment::getPublicPath() . '/' . $directory . 'anImage.gif',
                 3 => null,
             ],
             1 => [
                 0 => 'subdir/anotherImage.gif',
                 1 => 'subdir/anotherImage.gif',
-                2 => PATH_site . $directory . 'subdir/anotherImage.gif',
+                2 => Environment::getPublicPath() . '/' . $directory . 'subdir/anotherImage.gif',
                 3 => null,
             ],
         ];
index 0b2b933..9e7c604 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Backend\Tests\Unit\Tree;
 
 /*
@@ -14,37 +15,32 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Tree;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Tree\TreeNode;
+use TYPO3\CMS\Backend\Tree\TreeNodeCollection;
+use TYPO3\CMS\Backend\Tree\TreeRepresentationNode;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
 /**
- * Testcase for class \TYPO3\CMS\Backend\Tree\TreeNode.
+ * Test case
  */
-class TreeNodeTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class TreeNodeTest extends UnitTestCase
 {
-    //////////////////////
-    // Utility functions
-    //////////////////////
     /**
-     * Returns the absolute fixtures path for this testcase.
-     *
-     * @return string the absolute fixtures path for this testcase, will not be empty
+     * @test
      */
-    private function determineFixturesPath()
-    {
-        // We have to take the whole relative path as otherwise this test fails on Windows systems
-        return PATH_site . 'typo3/sysext/backend/Tests/Unit/Tree/Fixtures/';
-    }
-
-    protected function setUpNodeTestData()
+    public function serializeFixture()
     {
-        $fixture = new \TYPO3\CMS\Backend\Tree\TreeNode();
+        $expected = trim(file_get_contents(__DIR__ . '/Fixtures/serialized.txt'));
+        $fixture = new TreeNode();
         $fixture->setId('Root');
-        $nodeCollection = new \TYPO3\CMS\Backend\Tree\TreeNodeCollection();
+        $nodeCollection = new TreeNodeCollection();
         for ($i = 0; $i < 10; ++$i) {
-            $node = new \TYPO3\CMS\Backend\Tree\TreeNode();
+            $node = new TreeNode();
             $node->setId($i);
             $node->setParentNode($fixture);
-            $subNodeCollection = new \TYPO3\CMS\Backend\Tree\TreeNodeCollection();
+            $subNodeCollection = new TreeNodeCollection();
             for ($j = 0; $j < 5; ++$j) {
-                $subNode = new \TYPO3\CMS\Backend\Tree\TreeRepresentationNode();
+                $subNode = new TreeRepresentationNode();
                 $subNode->setId($j);
                 $subNode->setLabel('SubTest');
                 $subNode->setType('Type');
@@ -58,19 +54,6 @@ class TreeNodeTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
             $nodeCollection->append($node);
         }
         $fixture->setChildNodes($nodeCollection);
-        return $fixture;
-    }
-
-    ///////////////
-    // Test cases
-    ///////////////
-    /**
-     * @test
-     */
-    public function serializeFixture()
-    {
-        $expected = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
-        $fixture = $this->setUpNodeTestData();
         $serializedString = trim($fixture->serialize());
         $this->assertSame($expected, $serializedString);
     }
@@ -80,8 +63,8 @@ class TreeNodeTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function deserializeFixture()
     {
-        $source = trim(file_get_contents($this->determineFixturesPath() . 'serialized.txt'));
-        $node = new \TYPO3\CMS\Backend\Tree\TreeNode();
+        $source = trim(file_get_contents(__DIR__ . '/Fixtures/serialized.txt'));
+        $node = new TreeNode();
         $node->unserialize($source);
         $serializedString = $node->serialize();
         $this->assertSame($source, $serializedString);
@@ -92,9 +75,8 @@ class TreeNodeTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function compareNodes()
     {
-        $node = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => '15']);
-        $otherNode = new \TYPO3\CMS\Backend\Tree\TreeNode(['id' => '5']);
-        $compareResult = $node->compareTo($otherNode);
+        $node = new TreeNode(['id' => '15']);
+        $otherNode = new TreeNode(['id' => '5']);
         $otherNode->setId('25');
         $compareResult = $node->compareTo($otherNode);
         $this->assertSame(-1, $compareResult);