[BUGFIX] Use finder instance correctly 39/59839/13
authorJan Delius <me@jandelius.eu>
Mon, 4 Mar 2019 12:52:41 +0000 (13:52 +0100)
committerSusanne Moog <look@susi.dev>
Sun, 14 Apr 2019 15:28:26 +0000 (17:28 +0200)
Within SiteTcaConfiguration, the $finder is now reused as much as
possible. A new clean instance is used for the individual actions.

Resolves: #87832
Releases: master, 9.5
Change-Id: I34f2d08c51042f2cfe6b4a09ac6152e0b552ab14
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/59839
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Rico Drexler <rico.drexler@gmx.de>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <look@susi.dev>
typo3/sysext/backend/Classes/Configuration/SiteTcaConfiguration.php
typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a/Configuration/SiteConfiguration/Overrides/site.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a/ext_emconf.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b/Configuration/SiteConfiguration/Overrides/site.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b/ext_emconf.php [new file with mode: 0644]
typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/SiteConfigurationOverridesTest.php [new file with mode: 0644]

index f3da594..8d51a41 100644 (file)
@@ -45,26 +45,35 @@ class SiteTcaConfiguration
         $GLOBALS['SiteConfiguration'] = [];
         $activePackages = GeneralUtility::makeInstance(PackageManager::class)->getActivePackages();
         // First load "full table" files from Configuration/SiteConfiguration
-        $finder = new Finder();
+        $finder = (new Finder())->files()->depth(0)->name('*.php');
+        $hasDirectoryEntries = false;
         foreach ($activePackages as $package) {
             try {
-                $finder->files()->depth(0)->name('*.php')->in($package->getPackagePath() . 'Configuration/SiteConfiguration');
+                $finder->in($package->getPackagePath() . 'Configuration/SiteConfiguration');
             } catch (\InvalidArgumentException $e) {
                 // No such directory in this package
                 continue;
             }
+            $hasDirectoryEntries = true;
+        }
+        if ($hasDirectoryEntries) {
             foreach ($finder as $fileInfo) {
                 $GLOBALS['SiteConfiguration'][substr($fileInfo->getBasename(), 0, -4)] = require $fileInfo->getPathname();
             }
         }
         // Execute override files from Configuration/SiteConfiguration/Overrides
+        $finder = (new Finder())->files()->depth(0)->name('*.php');
+        $hasDirectoryEntries = false;
         foreach ($activePackages as $package) {
             try {
-                $finder->files()->depth(0)->name('*.php')->in($package->getPackagePath() . 'Configuration/SiteConfiguration/Overrides');
+                $finder->in($package->getPackagePath() . 'Configuration/SiteConfiguration/Overrides');
             } catch (\InvalidArgumentException $e) {
                 // No such directory in this package
                 continue;
             }
+            $hasDirectoryEntries = true;
+        }
+        if ($hasDirectoryEntries) {
             foreach ($finder as $fileInfo) {
                 require $fileInfo->getPathname();
             }
diff --git a/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a/Configuration/SiteConfiguration/Overrides/site.php b/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a/Configuration/SiteConfiguration/Overrides/site.php
new file mode 100644 (file)
index 0000000..56527c9
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+declare(strict_types = 1);
+defined('TYPO3_MODE') or die();
+
+$GLOBALS['SiteConfiguration']['site']['columns']['tx_a_a'] = [
+    'label' => 'a',
+    'description' => '',
+    'config' => [
+        'type' => 'input',
+        'size' => 25,
+        'max' => 255,
+    ]
+];
+
+$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',tx_a_a';
diff --git a/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a/ext_emconf.php b/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a/ext_emconf.php
new file mode 100644 (file)
index 0000000..bdd1dfe
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+$EM_CONF[$_EXTKEY] = [
+    'title' => '',
+    'description' => '',
+    'category' => 'example',
+    'author' => '',
+    'author_company' => '',
+    'author_email' => '',
+    'state' => 'stable',
+    'uploadfolder' => 0,
+    'createDirs' => '',
+    'clearCacheOnLoad' => 1,
+    'version' => '10.0.0',
+    'constraints' => [
+        'depends' => [
+            'typo3' => '10.0.0',
+        ],
+        'conflicts' => [],
+        'suggests' => [],
+    ],
+];
diff --git a/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b/Configuration/SiteConfiguration/Overrides/site.php b/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b/Configuration/SiteConfiguration/Overrides/site.php
new file mode 100644 (file)
index 0000000..eacc9c1
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+declare(strict_types = 1);
+defined('TYPO3_MODE') or die();
+
+$GLOBALS['SiteConfiguration']['site']['columns']['tx_b_a'] = [
+    'label' => 'a',
+    'config' => [
+        'type' => 'input',
+        'size' => 25,
+        'max' => 255,
+    ]
+];
+
+$GLOBALS['SiteConfiguration']['site']['types']['0']['showitem'] .= ',tx_b_a';
+
+$GLOBALS['SiteConfiguration']['site']['columns']['tx_a_a']['description'] = 'Awesome description by extension b';
diff --git a/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b/ext_emconf.php b/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b/ext_emconf.php
new file mode 100644 (file)
index 0000000..0edeaff
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+$EM_CONF[$_EXTKEY] = [
+    'title' => '',
+    'description' => '',
+    'category' => 'example',
+    'author' => '',
+    'author_company' => '',
+    'author_email' => '',
+    'state' => 'stable',
+    'uploadfolder' => 0,
+    'createDirs' => '',
+    'clearCacheOnLoad' => 1,
+    'version' => '10.0.0',
+    'constraints' => [
+        'depends' => [
+            'typo3' => '10.0.0',
+            'a' => '10.0.0',
+        ],
+        'conflicts' => [],
+        'suggests' => [],
+    ],
+];
diff --git a/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/SiteConfigurationOverridesTest.php b/typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/SiteConfigurationOverridesTest.php
new file mode 100644 (file)
index 0000000..01a132e
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Backend\Tests\Functional\Configuration\SiteConfiguration;
+
+/*
+ * 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 TYPO3\CMS\Backend\Configuration\SiteTcaConfiguration;
+use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
+
+/**
+ * Test case for TYPO3\CMS\Backend\Tests\Functional\Configuration\SiteConfiguration\SiteConfigurationOverridesTest
+ */
+class SiteConfigurationOverridesTest extends FunctionalTestCase
+{
+
+    /** @var array */
+    protected $subject;
+
+    /**
+     * @var string[]
+     */
+    protected $testExtensionsToLoad = [
+        'typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/a',
+        'typo3/sysext/backend/Tests/Functional/Configuration/SiteConfiguration/Fixtures/Extensions/conf_overriding/b',
+    ];
+
+    /**
+     * Sets up this test case.
+     */
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        $this->subject = (new SiteTcaConfiguration())->getTca();
+    }
+
+    /**
+     * @test
+     */
+    public function allOverridesLoaded(): void
+    {
+        $columnsConfiguration = $this->subject['site']['columns'];
+
+        $this->assertArrayHasKey('tx_a_a', $columnsConfiguration);
+        $this->assertArrayHasKey('tx_b_a', $columnsConfiguration);
+    }
+
+    /**
+     * @test
+     */
+    public function overrideOnlyLoadedOnce(): void
+    {
+        $showitemConfiguration = $this->subject['site']['types']['0']['showitem'];
+
+        $this->assertSame(1, mb_substr_count($showitemConfiguration, 'tx_a_a'));
+        $this->assertSame(1, mb_substr_count($showitemConfiguration, 'tx_b_a'));
+    }
+
+    /**
+     * @test
+     */
+    public function finderUsesCorrectOrder(): void
+    {
+        $columnsConfiguration = $this->subject['site']['columns'];
+
+        $this->assertSame('Awesome description by extension b', $columnsConfiguration['tx_a_a']['description']);
+    }
+}