[TASK] Less strict first install file recognition 50/36350/3
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Thu, 29 Jan 2015 12:25:45 +0000 (13:25 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 29 Jan 2015 17:59:33 +0000 (18:59 +0100)
Now install tool will recognize all files which starts
with FIRST_INSTALL (case insensitive) as a correct
first install file.

This solves common issue beginners hit on Windows
where files are saved with ".txt" extension,
and the extension is hidden by default.

Resolves: #63340
Releases: master
Change-Id: Ia2399e9764a299a416997f16bdbf3c5f915540f3
Reviewed-on: http://review.typo3.org/36350
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Mateusz WojtuƂa <matw88@gmail.com>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Service/EnableFileService.php
typo3/sysext/install/Tests/Unit/Service/EnableFileServiceTest.php [new file with mode: 0644]

index 47c1e43..e81c029 100644 (file)
@@ -35,10 +35,18 @@ class EnableFileService {
        const INSTALL_TOOL_ENABLE_FILE_LIFETIME = 3600;
 
        /**
+        * Path site property, needed for unit testing
+        *
+        * @var string
+        */
+       static protected $sitePath = PATH_site;
+
+       /**
         * @return bool
         */
        static public function isFirstInstallAllowed() {
-               if (!is_dir(PATH_typo3conf) && is_file(self::getFirstInstallFilePath())) {
+               $files = self::getFirstInstallFilePaths();
+               if (!is_dir(PATH_typo3conf) && !empty($files)) {
                        return TRUE;
                }
                return FALSE;
@@ -76,7 +84,12 @@ class EnableFileService {
         * @return bool
         */
        static public function removeFirstInstallFile() {
-               return unlink(self::getFirstInstallFilePath());
+               $result = TRUE;
+               $files = self::getFirstInstallFilePaths();
+               foreach ($files as $file) {
+                       $result = unlink(self::$sitePath . $file) && $result;
+               }
+               return $result;
        }
 
        /**
@@ -165,12 +178,14 @@ class EnableFileService {
        }
 
        /**
-        * Returns the path to the FIRST_INSTALL file
+        * Returns the paths to the FIRST_INSTALL files
         *
-        * @return string
+        * @return array
         */
-       static protected function getFirstInstallFilePath() {
-               return PATH_site . self::FIRST_INSTALL_FILE_PATH;
+       static protected function getFirstInstallFilePaths() {
+               $files = array_filter(scandir(self::$sitePath), function($file) {
+                       return (is_file(self::$sitePath . $file) && preg_match('~^' . self::FIRST_INSTALL_FILE_PATH . '.*~i', $file));
+               });
+               return $files;
        }
-
 }
diff --git a/typo3/sysext/install/Tests/Unit/Service/EnableFileServiceTest.php b/typo3/sysext/install/Tests/Unit/Service/EnableFileServiceTest.php
new file mode 100644 (file)
index 0000000..4d5eab3
--- /dev/null
@@ -0,0 +1,134 @@
+<?php
+namespace TYPO3\CMS\Install\Tests\Unit\Service;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use \org\bovigo\vfs\vfsStream;
+
+/**
+ * Test case
+ */
+class EnableFileServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * Data provider
+        *
+        * @return array
+        */
+       public function getFirstInstallFilePathsDataProvider() {
+               return array(
+                       'first-install-file-present' => array(
+                               array(
+                                       'FIRST_INSTALL2Folder' => array(),
+                                       'FIRST_INSTALL' => '',
+                                       'FIRST_INStall' => '',
+                                       'FIRST_INSTALL.txt' => 'with content',
+                                       'somethingelse' => '',
+                                       'dadadaFIRST_INStall' => '',
+                               ),
+                               array(
+                                       'FIRST_INSTALL',
+                                       'FIRST_INStall',
+                                       'FIRST_INSTALL.txt',
+                               ),
+                       ),
+                       'no-first-install-file' => array(
+                               array(
+                                       'FIRST_INSTALL2Folder' => array(),
+                                       'foo' => '',
+                                       'bar' => '',
+                                       'ddd.txt' => 'with content',
+                                       'somethingelse' => '',
+                                       'dadadaFIRST_INStall' => '',
+                               ),
+                               array(),
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider getFirstInstallFilePathsDataProvider
+        */
+       public function getFirstInstallFilePaths($structure, $expected) {
+               $vfs = vfsStream::setup("root");
+               vfsStream::create($structure, $vfs);
+               /** @var $instance \TYPO3\CMS\Install\Service\EnableFileService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $instance = $this->getAccessibleMock(\TYPO3\CMS\Install\Service\EnableFileService::class, array('dummy'), array(), '', FALSE);
+               $instance->_setStatic('sitePath', 'vfs://root/');
+               $this->assertEquals(array(), array_diff($expected, $instance->_call('getFirstInstallFilePaths')));
+       }
+
+       /**
+        * Data provider
+        *
+        * @return array
+        */
+       public function removeFirstInstallFileDataProvider() {
+               return array(
+                       'first-install-file-present' => array(
+                               array(
+                                       'FIRST_INSTALL2Folder' => array(),
+                                       'FIRST_INSTALL' => '',
+                                       'FIRST_INStall' => '',
+                                       'FIRST_INSTALL.txt' => 'with content',
+                                       'somethingelse' => '',
+                                       'dadadaFIRST_INStall' => '',
+                               ),
+                               array(
+                                       '.',
+                                       '..',
+                                       'FIRST_INSTALL2Folder',
+                                       'somethingelse',
+                                       'dadadaFIRST_INStall',
+                               ),
+                       ),
+                       'no-first-install-file' => array(
+                               array(
+                                       'FIRST_INSTALL2Folder' => array(),
+                                       'foo' => '',
+                                       'bar' => '',
+                                       'ddd.txt' => 'with content',
+                                       'somethingelse' => '',
+                                       'dadadaFIRST_INStall' => '',
+                               ),
+                               array(
+                                       '.',
+                                       '..',
+                                       'FIRST_INSTALL2Folder',
+                                       'foo',
+                                       'bar',
+                                       'ddd.txt',
+                                       'somethingelse',
+                                       'dadadaFIRST_INStall',
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider removeFirstInstallFileDataProvider
+        */
+       public function removeFirstInstallFile($structure, $expected) {
+               $vfs = vfsStream::setup("root");
+               vfsStream::create($structure, $vfs);
+               /** @var $instance \TYPO3\CMS\Install\Service\EnableFileService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $instance = $this->getAccessibleMock(\TYPO3\CMS\Install\Service\EnableFileService::class, array('dummy'), array(), '', FALSE);
+               $instance->_setStatic('sitePath', 'vfs://root/');
+               $instance->_call('removeFirstInstallFile');
+
+               $this->assertEquals(array(), array_diff($expected, scandir('vfs://root/')));
+       }
+}