From 57d979f3c66cf921c74fc1fa1d564b428c0aab05 Mon Sep 17 00:00:00 2001 From: Apen Date: Tue, 10 Dec 2024 17:17:01 +0100 Subject: [PATCH] [BUGFIX] Fix some tests --- .github/workflows/ci.yaml | 6 +- Build/FunctionalTests.xml | 51 ++++++------- Build/Local/FunctionalTests.xml | 35 --------- Build/Local/UnitTests.xml | 28 -------- Build/UnitTests.xml | 39 ++++------ Classes/Utility.php | 21 ++++-- Resources/Private/Language/locallang.xlf | 2 +- Tests/Functional/Fixtures/be_users.csv | 5 ++ Tests/Functional/Fixtures/pages.csv | 56 +++++++++++++++ Tests/Functional/Fixtures/tt_content.csv | 14 ++++ Tests/Functional/FunctionalTestCase.php | 17 ++++- Tests/Functional/UtilityTest.php | 92 +++++++++++++++++++++--- Tests/Unit/UtilityTest.php | 57 --------------- composer.json | 5 +- 14 files changed, 232 insertions(+), 196 deletions(-) delete mode 100644 Build/Local/FunctionalTests.xml delete mode 100644 Build/Local/UnitTests.xml create mode 100644 Tests/Functional/Fixtures/be_users.csv create mode 100644 Tests/Functional/Fixtures/pages.csv create mode 100644 Tests/Functional/Fixtures/tt_content.csv diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f2e7522..ece8a71 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,11 +14,11 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [ '8.1' ] + php-versions: [ '8.2' ] packages: - - typo3: '^11' - testingframework: '^7' - typo3: '^12' + testingframework: '^8' + - typo3: '^13' testingframework: 'dev-main' steps: - name: Check out repository diff --git a/Build/FunctionalTests.xml b/Build/FunctionalTests.xml index 8fd0507..873f6a6 100644 --- a/Build/FunctionalTests.xml +++ b/Build/FunctionalTests.xml @@ -1,35 +1,28 @@ - - - ../Tests/Functional/ - - + + + ../Tests/Functional/ + + - - - ../Classes/ - ../Tests/ - - - - - - + + + \ No newline at end of file diff --git a/Build/Local/FunctionalTests.xml b/Build/Local/FunctionalTests.xml deleted file mode 100644 index 0c5f94a..0000000 --- a/Build/Local/FunctionalTests.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - ../../Tests/Functional/ - - - - - - ../../Classes/ - ../Tests/ - - - - - - - - \ No newline at end of file diff --git a/Build/Local/UnitTests.xml b/Build/Local/UnitTests.xml deleted file mode 100644 index f5c59e8..0000000 --- a/Build/Local/UnitTests.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - ../../Tests/Unit/ - - - - - ../../Classes/ - - - - \ No newline at end of file diff --git a/Build/UnitTests.xml b/Build/UnitTests.xml index 080f632..08ad42d 100644 --- a/Build/UnitTests.xml +++ b/Build/UnitTests.xml @@ -1,28 +1,19 @@ - - - ../Tests/Unit/ - - - - - ../Classes/ - - + + + ../Tests/Unit/ + + \ No newline at end of file diff --git a/Classes/Utility.php b/Classes/Utility.php index 7c4bf15..7ff62ce 100644 --- a/Classes/Utility.php +++ b/Classes/Utility.php @@ -274,6 +274,9 @@ public static function getExtIcon($extKey) { if (!empty($extKey)) { $extType = self::getExtensionType($extKey); + if (!isset($extType['siteRelPath'])) { + return ''; + } $path = $extType['siteRelPath'] . ExtensionManagementUtility::getExtensionIcon( Utility::getPathSite() . '/' . $extType['siteRelPath'] ); @@ -328,7 +331,7 @@ public static function getContentInfosFromTca($type, $value) $icon = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class)->getIconConfigurationByIdentifier( $iconPath ); - if (isset($icon['options']) &&str_contains($icon['options']['source'], 'EXT:')) { + if (isset($icon['options']) && str_contains($icon['options']['source'], 'EXT:')) { $infos['iconext'] = PathUtility::getPublicResourceWebPath($icon['options']['source']); } elseif (isset($icon['options']['source'])) { $infos['iconext'] = PathUtility::getAbsoluteWebPath($icon['options']['source']); @@ -638,11 +641,12 @@ public static function getExtensionVersion($key): ?string if (self::isComposerMode()) { $packageManager = GeneralUtility::makeInstance(PackageManager::class); + /** @var \TYPO3\CMS\Core\Package\PackageInterface $package */ $package = $packageManager->getPackage($key); if ($package === null) { return null; } - return $package->getVersion(); + return $package->getPackageMetaData()->getVersion(); } if (!ExtensionManagementUtility::isLoaded($key)) { @@ -1131,7 +1135,14 @@ public static function getLl(string $key): string */ public static function exec_SELECT_queryArray($queryParts) { - return self::exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']); + return self::exec_SELECTquery( + $queryParts['SELECT'], + $queryParts['FROM'], + $queryParts['WHERE'], + $queryParts['GROUPBY'] ?? '', + $queryParts['ORDERBY'] ?? '', + $queryParts['LIMIT'] ?? '' + ); } /** @@ -1237,7 +1248,9 @@ public static function getLanguageService(): LanguageService if (!empty($GLOBALS['TSFE'])) { return $GLOBALS['TSFE']; } - return GeneralUtility::makeInstance(LanguageServiceFactory::class)->create($GLOBALS['BE_USER']->uc['lang'] ?? 'default'); + $languageService = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create($GLOBALS['BE_USER']->uc['lang'] ?? 'default'); + $GLOBALS['LANG'] = $languageService; + return $languageService; } public static function getPathSite(): string diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index f3e868a..b0ad3b8 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -27,7 +27,7 @@ List of all the CommandControllers declare in $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'] (old way) - List of all the Symfony Commands declare in Configuration/Commands.php of the extension + List of all the Symfony Commands Additional reports - Commands diff --git a/Tests/Functional/Fixtures/be_users.csv b/Tests/Functional/Fixtures/be_users.csv new file mode 100644 index 0000000..c993d2c --- /dev/null +++ b/Tests/Functional/Fixtures/be_users.csv @@ -0,0 +1,5 @@ +"be_users",,,,,,,, +,uid,pid,username,email,realName,admin,deleted,disable +,1,0,admin@test.fr,admin@test.fr,Admin,1,0,0 +,2,0,user@test.fr,user@test.fr,User,0,0,0 +,3,0,user2@test.fr,user2@test.fr,User,0,0,0 \ No newline at end of file diff --git a/Tests/Functional/Fixtures/pages.csv b/Tests/Functional/Fixtures/pages.csv new file mode 100644 index 0000000..ce518a4 --- /dev/null +++ b/Tests/Functional/Fixtures/pages.csv @@ -0,0 +1,56 @@ +"pages" +,"uid","pid","title","deleted","hidden","no_search" +,1,0,"Congratulations",0,0,0 +,2,1,"Frontend User",0,0,0 +,3,1,"File Collections",0,0,0 +,4,1,"Shared Content",0,0,0 +,5,1,"404",0,0,1 +,6,1,"Content Examples",0,0,0 +,7,6,"And more...",0,0,0 +,8,7,"Frames",0,0,0 +,9,7,"Images with links",0,0,0 +,10,7,"Any language, any character",0,0,0 +,11,6,"Special elements",0,0,0 +,12,11,"Divider",0,0,0 +,13,11,"HTML",0,0,0 +,14,11,"Insert records",0,0,0 +,15,6,"Menu's",0,0,0 +,16,15,"Thumbnails",0,0,0 +,17,15,"Sitemap",0,0,0 +,18,15,"Sections",0,0,0 +,19,15,"Related Pages",0,0,0 +,20,15,"Recently Updated",0,0,0 +,21,15,"Categorized",0,0,0 +,22,15,"Abstract",0,0,0 +,23,15,"Pages",0,0,0 +,24,6,"Form elements",0,0,0 +,25,24,"Search",0,0,0 +,26,24,"Login",0,0,0 +,27,24,"Forms",0,0,0 +,28,6,"Intreractive",0,0,0 +,29,28,"Tab",0,0,0 +,30,28,"Carousel",0,0,0 +,31,28,"Accordion",0,0,0 +,32,6,"Media",0,0,0 +,33,32,"External Media",0,0,0 +,34,32,"Media",0,0,0 +,35,32,"Images",0,0,0 +,36,32,"File downloads",0,0,0 +,37,32,"Text and Media",0,0,0 +,38,32,"Text and Images",0,0,0 +,39,32,"Audio",0,0,0 +,40,6,"Text",0,0,0 +,41,40,"Quote",0,0,0 +,42,40,"Table",0,0,0 +,43,40,"Panel",0,0,0 +,44,40,"List Group",0,0,0 +,45,40,"Text in Columns",0,0,0 +,46,40,"Text and Icon",0,0,0 +,47,40,"Text with Teaser",0,0,0 +,48,40,"Bullet List",0,0,0 +,49,40,"Headers",0,0,0 +,50,40,"Rich Text",0,0,0 +,51,6,"Overview",0,0,0 +,52,1,"Customizings",0,0,0 +,53,1,"Features",0,0,0 +,54,1,"Home",0,0,0 diff --git a/Tests/Functional/Fixtures/tt_content.csv b/Tests/Functional/Fixtures/tt_content.csv new file mode 100644 index 0000000..0ed4313 --- /dev/null +++ b/Tests/Functional/Fixtures/tt_content.csv @@ -0,0 +1,14 @@ +"tt_content" +,"uid","pid","deleted","hidden","CType","list_type","header" +,1,53,0,0,"text","","Upgrading TYPO3? No problem." +,2,53,0,0,"textpic","","Ease of Use" +,3,53,0,0,"textpic","","Publishing Content" +,4,53,0,0,"textpic","","Runs everywhere" +,5,53,0,0,"textpic","","Multi-Language and Multiple Domains" +,6,53,0,0,"textpic","","Your data - our strength" +,7,53,0,0,"textpic","","Granular Frontend and Backend Access Rights" +,8,53,0,0,"textpic","","No Design Constraints For Your Web Project" +,9,53,0,0,"textpic","","Frontend Editing" +,10,53,0,0,"text","","And More..." +,11,53,0,0,"text","","Enterprise Features" +,133,25,0,0,"list","indexedsearch_pi2","Search" \ No newline at end of file diff --git a/Tests/Functional/FunctionalTestCase.php b/Tests/Functional/FunctionalTestCase.php index e34f5d2..19d44ab 100644 --- a/Tests/Functional/FunctionalTestCase.php +++ b/Tests/Functional/FunctionalTestCase.php @@ -2,9 +2,15 @@ namespace Sng\AdditionalReports\Tests\Functional; +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Core\Bootstrap; +use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; +use TYPO3\CMS\Core\Http\NormalizedParams; +use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Core\Http\Uri; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Reports\Controller\ReportController; +use TYPO3\CMS\Core\Http\Application as CoreHttpApplication; class FunctionalTestCase extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase { @@ -23,12 +29,21 @@ class FunctionalTestCase extends \TYPO3\TestingFramework\Core\Functional\Functio protected function setUp(): void { parent::setUp(); - $this->setUpBackendUserFromFixture(1); + + $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv'); + $backendUser = $this->setUpBackendUser(1); Bootstrap::initializeLanguageObject(); + + $uri = new Uri('https://localhost/typo3/'); + $request = new ServerRequest($uri); + $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); + $GLOBALS['TYPO3_REQUEST'] = $request; } public static function getReportObject() { return GeneralUtility::makeInstance(ReportController::class); } + + } \ No newline at end of file diff --git a/Tests/Functional/UtilityTest.php b/Tests/Functional/UtilityTest.php index a26eb96..a709cfd 100644 --- a/Tests/Functional/UtilityTest.php +++ b/Tests/Functional/UtilityTest.php @@ -7,6 +7,12 @@ use Sng\AdditionalReports\Utility; use TYPO3\CMS\Core\Configuration\SiteConfiguration; use TYPO3\CMS\Core\Core\Bootstrap; +use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; +use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; +use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Core\Http\Uri; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; @@ -48,10 +54,72 @@ class UtilityTest extends FunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->setUpBackendUserFromFixture(1); + $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv'); + $this->setUpBackendUser(1); Bootstrap::initializeLanguageObject(); - $this->importDataSet(__DIR__ . '/Fixtures/pages.xml'); - $this->importDataSet(__DIR__ . '/Fixtures/tt_content.xml'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tt_content.csv'); + $uri = new Uri('https://localhost/typo3/'); + $request = new ServerRequest($uri); + $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); + $GLOBALS['TYPO3_REQUEST'] = $request; + } + + public function testGetInstExtList() + { + $extLits = Utility::getInstExtList(Environment::getPublicPath() . '/typo3/sysext/'); + self::assertNotEmpty($extLits); + self::assertEquals('core', $extLits['dev']['core']['extkey']); + } + + public function testGetExtensionType() + { + self::assertNotEmpty(Utility::getExtensionType('core')); + } + + public function testGetExtPath() + { + self::assertNotEmpty(Utility::getExtPath('core')); + } + + public function testGetExtensionVersion() + { + self::assertEquals(GeneralUtility::makeInstance(Typo3Version::class)->getVersion(), Utility::getExtensionVersion('core')); + } + + public function testGetExtIcon() + { + self::assertNotEmpty(Utility::getExtIcon('core')); + } + + public function testGetJsonVersionInfos() + { + self::assertNotEmpty(Utility::getJsonVersionInfos()); + } + + public function testGetCurrentVersionInfos() + { + self::assertNotEmpty(Utility::getCurrentVersionInfos(Utility::getJsonVersionInfos(), GeneralUtility::makeInstance(Typo3Version::class)->getVersion())); + } + + public function testGetCurrentBranchInfos() + { + self::assertNotEmpty(Utility::getCurrentBranchInfos(Utility::getJsonVersionInfos(), GeneralUtility::makeInstance(Typo3Version::class)->getVersion())); + } + + public function testGetLatestStableInfos() + { + self::assertNotEmpty(Utility::getLatestStableInfos(Utility::getJsonVersionInfos())); + } + + public function testGetLatestLtsInfos() + { + self::assertNotEmpty(Utility::getLatestLtsInfos(Utility::getJsonVersionInfos())); + } + + public function testDownloadT3x() + { + self::assertNotEmpty(Utility::downloadT3x('additional_reports', '3.3.2')); } public function testBaseUrl() @@ -215,16 +283,17 @@ public static function isNotSqlite() /** * @param string $identifier - * @param array $site - * @param array $languages - * @param array $errorHandling + * @param array $site + * @param array $languages + * @param array $errorHandling */ protected function writeSiteConfiguration( string $identifier, - array $site = [], - array $languages = [], - array $errorHandling = [] - ) { + array $site = [], + array $languages = [], + array $errorHandling = [] + ) + { $configuration = $site; if (!empty($languages)) { $configuration['languages'] = $languages; @@ -233,7 +302,8 @@ protected function writeSiteConfiguration( $configuration['errorHandling'] = $errorHandling; } $siteConfiguration = new SiteConfiguration( - $this->instancePath . '/typo3conf/sites/' + $this->instancePath . '/typo3conf/sites/', + $this->getContainer()->get(EventDispatcher::class) ); try { diff --git a/Tests/Unit/UtilityTest.php b/Tests/Unit/UtilityTest.php index 68d08ed..9daea1d 100644 --- a/Tests/Unit/UtilityTest.php +++ b/Tests/Unit/UtilityTest.php @@ -16,13 +16,6 @@ public function testReportsList() self::assertNotEmpty(Utility::getReportsList()); } - public function testGetInstExtList() - { - $extLits = Utility::getInstExtList(Environment::getBackendPath() . '/sysext/'); - self::assertNotEmpty($extLits); - self::assertEquals('core', $extLits['dev']['core']['extkey']); - } - public function testIncludeEMCONF() { $emConf = Utility::includeEMCONF(__DIR__ . '../../../ext_emconf.php', 'additional_reports'); @@ -35,21 +28,6 @@ public function testCheckExtensionUpdate() self::assertEmpty(Utility::checkExtensionUpdate(['extkey' => 'additional_reports'])); } - public function testGetExtIcon() - { - self::assertNotEmpty(Utility::getExtIcon('core')); - } - - public function testGetExtensionType() - { - self::assertNotEmpty(Utility::getExtensionType('core')); - } - - public function testGetExtPath() - { - self::assertNotEmpty(Utility::getExtPath('core')); - } - public function testViewArray() { self::assertNotEmpty(Utility::viewArray(['foo' => 'bar'])); @@ -60,51 +38,16 @@ public function testGenerateLink() self::assertNotEmpty(Utility::generateLink()); } - public function testGetExtensionVersion() - { - self::assertEquals(GeneralUtility::makeInstance(Typo3Version::class)->getVersion(), Utility::getExtensionVersion('core')); - } - public function testWriteInformation() { self::assertNotEmpty(Utility::writeInformation('foo', 'bar')); } - public function testGetJsonVersionInfos() - { - self::assertNotEmpty(Utility::getJsonVersionInfos()); - } - - public function testGetCurrentVersionInfos() - { - self::assertNotEmpty(Utility::getCurrentVersionInfos(Utility::getJsonVersionInfos(), GeneralUtility::makeInstance(Typo3Version::class)->getVersion())); - } - - public function testGetCurrentBranchInfos() - { - self::assertNotEmpty(Utility::getCurrentBranchInfos(Utility::getJsonVersionInfos(), GeneralUtility::makeInstance(Typo3Version::class)->getVersion())); - } - - public function testGetLatestStableInfos() - { - self::assertNotEmpty(Utility::getLatestStableInfos(Utility::getJsonVersionInfos())); - } - - public function testGetLatestLtsInfos() - { - self::assertNotEmpty(Utility::getLatestLtsInfos(Utility::getJsonVersionInfos())); - } - public function testGetPluginsDisplayMode() { self::assertEmpty(Utility::getPluginsDisplayMode()); } - public function testDownloadT3x() - { - self::assertNotEmpty(Utility::downloadT3x('additional_reports', '3.3.2')); - } - public function testIsHook() { $hook = EmailLoginNotification::class . '->emailAtLogin'; diff --git a/composer.json b/composer.json index ef7031b..087a424 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3", "saschaegerer/phpstan-typo3": "^1", - "typo3/testing-framework": "dev-main", + "typo3/testing-framework": "^8", "ssch/typo3-rector": "^1", "nikic/php-parser": "^4", "helmich/typo3-typoscript-lint": "^3", @@ -34,8 +34,7 @@ "allow-plugins": { "typo3/class-alias-loader": true, "typo3/cms-composer-installers": true, - "dealerdirect/phpcodesniffer-composer-installer": true, - "composer/package-versions-deprecated": true + "sbuerk/typo3-cmscomposerinstallers-testingframework-bridge": true } }, "autoload": {