Skip to content

Commit

Permalink
Merge pull request #48 from okmiim/task/update
Browse files Browse the repository at this point in the history
Add support for TYPO3 v12 and calendarize 13
  • Loading branch information
lochmueller authored Mar 12, 2024
2 parents 96d7844 + 21725a4 commit bdab628
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 47 deletions.
51 changes: 35 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@ 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
if: (github.event_name == 'schedule' && github.repository == 'lochmueller/calendarize_news') || (github.event_name != 'schedule')
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
Expand All @@ -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') }}
Expand All @@ -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

42 changes: 42 additions & 0 deletions Classes/EventListener/ModifyFlexformEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace HDNET\CalendarizeNews\EventListener;

use TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureParsedEvent;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* This adds additional flexform configurations to calendarize.
* In this case a field for the news PID.
*/
final class ModifyFlexformEvent
{
public function __invoke(AfterFlexFormDataStructureParsedEvent $event)
{
$identifier = $event->getIdentifier();
if (
'tca' === ($identifier['type'] ?? '')
&& 'tt_content' === ($identifier['tableName'] ?? '')
&& str_starts_with($identifier['dataStructureKey'] ?? '', 'calendarize_')
) {
$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);
}
}
}
}
}
3 changes: 3 additions & 0 deletions Classes/Hooks/FlexFormHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @deprecated Remove when dropping TYPO3 v11
*/
class FlexFormHook
{
/**
Expand Down
8 changes: 3 additions & 5 deletions Classes/Service/NewsOverwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
6 changes: 4 additions & 2 deletions Classes/Xclass/NewsLinkViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down
18 changes: 18 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions Configuration/TCA/Overrides/tx_news_domain_model_news.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

defined('TYPO3') or exit();

\HDNET\Calendarize\Register::createTcaConfiguration(\HDNET\CalendarizeNews\Register::getConfiguration());
2 changes: 2 additions & 0 deletions Configuration/page.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Partials for BE module
templates.lochmueller/calendarize.1700776845 = lochmueller/calendarize-news:Resources/Private/
8 changes: 8 additions & 0 deletions Tests/Functional/Fixtures/News.csv
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions Tests/Functional/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
backupGlobals="true"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
cacheResult="false"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="false"
convertNoticesToExceptions="true"
forceCoversAnnotation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
beStrictAboutTestsThatDoNotTestAnything="false"
failOnWarning="true"
failOnRisky="true"
>
<testsuites>
<testsuite name="Functional tests">
<!--
This path either needs an adaption in extensions, or an extension's
test location path needs to be given to phpunit.
-->
<directory suffix="Test.php">./</directory>
</testsuite>
</testsuites>
<php>
<!-- @deprecated: will be removed with next major version, constant TYPO3_MODE is deprecated -->
<const name="TYPO3_MODE" value="BE" />
<!--
@deprecated: Set this to not suppress warnings, notices and deprecations in functional tests
with TYPO3 core v11 and up.
Will always be done with next major version.
To still suppress warnings, notices and deprecations, do NOT define the constant at all.
-->
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true" />
<ini name="display_errors" value="1" />
<env name="TYPO3_CONTEXT" value="Testing" />
</php>
</phpunit>
46 changes: 46 additions & 0 deletions Tests/Functional/NewsIndexTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace HDNET\CalendarizeNews\Tests\Functional;

use HDNET\Calendarize\Service\IndexerService;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class NewsIndexTest extends FunctionalTestCase
{
public function __construct()
{
// Initialize inside constructor to support TYPO3 v10
$this->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']);
}
}
57 changes: 57 additions & 0 deletions Tests/Functional/Xclass/NewsLinkViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace HDNET\CalendarizeNews\Tests\Functional\Xclass;

use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class NewsLinkViewHelperTest extends FunctionalTestCase
{
public function __construct()
{
// Initialize inside constructor to support TYPO3 v10
$this->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}' .
'<n:link newsItem="{news}">MyLink</n:link>';

$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}' .
'<n:link newsItem="{news}" index="{index}">MyLink</n:link>';

$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}' .
'<n:link newsItem="{news}" index="{index}">MyLink</n:link>';

$view->setTemplateSource($template);
$view->assign('news', null);
$view->assign('index', 22);

self::assertEquals('MyLink', $view->render());
}
}
6 changes: 3 additions & 3 deletions Tests/Unit/Service/NewsOverwriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
}
}
Loading

0 comments on commit bdab628

Please sign in to comment.