Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typo3v12 #17

Merged
merged 12 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
typo3: [ '^11.5' ]
php: ['8.0', '8.1', '8.2', '8.3']
typo3: [ '^12.4' ]
php: ['8.1', '8.2', '8.3']

steps:
- name: Start database server
Expand All @@ -35,32 +35,32 @@ jobs:
- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies with nimut/typo3-complete:${{ matrix.typo3 }}
- name: Install dependencies with typo3/cms-core:${{ matrix.typo3 }}
run: |
composer require --dev nimut/typo3-complete:${{ matrix.typo3 }} --no-progress
composer require --dev typo3/cms-core:${{ matrix.typo3 }} --no-progress
git checkout composer.json
ln -nfs .Build/vendor/typo3/cms/typo3 typo3

- name: Lint PHP
run: find . -name \*.php ! -path "./.Build/*" ! -path "./scripts/*" ! -path "./typo3_src/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;

- name: Unit Tests without coverage
if: matrix.typo3 != '^11.5' && matrix.php != '8.3'
if: matrix.typo3 != '^12.5' && matrix.php != '8.3'
run: |
export "UNIT_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml
.Build/bin/phpunit --colors -c $UNIT_XML Tests/Unit

- name: Unit Tests with coverage
if: matrix.typo3 == '^11.5' && matrix.php == '8.3'
if: matrix.typo3 == '^12.5' && matrix.php == '8.3'
run: |
export "UNIT_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests-v10.xml
.Build/bin/phpunit --coverage-filter Classes --coverage-clover=unittest-coverage.clover --colors -c $UNIT_XML Tests/Unit

- name: Functional Tests without coverage
run: |
export "FUNCTIONAL_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests-v10.xml
export "FUNCTIONAL_XML"=Tests/Functional/FunctionalTests.xml
.Build/bin/phpunit --coverage-filter Classes --colors -c $FUNCTIONAL_XML Tests/Functional
if: matrix.typo3 != '^11.5' && matrix.php != '8.3'
if: matrix.typo3 != '^12.5' && matrix.php != '8.3'
env:
typo3DatabaseHost: 127.0.0.1
typo3DatabaseName: typo3
Expand All @@ -71,7 +71,7 @@ jobs:
run: |
export "FUNCTIONAL_XML"=.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests-v10.xml
.Build/bin/phpunit --coverage-filter Classes --coverage-clover=functional-coverage.clover --colors -c $FUNCTIONAL_XML Tests/Functional
if: matrix.typo3 == '^11.5' && matrix.php == '8.3'
if: matrix.typo3 == '^12.5' && matrix.php == '8.3'
env:
typo3DatabaseHost: 127.0.0.1
typo3DatabaseName: typo3
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ nbproject
composer.lock
.php_cs.cache
var
.cache
# PHPUnit Reports
Tests/reports
reports
.cache
.phpunit.cache
.phpunit.result.cache
63 changes: 40 additions & 23 deletions Classes/Controller/BackendModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

use Aoe\Cachemgm\Domain\Repository\CacheTableRepository;
use Aoe\Cachemgm\Utility\CacheUtility;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Cache\Backend\BackendInterface;
use TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend;
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
Expand All @@ -38,60 +39,67 @@
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Fluid\View\TemplatePaths;

class BackendModuleController extends ActionController
{
/**
* Backend Template Container
*
* @var string
* @var ModuleTemplateFactory
*/
protected $defaultViewObjectName = BackendTemplateView::class;
public $moduleTemplateFactory;

/**
* BackendTemplateContainer
*
* @var BackendTemplateView
*/
protected $view;

/**
* @var CacheManager
*/
private $cacheManager;
private readonly object $cacheManager;

/**
* @var LanguageService
*/
private $languageService;

public function __construct()
{
public function __construct(
ModuleTemplateFactory $moduleTemplateFactory,
) {
$this->cacheManager = GeneralUtility::makeInstance(CacheManager::class);
$this->languageService = $GLOBALS['LANG'];
$this->moduleTemplateFactory = $moduleTemplateFactory;
}

public function indexAction(): void
public function indexAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);

$this->view->assignMultiple([
'cacheConfigurations' => $this->buildCacheConfigurationArray(),
'action_confirm_flush_message' => $this->languageService->sL(
'LLL:EXT:cachemgm/Resources/Private/BackendModule/Language/locallang.xlf:bemodule.action_confirm_flush'
),
]);

$moduleTemplate->setContent($this->view->render());

return $this->htmlResponse($moduleTemplate->renderContent());
}

public function detailAction(): void
public function detailAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);

try {
$cacheId = $this->request->getArgument('cacheId');
} catch (NoSuchArgumentException) {
$this->showFlashMessage($this->getNoCacheFoundMessage());
$this->forward('index');
return new ForwardResponse('index');
}

$cache = $this->cacheManager->getCache($cacheId);
Expand All @@ -114,28 +122,37 @@ public function detailAction(): void
'overviewLink' => $this->getHref('BackendModule', 'index'),
]
);

$moduleTemplate->setContent($this->view->render());

return $this->htmlResponse($moduleTemplate->renderContent());
}

public function flushAction(): void
public function flushAction(): ResponseInterface
{
try {
$cacheId = $this->request->getArgument('cacheId');
} catch (NoSuchArgumentException) {
$this->showFlashMessage($this->getNoCacheFoundMessage());
$this->forward('index');
return new ForwardResponse('index');
}

$cache = $this->cacheManager->getCache($cacheId);
$cache->flush();
$this->showFlashMessage($this->getFlushCacheMessage($cacheId));
$this->forward('index');
return new ForwardResponse('index');
}

protected function initializeView(ViewInterface $view): void
protected function initializeView(): void
{
$this->view->setLayoutRootPaths(['EXT:cachemgm/Resources/Private/Layouts']);
$this->view->setPartialRootPaths(['EXT:cachemgm/Resources/Private/Partials']);
$this->view->setTemplateRootPaths(['EXT:cachemgm/Resources/Private/Templates/BackendModule']);
if ($this->view instanceof \TYPO3\CMS\Fluid\View\StandaloneView) {
$this->view->setLayoutRootPaths(['EXT:cachemgm/Resources/Private/Layouts']);
$this->view->setPartialRootPaths(['EXT:cachemgm/Resources/Private/Partials']);
$this->view->setTemplateRootPaths(['EXT:cachemgm/Resources/Private/Templates/BackendModule']);
}

$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
}

/**
Expand Down Expand Up @@ -248,7 +265,7 @@ private function getFlushCacheMessage(string $cacheId): object
$this->languageService->sL(
'LLL:EXT:cachemgm/Resources/Private/BackendModule/Language/locallang.xlf:bemodule.flash.flush.header'
),
FlashMessage::OK,
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::OK,
true
);
}
Expand All @@ -261,7 +278,7 @@ private function getNoCacheFoundMessage(): object
'LLL:EXT:cachemgm/Resources/Private/BackendModule/Language/locallang.xlf:bemodule.flash.detailed.error'
),
'',
FlashMessage::NOTICE,
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::NOTICE,
true
);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function countRowsInTable(string $table): int
return $queryBuilder
->count('*')
->from($table)
->execute()
->fetchColumn(0);
->executeQuery()
->fetchOne();
}
}
23 changes: 23 additions & 0 deletions Configuration/Backend/Modules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Aoe\Cachemgm\Controller\BackendModuleController;

return [
'cachemgm' => [
'parent' => 'tools',
'access' => 'admin',
'labels' => 'LLL:EXT:' . 'cachemgm' . '/Resources/Private/BackendModule/Language/locallang.xlf',
'iconIdentifier' => 'module-cachemgm-backend-module',
'extensionName' => 'Cachemgm',
'controllerActions' => [
BackendModuleController::class => [
'index',
'detail',
'flush',
]
],
'path' => 'module/tools/cachemgm',
],
];
13 changes: 13 additions & 0 deletions Configuration/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;

return [
// Icon identifier
'module-cachemgm-backend-module' => [
'provider' => SvgIconProvider::class,
'source' => 'EXT:cachemgm/Resources/Public/Icons/Extension.svg',
],
];
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ And then open `Documentation-GENERATED-temp/Result/project/0.0.0/Index.html` wit

## Copyright / License

Copyright: (c) 2009 - 2019, Kasper Skaarhoj & AOE GmbH
Copyright: (c) 2009 - 2024, Kasper Skaarhoj & AOE GmbH
License: GPLv3, <http://www.gnu.org/licenses/gpl-3.0.en.html>

[1]: http://typo3.org/extensions/repository/view/cachemgm
Expand Down
10 changes: 10 additions & 0 deletions Resources/Private/Layouts/Default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- Resources/Private/Layouts/Default.html -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<f:render section="content" />
</body>
</html>
6 changes: 6 additions & 0 deletions Resources/Private/Templates/BackendModule/Flush.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!-- Resources/Private/Templates/BackendModule/Flush.html -->
<f:layout name="Default" />
<f:section name="content">
<h1>Cache Flush</h1>
<p>The cache has been successfully flushed.</p>
</f:section>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function setUp(): void

public function testCountRowsInTable(): void
{
$this->importDataSet(__DIR__ . '/Fixtures/cache_pages.xml');
$this->importCSVDataSet(__DIR__ . '/Fixtures/cache_pages.csv');
$this->assertSame(
2,
$this->subject->countRowsInTable('cache_pages')
Expand Down
4 changes: 4 additions & 0 deletions Tests/Functional/Domain/Repository/Fixtures/cache_pages.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache_pages,,,
,id,identifier,content
,1,c4355df29142213662c0561fe304de25,this-is-a-string-in-md5
,2,f9982c771f6d32fe6830b4b3c2ef646a,this-is-another-string-in-md5
13 changes: 0 additions & 13 deletions Tests/Functional/Domain/Repository/Fixtures/cache_pages.xml

This file was deleted.

34 changes: 34 additions & 0 deletions Tests/Functional/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
backupGlobals="true"
colors="true"
processIsolation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false">
<coverage>
<report>
<clover outputFile="../reports/php_functionaltests/coverage_clover.xml"/>
<html outputDirectory="../reports/php_functionaltests/coverage/" lowUpperBound="35" highLowerBound="70"/>
</report>
</coverage>
<logging>
<junit outputFile="../reports/php_functionaltests/coverage_junit.xml"/>
<testdoxHtml outputFile="../reports/php_functionaltests/testdox.html"/>
</logging>
<source>
<include>
<directory>../../Classes</directory>
</include>
</source>
</phpunit>
25 changes: 25 additions & 0 deletions Tests/Unit/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="true"
bootstrap="../../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false"
>
<source>
<include>
<directory suffix=".php">../Classes</directory>
</include>
</source>
</phpunit>
1 change: 1 addition & 0 deletions Tests/Unit/Utility/CacheUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CacheUtilityTest extends UnitTestCase
{
protected function setUp(): void
{
parent::setUp();
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
'cache_core' => [
'frontend' => PhpFrontend::class,
Expand Down
Loading