From a6750d13d65b6392b26b0a8d971a8428d6e6da46 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Thu, 23 Nov 2023 19:15:35 +0100 Subject: [PATCH 1/7] Update calendarize registration --- Configuration/TCA/Overrides/tx_news_domain_model_news.php | 5 +++++ ext_tables.php | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Configuration/TCA/Overrides/tx_news_domain_model_news.php diff --git a/Configuration/TCA/Overrides/tx_news_domain_model_news.php b/Configuration/TCA/Overrides/tx_news_domain_model_news.php new file mode 100644 index 0000000..28d2d6d --- /dev/null +++ b/Configuration/TCA/Overrides/tx_news_domain_model_news.php @@ -0,0 +1,5 @@ + Date: Thu, 23 Nov 2023 23:01:59 +0100 Subject: [PATCH 2/7] Add support for TYPO3 v12 and calendarize 13 --- Classes/EventListener/ModifyFlexformEvent.php | 42 +++++++++++++++++++ Classes/Hooks/FlexFormHook.php | 3 ++ Configuration/Services.yaml | 18 ++++++++ Configuration/page.tsconfig | 2 + composer.json | 6 +-- ext_conf_template.txt | 4 +- ext_emconf.php | 6 +-- ext_localconf.php | 3 +- ext_typoscript_setup.typoscript | 1 + 9 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 Classes/EventListener/ModifyFlexformEvent.php create mode 100644 Configuration/Services.yaml create mode 100644 Configuration/page.tsconfig diff --git a/Classes/EventListener/ModifyFlexformEvent.php b/Classes/EventListener/ModifyFlexformEvent.php new file mode 100644 index 0000000..ab9138d --- /dev/null +++ b/Classes/EventListener/ModifyFlexformEvent.php @@ -0,0 +1,42 @@ +getIdentifier(); + if ( + 'tca' === ($identifier['type'] ?? '') + && 'tt_content' === ($identifier['tableName'] ?? '') + && 'calendarize_list,list' === ($identifier['dataStructureKey'] ?? '') + ) { + $file = GeneralUtility::getFileAbsFileName('EXT:calendarize_news/Configuration/FlexForms/Calendar.xml'); + $content = file_get_contents($file); + if ($content) { + $overwrite = GeneralUtility::xml2array($content); + // Deprecated: remove when dropping TYPO3 v11 support and remove TCEforms & internal_type in Calendar.xml + $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class); + $overwrite = $flexFormTools->removeElementTceFormsRecursive($overwrite); + + if (\is_array($overwrite)) { + $parsedDataStructure = $event->getDataStructure(); + ArrayUtility::mergeRecursiveWithOverrule($parsedDataStructure, $overwrite); + $event->setDataStructure($parsedDataStructure); + } + } + } + } +} diff --git a/Classes/Hooks/FlexFormHook.php b/Classes/Hooks/FlexFormHook.php index 1715c74..3ffabaa 100644 --- a/Classes/Hooks/FlexFormHook.php +++ b/Classes/Hooks/FlexFormHook.php @@ -7,6 +7,9 @@ use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +/** + * @deprecated Remove when dropping TYPO3 v11 + */ class FlexFormHook { /** diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..575e771 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,18 @@ +services: + _defaults: + autowire: true + autoconfigure: True + public: false + + HDNET\CalendarizeNews\: + resource: '../Classes/*' + # TODO: see https://github.com/lochmueller/calendarize_news/issues/46 + exclude: + - '../Classes/Persistence' + - '../Classes/Xclass/{NewsRepository,NewsController.php}' + + HDNET\CalendarizeNews\EventListener\ModifyFlexformEvent: + tags: + - name: event.listener + identifier: 'calendarize-news/modify-flexform' + event: TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureParsedEvent diff --git a/Configuration/page.tsconfig b/Configuration/page.tsconfig new file mode 100644 index 0000000..892d0a9 --- /dev/null +++ b/Configuration/page.tsconfig @@ -0,0 +1,2 @@ +# Partials for BE module +templates.lochmueller/calendarize.1700776845 = lochmueller/calendarize-news:Resources/Private/ diff --git a/composer.json b/composer.json index ca6de40..aa6e613 100644 --- a/composer.json +++ b/composer.json @@ -34,9 +34,9 @@ ], "require": { "php": "^7.4||^8.0||^8.1||^8.2", - "typo3/cms-core": "^10.4||^11.5", - "typo3/cms-extbase": "^10.4||^11.5", - "lochmueller/calendarize": "^10.0||^11.0||^12.0", + "typo3/cms-core": "^10.4||^11.5||^12.4", + "typo3/cms-extbase": "^10.4||^11.5||^12.4", + "lochmueller/calendarize": "^10.0||^11.0||^12.0||^13.0||dev-master", "georgringer/news": "^8.5||^9.0||^10.0||^11.0" }, "replace": { diff --git a/ext_conf_template.txt b/ext_conf_template.txt index d667776..164b3e9 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -1,2 +1,2 @@ -# cat=basic/enable; type=boolean; label=Replace News Repository Index Selection:Repalce the normal News selection by a index based selection. The index is get from the calendarize extension -replaceNewsRepositoryByIndexSelection = 0 \ No newline at end of file +# cat=basic/enable; type=boolean; label=Replace News Repository Index Selection:Replace the normal News selection by a index based selection. The index is get from the calendarize extension +replaceNewsRepositoryByIndexSelection = 0 diff --git a/ext_emconf.php b/ext_emconf.php index 3fa2575..5b4ec50 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -6,8 +6,6 @@ * @package Calendarize * @author Tim Lochmüller */ - - $EM_CONF[$_EXTKEY] = [ 'title' => 'Calendarize for News', 'description' => 'Add Event options to the news extension.', @@ -19,9 +17,9 @@ 'author_email' => 'tim@fruit-lab.de', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.6-11.5.99', + 'typo3' => '10.4.6-12.4.99', 'php' => '7.4.0-8.2.99', - 'calendarize' => '10.0.0-12.99.99', + 'calendarize' => '10.0.0-13.99.99', 'news' => '8.5.0-11.99.99', ], ], diff --git a/ext_localconf.php b/ext_localconf.php index ef7d540..584dc20 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -7,8 +7,6 @@ * @author Tim Lochmüller */ -declare(strict_types=1); - defined('TYPO3') or exit(); \HDNET\Calendarize\Register::extLocalconf(\HDNET\CalendarizeNews\Register::getConfiguration()); @@ -30,4 +28,5 @@ ]; } +// Deprecated: remove when dropping TYPO3 v11 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::class]['flexParsing'][\HDNET\CalendarizeNews\Hooks\FlexFormHook::class] = \HDNET\CalendarizeNews\Hooks\FlexFormHook::class; diff --git a/ext_typoscript_setup.typoscript b/ext_typoscript_setup.typoscript index 5492e8f..d168ba8 100644 --- a/ext_typoscript_setup.typoscript +++ b/ext_typoscript_setup.typoscript @@ -1,3 +1,4 @@ +# Deprecated: remove when dropping TYPO3 v11 module.tx_calendarize.view { partialRootPaths { 200 = EXT:calendarize_news/Resources/Private/Partials/ From e9aebf83d54832583fca09513f62586a46127228 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Mon, 27 Nov 2023 20:33:29 +0100 Subject: [PATCH 3/7] Update tests --- Tests/Functional/FunctionalTests.xml | 45 +++++++++++++++ .../Xclass/NewsLinkViewHelperTest.php | 57 +++++++++++++++++++ Tests/Unit/Service/NewsOverwriteTest.php | 6 +- Tests/Unit/UnitTests.xml | 39 +++++++++++++ composer.json | 16 +++--- 5 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 Tests/Functional/FunctionalTests.xml create mode 100644 Tests/Functional/Xclass/NewsLinkViewHelperTest.php create mode 100644 Tests/Unit/UnitTests.xml diff --git a/Tests/Functional/FunctionalTests.xml b/Tests/Functional/FunctionalTests.xml new file mode 100644 index 0000000..d97709b --- /dev/null +++ b/Tests/Functional/FunctionalTests.xml @@ -0,0 +1,45 @@ + + + + + + ./ + + + + + + + + + + + diff --git a/Tests/Functional/Xclass/NewsLinkViewHelperTest.php b/Tests/Functional/Xclass/NewsLinkViewHelperTest.php new file mode 100644 index 0000000..ceb51df --- /dev/null +++ b/Tests/Functional/Xclass/NewsLinkViewHelperTest.php @@ -0,0 +1,57 @@ +coreExtensionsToLoad = ['extbase', 'fluid']; + $this->testExtensionsToLoad = ['typo3conf/ext/news', 'typo3conf/ext/calendarize_news']; + parent::__construct(); + } + + public function testViewHelperRender(): void + { + $view = new StandaloneView(); + $template = '{namespace n=GeorgRinger\News\ViewHelpers}' . + 'MyLink'; + + $view->setTemplateSource($template); + $view->assign('news', null); + + self::assertEquals('MyLink', $view->render()); + } + + public function testXclassLoadedAndIndexArgumentIsAccepted(): void + { + $view = new StandaloneView(); + $template = '{namespace n=GeorgRinger\News\ViewHelpers}' . + 'MyLink'; + + $view->setTemplateSource($template); + $view->assign('news', null); + $view->assign('index', null); + + self::assertEquals('MyLink', $view->render()); + } + + public function testIndexId(): void + { + $view = new StandaloneView(); + $template = '{namespace n=GeorgRinger\News\ViewHelpers}' . + 'MyLink'; + + $view->setTemplateSource($template); + $view->assign('news', null); + $view->assign('index', 22); + + self::assertEquals('MyLink', $view->render()); + } +} diff --git a/Tests/Unit/Service/NewsOverwriteTest.php b/Tests/Unit/Service/NewsOverwriteTest.php index 8e1bb16..ff68586 100644 --- a/Tests/Unit/Service/NewsOverwriteTest.php +++ b/Tests/Unit/Service/NewsOverwriteTest.php @@ -8,7 +8,7 @@ use GeorgRinger\News\Domain\Model\News; use HDNET\Calendarize\Domain\Model\Index; use HDNET\CalendarizeNews\Service\NewsOverwrite; -use TYPO3\CMS\Core\Tests\UnitTestCase; +use TYPO3\TestingFramework\Core\Unit\UnitTestCase; /** * NewsOverwriteTest. @@ -21,12 +21,12 @@ public function testOverWriteNewsPropertiesByIndexObject() $index = new Index(); $index->setAllDay(true); - $date = new \DateTime(); + $date = (new \DateTime())->setTime(0, 0); $index->setStartDate($date); $index->setEndDate($date); $news = new News(); $service->overWriteNewsPropertiesByIndex($news, $index); - self::assertTrue($news->getDatetime() == $date); + self::assertEquals($date, $news->getDatetime()); } } diff --git a/Tests/Unit/UnitTests.xml b/Tests/Unit/UnitTests.xml new file mode 100644 index 0000000..fca10ef --- /dev/null +++ b/Tests/Unit/UnitTests.xml @@ -0,0 +1,39 @@ + + + + + + ./ + + + + + + + + + diff --git a/composer.json b/composer.json index aa6e613..8881782 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,8 @@ "phpmd/phpmd": "^2.4", "friendsofphp/php-cs-fixer": "^3.0", "phpunit/phpunit": "^9.5", - "phpstan/phpstan": "^0.12.82" + "phpstan/phpstan": "^0.12.82", + "typo3/testing-framework": "^6.0.0||^7.0.4" }, "config": { "vendor-dir": ".Build/vendor", @@ -84,23 +85,20 @@ "tool:php-cs-fixer-check": [ "php-cs-fixer fix --config Resources/Private/Build/PhpCsFixer.php --dry-run" ], - "todo-tool:phpunit": [ - "phpunit --configuration=Tests/Unit/Build/UnitTests.xml" + "tool:phpunit": [ + "phpunit --configuration=Tests/Unit/UnitTests.xml" ], "tool:phpunit:functional": [ - "phpunit --configuration=Tests/Functional/Build/FunctionalTests.xml" + "phpunit --configuration=Tests/Functional/FunctionalTests.xml" ], "tool:phpdoc": [ "docker run --rm -v $(pwd):/data phpdoc/phpdoc -d Classes -t .Build/phpdoc" ], - "tool:rector": [ - "docker run --rm --volume $PWD:/app --user $(id -u):$(id -g) ghcr.io/sabbelasichon/typo3-rector process --config=Resources/Private/Build/Rector.php" - ], "tool:phpstan": [ "phpstan analyse -c phpstan.neon" ], - "tool:deptrac": [ - "deptrac" + "post-autoload-dump": [ + "TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare" ] } } From 5ea3fb612cc4d7c827ac9a342ee7470dbc17f6a1 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Mon, 27 Nov 2023 20:36:15 +0100 Subject: [PATCH 4/7] Fix object access --- Classes/Service/NewsOverwrite.php | 8 +++----- Classes/Xclass/NewsLinkViewHelper.php | 6 ++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/Service/NewsOverwrite.php b/Classes/Service/NewsOverwrite.php index e77760e..1ade387 100644 --- a/Classes/Service/NewsOverwrite.php +++ b/Classes/Service/NewsOverwrite.php @@ -28,18 +28,16 @@ public function overWriteNewsPropertiesByIndex(News $news, Index $index) $news, 'datetime', $index->getStartDateComplete(), - true ); - ObjectAccess::setProperty($news, 'sorting', $index, true); + ObjectAccess::setProperty($news, 'sorting', $index); if (ExtensionManagementUtility::isLoaded('eventnews')) { - ObjectAccess::setProperty($news, 'isEvent', true, true); + ObjectAccess::setProperty($news, 'isEvent', true); ObjectAccess::setProperty( $news, 'eventEnd', $index->getEndDateComplete(), - true ); - ObjectAccess::setProperty($news, 'fullDay', $index->isAllDay(), true); + ObjectAccess::setProperty($news, 'fullDay', $index->isAllDay()); } } } diff --git a/Classes/Xclass/NewsLinkViewHelper.php b/Classes/Xclass/NewsLinkViewHelper.php index 9fb7de7..b6ab490 100644 --- a/Classes/Xclass/NewsLinkViewHelper.php +++ b/Classes/Xclass/NewsLinkViewHelper.php @@ -30,12 +30,14 @@ public function initializeArguments() public function render(): ?string { try { - $index = ObjectAccess::getProperty($this->arguments['newsItem'], 'sorting', true); + $index = ObjectAccess::getProperty($this->arguments['newsItem'] ?? [], 'sorting'); if ($index instanceof Index) { $this->arguments['configuration']['additionalParams'] .= '&tx_news_pi1[index]=' . $index->getUid(); } if ($this->arguments['index'] > 0) { - $this->arguments['configuration']['additionalParams'] .= '&tx_news_pi1[index]=' . $this->arguments['index']; + $this->arguments['configuration']['additionalParams'] = + ($this->arguments['configuration']['additionalParams'] ?? '') + . '&tx_news_pi1[index]=' . $this->arguments['index']; } } catch (\Exception $ex) { } From 5cbdcd7ad0355d391180713db788322eca938ad7 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Mon, 27 Nov 2023 20:51:48 +0100 Subject: [PATCH 5/7] Add tests to CI --- .github/workflows/ci.yml | 51 +++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c38c95f..b7f2b87 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,8 @@ name: Testing calendarize_news on: push: pull_request: - schedule: - - cron: '10 3 * * *' +# schedule: +# - cron: '10 3 * * 1' jobs: build: # only run jobs via scheduled workflow in main repo, not in forks @@ -11,17 +11,23 @@ jobs: strategy: fail-fast: false matrix: - php: ["7.4"] - typo3: ["10.4"] - news: ["8.5", "9.0"] - exclude: - # leave this in here for later when TYPO3 v11 and PHP 8 support is added - - php: "8.0" + include: + - php: "7.4" typo3: "10.4" + news: "8.6" + - php: "7.4" + typo3: "11.5" + news: "9.4" + - php: "7.4" + typo3: "11.5" + news: "10.0.3" + - php: "8.2" + typo3: "12.4" + news: "11.2" runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -36,10 +42,10 @@ jobs: - name: Get composer cache directory id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache composer dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} @@ -54,12 +60,25 @@ jobs: - name: Run PHP CS Fixer checks run: composer run tool:php-cs-fixer-check - - name: Run phpstan checks - run: composer run tool:phpstan + #- name: Run phpstan checks + # run: composer run tool:phpstan + # continue-on-error: true - #- name: Unit Tests with phpunit - # run: composer run tool:phpunit -- + - name: Unit Tests with phpunit + run: composer run tool:phpunit -- + + # start db + - name: Start MySQL + run: sudo /etc/init.d/mysql start + + # functional tests + - name: Functional Tests + run: | + export typo3DatabaseName="typo3"; + export typo3DatabaseHost="localhost"; + export typo3DatabaseUsername="root"; + export typo3DatabasePassword="root"; + composer run tool:phpunit:functional -- #- name: Run DepTrac # run: composer run tool:deptrac - From c077efbbd6cd8aba73e726bef760ef635db2daf5 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Mon, 27 Nov 2023 22:38:03 +0100 Subject: [PATCH 6/7] Add indexing test --- Tests/Functional/Fixtures/News.csv | 8 +++++ Tests/Functional/FunctionalTests.xml | 2 +- Tests/Functional/NewsIndexTest.php | 46 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/Fixtures/News.csv create mode 100644 Tests/Functional/NewsIndexTest.php diff --git a/Tests/Functional/Fixtures/News.csv b/Tests/Functional/Fixtures/News.csv new file mode 100644 index 0000000..bfff57a --- /dev/null +++ b/Tests/Functional/Fixtures/News.csv @@ -0,0 +1,8 @@ +"tx_news_domain_model_news" +,"uid","pid","type","title","calendarize" +,10,1,0,"NormalNews", +,20,1,0,"WithCalendarizeConfiguration",21 + +"tx_calendarize_domain_model_configuration" +,"uid","pid","type","handling","start_date","all_day","t3ver_oid","t3ver_wsid","t3ver_state" +,21,1,"time","include","2026-05-02",1,0,0,0 diff --git a/Tests/Functional/FunctionalTests.xml b/Tests/Functional/FunctionalTests.xml index d97709b..579955c 100644 --- a/Tests/Functional/FunctionalTests.xml +++ b/Tests/Functional/FunctionalTests.xml @@ -8,7 +8,7 @@ colors="true" convertErrorsToExceptions="true" convertWarningsToExceptions="true" - convertDeprecationsToExceptions="true" + convertDeprecationsToExceptions="false" convertNoticesToExceptions="true" forceCoversAnnotation="false" stopOnError="false" diff --git a/Tests/Functional/NewsIndexTest.php b/Tests/Functional/NewsIndexTest.php new file mode 100644 index 0000000..c014d55 --- /dev/null +++ b/Tests/Functional/NewsIndexTest.php @@ -0,0 +1,46 @@ +coreExtensionsToLoad = ['extbase', 'fluid']; + $this->testExtensionsToLoad = ['typo3conf/ext/news', 'typo3conf/ext/calendarize', 'typo3conf/ext/calendarize_news']; + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 12) { + array_splice($this->testExtensionsToLoad, 1, 0, 'typo3conf/ext/autoloader'); + } + parent::__construct(); + } + + public function testNewsIndexing(): void + { + $this->importCSVDataSet(__DIR__ . "/Fixtures/News.csv"); + + /** @var IndexerService $indexerService */ + $indexerService = GeneralUtility::makeInstance(IndexerService::class); + $indexerService->reindexAll(); + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('tx_calendarize_domain_model_index'); + + $rows = $queryBuilder + ->select('*') + ->from('tx_calendarize_domain_model_index') + ->execute()->fetchAllAssociative(); + + self::assertCount(1, $rows); + self::assertEquals(20, $rows[0]['foreign_uid']); + self::assertEquals('2026-05-02', $rows[0]['start_date']); + } +} From 21725a4f34d2db575924e69be7beca02ee00cb26 Mon Sep 17 00:00:00 2001 From: Imko Schumacher Date: Tue, 12 Dec 2023 21:33:49 +0100 Subject: [PATCH 7/7] Extend flexform in all plugins In TYPO3 v12, the extension of the flexform is now applied to all calendarize plugins. --- Classes/EventListener/ModifyFlexformEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/EventListener/ModifyFlexformEvent.php b/Classes/EventListener/ModifyFlexformEvent.php index ab9138d..b701dbc 100644 --- a/Classes/EventListener/ModifyFlexformEvent.php +++ b/Classes/EventListener/ModifyFlexformEvent.php @@ -21,7 +21,7 @@ public function __invoke(AfterFlexFormDataStructureParsedEvent $event) if ( 'tca' === ($identifier['type'] ?? '') && 'tt_content' === ($identifier['tableName'] ?? '') - && 'calendarize_list,list' === ($identifier['dataStructureKey'] ?? '') + && str_starts_with($identifier['dataStructureKey'] ?? '', 'calendarize_') ) { $file = GeneralUtility::getFileAbsFileName('EXT:calendarize_news/Configuration/FlexForms/Calendar.xml'); $content = file_get_contents($file);