From 318386ac75229be3aed1b1cf6be0591159a1e459 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Wed, 26 Oct 2022 16:46:19 +0200 Subject: [PATCH 01/21] [TASK] !!! drop v9 prepare for v12 support * drop v9 and PHP < 7.4 Support * use strict and type declarations * use proper DI * add more Frontend Tests, use CSV Fixture, remove prophecy * improve Typoscript ContentObjects --- .github/workflows/ci.yml | 10 +-- Build/phpstan10.neon | 3 - Build/phpstan11.neon | 6 -- Classes/CacheHelper.php | 29 ++------ Classes/Compiler/AbstractMenuCompiler.php | 38 +++-------- .../BreadcrumbsContentObject.php | 14 ++-- .../ContentObjectServiceContainer.php | 62 +++++++++++++++++ .../LanguageMenuContentObject.php | 14 +++- .../ContentObject/ListMenuContentObject.php | 14 +++- .../ContentObject/TreeMenuContentObject.php | 14 +++- Classes/DataProcessing/AbstractMenu.php | 22 ++---- Classes/DataProcessing/BreadcrumbsMenu.php | 10 +-- Classes/DataProcessing/LanguageMenu.php | 15 ++-- Classes/DataProcessing/ListMenu.php | 12 +++- Classes/DataProcessing/TreeMenu.php | 11 ++- Classes/Domain/Repository/MenuRepository.php | 31 ++------- Classes/Hooks/DataHandlerHook.php | 13 ++-- Configuration/Services.yaml | 24 +++++++ README.md | 20 ++++-- .../Compiler/LanguageMenuCompilerTest.php | 34 ++++++++-- .../DataProcessing/BreadcrumbsMenuTest.php | 2 + .../DataProcessing/DataProcessingTest.php | 49 ++++++------- .../DataProcessing/ListMenuProcessorTest.php | 5 +- .../DataProcessing/TreeMenuProcessorTest.php | 2 + .../translated_page_with_nav_hide.csv | 4 ++ .../translated_page_with_nav_hide.xml | 24 ------- .../Domain/Repository/MenuRepositoryTest.php | 19 +++--- Tests/Functional/Fixtures/caches.csv | 7 ++ Tests/Functional/Fixtures/caches.xml | 14 ---- Tests/Functional/Fixtures/pages.csv | 8 +++ Tests/Functional/Fixtures/pages.xml | 56 --------------- .../BreadcrumbMenuContentObjectTest.php | 47 +++++++++++++ .../Frontend/BreadcrumbMenuFluidTest.php | 47 +++++++++++++ .../Fixtures/Templates/Breadcrumbs.html | 7 ++ .../Fixtures/Templates/LanguageMenu.html | 7 ++ .../Frontend/Fixtures/Templates/ListMenu.html | 7 ++ .../Frontend/Fixtures/Templates/TreeMenu.html | 7 ++ ...adcrumb_menu_content_object_typoscript.csv | 8 +++ .../breadcrumb_menu_fluid_typoscript.csv | 9 +++ ...anguage_menu_content_object_typoscript.csv | 14 ++++ .../language_menu_fluid_typoscript.csv | 10 +++ .../list_menu_content_object_typoscript.csv | 9 +++ .../Fixtures/list_menu_fluid_typoscript.csv | 11 +++ Tests/Functional/Frontend/Fixtures/pages.csv | 5 ++ .../Frontend/Fixtures/translated_pages.csv | 5 ++ .../tree_menu_content_object_typoscript.csv | 10 +++ .../Fixtures/tree_menu_fluid_typoscript.csv | 10 +++ .../LanguageMenuContentObjectTest.php | 49 +++++++++++++ .../Frontend/LanguageMenuFluidTest.php | 49 +++++++++++++ .../Frontend/ListMenuContentObjectTest.php | 47 +++++++++++++ .../Functional/Frontend/ListMenuFluidTest.php | 47 +++++++++++++ .../Frontend/TreeMenuContentObjectTest.php | 47 +++++++++++++ .../Functional/Frontend/TreeMenuFluidTest.php | 47 +++++++++++++ Tests/Functional/Hooks/DataHandlerTest.php | 30 ++------ .../DataProcessing/BreadcrumbsMenuTest.php | 24 ++++--- .../Domain/Repository/MenuRepositoryTest.php | 68 +++++++++++-------- Tests/Unit/PageStateMarkerTest.php | 2 + composer.json | 13 ++-- ext_emconf.php | 2 +- ext_localconf.php | 6 +- 60 files changed, 860 insertions(+), 370 deletions(-) create mode 100644 Classes/ContentObject/ContentObjectServiceContainer.php create mode 100644 Configuration/Services.yaml create mode 100644 Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.csv delete mode 100644 Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.xml create mode 100644 Tests/Functional/Fixtures/caches.csv delete mode 100644 Tests/Functional/Fixtures/caches.xml create mode 100644 Tests/Functional/Fixtures/pages.csv delete mode 100644 Tests/Functional/Fixtures/pages.xml create mode 100644 Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php create mode 100644 Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php create mode 100644 Tests/Functional/Frontend/Fixtures/Templates/Breadcrumbs.html create mode 100644 Tests/Functional/Frontend/Fixtures/Templates/LanguageMenu.html create mode 100644 Tests/Functional/Frontend/Fixtures/Templates/ListMenu.html create mode 100644 Tests/Functional/Frontend/Fixtures/Templates/TreeMenu.html create mode 100644 Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/pages.csv create mode 100644 Tests/Functional/Frontend/Fixtures/translated_pages.csv create mode 100644 Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv create mode 100644 Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv create mode 100644 Tests/Functional/Frontend/LanguageMenuContentObjectTest.php create mode 100644 Tests/Functional/Frontend/LanguageMenuFluidTest.php create mode 100644 Tests/Functional/Frontend/ListMenuContentObjectTest.php create mode 100644 Tests/Functional/Frontend/ListMenuFluidTest.php create mode 100644 Tests/Functional/Frontend/TreeMenuContentObjectTest.php create mode 100644 Tests/Functional/Frontend/TreeMenuFluidTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 560f064..deea435 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,14 +13,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '7.4', '7.3', '7.2' ] - TYPO3: [ '10' ] + php: [ '7.4', '8.0', '8.1' ] + TYPO3: [ '11' ] include: - - TYPO3: '11' - php: '8.1' - - TYPO3: '11' - php: '8.0' - - TYPO3: '11' + - TYPO3: '10' php: '7.4' steps: - name: Checkout diff --git a/Build/phpstan10.neon b/Build/phpstan10.neon index 8bcb0ab..53320a4 100644 --- a/Build/phpstan10.neon +++ b/Build/phpstan10.neon @@ -9,6 +9,3 @@ parameters: - message: '#Constant ORIGINAL_ROOT not found.#' path: %currentWorkingDirectory%/Tests - - - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::.*#' - path: %currentWorkingDirectory%/Tests diff --git a/Build/phpstan11.neon b/Build/phpstan11.neon index a9bf0e4..53320a4 100644 --- a/Build/phpstan11.neon +++ b/Build/phpstan11.neon @@ -6,12 +6,6 @@ parameters: - %currentWorkingDirectory%/Tests ignoreErrors: - - - message: '#.*TYPO3\\CMS\\Frontend\\Page\\PageRepository.*#' - path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php - message: '#Constant ORIGINAL_ROOT not found.#' path: %currentWorkingDirectory%/Tests - - - message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::.*#' - path: %currentWorkingDirectory%/Tests diff --git a/Classes/CacheHelper.php b/Classes/CacheHelper.php index c9bb9bf..a196c66 100644 --- a/Classes/CacheHelper.php +++ b/Classes/CacheHelper.php @@ -11,13 +11,10 @@ * of the License, or any later version. */ -use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\SingletonInterface; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** @@ -28,23 +25,12 @@ */ class CacheHelper implements SingletonInterface { - /** - * @var FrontendInterface - */ - protected $cache; + protected FrontendInterface $cache; + protected bool $disableCaching = false; - protected $disableCaching = false; - - public function __construct(FrontendInterface $cache = null, Context $context = null) + public function __construct(FrontendInterface $cache, Context $context) { - if ((new Typo3Version())->getMajorVersion() < 10) { - $this->cache = $cache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash'); - } else { - $this->cache = $cache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('hash'); - } - if ($context === null) { - $context = GeneralUtility::makeInstance(Context::class); - } + $this->cache = $cache; try { $this->disableCaching = $context->getPropertyFromAspect('workspace', 'id', 0) > 0; } catch (AspectNotFoundException $e) { @@ -60,10 +46,6 @@ public function __construct(FrontendInterface $cache = null, Context $context = /** * Looks up the items inside the cache, if it exists, takes the cached entry, otherwise computes the data * via the $loader(). - * - * @param string $cacheIdentifier - * @param callable $loader - * @return array */ public function get(string $cacheIdentifier, callable $loader): array { @@ -146,9 +128,6 @@ protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null): return $maxLifetime; } - /** - * @return TypoScriptFrontendController - */ protected function getFrontendController(): TypoScriptFrontendController { return $GLOBALS['TSFE']; diff --git a/Classes/Compiler/AbstractMenuCompiler.php b/Classes/Compiler/AbstractMenuCompiler.php index a55fa9b..4d19000 100644 --- a/Classes/Compiler/AbstractMenuCompiler.php +++ b/Classes/Compiler/AbstractMenuCompiler.php @@ -17,6 +17,7 @@ use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Context\UserAspect; use TYPO3\CMS\Core\Context\VisibilityAspect; +use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Site\Entity\SiteInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -24,36 +25,21 @@ /** * MenuCompiler sorts out all relevant parts in the constructor which most menu compilers need. */ -abstract class AbstractMenuCompiler +abstract class AbstractMenuCompiler implements SingletonInterface { - /** - * @var MenuRepository - */ - protected $menuRepository; - - /** - * @var CacheHelper - */ - protected $cache; + protected MenuRepository $menuRepository; + protected CacheHelper $cache; + protected Context $context; - /** - * @var Context - */ - protected $context; - - public function __construct(Context $context = null, CacheHelper $cache = null) + public function __construct(Context $context, CacheHelper $cache, MenuRepository $menuRepository) { - $this->context = $context ?? GeneralUtility::makeInstance(Context::class); - $this->menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $this->context); - $this->cache = $cache ?? GeneralUtility::makeInstance(CacheHelper::class); + $this->context = $context; + $this->menuRepository = $menuRepository; + $this->cache = $cache; } /** * Fetch the related pages and caches it via the cache helper. - * - * @param ContentObjectRenderer $contentObjectRenderer - * @param array $configuration - * @return array */ abstract public function compile(ContentObjectRenderer $contentObjectRenderer, array $configuration): array; @@ -91,12 +77,8 @@ protected function getCurrentSite(): ?SiteInterface /** * Function to parse typoscript config with stdWrap - * @param string $content - * @param string $configuration - * - * @return string */ - public function parseStdWrap($content, $configuration): string + public function parseStdWrap(string $content, array $configuration): string { $return = GeneralUtility::makeInstance(ContentObjectRenderer::class)->stdWrap($content, $configuration); if ($return !== null) { diff --git a/Classes/ContentObject/BreadcrumbsContentObject.php b/Classes/ContentObject/BreadcrumbsContentObject.php index a514e84..09861e2 100644 --- a/Classes/ContentObject/BreadcrumbsContentObject.php +++ b/Classes/ContentObject/BreadcrumbsContentObject.php @@ -22,23 +22,17 @@ */ class BreadcrumbsContentObject extends AbstractContentObject { - /** - * @var MenuRepository - */ - protected $menuRepository; + protected MenuRepository $menuRepository; - /** - * @param ContentObjectRenderer $cObj - */ public function __construct(ContentObjectRenderer $cObj) { - $this->menuRepository = GeneralUtility::makeInstance(MenuRepository::class); parent::__construct($cObj); + $this->menuRepository = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getMenuRepository(); } /** * @param array $conf - * @return string|void + * @return string */ public function render($conf = []) { @@ -49,7 +43,7 @@ public function render($conf = []) foreach ($pages as $page) { PageStateMarker::markStates($page, $rootLevelCount--); $cObjForItems->start($page, 'pages'); - $content .= $cObjForItems->cObjGetSingle($conf['renderObj'], $conf['renderObj.']); + $content .= $cObjForItems->cObjGetSingle($conf['renderObj'] ?? '', $conf['renderObj.'] ?? []); } return $this->cObj->stdWrap($content, $conf); } diff --git a/Classes/ContentObject/ContentObjectServiceContainer.php b/Classes/ContentObject/ContentObjectServiceContainer.php new file mode 100644 index 0000000..5f595f8 --- /dev/null +++ b/Classes/ContentObject/ContentObjectServiceContainer.php @@ -0,0 +1,62 @@ +languageMenuCompiler = $languageMenuCompiler; + $this->menuRepository = $menuRepository; + $this->listMenuCompiler = $listMenuCompiler; + $this->treeMenuCompiler = $treeMenuCompiler; + } + + public function getLanguageMenuCompiler(): LanguageMenuCompiler + { + return $this->languageMenuCompiler; + } + + public function getMenuRepository(): MenuRepository + { + return $this->menuRepository; + } + + public function getListMenuCompiler(): ListMenuCompiler + { + return $this->listMenuCompiler; + } + + public function getTreeMenuCompiler(): TreeMenuCompiler + { + return $this->treeMenuCompiler; + } +} diff --git a/Classes/ContentObject/LanguageMenuContentObject.php b/Classes/ContentObject/LanguageMenuContentObject.php index 24ed1a5..1a31af7 100644 --- a/Classes/ContentObject/LanguageMenuContentObject.php +++ b/Classes/ContentObject/LanguageMenuContentObject.php @@ -23,13 +23,21 @@ */ class LanguageMenuContentObject extends AbstractContentObject { + protected LanguageMenuCompiler $languageMenuCompiler; + + public function __construct(ContentObjectRenderer $cObj) + { + parent::__construct($cObj); + $this->languageMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getLanguageMenuCompiler(); + } + /** * @param array $conf - * @return string|void + * @return string */ public function render($conf = []) { - $pages = GeneralUtility::makeInstance(LanguageMenuCompiler::class)->compile($this->cObj, $conf); + $pages = $this->languageMenuCompiler->compile($this->cObj, $conf); $content = $this->renderItems($pages, $conf); return $this->cObj->stdWrap($content, $conf); } @@ -47,7 +55,7 @@ protected function renderItems(array $pages, array $conf): string $page['isActiveLanguage'] = false; } $cObjForItems->start($page, 'pages'); - $content .= $cObjForItems->cObjGetSingle($conf['renderObj'], $conf['renderObj.']); + $content .= $cObjForItems->cObjGetSingle($conf['renderObj'] ?? '', $conf['renderObj.'] ?? []); } return $content; } diff --git a/Classes/ContentObject/ListMenuContentObject.php b/Classes/ContentObject/ListMenuContentObject.php index 44d732f..e199e90 100644 --- a/Classes/ContentObject/ListMenuContentObject.php +++ b/Classes/ContentObject/ListMenuContentObject.php @@ -22,13 +22,21 @@ */ class ListMenuContentObject extends AbstractContentObject { + protected ListMenuCompiler $listMenuCompiler; + + public function __construct(ContentObjectRenderer $cObj) + { + parent::__construct($cObj); + $this->listMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getListMenuCompiler(); + } + /** * @param array $conf - * @return string|void + * @return string */ public function render($conf = []) { - $pages = GeneralUtility::makeInstance(ListMenuCompiler::class)->compile($this->cObj, $conf); + $pages = $this->listMenuCompiler->compile($this->cObj, $conf); $content = $this->renderItems($pages, $conf); return $this->cObj->stdWrap($content, $conf); } @@ -40,7 +48,7 @@ protected function renderItems(array $pages, array $conf): string foreach ($pages as $page) { PageStateMarker::markStates($page); $cObjForItems->start($page, 'pages'); - $content .= $cObjForItems->cObjGetSingle($conf['renderObj'], $conf['renderObj.']); + $content .= $cObjForItems->cObjGetSingle($conf['renderObj'] ?? '', $conf['renderObj.'] ?? []); } return $content; } diff --git a/Classes/ContentObject/TreeMenuContentObject.php b/Classes/ContentObject/TreeMenuContentObject.php index ea1d1ca..2fbe764 100644 --- a/Classes/ContentObject/TreeMenuContentObject.php +++ b/Classes/ContentObject/TreeMenuContentObject.php @@ -22,13 +22,21 @@ */ class TreeMenuContentObject extends AbstractContentObject { + protected TreeMenuCompiler $treeMenuCompiler; + + public function __construct(ContentObjectRenderer $cObj) + { + parent::__construct($cObj); + $this->treeMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getTreeMenuCompiler(); + } + /** * @param array $conf - * @return string|void + * @return string */ public function render($conf = []) { - $tree = GeneralUtility::makeInstance(TreeMenuCompiler::class)->compile($this->cObj, $conf); + $tree = $this->treeMenuCompiler->compile($this->cObj, $conf); $content = $this->renderItems($tree, 0, $conf['renderObj.'] ?? []); return $this->cObj->stdWrap($content, $conf); } @@ -47,7 +55,7 @@ protected function renderItems(array $pages, int $level, array $renderConfigurat $page['subpageContent'] = $this->renderItems($page['subpages'], $level++, $renderConfiguration); } $cObjForItems->start($page, 'pages'); - $content .= $cObjForItems->cObjGetSingle($renderConfiguration['level' . $level], $renderConfiguration['level' . $level . '.']); + $content .= $cObjForItems->cObjGetSingle($renderConfiguration['level' . $level] ?? '', $renderConfiguration['level' . $level . '.'] ?? []); } return $content; } diff --git a/Classes/DataProcessing/AbstractMenu.php b/Classes/DataProcessing/AbstractMenu.php index d995111..2d2e88c 100644 --- a/Classes/DataProcessing/AbstractMenu.php +++ b/Classes/DataProcessing/AbstractMenu.php @@ -21,28 +21,14 @@ */ abstract class AbstractMenu implements DataProcessorInterface { + protected ContentDataProcessor $contentDataProcessor; - /** - * @var ContentDataProcessor - */ - protected $contentDataProcessor; - - /** - * Constructor - */ - public function __construct(ContentDataProcessor $contentDataProcessor = null) + public function __construct(ContentDataProcessor $contentDataProcessor) { - $this->contentDataProcessor = $contentDataProcessor ?? GeneralUtility::makeInstance(ContentDataProcessor::class); + $this->contentDataProcessor = $contentDataProcessor; } - /** - * Process additional data processors - * - * @param array $page - * @param array $processorConfiguration - * @return array - */ - protected function processAdditionalDataProcessors(&$page, $processorConfiguration) + protected function processAdditionalDataProcessors(array &$page, array $processorConfiguration): array { if (isset($page['subpages']) && is_array($page['subpages'])) { foreach ($page['subpages'] as &$item) { diff --git a/Classes/DataProcessing/BreadcrumbsMenu.php b/Classes/DataProcessing/BreadcrumbsMenu.php index 6166d7a..ae5a85a 100644 --- a/Classes/DataProcessing/BreadcrumbsMenu.php +++ b/Classes/DataProcessing/BreadcrumbsMenu.php @@ -13,7 +13,6 @@ use B13\Menus\Domain\Repository\MenuRepository; use B13\Menus\PageStateMarker; -use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -22,15 +21,12 @@ */ class BreadcrumbsMenu extends AbstractMenu { - /** - * @var MenuRepository - */ - protected $menuRepository; + protected MenuRepository $menuRepository; - public function __construct(ContentDataProcessor $contentDataProcessor = null, MenuRepository $menuRepository = null) + public function __construct(ContentDataProcessor $contentDataProcessor, MenuRepository $menuRepository) { parent::__construct($contentDataProcessor); - $this->menuRepository = $menuRepository ?? GeneralUtility::makeInstance(MenuRepository::class); + $this->menuRepository = $menuRepository; } /** diff --git a/Classes/DataProcessing/LanguageMenu.php b/Classes/DataProcessing/LanguageMenu.php index 44d93cd..754643a 100644 --- a/Classes/DataProcessing/LanguageMenu.php +++ b/Classes/DataProcessing/LanguageMenu.php @@ -14,7 +14,7 @@ use B13\Menus\Compiler\LanguageMenuCompiler; use B13\Menus\PageStateMarker; use TYPO3\CMS\Core\Site\Entity\SiteLanguage; -use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; /** @@ -22,6 +22,14 @@ */ class LanguageMenu extends AbstractMenu { + protected $languageMenuCompliler; + + public function __construct(ContentDataProcessor $contentDataProcessor, LanguageMenuCompiler $languageMenuCompiler) + { + $this->languageMenuCompliler = $languageMenuCompiler; + parent::__construct($contentDataProcessor); + } + /** * @inheritDoc */ @@ -30,7 +38,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } - $pages = GeneralUtility::makeInstance(LanguageMenuCompiler::class)->compile($cObj, $processorConfiguration); + $pages = $this->languageMenuCompliler->compile($cObj, $processorConfiguration); $currentLanguage = $this->getCurrentSiteLanguage(); foreach ($pages as &$page) { PageStateMarker::markStates($page); @@ -48,9 +56,6 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu return $processedData; } - /** - * @return SiteLanguage|null - */ protected function getCurrentSiteLanguage(): ?SiteLanguage { return $GLOBALS['TYPO3_REQUEST']->getAttribute('language'); diff --git a/Classes/DataProcessing/ListMenu.php b/Classes/DataProcessing/ListMenu.php index 8e7c32e..0535eac 100644 --- a/Classes/DataProcessing/ListMenu.php +++ b/Classes/DataProcessing/ListMenu.php @@ -13,7 +13,7 @@ use B13\Menus\Compiler\ListMenuCompiler; use B13\Menus\PageStateMarker; -use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; /** @@ -21,6 +21,14 @@ */ class ListMenu extends AbstractMenu { + protected ListMenuCompiler $listMenuCompiler; + + public function __construct(ContentDataProcessor $contentDataProcessor, ListMenuCompiler $listMenuCompiler) + { + $this->listMenuCompiler = $listMenuCompiler; + parent::__construct($contentDataProcessor); + } + /** * @inheritDoc */ @@ -30,7 +38,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu return $processedData; } - $pages = GeneralUtility::makeInstance(ListMenuCompiler::class)->compile($cObj, $processorConfiguration); + $pages = $this->listMenuCompiler->compile($cObj, $processorConfiguration); foreach ($pages as &$page) { PageStateMarker::markStates($page); } diff --git a/Classes/DataProcessing/TreeMenu.php b/Classes/DataProcessing/TreeMenu.php index 9d7bfa3..1e2de85 100644 --- a/Classes/DataProcessing/TreeMenu.php +++ b/Classes/DataProcessing/TreeMenu.php @@ -13,7 +13,7 @@ use B13\Menus\Compiler\TreeMenuCompiler; use B13\Menus\PageStateMarker; -use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; /** @@ -21,6 +21,13 @@ */ class TreeMenu extends AbstractMenu { + protected TreeMenuCompiler $treeMenuCompiler; + + public function __construct(ContentDataProcessor $contentDataProcessor, TreeMenuCompiler $treeMenuCompiler) + { + $this->treeMenuCompiler = $treeMenuCompiler; + parent::__construct($contentDataProcessor); + } /** * @inheritDoc @@ -30,7 +37,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { return $processedData; } - $pages = GeneralUtility::makeInstance(TreeMenuCompiler::class)->compile($cObj, $processorConfiguration); + $pages = $this->treeMenuCompiler->compile($cObj, $processorConfiguration); foreach ($pages as &$page) { PageStateMarker::markStatesRecursively($page, 1); } diff --git a/Classes/Domain/Repository/MenuRepository.php b/Classes/Domain/Repository/MenuRepository.php index 042a6b8..d049fb6 100644 --- a/Classes/Domain/Repository/MenuRepository.php +++ b/Classes/Domain/Repository/MenuRepository.php @@ -13,8 +13,8 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; +use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Frontend\Page\PageRepository; /** * Responsible for interacting with the PageRepository class, in addition, should be responsible for overlays @@ -22,15 +22,8 @@ */ class MenuRepository { - /** - * @var Context - */ - protected $context; - - /** - * @var PageRepository - */ - protected $pageRepository; + protected Context $context; + protected PageRepository $pageRepository; // Never show or query them. protected $excludedDoktypes = [ @@ -39,10 +32,10 @@ class MenuRepository PageRepository::DOKTYPE_SYSFOLDER, ]; - public function __construct(Context $context = null, PageRepository $pageRepository = null) + public function __construct(Context $context, PageRepository $pageRepository) { - $this->context = $context ?? GeneralUtility::makeInstance(Context::class); - $this->pageRepository = $pageRepository ?? GeneralUtility::makeInstance(PageRepository::class, $this->context); + $this->context = $context; + $this->pageRepository = $pageRepository; } public function getBreadcrumbsMenu(array $originalRootLine, array $configuration): array @@ -108,10 +101,6 @@ public function getPageTree(int $startPageId, int $depth, array $configuration): return $page; } - /** - * @param array $configuration - * @return array - */ protected function getExcludeDoktypes(array $configuration): array { if (!empty($configuration['excludeDoktypes'])) { @@ -122,10 +111,6 @@ protected function getExcludeDoktypes(array $configuration): array return $excludedDoktypes; } - /** - * @param array $configuration - * @return array - */ protected function getExcludePages(array $configuration): ?array { $excludePages = null; @@ -135,10 +120,6 @@ protected function getExcludePages(array $configuration): ?array return empty($excludePages) ? null : $excludePages; } - /** - * @param array $configuration - * @return bool - */ protected function getIncludeNotInMenu(array $configuration): bool { return (int)($configuration['includeNotInMenu'] ?? 0) === 1; diff --git a/Classes/Hooks/DataHandlerHook.php b/Classes/Hooks/DataHandlerHook.php index e5b8035..6e1e00f 100644 --- a/Classes/Hooks/DataHandlerHook.php +++ b/Classes/Hooks/DataHandlerHook.php @@ -14,7 +14,6 @@ use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\DataHandling\DataHandler; -use TYPO3\CMS\Core\Utility\GeneralUtility; /** * This hook is triggered before caches for a page get flushed. @@ -23,6 +22,13 @@ */ class DataHandlerHook { + protected CacheManager $cacheManager; + + public function __construct(CacheManager $cacheManager) + { + $this->cacheManager = $cacheManager; + } + public function clearMenuCaches(array $params, DataHandler $dataHandler): void { $pageId = (int)($params['uid_page'] ?? 0); @@ -36,9 +42,6 @@ public function clearMenuCaches(array $params, DataHandler $dataHandler): void if ($parentPageId > 0) { $menuTags[] = 'menuId_' . $parentPageId; } - - /** @var CacheManager $cacheManager */ - $cacheManager = GeneralUtility::makeInstance(CacheManager::class); - $cacheManager->flushCachesByTags($menuTags); + $this->cacheManager->flushCachesByTags($menuTags); } } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml new file mode 100644 index 0000000..7aa4968 --- /dev/null +++ b/Configuration/Services.yaml @@ -0,0 +1,24 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + B13\Menus\: + resource: '../Classes/*' + + B13\Menus\DataProcessing\BreadcrumbsMenu: + public: true + B13\Menus\DataProcessing\LanguageMenu: + public: true + B13\Menus\DataProcessing\ListMenu: + public: true + B13\Menus\DataProcessing\TreeMenu: + public: true + B13\Menus\ContentObject\ContentObjectServiceContainer: + public: true + B13\Menus\CacheHelper: + arguments: + $cache: '@cache.hash' + B13\Menus\Hooks\DataHandlerHook: + public: true diff --git a/README.md b/README.md index c003556..b3379bc 100644 --- a/README.md +++ b/README.md @@ -78,11 +78,11 @@ Pure TypoScript-based solution: page.10.excludePages = 4,51 # 0: default, 1 to include nav_hide = 1 pages page.10.includeNotInMenu = 0 - page.10.renderObj.level1 = TEXT - page.10.renderObj.level1.typolink.parameter.data = field:uid - page.10.renderObj.level1.typolink.ATagParams = class="active" - page.10.renderObj.level1.typolink.ATagParams.if.isTrue = field:isInRootLine - page.10.renderObj.level1.dataWrap =
  • |
  • + page.10.renderObj.level0 = TEXT + page.10.renderObj.level0.typolink.parameter.data = field:uid + page.10.renderObj.level0.typolink.ATagParams = class="active" + page.10.renderObj.level0.typolink.ATagParams.if.isTrue.field = isInRootLine + page.10.renderObj.level0.dataWrap =
  • |
  • Fluid-based solution: @@ -125,9 +125,11 @@ Pure TypoScript solution: # add all siteLanguages to menu even if page is not available in language (default 0) page.10.addAllSiteLanguages = 1 page.10.wrap = - page.10.renderObj = TEXT page.10.renderObj.typolink.parameter.data = field:uid - page.10.renderObj.data = field:language_title // field:language_two_letter_iso_code + page.10.renderObj.typolink.additionalParams.data = field:language|languageId + page.10.renderObj.typolink.additionalParams.intval = 1 + page.10.renderObj.typolink.additionalParams.wrap = &L=| + page.10.renderObj.data = field:language|title // field:language|twoLetterIsoCode page.10.renderObj.wrap =
  • |
  • The stdWrap `data` is the information of the current page plus the information merged from the selected SiteLanguage. @@ -164,6 +166,10 @@ Pure TypoScript-based solution: page.10.pages = 13,14,15 # 0: default, 1 to include nav_hide = 1 pages page.10.includeNotInMenu = 0 + page.10.wrap = + page.10.renderObj = TEXT + page.10.renderObj.typolink.parameter.data = field:uid + page.10.renderObj.wrap =
  • |
  • Fluid-based solution: diff --git a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php index d90b738..5bc372f 100644 --- a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php +++ b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php @@ -1,5 +1,7 @@ getSiteByIdentifier('main'); - $languageMenuCompiler = $this->getAccessibleMock( - LanguageMenuCompiler::class, - [ - 'generateCacheIdentifierForMenu', - 'getCurrentSite', - ] - ); + $context = $this->getMockBuilder(Context::class) + ->getMock(); + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); + $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository); + $cacheHelper = $this->getAccessibleMock(CacheHelper::class, ['foo'], [], '', false); + $cacheHelper->_set('disableCaching', true); + $languageMenuCompiler = $this->getMockBuilder(LanguageMenuCompiler::class) + ->onlyMethods( + [ + 'generateCacheIdentifierForMenu', + 'getCurrentSite', + ] + ) + ->setConstructorArgs( + [ + $context, + $cacheHelper, + $menuRepository, + ] + ) + ->getMock(); $languageMenuCompiler->expects(self::any())->method('generateCacheIdentifierForMenu')->willReturn('foo'); $languageMenuCompiler->expects(self::any())->method('getCurrentSite')->willReturn($site); $menu = $languageMenuCompiler->compile($contentObjectRenderer, $configuration); diff --git a/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php b/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php index 1c635ff..e5e3f17 100644 --- a/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php +++ b/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php @@ -1,5 +1,7 @@ importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.xml'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.csv'); } protected function reduceResults(array $results): array @@ -70,26 +65,32 @@ protected function getTypoScriptFrontendController(SiteInterface $site, int $pag if ((new Typo3Version())->getMajorVersion() < 11) { return GeneralUtility::makeInstance(TypoScriptFrontendController::class, null, $site, $site->getLanguageById(0)); } - $context = $this->prophesize(Context::class); - $context->hasAspect('frontend.preview')->willReturn(false); - $context->setAspect('frontend.preview', Argument::any()); - $siteLanguage = $this->prophesize(SiteLanguage::class); - $siteLanguage->getTypo3Language()->willReturn('default'); - $pageArguments = $this->prophesize(PageArguments::class); - $pageArguments->getPageid()->willReturn($pageId); - $pageArguments->getPageType()->willReturn(0); - $pageArguments->getArguments()->willReturn([]); - $frontendUserAuth = $this->prophesize(FrontendUserAuthentication::class); - + $context = $this->getMockBuilder(Context::class) + ->getMock(); + $context->expects(self::any())->method('hasAspect')->with('frontend.preview')->willReturn(false); + $context->expects(self::any())->method('setAspect'); + $siteLanguage = $this->getMockBuilder(SiteLanguage::class) + ->disableOriginalConstructor() + ->getMock(); + $siteLanguage->expects(self::any())->method('getTypo3Language')->willReturn('default'); + $pageArguments = $this->getMockBuilder(PageArguments::class) + ->disableOriginalConstructor() + ->getMock(); + $pageArguments->expects(self::any())->method('getPageId')->willReturn($pageId); + $pageArguments->expects(self::any())->method('getPageType')->willReturn('0'); + $pageArguments->expects(self::any())->method('getArguments')->willReturn([]); + $frontendUserAuth = $this->getMockBuilder(FrontendUserAuthentication::class) + ->disableOriginalConstructor() + ->getMock(); $controller = $this->getAccessibleMock( TypoScriptFrontendController::class, ['get_cache_timeout'], [ - $context->reveal(), + $context, $site, - $siteLanguage->reveal(), - $pageArguments->reveal(), - $frontendUserAuth->reveal(), + $siteLanguage, + $pageArguments, + $frontendUserAuth, ] ); $controller->expects(self::any())->method('get_cache_timeout')->willReturn(1); diff --git a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php index 8ba302e..5904183 100644 --- a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php @@ -1,6 +1,8 @@ - - - 1 - 0 - de - - - 1 - 0 - 0 - page-1 - 0 - 0 - - - 2 - 0 - 1 - page-1-de - 1 - 1 - - diff --git a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php index d3689ec..d36d605 100644 --- a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php @@ -13,29 +13,25 @@ use B13\Menus\Domain\Repository\MenuRepository; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; +use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; class MenuRepositoryTest extends FunctionalTestCase { - - /** - * @var array - */ - protected $testExtensionsToLoad = [ - 'typo3conf/ext/menus', - ]; + protected $testExtensionsToLoad = ['typo3conf/ext/menus']; /** * @test */ public function translatedPageIsNotInMenuIfNavHideIsSet(): void { - $this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.xml'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.csv'); $languageAspect = GeneralUtility::makeInstance(LanguageAspect::class, 1); $context = GeneralUtility::makeInstance(Context::class); $context->setAspect('language', $languageAspect); - $menuRepository = GeneralUtility::makeInstance(MenuRepository::class); + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); + $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository); $page = $menuRepository->getPage(1, []); $pageInLanguage = $menuRepository->getPageInLanguage(1, $context, []); self::assertSame([], $page); @@ -47,11 +43,12 @@ public function translatedPageIsNotInMenuIfNavHideIsSet(): void */ public function translatedPageIsInMenuIfNavHideAndIgnoreNavHideIsSet(): void { - $this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.xml'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.csv'); $languageAspect = GeneralUtility::makeInstance(LanguageAspect::class, 1); $context = GeneralUtility::makeInstance(Context::class); $context->setAspect('language', $languageAspect); - $menuRepository = GeneralUtility::makeInstance(MenuRepository::class); + $pageRepository = GeneralUtility::makeInstance(PageRepository::class); + $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository); $page = $menuRepository->getPage(1, ['includeNotInMenu' => 1]); $pageInLanguage = $menuRepository->getPageInLanguage(1, $context, ['includeNotInMenu' => 1]); $page = $this->reduceResults($page); diff --git a/Tests/Functional/Fixtures/caches.csv b/Tests/Functional/Fixtures/caches.csv new file mode 100644 index 0000000..1984f52 --- /dev/null +++ b/Tests/Functional/Fixtures/caches.csv @@ -0,0 +1,7 @@ +"cache_pages" +,"identifier" +,"foo" +"cache_pages_tags" +,"identifier","tag" +,"foo","pageId_1" +,"foo","menuId_2" diff --git a/Tests/Functional/Fixtures/caches.xml b/Tests/Functional/Fixtures/caches.xml deleted file mode 100644 index a39244f..0000000 --- a/Tests/Functional/Fixtures/caches.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - foo - - - foo - pageId_1 - - - foo - menuId_2 - - diff --git a/Tests/Functional/Fixtures/pages.csv b/Tests/Functional/Fixtures/pages.csv new file mode 100644 index 0000000..ffdef0f --- /dev/null +++ b/Tests/Functional/Fixtures/pages.csv @@ -0,0 +1,8 @@ +"pages" +,"uid","pid","title","slug",nav_hide,doktype +,1,0,"page-1","/page-1",0,0 +,2,1,"page-2","/page-1/page-2",0,99 +,3,2,"page-3","/page-1/page-2/page-3",0,0 +,4,1,"page-4","/page-1/page-4",0,0 +,5,2,"page-5","/page-1/page-2/page-5",1,0 +,6,1,"page-6","/page-1/page-6",1,0 diff --git a/Tests/Functional/Fixtures/pages.xml b/Tests/Functional/Fixtures/pages.xml deleted file mode 100644 index 11d1eb3..0000000 --- a/Tests/Functional/Fixtures/pages.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - - - 1 - 0 - page-1 - /page-1 - 0 - - - 2 - 1 - 99 - page-2 - /page-1/page-2 - 0 - - - 3 - 2 - page-3 - /page-1/page-2/page-3 - 0 - - - 4 - 1 - page-4 - /page-1/page-4 - 0 - - - 5 - 2 - page-5 - /page-1/page-2/page-5 - 1 - - - 6 - 1 - page-6 - /page-1/page-6 - 1 - - diff --git a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php new file mode 100644 index 0000000..a217e42 --- /dev/null +++ b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php @@ -0,0 +1,47 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'root'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $expected = 'rootpage-1'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php new file mode 100644 index 0000000..6cf7fd1 --- /dev/null +++ b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php @@ -0,0 +1,47 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'root'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $expected = 'rootpage-1'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/Fixtures/Templates/Breadcrumbs.html b/Tests/Functional/Frontend/Fixtures/Templates/Breadcrumbs.html new file mode 100644 index 0000000..a5df2bf --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/Templates/Breadcrumbs.html @@ -0,0 +1,7 @@ + + + + {page.title} + + + diff --git a/Tests/Functional/Frontend/Fixtures/Templates/LanguageMenu.html b/Tests/Functional/Frontend/Fixtures/Templates/LanguageMenu.html new file mode 100644 index 0000000..dc81751 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/Templates/LanguageMenu.html @@ -0,0 +1,7 @@ + + + + {item.language.title} + + + diff --git a/Tests/Functional/Frontend/Fixtures/Templates/ListMenu.html b/Tests/Functional/Frontend/Fixtures/Templates/ListMenu.html new file mode 100644 index 0000000..243f308 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/Templates/ListMenu.html @@ -0,0 +1,7 @@ + + + + {page.title} + + + diff --git a/Tests/Functional/Frontend/Fixtures/Templates/TreeMenu.html b/Tests/Functional/Frontend/Fixtures/Templates/TreeMenu.html new file mode 100644 index 0000000..fea496d --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/Templates/TreeMenu.html @@ -0,0 +1,7 @@ + + + + {page.title} + + + diff --git a/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv b/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv new file mode 100644 index 0000000..8c34e8e --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv @@ -0,0 +1,8 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.20 = BREADCRUMBS +page.20.renderObj = TEXT +page.20.renderObj.typolink.parameter.data = field:uid +" diff --git a/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv b/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv new file mode 100644 index 0000000..495eb3b --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv @@ -0,0 +1,9 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.10 = FLUIDTEMPLATE +page.10.templateRootPaths.10 = EXT:menus/Tests/Functional/Frontend/Fixtures/Templates +page.10.templateName = Breadcrumbs.html +page.10.dataProcessing.10 = B13\Menus\DataProcessing\BreadcrumbsMenu +" diff --git a/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv b/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv new file mode 100644 index 0000000..4e3f4d8 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv @@ -0,0 +1,14 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.20 = LANGUAGEMENU +page.20.renderObj = TEXT +page.20.renderObj.typolink.parameter.data = field:uid +page.20.renderObj.typolink.ATagParams = class='active' +page.20.renderObj.typolink.ATagParams.if.isTrue.field = isActiveLanguage +page.20.renderObj.typolink.additionalParams.data = field:language|languageId +page.20.renderObj.typolink.additionalParams.intval = 1 +page.20.renderObj.typolink.additionalParams.wrap = &L=| +page.20.renderObj.data = field:language|title // field:language|twoLetterIsoCode +" diff --git a/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv b/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv new file mode 100644 index 0000000..beb6fe6 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv @@ -0,0 +1,10 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.10 = FLUIDTEMPLATE +page.10.templateRootPaths.10 = EXT:menus/Tests/Functional/Frontend/Fixtures/Templates +page.10.templateName = LanguageMenu.html +page.10.dataProcessing.10 = B13\Menus\DataProcessing\LanguageMenu +page.10.dataProcessing.10.as = menu +" diff --git a/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv b/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv new file mode 100644 index 0000000..6fd3927 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv @@ -0,0 +1,9 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.20 = LISTMENU +page.20.pages = 2 +page.20.renderObj = TEXT +page.20.renderObj.typolink.parameter.data = field:uid +" diff --git a/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv b/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv new file mode 100644 index 0000000..b45e981 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv @@ -0,0 +1,11 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.10 = FLUIDTEMPLATE +page.10.templateRootPaths.10 = EXT:menus/Tests/Functional/Frontend/Fixtures/Templates +page.10.templateName = ListMenu.html +page.10.dataProcessing.10 = B13\Menus\DataProcessing\ListMenu +page.10.dataProcessing.10.pages = 2 +page.10.dataProcessing.10.as = menu +" diff --git a/Tests/Functional/Frontend/Fixtures/pages.csv b/Tests/Functional/Frontend/Fixtures/pages.csv new file mode 100644 index 0000000..f2918cf --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/pages.csv @@ -0,0 +1,5 @@ +"pages" +,"uid","pid","title","slug" +,1,0,"root","/" +,2,1,"page-1","/page-1" +,3,1,"page-2","/page-2" diff --git a/Tests/Functional/Frontend/Fixtures/translated_pages.csv b/Tests/Functional/Frontend/Fixtures/translated_pages.csv new file mode 100644 index 0000000..ae3a9b6 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/translated_pages.csv @@ -0,0 +1,5 @@ +"pages" +,"uid","pid","title","slug","l10n_parent","sys_language_uid" +,11,0,"root-de","/",1,1 +,12,1,"page-de-1","/page-1",2,1 +,13,1,"page-de-2","/page-2",3,1 diff --git a/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv b/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv new file mode 100644 index 0000000..8a37b2d --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv @@ -0,0 +1,10 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.20 = TREEMENU +page.20.renderObj.level0 = TEXT +page.20.renderObj.level0.typolink.parameter.data = field:uid +page.20.renderObj.level0.typolink.ATagParams = class='active' +page.20.renderObj.level0.typolink.ATagParams.if.isTrue.field = isInRootLine +" diff --git a/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv b/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv new file mode 100644 index 0000000..58e1bf9 --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv @@ -0,0 +1,10 @@ +"sys_template" +,"uid","pid","root","config" +,1,1,1,"page = PAGE +page.config.disableAllHeaderCode = 1 +page.10 = FLUIDTEMPLATE +page.10.templateRootPaths.10 = EXT:menus/Tests/Functional/Frontend/Fixtures/Templates +page.10.templateName = TreeMenu.html +page.10.dataProcessing.10 = B13\Menus\DataProcessing\TreeMenu +page.10.dataProcessing.10.as = menu +" diff --git a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php new file mode 100644 index 0000000..5202a4b --- /dev/null +++ b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php @@ -0,0 +1,49 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'englishgerman'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/de/')); + $expected = 'englishgerman'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/LanguageMenuFluidTest.php b/Tests/Functional/Frontend/LanguageMenuFluidTest.php new file mode 100644 index 0000000..7833241 --- /dev/null +++ b/Tests/Functional/Frontend/LanguageMenuFluidTest.php @@ -0,0 +1,49 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'englishgerman'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/de/')); + $expected = 'englishgerman'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/ListMenuContentObjectTest.php b/Tests/Functional/Frontend/ListMenuContentObjectTest.php new file mode 100644 index 0000000..14b1790 --- /dev/null +++ b/Tests/Functional/Frontend/ListMenuContentObjectTest.php @@ -0,0 +1,47 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'page-1'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $expected = 'page-1'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/ListMenuFluidTest.php b/Tests/Functional/Frontend/ListMenuFluidTest.php new file mode 100644 index 0000000..6c4e9e7 --- /dev/null +++ b/Tests/Functional/Frontend/ListMenuFluidTest.php @@ -0,0 +1,47 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'page-1'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $expected = 'page-1'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php new file mode 100644 index 0000000..3ae4db4 --- /dev/null +++ b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php @@ -0,0 +1,47 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'page-1page-2'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $expected = 'page-1page-2'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Frontend/TreeMenuFluidTest.php b/Tests/Functional/Frontend/TreeMenuFluidTest.php new file mode 100644 index 0000000..c5dbd5c --- /dev/null +++ b/Tests/Functional/Frontend/TreeMenuFluidTest.php @@ -0,0 +1,47 @@ + 'typo3conf/sites']; + + /** + * @test + */ + public function menuOnRootPage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $expected = 'page-1page-2'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } + + /** + * @test + */ + public function menuOnSubpage(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $expected = 'page-1page-2'; + $body = (string)$response->getBody(); + self::assertStringContainsString($expected, $body); + } +} diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index bc18e6e..262a3c3 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -20,23 +20,10 @@ class DataHandlerTest extends FunctionalTestCase { + protected DataHandler $dataHandler; + protected BackendUserAuthentication $backendUser; - /** - * @var DataHandler - */ - protected $dataHandler; - - /** - * @var BackendUserAuthentication - */ - protected $backendUser; - - /** - * @var array - */ - protected $testExtensionsToLoad = [ - 'typo3conf/ext/menus', - ]; + protected $testExtensionsToLoad = ['typo3conf/ext/menus']; /** * @throws \Doctrine\DBAL\DBALException @@ -45,17 +32,14 @@ class DataHandlerTest extends FunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.xml'); - $this->importDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/caches.xml'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/caches.csv'); $this->backendUser = $this->setUpBackendUserFromFixture(1); Bootstrap::initializeLanguageObject(); $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); } - /** - * @return array - */ - public function cmdmapDataProvider() + public function cmdmapDataProvider(): array { return [ 'copy page' => ['cmdmap' => ['pages' => [ @@ -112,7 +96,7 @@ protected function assertCacheIsEmpty(): void $rows = $queryBuilder->select('*') ->from('cache_pages') ->execute() - ->fetchAll(); + ->fetchAllAssociative(); self::assertSame(0, count($rows)); } } diff --git a/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php b/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php index e1d51d8..bcf72f3 100644 --- a/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php +++ b/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php @@ -1,5 +1,7 @@ 2], ]; $GLOBALS['TSFE']->id = 2; - $menuRepository = $this->prophesize(MenuRepository::class); - $menuRepository->getBreadcrumbsMenu($GLOBALS['TSFE']->rootLine, [])->willReturn($pages); - $contentDataProcessor = $this->prophesize(ContentDataProcessor::class); - $contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class); + $menuRepository = $this->getMockBuilder(MenuRepository::class) + ->disableOriginalConstructor() + ->getMock(); + $menuRepository->expects(self::once())->method('getBreadcrumbsMenu')->with($GLOBALS['TSFE']->rootLine, [])->willReturn($pages); + $contentDataProcessor = $this->getMockBuilder(ContentDataProcessor::class) + ->disableOriginalConstructor() + ->getMock(); + $contentObjectRenderer = $this->getMockBuilder(ContentObjectRenderer::class) + ->disableOriginalConstructor() + ->getMock(); + $contentObjectRenderer->expects(self::once())->method('stdWrapValue')->with('as', [], 'breadcrumbs')->willReturn('breadcrumbs'); $breadcrumbsMenuDataProcessor = $this->getMockBuilder(BreadcrumbsMenu::class) - ->setMethods(['processAdditionalDataProcessors']) - ->setConstructorArgs([$contentDataProcessor->reveal(), $menuRepository->reveal()]) + ->onlyMethods(['processAdditionalDataProcessors']) + ->setConstructorArgs([$contentDataProcessor, $menuRepository]) ->getMock(); - $contentObjectRenderer->stdWrapValue('as', [], 'breadcrumbs')->willReturn('breadcrumbs'); - $processedData = $breadcrumbsMenuDataProcessor->process($contentObjectRenderer->reveal(), [], [], []); + $processedData = $breadcrumbsMenuDataProcessor->process($contentObjectRenderer, [], [], []); self::assertTrue($processedData['breadcrumbs'][0]['isInRootLine']); self::assertTrue($processedData['breadcrumbs'][1]['isInRootLine']); self::assertFalse($processedData['breadcrumbs'][0]['isCurrentPage']); diff --git a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php index 36d635a..e015cfb 100644 --- a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php @@ -1,5 +1,7 @@ prophesize(Context::class); - $context->getAspect('language')->willReturn($this->prophesize(LanguageAspect::class)->reveal()); - $pageRepository = $this->prophesize(PageRepository::class); + $languageAspect = $this->getMockBuilder(LanguageAspect::class) + ->getMock(); + $context = $this->getMockBuilder(Context::class) + ->getMock(); + $context->expects(self::once())->method('getAspect')->with('language')->willReturn($languageAspect); + $pageRepository = $this->getMockBuilder(PageRepository::class) + ->disableOriginalConstructor() + ->getMock(); $excludedDoktypes = [ PageRepository::DOKTYPE_BE_USER_SECTION, PageRepository::DOKTYPE_RECYCLER, PageRepository::DOKTYPE_SYSFOLDER, ]; - $pageRepository->getMenu(1, '*', 'sorting', Argument::any(), false)->willReturn([]); - $pageRepository->getMenu(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ') ', false)->shouldBeCalled()->willReturn([]); - - $menuRepository = $this->getMockBuilder(MenuRepository::class) - ->setMethods(['foo']) - ->setConstructorArgs([$context->reveal(), $pageRepository->reveal()]) - ->getMock(); + $pageRepository->expects(self::once())->method('getMenu') + ->with(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ') ', false) + ->willReturn([]); + $menuRepository = new MenuRepository($context, $pageRepository); $menuRepository->getSubPagesOfPage(1, 1, []); } @@ -48,21 +51,23 @@ public function getSubPagesOfPageRestrictQueryToExcludeDoktypes(): void */ public function getSubPagesOfPageMergeExcludeDoktypesFromConfiguration(): void { - $context = $this->prophesize(Context::class); - $context->getAspect('language')->willReturn($this->prophesize(LanguageAspect::class)->reveal()); - $pageRepository = $this->prophesize(PageRepository::class); + $languageAspect = $this->getMockBuilder(LanguageAspect::class) + ->getMock(); + $context = $this->getMockBuilder(Context::class) + ->getMock(); + $context->expects(self::once())->method('getAspect')->with('language')->willReturn($languageAspect); + $pageRepository = $this->getMockBuilder(PageRepository::class) + ->disableOriginalConstructor() + ->getMock(); $excludedDoktypes = [ PageRepository::DOKTYPE_BE_USER_SECTION, PageRepository::DOKTYPE_RECYCLER, PageRepository::DOKTYPE_SYSFOLDER, ]; - $pageRepository->getMenu(1, '*', 'sorting', Argument::any(), false)->willReturn([]); - $pageRepository->getMenu(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ',99) ', false)->shouldBeCalled()->willReturn([]); - - $menuRepository = $this->getMockBuilder(MenuRepository::class) - ->setMethods(['foo']) - ->setConstructorArgs([$context->reveal(), $pageRepository->reveal()]) - ->getMock(); + $pageRepository->expects(self::once())->method('getMenu') + ->with(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ',99) ', false) + ->willReturn([]); + $menuRepository = new MenuRepository($context, $pageRepository); $menuRepository->getSubPagesOfPage(1, 1, ['excludeDoktypes' => 99]); } @@ -75,16 +80,21 @@ public function getBreadcrumbsMenuRespectConfiguredExcludeDoktypes(): void ['uid' => 1, 'doktype' => 99, 'nav_hide'=> 0], ['uid' => 2, 'doktype' => 98, 'nav_hide'=> 0], ]; - $context = $this->prophesize(Context::class); - $context->getAspect('language')->willReturn($this->prophesize(LanguageAspect::class)->reveal()); - $pageRepository = $this->prophesize(PageRepository::class); - $pageRepository->getPage(1)->willReturn($rootLine[0]); - $pageRepository->getPage(2)->willReturn($rootLine[1]); - $pageRepository->isPageSuitableForLanguage(Argument::any(), Argument::any())->willReturn(true); + $languageAspect = $this->getMockBuilder(LanguageAspect::class) + ->getMock(); + $context = $this->getMockBuilder(Context::class) + ->getMock(); + $context->expects(self::once())->method('getAspect')->with('language')->willReturn($languageAspect); + $pageRepository = $this->getMockBuilder(PageRepository::class) + ->disableOriginalConstructor() + ->getMock(); + $pageRepository->expects(self::at(0))->method('getPage')->with(1)->willReturn($rootLine[0]); + $pageRepository->expects(self::at(1))->method('getPage')->with(2)->willReturn($rootLine[1]); $menuRepository = $this->getMockBuilder(MenuRepository::class) - ->setMethods(['populateAdditionalKeysForPage']) - ->setConstructorArgs([$context->reveal(), $pageRepository->reveal()]) + ->onlyMethods(['populateAdditionalKeysForPage', 'isPageSuitableForLanguage']) + ->setConstructorArgs([$context, $pageRepository]) ->getMock(); + $menuRepository->expects(self::any())->method('isPageSuitableForLanguage')->willReturn(true); $breadcrumbs = $menuRepository->getBreadcrumbsMenu($rootLine, ['excludeDoktypes' => 99]); self::assertSame(1, count($breadcrumbs)); } diff --git a/Tests/Unit/PageStateMarkerTest.php b/Tests/Unit/PageStateMarkerTest.php index 2a3d6b2..35346d2 100644 --- a/Tests/Unit/PageStateMarkerTest.php +++ b/Tests/Unit/PageStateMarkerTest.php @@ -1,5 +1,7 @@ 'b13 GmbH', 'constraints' => [ 'depends' => [ - 'typo3' => '9.5.0-11.99.99', + 'typo3' => '10.4.0-11.99.99', ], ], ]; diff --git a/ext_localconf.php b/ext_localconf.php index e86ab26..e1c4802 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,6 @@ \B13\Menus\ContentObject\TreeMenuContentObject::class, @@ -11,7 +11,3 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc']['tx-menus'] = \B13\Menus\Hooks\DataHandlerHook::class . '->clearMenuCaches'; - -if (!class_exists(\TYPO3\CMS\Frontend\Page\PageRepository::class)) { - class_alias(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class, \TYPO3\CMS\Frontend\Page\PageRepository::class); -} From 32e5e349691da1e740741bc98dd5c0d2e00da24d Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Fri, 28 Oct 2022 10:30:05 +0200 Subject: [PATCH 02/21] [TASK] new frontend test provide a frontend request test for access restricted pages Relates to: #72 --- .../Frontend/Fixtures/access_restriction.csv | 11 ++++++++ .../Functional/Frontend/TreeMenuFluidTest.php | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Tests/Functional/Frontend/Fixtures/access_restriction.csv diff --git a/Tests/Functional/Frontend/Fixtures/access_restriction.csv b/Tests/Functional/Frontend/Fixtures/access_restriction.csv new file mode 100644 index 0000000..0830e1f --- /dev/null +++ b/Tests/Functional/Frontend/Fixtures/access_restriction.csv @@ -0,0 +1,11 @@ +"pages" +,"uid","pid","title","slug","fe_group" +,1,0,"root","/","" +,2,1,"page-1","/page-1","" +,3,1,"page-2","/page-2","1" +"fe_groups" +,"uid","pid" +,1,1 +"fe_users" +,"uid","pid","usergroup" +,1,1,"1" diff --git a/Tests/Functional/Frontend/TreeMenuFluidTest.php b/Tests/Functional/Frontend/TreeMenuFluidTest.php index c5dbd5c..08c7326 100644 --- a/Tests/Functional/Frontend/TreeMenuFluidTest.php +++ b/Tests/Functional/Frontend/TreeMenuFluidTest.php @@ -11,6 +11,7 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; class TreeMenuFluidTest extends FunctionalTestCase @@ -44,4 +45,31 @@ public function menuOnSubpage(): void $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); } + + /** + * @test + */ + public function menuWithAccessRestrictionForNotLoggedinUser(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/access_restriction.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $body = (string)$response->getBody(); + self::assertStringContainsString('page-1', $body); + self::assertStringNotContainsString('page-2', $body); + } + + /** + * @test + */ + public function menuWithAccessRestrictionForLoggedinUser(): void + { + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/access_restriction.csv'); + $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $context = (new InternalRequestContext())->withFrontendUserId(1); + $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/'), $context); + $body = (string)$response->getBody(); + self::assertStringContainsString('page-1', $body); + self::assertStringContainsString('page-2', $body); + } } From 8a9251b78d59a30d08ef74bec09600c6446d77a0 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Thu, 3 Nov 2022 16:55:41 +0100 Subject: [PATCH 03/21] [TASK] TYPO3 v12 Support --- .github/workflows/ci.yml | 6 ++++ Build/Scripts/runTests.sh | 6 ++++ Build/phpstan10.neon | 6 ++++ Build/phpstan12.neon | 17 ++++++++++ Build/phpunit/FunctionalTests.xml | 1 - Build/phpunit/UnitTestsBootstrap.php | 3 -- Build/testing-docker/docker-compose.yml | 31 +++++++++++++++-- .../BreadcrumbsContentObject.php | 7 +++- .../LanguageMenuContentObject.php | 7 +++- .../ContentObject/ListMenuContentObject.php | 7 +++- .../ContentObject/TreeMenuContentObject.php | 7 +++- Classes/Domain/Repository/MenuRepository.php | 6 ++-- Configuration/Services.yaml | 17 ++++++++++ .../Compiler/LanguageMenuCompilerTest.php | 13 +++++--- .../DataProcessing/DataProcessingTest.php | 10 ++---- .../DataProcessing/ListMenuProcessorTest.php | 7 ++-- .../DataProcessing/TreeMenuProcessorTest.php | 6 ++-- .../Domain/Repository/MenuRepositoryTest.php | 2 +- Tests/Functional/Fixtures/be_users.csv | 4 +++ .../Frontend/AbstractFrontendTest.php | 33 +++++++++++++++++++ .../BreadcrumbMenuContentObjectTest.php | 11 ++----- .../Frontend/BreadcrumbMenuFluidTest.php | 11 ++----- .../LanguageMenuContentObjectTest.php | 11 ++----- .../Frontend/LanguageMenuFluidTest.php | 11 ++----- .../Frontend/ListMenuContentObjectTest.php | 11 ++----- .../Functional/Frontend/ListMenuFluidTest.php | 11 ++----- .../Frontend/TreeMenuContentObjectTest.php | 11 ++----- .../Functional/Frontend/TreeMenuFluidTest.php | 16 ++++----- Tests/Functional/Hooks/DataHandlerTest.php | 9 ++--- .../DataProcessing/BreadcrumbsMenuTest.php | 1 - .../Domain/Repository/MenuRepositoryTest.php | 22 ++++++++++--- Tests/Unit/PageStateMarkerTest.php | 1 - composer.json | 17 +++++----- ext_localconf.php | 14 ++++---- 34 files changed, 226 insertions(+), 127 deletions(-) create mode 100644 Build/phpstan12.neon create mode 100644 Tests/Functional/Fixtures/be_users.csv create mode 100644 Tests/Functional/Frontend/AbstractFrontendTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index deea435..29a3b47 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,16 @@ jobs: include: - TYPO3: '10' php: '7.4' + - TYPO3: '12' + php: '8.1' steps: - name: Checkout uses: actions/checkout@v2 + - name: Patch 10 + if: matrix.TYPO3 == '10' + run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t ${{ matrix.TYPO3 }} -s patchV10 + - name: Install testing system run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t ${{ matrix.TYPO3 }} -s composerInstall diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 2d7e106..3b7d456 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -241,6 +241,12 @@ case ${TEST_SUITE} in SUITE_EXIT_CODE=$? docker-compose down ;; + patchV10) + setUpDockerComposeDotEnv + docker-compose run patchV10 + SUITE_EXIT_CODE=$? + docker-compose down + ;; functional) setUpDockerComposeDotEnv case ${DBMS} in diff --git a/Build/phpstan10.neon b/Build/phpstan10.neon index 53320a4..e3aecbf 100644 --- a/Build/phpstan10.neon +++ b/Build/phpstan10.neon @@ -9,3 +9,9 @@ parameters: - message: '#Constant ORIGINAL_ROOT not found.#' path: %currentWorkingDirectory%/Tests + - + message: '#Call to an undefined method B13\\Menus\\ContentObject\\.*ContentObject::setContentObjectRenderer\(\).#' + path: %currentWorkingDirectory%/Classes/ContentObject/* + - + message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(string\) does not accept int#' + path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php diff --git a/Build/phpstan12.neon b/Build/phpstan12.neon new file mode 100644 index 0000000..565faf6 --- /dev/null +++ b/Build/phpstan12.neon @@ -0,0 +1,17 @@ +parameters: + level: 5 + + paths: + - %currentWorkingDirectory%/Classes + - %currentWorkingDirectory%/Tests + + ignoreErrors: + - + message: '#Constant ORIGINAL_ROOT not found.#' + path: %currentWorkingDirectory%/Tests + - + message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#' + path: %currentWorkingDirectory%/Classes/ContentObject/* + - + message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#' + path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php diff --git a/Build/phpunit/FunctionalTests.xml b/Build/phpunit/FunctionalTests.xml index 17f81d2..ded3940 100644 --- a/Build/phpunit/FunctionalTests.xml +++ b/Build/phpunit/FunctionalTests.xml @@ -24,6 +24,5 @@ - diff --git a/Build/phpunit/UnitTestsBootstrap.php b/Build/phpunit/UnitTestsBootstrap.php index 9e9222f..b12ccf0 100644 --- a/Build/phpunit/UnitTestsBootstrap.php +++ b/Build/phpunit/UnitTestsBootstrap.php @@ -15,9 +15,6 @@ use TYPO3\CMS\Core\Information\Typo3Version; call_user_func(function () { - if (!class_exists(\TYPO3\CMS\Frontend\Page\PageRepository::class)) { - class_alias(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class, \TYPO3\CMS\Frontend\Page\PageRepository::class); - } $testbase = new \TYPO3\TestingFramework\Core\Testbase(); // These if's are for core testing (package typo3/cms) only. cms-composer-installer does diff --git a/Build/testing-docker/docker-compose.yml b/Build/testing-docker/docker-compose.yml index 7d0ddef..3ee9e1c 100644 --- a/Build/testing-docker/docker-compose.yml +++ b/Build/testing-docker/docker-compose.yml @@ -82,13 +82,38 @@ services: set -x fi php -v | grep '^PHP'; - if [ ${TYPO3} -eq 10 ]; then - composer install --no-progress --no-interaction; + if [ ${TYPO3} -eq 11 ]; then + composer install --no-progress --no-interaction + composer prepare-tests + elif [ ${TYPO3} -eq 10 ]; then + composer require friendsofphp/php-cs-fixer:^3.4 typo3/cms-install:^10.4 typo3/cms-fluid-styled-content:^10.4 typo3/testing-framework:^6 --dev -W --no-progress --no-interaction + if [ "${PHP_VERSION}" == "7.4" ]; then + composer require friendsofphp/php-cs-fixer:~3.9.0 --dev --no-progress --no-interaction + fi + composer prepare-tests-10 && composer prepare-tests else - composer remove typo3/cms* --dev --no-progress --no-interaction && composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction + composer remove typo3/cms* --dev --no-progress --no-interaction && composer config --no-interaction --no-plugins allow-plugins.sbuerk/typo3-cmscomposerinstallers-testingframework-bridge true && composer require typo3/cms-install:12.*.*@dev typo3/cms-fluid-styled-content:12.*.*@dev sbuerk/typo3-cmscomposerinstallers-testingframework-bridge:^0.0.1 --dev -W --no-progress --no-interaction + composer prepare-tests fi " + patchV10: + image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest + user: ${HOST_UID} + volumes: + - ${ROOT_DIR}:${ROOT_DIR} + - ${HOST_HOME}:${HOST_HOME} + - /etc/passwd:/etc/passwd:ro + - /etc/group:/etc/group:ro + working_dir: ${ROOT_DIR} + command: > + /bin/sh -c " + find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)testExtensionsToLoad = \[/protected \1testExtensionsToLoad = [/g'; + find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected bool \(.*\)resetSingletonInstances = /protected \1resetSingletonInstances = /g'; + find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)coreExtensionsToLoad = \[/protected \1coreExtensionsToLoad = [/g'; + find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)pathsToLinkInTestInstance = \[/protected \1pathsToLinkInTestInstance = [/g'; + " + composer_validate: image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest user: ${HOST_UID} diff --git a/Classes/ContentObject/BreadcrumbsContentObject.php b/Classes/ContentObject/BreadcrumbsContentObject.php index 09861e2..ddbcdec 100644 --- a/Classes/ContentObject/BreadcrumbsContentObject.php +++ b/Classes/ContentObject/BreadcrumbsContentObject.php @@ -13,6 +13,7 @@ use B13\Menus\Domain\Repository\MenuRepository; use B13\Menus\PageStateMarker; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -26,7 +27,11 @@ class BreadcrumbsContentObject extends AbstractContentObject public function __construct(ContentObjectRenderer $cObj) { - parent::__construct($cObj); + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { + parent::__construct($cObj); + } else { + $this->setContentObjectRenderer($cObj); + } $this->menuRepository = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getMenuRepository(); } diff --git a/Classes/ContentObject/LanguageMenuContentObject.php b/Classes/ContentObject/LanguageMenuContentObject.php index 1a31af7..695c780 100644 --- a/Classes/ContentObject/LanguageMenuContentObject.php +++ b/Classes/ContentObject/LanguageMenuContentObject.php @@ -13,6 +13,7 @@ use B13\Menus\Compiler\LanguageMenuCompiler; use B13\Menus\PageStateMarker; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; @@ -27,7 +28,11 @@ class LanguageMenuContentObject extends AbstractContentObject public function __construct(ContentObjectRenderer $cObj) { - parent::__construct($cObj); + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { + parent::__construct($cObj); + } else { + $this->setContentObjectRenderer($cObj); + } $this->languageMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getLanguageMenuCompiler(); } diff --git a/Classes/ContentObject/ListMenuContentObject.php b/Classes/ContentObject/ListMenuContentObject.php index e199e90..8a9f775 100644 --- a/Classes/ContentObject/ListMenuContentObject.php +++ b/Classes/ContentObject/ListMenuContentObject.php @@ -13,6 +13,7 @@ use B13\Menus\Compiler\ListMenuCompiler; use B13\Menus\PageStateMarker; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -26,7 +27,11 @@ class ListMenuContentObject extends AbstractContentObject public function __construct(ContentObjectRenderer $cObj) { - parent::__construct($cObj); + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { + parent::__construct($cObj); + } else { + $this->setContentObjectRenderer($cObj); + } $this->listMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getListMenuCompiler(); } diff --git a/Classes/ContentObject/TreeMenuContentObject.php b/Classes/ContentObject/TreeMenuContentObject.php index 2fbe764..310167e 100644 --- a/Classes/ContentObject/TreeMenuContentObject.php +++ b/Classes/ContentObject/TreeMenuContentObject.php @@ -13,6 +13,7 @@ use B13\Menus\Compiler\TreeMenuCompiler; use B13\Menus\PageStateMarker; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -26,7 +27,11 @@ class TreeMenuContentObject extends AbstractContentObject public function __construct(ContentObjectRenderer $cObj) { - parent::__construct($cObj); + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { + parent::__construct($cObj); + } else { + $this->setContentObjectRenderer($cObj); + } $this->treeMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getTreeMenuCompiler(); } diff --git a/Classes/Domain/Repository/MenuRepository.php b/Classes/Domain/Repository/MenuRepository.php index d049fb6..e697f50 100644 --- a/Classes/Domain/Repository/MenuRepository.php +++ b/Classes/Domain/Repository/MenuRepository.php @@ -104,7 +104,7 @@ public function getPageTree(int $startPageId, int $depth, array $configuration): protected function getExcludeDoktypes(array $configuration): array { if (!empty($configuration['excludeDoktypes'])) { - $excludedDoktypes = array_unique(array_merge($this->excludedDoktypes, GeneralUtility::intExplode(',', $configuration['excludeDoktypes']))); + $excludedDoktypes = array_unique(array_merge($this->excludedDoktypes, GeneralUtility::intExplode(',', (string)$configuration['excludeDoktypes']))); } else { $excludedDoktypes = $this->excludedDoktypes; } @@ -115,7 +115,7 @@ protected function getExcludePages(array $configuration): ?array { $excludePages = null; if (!empty($configuration['excludePages'])) { - $excludePages = array_unique(GeneralUtility::intExplode(',', $configuration['excludePages'])); + $excludePages = array_unique(GeneralUtility::intExplode(',', (string)$configuration['excludePages'])); } return empty($excludePages) ? null : $excludePages; } @@ -130,7 +130,7 @@ public function getSubPagesOfPage(int $pageId, int $depth, array $configuration) $whereClause = ''; if (!empty($configuration['excludePages'])) { - $excludedPagesArray = GeneralUtility::intExplode(',', $configuration['excludePages']); + $excludedPagesArray = GeneralUtility::intExplode(',', (string)$configuration['excludePages']); $whereClause .= ' AND uid NOT IN (' . implode(',', $excludedPagesArray) . ')'; } $excludedDoktypes = $this->getExcludeDoktypes($configuration); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 7aa4968..cf0247c 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -22,3 +22,20 @@ services: $cache: '@cache.hash' B13\Menus\Hooks\DataHandlerHook: public: true + + B13\Menus\ContentObject\TreeMenuContentObject: + tags: + - name: frontend.contentobject + identifier: 'TREEMENU' + B13\Menus\ContentObject\ListMenuContentObject: + tags: + - name: frontend.contentobject + identifier: 'LISTMENU' + B13\Menus\ContentObject\LanguageMenuContentObject: + tags: + - name: frontend.contentobject + identifier: 'LANGUAGEMENU' + B13\Menus\ContentObject\BreadcrumbsContentObject: + tags: + - name: frontend.contentobject + identifier: 'BREADCRUMBS' diff --git a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php index 5bc372f..0aacf5c 100644 --- a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php +++ b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php @@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Domain\Repository\PageRepository; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -26,15 +27,15 @@ class LanguageMenuCompilerTest extends FunctionalTestCase { - protected $testExtensionsToLoad = [ + protected array $testExtensionsToLoad = [ 'typo3conf/ext/menus', ]; - protected $pathsToLinkInTestInstance = [ + protected array $pathsToLinkInTestInstance = [ 'typo3conf/ext/menus/Build/sites' => 'typo3conf/sites', ]; - protected $defaultPageDataSet = [ + protected array $defaultPageDataSet = [ 'defaultPage' => [ 'uid' => 1, 'pid' => 0, @@ -245,7 +246,11 @@ protected function compileMenu(array $pageDataset, array $configuration = []): a false ); $GLOBALS['TSFE'] = $controller; - $GLOBALS['TSFE']->id = '1'; + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { + $GLOBALS['TSFE']->id = '1'; + } else { + $GLOBALS['TSFE']->id = 1; + } $contentObjectRenderer = new ContentObjectRenderer(); $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); $site = $siteFinder->getSiteByIdentifier('main'); diff --git a/Tests/Functional/DataProcessing/DataProcessingTest.php b/Tests/Functional/DataProcessing/DataProcessingTest.php index 7730ca0..cb391a2 100644 --- a/Tests/Functional/DataProcessing/DataProcessingTest.php +++ b/Tests/Functional/DataProcessing/DataProcessingTest.php @@ -15,7 +15,7 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Routing\PageArguments; -use TYPO3\CMS\Core\Site\Entity\SiteInterface; +use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; @@ -24,12 +24,8 @@ abstract class DataProcessingTest extends FunctionalTestCase { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; - /** - * @throws \Doctrine\DBAL\DBALException - * @throws \TYPO3\TestingFramework\Core\Exception - */ protected function setUp(): void { parent::setUp(); @@ -60,7 +56,7 @@ protected function reduceResultsRecursive(array &$results): void $results = $this->reduceResults($results); } - protected function getTypoScriptFrontendController(SiteInterface $site, int $pageId): TypoScriptFrontendController + protected function getTypoScriptFrontendController(Site $site, int $pageId): TypoScriptFrontendController { if ((new Typo3Version())->getMajorVersion() < 11) { return GeneralUtility::makeInstance(TypoScriptFrontendController::class, null, $site, $site->getLanguageById(0)); diff --git a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php index 5904183..7d7dfe9 100644 --- a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php @@ -15,13 +15,12 @@ use B13\Menus\DataProcessing\ListMenu; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Http\ServerRequest; -use TYPO3\CMS\Core\Site\Entity\NullSite; +use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; class ListMenuProcessorTest extends DataProcessingTest { - /** * @return array */ @@ -314,7 +313,7 @@ public function setupDataProvider() */ public function processTest(array $tsfe, array $configuration, array $expected) { - $site = GeneralUtility::makeInstance(NullSite::class); + $site = GeneralUtility::makeInstance(Site::class, 'main', $tsfe['id'], []); $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); @@ -368,7 +367,7 @@ public function cacheDataProvider() */ public function menuIdTagsAreAddedToPageCache(array $tsfe, array $configuration, array $expectedTags) { - $site = GeneralUtility::makeInstance(NullSite::class); + $site = GeneralUtility::makeInstance(Site::class, 'main', $tsfe['id'], []); $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); diff --git a/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php b/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php index d7260f4..7450a9c 100644 --- a/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php @@ -15,7 +15,7 @@ use B13\Menus\DataProcessing\TreeMenu; use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Http\ServerRequest; -use TYPO3\CMS\Core\Site\Entity\NullSite; +use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -397,7 +397,7 @@ public function setupDataProvider() */ public function processTest(array $tsfe, array $configuration, array $expected): void { - $site = GeneralUtility::makeInstance(NullSite::class); + $site = GeneralUtility::makeInstance(Site::class, 'main', $tsfe['id'], []); $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); @@ -462,7 +462,7 @@ public function cacheDataProvider() */ public function menuIdTagsAreAddedToPageCache(array $tsfe, int $entryPoints, array $expectedTags): void { - $site = GeneralUtility::makeInstance(NullSite::class); + $site = GeneralUtility::makeInstance(Site::class, 'main', $tsfe['id'], []); $request = GeneralUtility::makeInstance(ServerRequest::class); $request = $request->withAttribute('site', $site); $request = $request->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); diff --git a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php index d36d605..d9f58c4 100644 --- a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php @@ -19,7 +19,7 @@ class MenuRepositoryTest extends FunctionalTestCase { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; /** * @test diff --git a/Tests/Functional/Fixtures/be_users.csv b/Tests/Functional/Fixtures/be_users.csv new file mode 100644 index 0000000..bfc3c6b --- /dev/null +++ b/Tests/Functional/Fixtures/be_users.csv @@ -0,0 +1,4 @@ +"be_users" +,"uid","pid","tstamp","username","password","admin","disable","starttime","endtime","options","crdate","workspace_perms","deleted","TSconfig","lastlogin","workspace_id" +# The password is "password" +,1,0,1366642540,"admin","$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1",1,0,0,0,0,1366642540,1,0,,1371033743,0 \ No newline at end of file diff --git a/Tests/Functional/Frontend/AbstractFrontendTest.php b/Tests/Functional/Frontend/AbstractFrontendTest.php new file mode 100644 index 0000000..25357ca --- /dev/null +++ b/Tests/Functional/Frontend/AbstractFrontendTest.php @@ -0,0 +1,33 @@ + 'typo3conf/sites']; + + protected function executeFrontendRequestWrapper(InternalRequest $request, InternalRequestContext $context = null, bool $followRedirects = false): ResponseInterface + { + if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 11) { + return $this->executeFrontendRequest($request, $context, $followRedirects); + } + return $this->executeFrontendSubRequest($request, $context, $followRedirects); + } +} diff --git a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php index a217e42..5bd44d0 100644 --- a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class BreadcrumbMenuContentObjectTest extends FunctionalTestCase +class BreadcrumbMenuContentObjectTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -26,7 +21,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'root'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -39,7 +34,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'rootpage-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php index 6cf7fd1..5710117 100644 --- a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php +++ b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class BreadcrumbMenuFluidTest extends FunctionalTestCase +class BreadcrumbMenuFluidTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -26,7 +21,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'root'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -39,7 +34,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'rootpage-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php index 5202a4b..c209b9f 100644 --- a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class LanguageMenuContentObjectTest extends FunctionalTestCase +class LanguageMenuContentObjectTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -27,7 +22,7 @@ public function menuOnRootPage(): void $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -41,7 +36,7 @@ public function menuOnSubpage(): void $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/de/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/de/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/LanguageMenuFluidTest.php b/Tests/Functional/Frontend/LanguageMenuFluidTest.php index 7833241..615b0a1 100644 --- a/Tests/Functional/Frontend/LanguageMenuFluidTest.php +++ b/Tests/Functional/Frontend/LanguageMenuFluidTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class LanguageMenuFluidTest extends FunctionalTestCase +class LanguageMenuFluidTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -27,7 +22,7 @@ public function menuOnRootPage(): void $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -41,7 +36,7 @@ public function menuOnSubpage(): void $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/de/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/de/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/ListMenuContentObjectTest.php b/Tests/Functional/Frontend/ListMenuContentObjectTest.php index 14b1790..9b825e2 100644 --- a/Tests/Functional/Frontend/ListMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/ListMenuContentObjectTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class ListMenuContentObjectTest extends FunctionalTestCase +class ListMenuContentObjectTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -26,7 +21,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -39,7 +34,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/ListMenuFluidTest.php b/Tests/Functional/Frontend/ListMenuFluidTest.php index 6c4e9e7..dde9395 100644 --- a/Tests/Functional/Frontend/ListMenuFluidTest.php +++ b/Tests/Functional/Frontend/ListMenuFluidTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class ListMenuFluidTest extends FunctionalTestCase +class ListMenuFluidTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -26,7 +21,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -39,7 +34,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php index 3ae4db4..a393e65 100644 --- a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php @@ -11,14 +11,9 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class TreeMenuContentObjectTest extends FunctionalTestCase +class TreeMenuContentObjectTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -26,7 +21,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -39,7 +34,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/TreeMenuFluidTest.php b/Tests/Functional/Frontend/TreeMenuFluidTest.php index 08c7326..733fdb9 100644 --- a/Tests/Functional/Frontend/TreeMenuFluidTest.php +++ b/Tests/Functional/Frontend/TreeMenuFluidTest.php @@ -12,14 +12,9 @@ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext; -use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class TreeMenuFluidTest extends FunctionalTestCase +class TreeMenuFluidTest extends AbstractFrontendTest { - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; - protected $coreExtensionsToLoad = ['core', 'frontend']; - protected $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; - /** * @test */ @@ -27,7 +22,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -40,7 +35,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -53,7 +48,7 @@ public function menuWithAccessRestrictionForNotLoggedinUser(): void { $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/access_restriction.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $body = (string)$response->getBody(); self::assertStringContainsString('page-1', $body); self::assertStringNotContainsString('page-2', $body); @@ -67,7 +62,8 @@ public function menuWithAccessRestrictionForLoggedinUser(): void $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/access_restriction.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); $context = (new InternalRequestContext())->withFrontendUserId(1); - $response = $this->executeFrontendRequest(new InternalRequest('http://localhost/'), $context); + $request = new InternalRequest('http://localhost/'); + $response = $this->executeFrontendRequestWrapper($request, $context); $body = (string)$response->getBody(); self::assertStringContainsString('page-1', $body); self::assertStringContainsString('page-2', $body); diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index 262a3c3..01e6195 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -23,18 +23,15 @@ class DataHandlerTest extends FunctionalTestCase protected DataHandler $dataHandler; protected BackendUserAuthentication $backendUser; - protected $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; - /** - * @throws \Doctrine\DBAL\DBALException - * @throws \TYPO3\TestingFramework\Core\Exception - */ protected function setUp(): void { parent::setUp(); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.csv'); $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/caches.csv'); - $this->backendUser = $this->setUpBackendUserFromFixture(1); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv'); + $this->backendUser = $GLOBALS['BE_USER'] = $this->setUpBackendUser(1); Bootstrap::initializeLanguageObject(); $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); } diff --git a/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php b/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php index bcf72f3..0b3ec7b 100644 --- a/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php +++ b/Tests/Unit/DataProcessing/BreadcrumbsMenuTest.php @@ -20,7 +20,6 @@ class BreadcrumbsMenuTest extends UnitTestCase { - /** * @test */ diff --git a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php index e015cfb..b7aab53 100644 --- a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php @@ -20,6 +20,7 @@ class MenuRepositoryTest extends UnitTestCase { + protected bool $resetSingletonInstances = true; /** * @test @@ -85,11 +86,22 @@ public function getBreadcrumbsMenuRespectConfiguredExcludeDoktypes(): void $context = $this->getMockBuilder(Context::class) ->getMock(); $context->expects(self::once())->method('getAspect')->with('language')->willReturn($languageAspect); - $pageRepository = $this->getMockBuilder(PageRepository::class) - ->disableOriginalConstructor() - ->getMock(); - $pageRepository->expects(self::at(0))->method('getPage')->with(1)->willReturn($rootLine[0]); - $pageRepository->expects(self::at(1))->method('getPage')->with(2)->willReturn($rootLine[1]); + + $pageRepository = new class() extends PageRepository { + public function getPage($uid, $disableGroupAccessCheck = false) + { + if ($uid === 1) { + // $rootLine[0] + return ['uid' => 1, 'doktype' => 99, 'nav_hide'=> 0]; + } + if ($uid === 2) { + // $rootLine[0] + return ['uid' => 2, 'doktype' => 98, 'nav_hide'=> 0]; + } + return []; + } + }; + $menuRepository = $this->getMockBuilder(MenuRepository::class) ->onlyMethods(['populateAdditionalKeysForPage', 'isPageSuitableForLanguage']) ->setConstructorArgs([$context, $pageRepository]) diff --git a/Tests/Unit/PageStateMarkerTest.php b/Tests/Unit/PageStateMarkerTest.php index 35346d2..fc3ed41 100644 --- a/Tests/Unit/PageStateMarkerTest.php +++ b/Tests/Unit/PageStateMarkerTest.php @@ -17,7 +17,6 @@ class PageStateMarkerTest extends UnitTestCase { - /** * @test */ diff --git a/composer.json b/composer.json index 285200d..80d73e6 100644 --- a/composer.json +++ b/composer.json @@ -5,17 +5,16 @@ "description": "Easy and fast menus for TYPO3 Frontends", "require": { "php": "^7.4 || ~8.0", - "typo3/cms-core": "^10 || ^11", - "typo3/cms-frontend": "^10 || ^11" + "typo3/cms-core": "^10 || ^11 || 12.*.*@dev", + "typo3/cms-frontend": "^10 || ^11 || 12.*.*@dev" }, "require-dev": { "phpstan/phpstan": "^1.8.11", - "phpunit/phpunit": "^8.4", "typo3/cms-fluid-styled-content": "^11.5", "typo3/cms-install": "^11.5", "typo3/coding-standards": "^0.5", "typo3/tailor": "^1.0", - "typo3/testing-framework": "^6" + "typo3/testing-framework": "~7.0@dev" }, "config": { "vendor-dir": ".Build/vendor", @@ -35,11 +34,11 @@ } }, "scripts": { - "post-autoload-dump": [ - "TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare", - "if [ ! -e .Build/Web/vendor ]; then cd .Build/Web && ln -s ../vendor && cd -; fi", - "if [ ! -e .Build/Web/typo3conf/ext/json_response ]; then cd .Build/Web/typo3conf/ext && ln -s ../../../vendor/typo3/testing-framework/Resources/Core/Functional/Extensions/json_response && cd -; fi", - "if [ ! -e .Build/Web/typo3conf/sites ]; then cd .Build/Web/typo3conf && ln -s ../../../Build/sites && cd -; fi" + "prepare-tests-10": [ + "TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare" + ], + "prepare-tests": [ + "if [ ! -e .Build/Web/typo3conf/sites -a -e .Build/Web/typo3conf ]; then cd .Build/Web/typo3conf && ln -s ../../../Build/sites && cd -; fi" ] }, "autoload": { diff --git a/ext_localconf.php b/ext_localconf.php index e1c4802..830c563 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -2,12 +2,14 @@ defined('TYPO3') or die(); -$GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'], [ - 'TREEMENU' => \B13\Menus\ContentObject\TreeMenuContentObject::class, - 'LISTMENU' => \B13\Menus\ContentObject\ListMenuContentObject::class, - 'LANGUAGEMENU' => \B13\Menus\ContentObject\LanguageMenuContentObject::class, - 'BREADCRUMBS' => \B13\Menus\ContentObject\BreadcrumbsContentObject::class, -]); +if ((\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class))->getMajorVersion() < 12) { + $GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['FE']['ContentObjects'], [ + 'TREEMENU' => \B13\Menus\ContentObject\TreeMenuContentObject::class, + 'LISTMENU' => \B13\Menus\ContentObject\ListMenuContentObject::class, + 'LANGUAGEMENU' => \B13\Menus\ContentObject\LanguageMenuContentObject::class, + 'BREADCRUMBS' => \B13\Menus\ContentObject\BreadcrumbsContentObject::class, + ]); +} $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc']['tx-menus'] = \B13\Menus\Hooks\DataHandlerHook::class . '->clearMenuCaches'; From ffba7bf310410f74f2e5aa28fa2bd27e3446d667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Ceslav=20Przywara?= Date: Fri, 18 Nov 2022 21:48:05 +0100 Subject: [PATCH 04/21] Fix typo in entryPoints And wrap as code. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3379bc..5bd4ab1 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ If you want to get a menu of the direct siblings of a page, no matter what page as = listOfJobPages } -By using the `.data` property of the entryPointy attribute we can access each property of the currently build page. And so we can render the siblings of the page. +By using the `.data` property of the `entryPoints` attribute we can access each property of the currently build page. And so we can render the siblings of the page. ## Technical Details From a47afacef4f4e705deedaf9dabdf6613bfe81ccc Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 19 Nov 2022 13:17:10 +0100 Subject: [PATCH 05/21] [FEATURE] Add PopulatePageInformationEvent in MenuRepository --- Classes/Domain/Repository/MenuRepository.php | 10 +++++++- .../Event/PopulatePageInformationEvent.php | 25 +++++++++++++++++++ .../Compiler/LanguageMenuCompilerTest.php | 3 ++- .../Domain/Repository/MenuRepositoryTest.php | 5 ++-- .../Domain/Repository/MenuRepositoryTest.php | 7 +++--- 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 Classes/Event/PopulatePageInformationEvent.php diff --git a/Classes/Domain/Repository/MenuRepository.php b/Classes/Domain/Repository/MenuRepository.php index e697f50..86425c4 100644 --- a/Classes/Domain/Repository/MenuRepository.php +++ b/Classes/Domain/Repository/MenuRepository.php @@ -11,6 +11,8 @@ * of the License, or any later version. */ +use B13\Menus\Event\PopulatePageInformationEvent; +use Psr\EventDispatcher\EventDispatcherInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Domain\Repository\PageRepository; @@ -24,6 +26,7 @@ class MenuRepository { protected Context $context; protected PageRepository $pageRepository; + protected EventDispatcherInterface $eventDispatcher; // Never show or query them. protected $excludedDoktypes = [ @@ -32,10 +35,11 @@ class MenuRepository PageRepository::DOKTYPE_SYSFOLDER, ]; - public function __construct(Context $context, PageRepository $pageRepository) + public function __construct(Context $context, PageRepository $pageRepository, EventDispatcherInterface $eventDispatcher) { $this->context = $context; $this->pageRepository = $pageRepository; + $this->eventDispatcher = $eventDispatcher; } public function getBreadcrumbsMenu(array $originalRootLine, array $configuration): array @@ -176,5 +180,9 @@ protected function populateAdditionalKeysForPage(array &$page): void $page['isSpacer'] = true; } $page['nav_title'] = $page['nav_title'] ?: $page['title']; + + $event = new PopulatePageInformationEvent($page); + $this->eventDispatcher->dispatch($event); + $page = $event->getPage(); } } diff --git a/Classes/Event/PopulatePageInformationEvent.php b/Classes/Event/PopulatePageInformationEvent.php new file mode 100644 index 0000000..cb9c9e5 --- /dev/null +++ b/Classes/Event/PopulatePageInformationEvent.php @@ -0,0 +1,25 @@ +page = $page; + } + + public function getPage(): array + { + return $this->page; + } + + public function setPage(array $page): void + { + $this->page = $page; + } +} diff --git a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php index 0aacf5c..d2aa90b 100644 --- a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php +++ b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php @@ -15,6 +15,7 @@ use B13\Menus\CacheHelper; use B13\Menus\Compiler\LanguageMenuCompiler; use B13\Menus\Domain\Repository\MenuRepository; +use Psr\EventDispatcher\EventDispatcherInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Domain\Repository\PageRepository; @@ -257,7 +258,7 @@ protected function compileMenu(array $pageDataset, array $configuration = []): a $context = $this->getMockBuilder(Context::class) ->getMock(); $pageRepository = GeneralUtility::makeInstance(PageRepository::class); - $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository); + $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository, $this->createMock(EventDispatcherInterface::class)); $cacheHelper = $this->getAccessibleMock(CacheHelper::class, ['foo'], [], '', false); $cacheHelper->_set('disableCaching', true); $languageMenuCompiler = $this->getMockBuilder(LanguageMenuCompiler::class) diff --git a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php index d9f58c4..e07b89d 100644 --- a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php @@ -11,6 +11,7 @@ */ use B13\Menus\Domain\Repository\MenuRepository; +use Psr\EventDispatcher\EventDispatcherInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Domain\Repository\PageRepository; @@ -31,7 +32,7 @@ public function translatedPageIsNotInMenuIfNavHideIsSet(): void $context = GeneralUtility::makeInstance(Context::class); $context->setAspect('language', $languageAspect); $pageRepository = GeneralUtility::makeInstance(PageRepository::class); - $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository); + $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository, $this->createMock(EventDispatcherInterface::class)); $page = $menuRepository->getPage(1, []); $pageInLanguage = $menuRepository->getPageInLanguage(1, $context, []); self::assertSame([], $page); @@ -48,7 +49,7 @@ public function translatedPageIsInMenuIfNavHideAndIgnoreNavHideIsSet(): void $context = GeneralUtility::makeInstance(Context::class); $context->setAspect('language', $languageAspect); $pageRepository = GeneralUtility::makeInstance(PageRepository::class); - $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository); + $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository, $this->createMock(EventDispatcherInterface::class)); $page = $menuRepository->getPage(1, ['includeNotInMenu' => 1]); $pageInLanguage = $menuRepository->getPageInLanguage(1, $context, ['includeNotInMenu' => 1]); $page = $this->reduceResults($page); diff --git a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php index b7aab53..de54416 100644 --- a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php @@ -13,6 +13,7 @@ */ use B13\Menus\Domain\Repository\MenuRepository; +use Psr\EventDispatcher\EventDispatcherInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Domain\Repository\PageRepository; @@ -43,7 +44,7 @@ public function getSubPagesOfPageRestrictQueryToExcludeDoktypes(): void $pageRepository->expects(self::once())->method('getMenu') ->with(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ') ', false) ->willReturn([]); - $menuRepository = new MenuRepository($context, $pageRepository); + $menuRepository = new MenuRepository($context, $pageRepository, $this->createMock(EventDispatcherInterface::class)); $menuRepository->getSubPagesOfPage(1, 1, []); } @@ -68,7 +69,7 @@ public function getSubPagesOfPageMergeExcludeDoktypesFromConfiguration(): void $pageRepository->expects(self::once())->method('getMenu') ->with(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ',99) ', false) ->willReturn([]); - $menuRepository = new MenuRepository($context, $pageRepository); + $menuRepository = new MenuRepository($context, $pageRepository, $this->createMock(EventDispatcherInterface::class)); $menuRepository->getSubPagesOfPage(1, 1, ['excludeDoktypes' => 99]); } @@ -104,7 +105,7 @@ public function getPage($uid, $disableGroupAccessCheck = false) $menuRepository = $this->getMockBuilder(MenuRepository::class) ->onlyMethods(['populateAdditionalKeysForPage', 'isPageSuitableForLanguage']) - ->setConstructorArgs([$context, $pageRepository]) + ->setConstructorArgs([$context, $pageRepository, $this->createMock(EventDispatcherInterface::class)]) ->getMock(); $menuRepository->expects(self::any())->method('isPageSuitableForLanguage')->willReturn(true); $breadcrumbs = $menuRepository->getBreadcrumbsMenu($rootLine, ['excludeDoktypes' => 99]); From da61e08a8df524fcf8bc92f0e326a8c6340d440d Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Tue, 29 Nov 2022 15:15:32 +0100 Subject: [PATCH 06/21] [RELEASE] 1.0.0 --- ext_emconf.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext_emconf.php b/ext_emconf.php index 966bb4b..e4a8bde 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,14 +4,14 @@ 'title' => 'Menus', 'description' => 'Various Menu functionality for TYPO3 Frontend', 'category' => 'fe', - 'version' => '0.5.1', + 'version' => '1.0.0', 'state' => 'stable', 'author' => 'Benni Mack', 'author_email' => 'typo3@b13.com', 'author_company' => 'b13 GmbH', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-11.99.99', + 'typo3' => '10.4.0-12.99.99', ], ], ]; From 4c565d25e0ac0bacf097315cfe336006a844984d Mon Sep 17 00:00:00 2001 From: Julian Hofmann Date: Mon, 30 Jan 2023 09:13:46 +0100 Subject: [PATCH 07/21] Fix TypoScript example One line was `dataProcessors` instead of `dataProcessing`. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5bd4ab1..4f394b3 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Fluid-based solution: page.10 = FLUIDTEMPLATE page.10.dataProcessing.10 = B13\Menus\DataProcessing\BreadcrumbsMenu - page.10.dataProcessors.10.excludePages = 4,51 + page.10.dataProcessing.10.excludePages = 4,51 # 0: default, 1 to include nav_hide = 1 pages page.10.dataProcessing.10.includeNotInMenu = 0 page.10.dataProcessing.10.as = breadcrumbs From e46be99a2aec8fcfe7aaeac0c5351dcd5d1cbbc2 Mon Sep 17 00:00:00 2001 From: Andreas Steiner <77045250+RTPAst@users.noreply.github.com> Date: Thu, 9 Mar 2023 16:26:00 +0100 Subject: [PATCH 08/21] Update TreeMenuCompiler.php $startPageIds must be a string --- Classes/Compiler/TreeMenuCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Compiler/TreeMenuCompiler.php b/Classes/Compiler/TreeMenuCompiler.php index 2b70171..5e0117c 100644 --- a/Classes/Compiler/TreeMenuCompiler.php +++ b/Classes/Compiler/TreeMenuCompiler.php @@ -25,7 +25,7 @@ public function compile(ContentObjectRenderer $contentObjectRenderer, array $con $includeStartPageIds = $contentObjectRenderer->stdWrap($configuration['includeRootPages'] ?? false, $configuration['includeRootPages.'] ?? []); $startPageIds = $contentObjectRenderer->stdWrap($configuration['entryPoints'] ?? $this->getCurrentSite()->getRootPageId(), $configuration['entryPoints.'] ?? []); - $startPageIds = GeneralUtility::intExplode(',', $startPageIds); + $startPageIds = GeneralUtility::intExplode(',', (string)$startPageIds); $depth = (int)$contentObjectRenderer->stdWrap($configuration['depth'] ?? 1, $configuration['depth.'] ?? []); $excludePages = $this->parseStdWrap($configuration['excludePages'] ?? '', $configuration['excludePages.'] ?? []); $configuration['excludePages'] = $excludePages; From 07af3219d3ad6796a6533213f7607f06e73cc248 Mon Sep 17 00:00:00 2001 From: Andreas Steiner <77045250+RTPAst@users.noreply.github.com> Date: Thu, 9 Mar 2023 16:27:07 +0100 Subject: [PATCH 09/21] Update ListMenuCompiler.php $pageIds must be a string --- Classes/Compiler/ListMenuCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Compiler/ListMenuCompiler.php b/Classes/Compiler/ListMenuCompiler.php index 254f951..b4eabed 100644 --- a/Classes/Compiler/ListMenuCompiler.php +++ b/Classes/Compiler/ListMenuCompiler.php @@ -24,7 +24,7 @@ public function compile(ContentObjectRenderer $contentObjectRenderer, array $con $cacheIdentifier = $this->generateCacheIdentifierForMenu('list', $configuration); $pageIds = $contentObjectRenderer->stdWrap($configuration['pages'] ?? $this->getCurrentSite()->getRootPageId(), $configuration['pages.'] ?? []); - $pageIds = GeneralUtility::intExplode(',', $pageIds); + $pageIds = GeneralUtility::intExplode(',', (string)$pageIds); $cacheIdentifier .= '-' . substr(md5(json_encode([$pageIds])), 0, 10); From 4bcdc660b6a0db4c5625a0abc80a78ae9dbbe84b Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Wed, 15 Mar 2023 10:13:29 +0100 Subject: [PATCH 10/21] [BUGFIX] Fix Pipeline --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 80d73e6..acce1ee 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ }, "require-dev": { "phpstan/phpstan": "^1.8.11", + "phpunit/phpunit": "^9.5", "typo3/cms-fluid-styled-content": "^11.5", "typo3/cms-install": "^11.5", "typo3/coding-standards": "^0.5", From 1eb57035390bd97b88fbde9813fe3fbc2c74856e Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Wed, 3 May 2023 19:01:27 +0200 Subject: [PATCH 11/21] [TASK] TYPO3 12.4 LTS * change docker container working dir * use TYPO3 12.4 * use testing-framework 7 * do not use typo3conf in tests * phpunit accessible mock --- Build/phpstan10.neon | 3 --- Build/phpstan11.neon | 5 ---- Build/phpstan12.neon | 3 --- Build/testing-docker/docker-compose.yml | 14 +++++------ .../Compiler/LanguageMenuCompilerTest.php | 16 ++++++------ .../DataProcessing/DataProcessingTest.php | 25 ++++++++++--------- .../Domain/Repository/MenuRepositoryTest.php | 4 +-- .../BreadcrumbMenuContentObjectTest.php | 8 +++--- .../Frontend/BreadcrumbMenuFluidTest.php | 8 +++--- .../LanguageMenuContentObjectTest.php | 12 ++++----- .../Frontend/LanguageMenuFluidTest.php | 12 ++++----- .../Frontend/ListMenuContentObjectTest.php | 8 +++--- .../Functional/Frontend/ListMenuFluidTest.php | 8 +++--- .../Frontend/TreeMenuContentObjectTest.php | 8 +++--- .../Functional/Frontend/TreeMenuFluidTest.php | 16 ++++++------ Tests/Functional/Hooks/DataHandlerTest.php | 4 +-- composer.json | 6 ++--- 17 files changed, 75 insertions(+), 85 deletions(-) diff --git a/Build/phpstan10.neon b/Build/phpstan10.neon index e3aecbf..b36e70c 100644 --- a/Build/phpstan10.neon +++ b/Build/phpstan10.neon @@ -6,9 +6,6 @@ parameters: - %currentWorkingDirectory%/Tests ignoreErrors: - - - message: '#Constant ORIGINAL_ROOT not found.#' - path: %currentWorkingDirectory%/Tests - message: '#Call to an undefined method B13\\Menus\\ContentObject\\.*ContentObject::setContentObjectRenderer\(\).#' path: %currentWorkingDirectory%/Classes/ContentObject/* diff --git a/Build/phpstan11.neon b/Build/phpstan11.neon index 53320a4..885e254 100644 --- a/Build/phpstan11.neon +++ b/Build/phpstan11.neon @@ -4,8 +4,3 @@ parameters: paths: - %currentWorkingDirectory%/Classes - %currentWorkingDirectory%/Tests - - ignoreErrors: - - - message: '#Constant ORIGINAL_ROOT not found.#' - path: %currentWorkingDirectory%/Tests diff --git a/Build/phpstan12.neon b/Build/phpstan12.neon index 565faf6..aa46a85 100644 --- a/Build/phpstan12.neon +++ b/Build/phpstan12.neon @@ -6,9 +6,6 @@ parameters: - %currentWorkingDirectory%/Tests ignoreErrors: - - - message: '#Constant ORIGINAL_ROOT not found.#' - path: %currentWorkingDirectory%/Tests - message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#' path: %currentWorkingDirectory%/Classes/ContentObject/* diff --git a/Build/testing-docker/docker-compose.yml b/Build/testing-docker/docker-compose.yml index 3ee9e1c..0208c5a 100644 --- a/Build/testing-docker/docker-compose.yml +++ b/Build/testing-docker/docker-compose.yml @@ -92,7 +92,7 @@ services: fi composer prepare-tests-10 && composer prepare-tests else - composer remove typo3/cms* --dev --no-progress --no-interaction && composer config --no-interaction --no-plugins allow-plugins.sbuerk/typo3-cmscomposerinstallers-testingframework-bridge true && composer require typo3/cms-install:12.*.*@dev typo3/cms-fluid-styled-content:12.*.*@dev sbuerk/typo3-cmscomposerinstallers-testingframework-bridge:^0.0.1 --dev -W --no-progress --no-interaction + composer require typo3/cms-install:^12.4 typo3/cms-fluid-styled-content:^12.4 --dev -W --no-progress --no-interaction composer prepare-tests fi " @@ -147,7 +147,7 @@ services: typo3DatabaseUsername: root typo3DatabasePassword: funcp typo3DatabaseHost: mariadb10 - working_dir: ${ROOT_DIR}/.Build + working_dir: ${ROOT_DIR} command: > /bin/sh -c " if [ ${SCRIPT_VERBOSE} -eq 1 ]; then @@ -161,13 +161,13 @@ services: php -v | grep '^PHP'; if [ ${PHP_XDEBUG_ON} -eq 0 ]; then export XDEBUG_MODE=\"off\" - bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; + .Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; else DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` export XDEBUG_MODE=\"debug,develop\" \ XDEBUG_TRIGGER=\"foo\" \ XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" - bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; + .Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; fi " lint: @@ -213,7 +213,7 @@ services: - ${HOST_HOME}:${HOST_HOME} - /etc/passwd:/etc/passwd:ro - /etc/group:/etc/group:ro - working_dir: ${ROOT_DIR}/.Build + working_dir: ${ROOT_DIR} command: > /bin/sh -c " if [ ${SCRIPT_VERBOSE} -eq 1 ]; then @@ -222,12 +222,12 @@ services: php -v | grep '^PHP'; if [ ${PHP_XDEBUG_ON} -eq 0 ]; then XDEBUG_MODE=\"off\" \ - bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; + .Build/bin/phpunit -c Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; else DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'` XDEBUG_MODE=\"debug,develop\" \ XDEBUG_TRIGGER=\"foo\" \ XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \ - bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; + .Build/bin/phpunit -c menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}; fi " diff --git a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php index d2aa90b..8869ac4 100644 --- a/Tests/Functional/Compiler/LanguageMenuCompilerTest.php +++ b/Tests/Functional/Compiler/LanguageMenuCompilerTest.php @@ -239,13 +239,10 @@ protected function compileMenu(array $pageDataset, array $configuration = []): a foreach ($pageDataset as $page) { $connection->insert('pages', $page); } - $controller = $this->getAccessibleMock( - TypoScriptFrontendController::class, - ['get_cache_timeout'], - [], - '', - false - ); + $controller = $this->getMockBuilder($this->buildAccessibleProxy(TypoScriptFrontendController::class)) + ->onlyMethods(['get_cache_timeout']) + ->disableOriginalConstructor() + ->getMock(); $GLOBALS['TSFE'] = $controller; if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { $GLOBALS['TSFE']->id = '1'; @@ -259,7 +256,10 @@ protected function compileMenu(array $pageDataset, array $configuration = []): a ->getMock(); $pageRepository = GeneralUtility::makeInstance(PageRepository::class); $menuRepository = GeneralUtility::makeInstance(MenuRepository::class, $context, $pageRepository, $this->createMock(EventDispatcherInterface::class)); - $cacheHelper = $this->getAccessibleMock(CacheHelper::class, ['foo'], [], '', false); + $cacheHelper = $this->getMockBuilder($this->buildAccessibleProxy(CacheHelper::class)) + ->onlyMethods([]) + ->disableOriginalConstructor() + ->getMock(); $cacheHelper->_set('disableCaching', true); $languageMenuCompiler = $this->getMockBuilder(LanguageMenuCompiler::class) ->onlyMethods( diff --git a/Tests/Functional/DataProcessing/DataProcessingTest.php b/Tests/Functional/DataProcessing/DataProcessingTest.php index cb391a2..8472fae 100644 --- a/Tests/Functional/DataProcessing/DataProcessingTest.php +++ b/Tests/Functional/DataProcessing/DataProcessingTest.php @@ -29,7 +29,7 @@ abstract class DataProcessingTest extends FunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv'); } protected function reduceResults(array $results): array @@ -78,17 +78,18 @@ protected function getTypoScriptFrontendController(Site $site, int $pageId): Typ $frontendUserAuth = $this->getMockBuilder(FrontendUserAuthentication::class) ->disableOriginalConstructor() ->getMock(); - $controller = $this->getAccessibleMock( - TypoScriptFrontendController::class, - ['get_cache_timeout'], - [ - $context, - $site, - $siteLanguage, - $pageArguments, - $frontendUserAuth, - ] - ); + $controller = $this->getMockBuilder($this->buildAccessibleProxy(TypoScriptFrontendController::class)) + ->onlyMethods(['get_cache_timeout']) + ->setConstructorArgs( + [ + $context, + $site, + $siteLanguage, + $pageArguments, + $frontendUserAuth, + ] + ) + ->getMock(); $controller->expects(self::any())->method('get_cache_timeout')->willReturn(1); return $controller; } diff --git a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php index e07b89d..d0aca6c 100644 --- a/Tests/Functional/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/MenuRepositoryTest.php @@ -27,7 +27,7 @@ class MenuRepositoryTest extends FunctionalTestCase */ public function translatedPageIsNotInMenuIfNavHideIsSet(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_page_with_nav_hide.csv'); $languageAspect = GeneralUtility::makeInstance(LanguageAspect::class, 1); $context = GeneralUtility::makeInstance(Context::class); $context->setAspect('language', $languageAspect); @@ -44,7 +44,7 @@ public function translatedPageIsNotInMenuIfNavHideIsSet(): void */ public function translatedPageIsInMenuIfNavHideAndIgnoreNavHideIsSet(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Domain/Repository/Fixtures/translated_page_with_nav_hide.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_page_with_nav_hide.csv'); $languageAspect = GeneralUtility::makeInstance(LanguageAspect::class, 1); $context = GeneralUtility::makeInstance(Context::class); $context->setAspect('language', $languageAspect); diff --git a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php index 5bd44d0..2b2b628 100644 --- a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php @@ -19,8 +19,8 @@ class BreadcrumbMenuContentObjectTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'root'; $body = (string)$response->getBody(); @@ -32,8 +32,8 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'rootpage-1'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php index 5710117..681665d 100644 --- a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php +++ b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php @@ -19,8 +19,8 @@ class BreadcrumbMenuFluidTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'root'; $body = (string)$response->getBody(); @@ -32,8 +32,8 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'rootpage-1'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php index c209b9f..3241972 100644 --- a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php @@ -19,9 +19,9 @@ class LanguageMenuContentObjectTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); @@ -33,9 +33,9 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/de/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/LanguageMenuFluidTest.php b/Tests/Functional/Frontend/LanguageMenuFluidTest.php index 615b0a1..994ba58 100644 --- a/Tests/Functional/Frontend/LanguageMenuFluidTest.php +++ b/Tests/Functional/Frontend/LanguageMenuFluidTest.php @@ -19,9 +19,9 @@ class LanguageMenuFluidTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); @@ -33,9 +33,9 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/translated_pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/language_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/de/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/ListMenuContentObjectTest.php b/Tests/Functional/Frontend/ListMenuContentObjectTest.php index 9b825e2..ae4a8c6 100644 --- a/Tests/Functional/Frontend/ListMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/ListMenuContentObjectTest.php @@ -19,8 +19,8 @@ class ListMenuContentObjectTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1'; $body = (string)$response->getBody(); @@ -32,8 +32,8 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/ListMenuFluidTest.php b/Tests/Functional/Frontend/ListMenuFluidTest.php index dde9395..dbe362f 100644 --- a/Tests/Functional/Frontend/ListMenuFluidTest.php +++ b/Tests/Functional/Frontend/ListMenuFluidTest.php @@ -19,8 +19,8 @@ class ListMenuFluidTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1'; $body = (string)$response->getBody(); @@ -32,8 +32,8 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/list_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php index a393e65..8a22008 100644 --- a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php @@ -19,8 +19,8 @@ class TreeMenuContentObjectTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); @@ -32,8 +32,8 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_content_object_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_content_object_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); diff --git a/Tests/Functional/Frontend/TreeMenuFluidTest.php b/Tests/Functional/Frontend/TreeMenuFluidTest.php index 733fdb9..6553aa8 100644 --- a/Tests/Functional/Frontend/TreeMenuFluidTest.php +++ b/Tests/Functional/Frontend/TreeMenuFluidTest.php @@ -20,8 +20,8 @@ class TreeMenuFluidTest extends AbstractFrontendTest */ public function menuOnRootPage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); @@ -33,8 +33,8 @@ public function menuOnRootPage(): void */ public function menuOnSubpage(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); @@ -46,8 +46,8 @@ public function menuOnSubpage(): void */ public function menuWithAccessRestrictionForNotLoggedinUser(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/access_restriction.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/access_restriction.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); $body = (string)$response->getBody(); self::assertStringContainsString('page-1', $body); @@ -59,8 +59,8 @@ public function menuWithAccessRestrictionForNotLoggedinUser(): void */ public function menuWithAccessRestrictionForLoggedinUser(): void { - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/access_restriction.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Frontend/Fixtures/tree_menu_fluid_typoscript.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/access_restriction.csv'); + $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); $context = (new InternalRequestContext())->withFrontendUserId(1); $request = new InternalRequest('http://localhost/'); $response = $this->executeFrontendRequestWrapper($request, $context); diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index 01e6195..8b7cd24 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -28,8 +28,8 @@ class DataHandlerTest extends FunctionalTestCase protected function setUp(): void { parent::setUp(); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/pages.csv'); - $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3conf/ext/menus/Tests/Functional/Fixtures/caches.csv'); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv'); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/caches.csv'); $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv'); $this->backendUser = $GLOBALS['BE_USER'] = $this->setUpBackendUser(1); Bootstrap::initializeLanguageObject(); diff --git a/composer.json b/composer.json index acce1ee..1bb8c01 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "description": "Easy and fast menus for TYPO3 Frontends", "require": { "php": "^7.4 || ~8.0", - "typo3/cms-core": "^10 || ^11 || 12.*.*@dev", - "typo3/cms-frontend": "^10 || ^11 || 12.*.*@dev" + "typo3/cms-core": "^10 || ^11 || ^12.4", + "typo3/cms-frontend": "^10 || ^11 || ^12.4" }, "require-dev": { "phpstan/phpstan": "^1.8.11", @@ -15,7 +15,7 @@ "typo3/cms-install": "^11.5", "typo3/coding-standards": "^0.5", "typo3/tailor": "^1.0", - "typo3/testing-framework": "~7.0@dev" + "typo3/testing-framework": "^7" }, "config": { "vendor-dir": ".Build/vendor", From 1cf95155c9f7cd35579906092a4ac567441c4d6e Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Thu, 4 May 2023 12:39:52 +0200 Subject: [PATCH 12/21] [RELEASE] 1.0.1 --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index e4a8bde..d66fb26 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Menus', 'description' => 'Various Menu functionality for TYPO3 Frontend', 'category' => 'fe', - 'version' => '1.0.0', + 'version' => '1.0.1', 'state' => 'stable', 'author' => 'Benni Mack', 'author_email' => 'typo3@b13.com', From 659e7635b7820a2c469b2ef9861261ef223746c1 Mon Sep 17 00:00:00 2001 From: Lina Wolf <48202465+linawolf@users.noreply.github.com> Date: Sat, 3 Jun 2023 07:33:35 +0200 Subject: [PATCH 13/21] Update README.md [DOCS] Language Switcher Use the same variable name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f394b3..986f7d4 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ Fluid-based solution: Usage in Fluid: From 4041a229d8ac3d55ab3e9a61a56ee9367f5d1367 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Fri, 9 Jun 2023 10:33:37 +0200 Subject: [PATCH 14/21] [BUGFIX] short cache identifier by md5 Fixes: #96 --- Classes/Compiler/AbstractMenuCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Compiler/AbstractMenuCompiler.php b/Classes/Compiler/AbstractMenuCompiler.php index 4d19000..850159c 100644 --- a/Classes/Compiler/AbstractMenuCompiler.php +++ b/Classes/Compiler/AbstractMenuCompiler.php @@ -66,7 +66,7 @@ protected function generateCacheIdentifierForMenu(string $prefix, array $configu $visibilityAspect = $this->context->getAspect('visibility'); $visibility = $visibilityAspect->includeHiddenPages() ? '-with-hidden' : ''; $root = $this->getCurrentSite()->getRootPageId(); - $identifier = $prefix . '-root-' . $root . '-language-' . $language . '-groups-' . implode('_', $groupIds) . '-' . $visibility . '-' . substr(md5(json_encode($configuration)), 0, 10); + $identifier = $prefix . '-root-' . $root . '-language-' . $language . '-groups-' . md5(implode('_', $groupIds)) . '-' . $visibility . '-' . substr(md5(json_encode($configuration)), 0, 10); return $identifier; } From 0e934346233c54794c113fc1345340d9b170d362 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Wed, 14 Jun 2023 09:02:37 +0200 Subject: [PATCH 15/21] [RELEASE] 1.0.2 --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index d66fb26..a5835ac 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Menus', 'description' => 'Various Menu functionality for TYPO3 Frontend', 'category' => 'fe', - 'version' => '1.0.1', + 'version' => '1.0.2', 'state' => 'stable', 'author' => 'Benni Mack', 'author_email' => 'typo3@b13.com', From a80100b3b7193ea926f24b099cc0c708fdb408ce Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Tue, 8 Aug 2023 15:51:00 +0200 Subject: [PATCH 16/21] [BUGFIX] do not set ContentObjectRenderer in ContentObjects for v12 Fixes: #99 --- Build/phpstan10.neon | 3 --- Classes/ContentObject/BreadcrumbsContentObject.php | 2 -- Classes/ContentObject/LanguageMenuContentObject.php | 2 -- Classes/ContentObject/ListMenuContentObject.php | 2 -- Classes/ContentObject/TreeMenuContentObject.php | 2 -- 5 files changed, 11 deletions(-) diff --git a/Build/phpstan10.neon b/Build/phpstan10.neon index b36e70c..c010b87 100644 --- a/Build/phpstan10.neon +++ b/Build/phpstan10.neon @@ -6,9 +6,6 @@ parameters: - %currentWorkingDirectory%/Tests ignoreErrors: - - - message: '#Call to an undefined method B13\\Menus\\ContentObject\\.*ContentObject::setContentObjectRenderer\(\).#' - path: %currentWorkingDirectory%/Classes/ContentObject/* - message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(string\) does not accept int#' path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php diff --git a/Classes/ContentObject/BreadcrumbsContentObject.php b/Classes/ContentObject/BreadcrumbsContentObject.php index ddbcdec..5038c9c 100644 --- a/Classes/ContentObject/BreadcrumbsContentObject.php +++ b/Classes/ContentObject/BreadcrumbsContentObject.php @@ -29,8 +29,6 @@ public function __construct(ContentObjectRenderer $cObj) { if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { parent::__construct($cObj); - } else { - $this->setContentObjectRenderer($cObj); } $this->menuRepository = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getMenuRepository(); } diff --git a/Classes/ContentObject/LanguageMenuContentObject.php b/Classes/ContentObject/LanguageMenuContentObject.php index 695c780..f4cd43d 100644 --- a/Classes/ContentObject/LanguageMenuContentObject.php +++ b/Classes/ContentObject/LanguageMenuContentObject.php @@ -30,8 +30,6 @@ public function __construct(ContentObjectRenderer $cObj) { if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { parent::__construct($cObj); - } else { - $this->setContentObjectRenderer($cObj); } $this->languageMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getLanguageMenuCompiler(); } diff --git a/Classes/ContentObject/ListMenuContentObject.php b/Classes/ContentObject/ListMenuContentObject.php index 8a9f775..8d2433a 100644 --- a/Classes/ContentObject/ListMenuContentObject.php +++ b/Classes/ContentObject/ListMenuContentObject.php @@ -29,8 +29,6 @@ public function __construct(ContentObjectRenderer $cObj) { if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { parent::__construct($cObj); - } else { - $this->setContentObjectRenderer($cObj); } $this->listMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getListMenuCompiler(); } diff --git a/Classes/ContentObject/TreeMenuContentObject.php b/Classes/ContentObject/TreeMenuContentObject.php index 310167e..0e96274 100644 --- a/Classes/ContentObject/TreeMenuContentObject.php +++ b/Classes/ContentObject/TreeMenuContentObject.php @@ -29,8 +29,6 @@ public function __construct(ContentObjectRenderer $cObj) { if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) { parent::__construct($cObj); - } else { - $this->setContentObjectRenderer($cObj); } $this->treeMenuCompiler = (GeneralUtility::makeInstance(ContentObjectServiceContainer::class))->getTreeMenuCompiler(); } From 02b9d1bcd4383ba3a9578a0d09eacb8085d64973 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Tue, 8 Aug 2023 16:05:22 +0200 Subject: [PATCH 17/21] [BUGFIX] use testing-framework 7.0.2 7.0.3 breaks cache tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1bb8c01..78801d2 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "typo3/cms-install": "^11.5", "typo3/coding-standards": "^0.5", "typo3/tailor": "^1.0", - "typo3/testing-framework": "^7" + "typo3/testing-framework": "7.0.2" }, "config": { "vendor-dir": ".Build/vendor", From 6479289b3d84ebf86899e6bee590dcc9218882d3 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Tue, 8 Aug 2023 16:21:56 +0200 Subject: [PATCH 18/21] [RELEASE] 1.0.3 --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index a5835ac..5011245 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Menus', 'description' => 'Various Menu functionality for TYPO3 Frontend', 'category' => 'fe', - 'version' => '1.0.2', + 'version' => '1.0.3', 'state' => 'stable', 'author' => 'Benni Mack', 'author_email' => 'typo3@b13.com', From 6b50d915f151db487ff89af6f4c8a1838ecf76f3 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Thu, 21 Sep 2023 15:48:43 +0200 Subject: [PATCH 19/21] "[TASK] reuse current testing-framework 7" * This reverts commit 02b9d1bcd4383ba3a9578a0d09eacb8085d64973. * override testing-framework cache configuration --- Build/testing-docker/docker-compose.yml | 1 + Tests/Functional/Hooks/DataHandlerTest.php | 12 ++++++++++++ composer.json | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Build/testing-docker/docker-compose.yml b/Build/testing-docker/docker-compose.yml index 0208c5a..24d78f5 100644 --- a/Build/testing-docker/docker-compose.yml +++ b/Build/testing-docker/docker-compose.yml @@ -112,6 +112,7 @@ services: find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected bool \(.*\)resetSingletonInstances = /protected \1resetSingletonInstances = /g'; find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)coreExtensionsToLoad = \[/protected \1coreExtensionsToLoad = [/g'; find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)pathsToLinkInTestInstance = \[/protected \1pathsToLinkInTestInstance = [/g'; + find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)configurationToUseInTestInstance = \[/protected \1configurationToUseInTestInstance = [/g'; " composer_validate: diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index 8b7cd24..8ed04e0 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -25,6 +25,18 @@ class DataHandlerTest extends FunctionalTestCase protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $configurationToUseInTestInstance = [ + 'SYS' => [ + 'caching' => [ + 'cacheConfigurations' => [ + 'pages' => [ + 'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class, + ], + ], + ], + ], + ]; + protected function setUp(): void { parent::setUp(); diff --git a/composer.json b/composer.json index 78801d2..1bb8c01 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "typo3/cms-install": "^11.5", "typo3/coding-standards": "^0.5", "typo3/tailor": "^1.0", - "typo3/testing-framework": "7.0.2" + "typo3/testing-framework": "^7" }, "config": { "vendor-dir": ".Build/vendor", From fcfe3d5304fa196e565fa6e14a72e80d3fc9f014 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Fri, 24 May 2024 16:19:54 +0200 Subject: [PATCH 20/21] !!! [TASK] change requirements * drop TYPO3 10 Support * add TYPO3 13 Support --- .github/workflows/ci.yml | 8 +-- Build/Scripts/runTests.sh | 6 -- Build/phpstan10.neon | 11 ---- Build/phpstan11.neon | 12 ++++ Build/phpstan12.neon | 6 +- Build/phpstan13.neon | 27 ++++++++ Build/phpunit/UnitTestsBootstrap.php | 31 ++-------- Build/testing-docker/docker-compose.yml | 31 ++-------- Classes/CacheHelper.php | 62 ++++++++++++++++++- Classes/Compiler/LanguageMenuCompiler.php | 12 +++- Classes/Domain/Repository/MenuRepository.php | 5 +- .../DataProcessing/BreadcrumbsMenuTest.php | 4 +- ...aProcessingTest.php => DataProcessing.php} | 2 +- .../DataProcessing/ListMenuProcessorTest.php | 6 +- .../DataProcessing/TreeMenuProcessorTest.php | 6 +- .../Frontend/AbstractFrontendTest.php | 33 ---------- .../BreadcrumbMenuContentObjectTest.php | 11 +++- .../Frontend/BreadcrumbMenuFluidTest.php | 11 +++- .../LanguageMenuContentObjectTest.php | 11 +++- .../Frontend/LanguageMenuFluidTest.php | 11 +++- .../Frontend/ListMenuContentObjectTest.php | 11 +++- .../Functional/Frontend/ListMenuFluidTest.php | 11 +++- .../Frontend/TreeMenuContentObjectTest.php | 11 +++- .../Functional/Frontend/TreeMenuFluidTest.php | 15 +++-- Tests/Functional/Hooks/DataHandlerTest.php | 8 +-- .../Domain/Repository/MenuRepositoryTest.php | 54 +++++++++++----- composer.json | 20 +++--- 27 files changed, 256 insertions(+), 180 deletions(-) delete mode 100644 Build/phpstan10.neon create mode 100644 Build/phpstan13.neon rename Tests/Functional/DataProcessing/{DataProcessingTest.php => DataProcessing.php} (98%) delete mode 100644 Tests/Functional/Frontend/AbstractFrontendTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29a3b47..a8e46c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,18 +16,14 @@ jobs: php: [ '7.4', '8.0', '8.1' ] TYPO3: [ '11' ] include: - - TYPO3: '10' - php: '7.4' - TYPO3: '12' php: '8.1' + - TYPO3: '13' + php: '8.3' steps: - name: Checkout uses: actions/checkout@v2 - - name: Patch 10 - if: matrix.TYPO3 == '10' - run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t ${{ matrix.TYPO3 }} -s patchV10 - - name: Install testing system run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t ${{ matrix.TYPO3 }} -s composerInstall diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 3b7d456..2d7e106 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -241,12 +241,6 @@ case ${TEST_SUITE} in SUITE_EXIT_CODE=$? docker-compose down ;; - patchV10) - setUpDockerComposeDotEnv - docker-compose run patchV10 - SUITE_EXIT_CODE=$? - docker-compose down - ;; functional) setUpDockerComposeDotEnv case ${DBMS} in diff --git a/Build/phpstan10.neon b/Build/phpstan10.neon deleted file mode 100644 index c010b87..0000000 --- a/Build/phpstan10.neon +++ /dev/null @@ -1,11 +0,0 @@ -parameters: - level: 5 - - paths: - - %currentWorkingDirectory%/Classes - - %currentWorkingDirectory%/Tests - - ignoreErrors: - - - message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(string\) does not accept int#' - path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php diff --git a/Build/phpstan11.neon b/Build/phpstan11.neon index 885e254..8bf0294 100644 --- a/Build/phpstan11.neon +++ b/Build/phpstan11.neon @@ -4,3 +4,15 @@ parameters: paths: - %currentWorkingDirectory%/Classes - %currentWorkingDirectory%/Tests + excludePaths: + - %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php + ignoreErrors: + - + message: '#Cannot call method getLanguageCode\(\) on string.#' + path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php + - + message: '#Class TYPO3\\CMS\\Frontend\\Cache\\CacheLifetimeCalculator not found.#' + path: %currentWorkingDirectory%/Classes/CacheHelper.php + - + message: '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#' + path: %currentWorkingDirectory%/Classes/CacheHelper.php diff --git a/Build/phpstan12.neon b/Build/phpstan12.neon index aa46a85..e8f1027 100644 --- a/Build/phpstan12.neon +++ b/Build/phpstan12.neon @@ -4,7 +4,8 @@ parameters: paths: - %currentWorkingDirectory%/Classes - %currentWorkingDirectory%/Tests - + excludePaths: + - %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php ignoreErrors: - message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#' @@ -12,3 +13,6 @@ parameters: - message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#' path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php + - + message: '#Call to an undefined method TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript::getConfigArray\(\).#' + path: %currentWorkingDirectory%/Classes/CacheHelper.php diff --git a/Build/phpstan13.neon b/Build/phpstan13.neon new file mode 100644 index 0000000..e396ce1 --- /dev/null +++ b/Build/phpstan13.neon @@ -0,0 +1,27 @@ +parameters: + level: 5 + + paths: + - %currentWorkingDirectory%/Classes + - %currentWorkingDirectory%/Tests + excludePaths: + - %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php + ignoreErrors: + - + message: '#Call to an undefined method TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage::getTwoLetterIsoCode\(\).#' + path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php + - + message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#' + path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php + - + message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#' + path: %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php + - + message: '#.*get_cache_timeout\(\).*#' + path: %currentWorkingDirectory%/Classes/CacheHelper.php + - + message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#' + path: %currentWorkingDirectory%/Classes/ContentObject/* + - + message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#' + path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php diff --git a/Build/phpunit/UnitTestsBootstrap.php b/Build/phpunit/UnitTestsBootstrap.php index b12ccf0..a91159e 100644 --- a/Build/phpunit/UnitTestsBootstrap.php +++ b/Build/phpunit/UnitTestsBootstrap.php @@ -12,25 +12,9 @@ * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Core\Information\Typo3Version; - call_user_func(function () { $testbase = new \TYPO3\TestingFramework\Core\Testbase(); - // These if's are for core testing (package typo3/cms) only. cms-composer-installer does - // not create the autoload-include.php file that sets these env vars and sets composer - // mode to true. testing-framework can not be used without composer anyway, so it is safe - // to do this here. This way it does not matter if 'bin/phpunit' or 'vendor/phpunit/phpunit/phpunit' - // is called to run the tests since the 'relative to entry script' path calculation within - // SystemEnvironmentBuilder is not used. However, the binary must be called from the document - // root since getWebRoot() uses 'getcwd()'. - if (!getenv('TYPO3_PATH_ROOT')) { - putenv('TYPO3_PATH_ROOT=' . rtrim($testbase->getWebRoot(), '/')); - } - if (!getenv('TYPO3_PATH_WEB')) { - putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/')); - } - $testbase->defineSitePath(); $requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI; @@ -54,17 +38,10 @@ new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', []) ); // Set all packages to active - if (version_compare((new Typo3Version())->getVersion(), '11.3.0', '>')) { - $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager( - \TYPO3\CMS\Core\Package\UnitTestPackageManager::class, - \TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache) - ); - } else { - $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager( - \TYPO3\CMS\Core\Package\UnitTestPackageManager::class, - $cache - ); - } + $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager( + \TYPO3\CMS\Core\Package\UnitTestPackageManager::class, + \TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache) + ); \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager); diff --git a/Build/testing-docker/docker-compose.yml b/Build/testing-docker/docker-compose.yml index 24d78f5..61d3325 100644 --- a/Build/testing-docker/docker-compose.yml +++ b/Build/testing-docker/docker-compose.yml @@ -83,38 +83,17 @@ services: fi php -v | grep '^PHP'; if [ ${TYPO3} -eq 11 ]; then - composer install --no-progress --no-interaction + composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction composer prepare-tests - elif [ ${TYPO3} -eq 10 ]; then - composer require friendsofphp/php-cs-fixer:^3.4 typo3/cms-install:^10.4 typo3/cms-fluid-styled-content:^10.4 typo3/testing-framework:^6 --dev -W --no-progress --no-interaction - if [ "${PHP_VERSION}" == "7.4" ]; then - composer require friendsofphp/php-cs-fixer:~3.9.0 --dev --no-progress --no-interaction - fi - composer prepare-tests-10 && composer prepare-tests - else + elif [ ${TYPO3} -eq 12 ]; then composer require typo3/cms-install:^12.4 typo3/cms-fluid-styled-content:^12.4 --dev -W --no-progress --no-interaction composer prepare-tests + else + composer install --no-progress --no-interaction + composer prepare-tests fi " - patchV10: - image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest - user: ${HOST_UID} - volumes: - - ${ROOT_DIR}:${ROOT_DIR} - - ${HOST_HOME}:${HOST_HOME} - - /etc/passwd:/etc/passwd:ro - - /etc/group:/etc/group:ro - working_dir: ${ROOT_DIR} - command: > - /bin/sh -c " - find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)testExtensionsToLoad = \[/protected \1testExtensionsToLoad = [/g'; - find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected bool \(.*\)resetSingletonInstances = /protected \1resetSingletonInstances = /g'; - find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)coreExtensionsToLoad = \[/protected \1coreExtensionsToLoad = [/g'; - find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)pathsToLinkInTestInstance = \[/protected \1pathsToLinkInTestInstance = [/g'; - find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)configurationToUseInTestInstance = \[/protected \1configurationToUseInTestInstance = [/g'; - " - composer_validate: image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest user: ${HOST_UID} diff --git a/Classes/CacheHelper.php b/Classes/CacheHelper.php index a196c66..4fedd6e 100644 --- a/Classes/CacheHelper.php +++ b/Classes/CacheHelper.php @@ -11,10 +11,15 @@ * of the License, or any later version. */ +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\TypoScript\FrontendTypoScript; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** @@ -27,9 +32,11 @@ class CacheHelper implements SingletonInterface { protected FrontendInterface $cache; protected bool $disableCaching = false; + protected Context $context; public function __construct(FrontendInterface $cache, Context $context) { + $this->context = $context; $this->cache = $cache; try { $this->disableCaching = $context->getPropertyFromAspect('workspace', 'id', 0) > 0; @@ -63,7 +70,8 @@ public function get(string $cacheIdentifier, callable $loader): array // Calculate tags + lifetime $tags = $this->buildTagsAndAddThemToPageCache($pages); - $maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $this->getFrontendController()->get_cache_timeout()); + $defaultMaxLifeTime = $this->getDefaultMaxLifeTime(); + $maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $defaultMaxLifeTime); $this->cache->set($cacheIdentifier, $pages, $tags, $maximumLifeTime); return $pages; } @@ -108,15 +116,58 @@ protected function getAllPageIdsFromItems(array $pages): array return $pageIds; } + protected function getDefaultMaxLifeTime(): int + { + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + $maxLifetime = (int)$this->getFrontendController()->get_cache_timeout(); + } else { + $request = $this->getServerRequest(); + $pageInformation = $request->getAttribute('frontend.page.information'); + /** @var ?FrontendTypoScript $typoScript */ + $typoScript = $request->getAttribute('frontend.typoscript'); + if ($typoScript === null || $pageInformation === null) { + return 0; + } + $typoScriptConfigArray = $typoScript->getConfigArray(); + $maxLifetime = GeneralUtility::makeInstance(CacheLifetimeCalculator::class) + ->calculateLifetimeForPage( + $pageInformation->getId(), + $pageInformation->getPageRecord(), + $typoScriptConfigArray, + 0, + $this->context + ); + } + return $maxLifetime; + } + /** * pages.cache_timeout is not used here, as this is supposed to be relevant for content of a page, not the * metadata. */ - protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null): ?int + protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime): int { foreach ($pages as $page) { if (!empty($page['endtime'])) { - $maxLifetimeOfPage = $page['endtime'] - $GLOBALS['EXEC_TIME']; + $maxLifetimeOfPage = (int)$page['endtime'] - $GLOBALS['EXEC_TIME']; + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() === 13) { + $request = $this->getServerRequest(); + /** @var ?FrontendTypoScript $typoScript */ + $typoScript = $request->getAttribute('frontend.typoscript'); + if ($typoScript === null) { + $typoScriptConfigArray = []; + } else { + $typoScriptConfigArray = $typoScript->getConfigArray(); + } + $maxLifetimeOfPage = GeneralUtility::makeInstance(CacheLifetimeCalculator::class) + ->calculateLifetimeForPage( + $page['uid'], + $page, + $typoScriptConfigArray, + 0, + $this->context + ); + } if ($maxLifetimeOfPage < $maxLifetime) { $maxLifetime = $maxLifetimeOfPage; } @@ -128,6 +179,11 @@ protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null): return $maxLifetime; } + protected function getServerRequest(): ServerRequestInterface + { + return $GLOBALS['TYPO3_REQUEST']; + } + protected function getFrontendController(): TypoScriptFrontendController { return $GLOBALS['TSFE']; diff --git a/Classes/Compiler/LanguageMenuCompiler.php b/Classes/Compiler/LanguageMenuCompiler.php index efbe5a7..c1a0c5e 100644 --- a/Classes/Compiler/LanguageMenuCompiler.php +++ b/Classes/Compiler/LanguageMenuCompiler.php @@ -13,6 +13,8 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspectFactory; +use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -38,7 +40,7 @@ public function compile(ContentObjectRenderer $contentObjectRenderer, array $con $context = clone GeneralUtility::makeInstance(Context::class); $pages = []; foreach ($site->getLanguages() as $language) { - if (in_array($language->getTwoLetterIsoCode(), $excludedLanguages, true)) { + if (in_array($this->getLanguageCode($language), $excludedLanguages, true)) { continue; } if (in_array((string)$language->getLanguageId(), $excludedLanguages, true)) { @@ -62,4 +64,12 @@ public function compile(ContentObjectRenderer $contentObjectRenderer, array $con return $pages; }); } + + protected function getLanguageCode(SiteLanguage $language): string + { + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() === 11) { + return $language->getTwoLetterIsoCode(); + } + return $language->getLocale()->getLanguageCode(); + } } diff --git a/Classes/Domain/Repository/MenuRepository.php b/Classes/Domain/Repository/MenuRepository.php index 86425c4..b9579a3 100644 --- a/Classes/Domain/Repository/MenuRepository.php +++ b/Classes/Domain/Repository/MenuRepository.php @@ -16,6 +16,7 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Domain\Repository\PageRepository; +use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -31,7 +32,6 @@ class MenuRepository // Never show or query them. protected $excludedDoktypes = [ PageRepository::DOKTYPE_BE_USER_SECTION, - PageRepository::DOKTYPE_RECYCLER, PageRepository::DOKTYPE_SYSFOLDER, ]; @@ -40,6 +40,9 @@ public function __construct(Context $context, PageRepository $pageRepository, Ev $this->context = $context; $this->pageRepository = $pageRepository; $this->eventDispatcher = $eventDispatcher; + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + $this->excludedDoktypes[] = PageRepository::DOKTYPE_RECYCLER; + } } public function getBreadcrumbsMenu(array $originalRootLine, array $configuration): array diff --git a/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php b/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php index e5e3f17..f62373a 100644 --- a/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php +++ b/Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php @@ -16,12 +16,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; -class BreadcrumbsMenuTest extends DataProcessingTest +class BreadcrumbsMenuTest extends DataProcessing { /** * @return array */ - public function setupDataProvider() + public static function setupDataProvider() { return [ [ diff --git a/Tests/Functional/DataProcessing/DataProcessingTest.php b/Tests/Functional/DataProcessing/DataProcessing.php similarity index 98% rename from Tests/Functional/DataProcessing/DataProcessingTest.php rename to Tests/Functional/DataProcessing/DataProcessing.php index 8472fae..44934ed 100644 --- a/Tests/Functional/DataProcessing/DataProcessingTest.php +++ b/Tests/Functional/DataProcessing/DataProcessing.php @@ -22,7 +22,7 @@ use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -abstract class DataProcessingTest extends FunctionalTestCase +abstract class DataProcessing extends FunctionalTestCase { protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; diff --git a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php index 7d7dfe9..5459d22 100644 --- a/Tests/Functional/DataProcessing/ListMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/ListMenuProcessorTest.php @@ -19,12 +19,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; -class ListMenuProcessorTest extends DataProcessingTest +class ListMenuProcessorTest extends DataProcessing { /** * @return array */ - public function setupDataProvider() + public static function setupDataProvider() { return [ [ @@ -335,7 +335,7 @@ public function processTest(array $tsfe, array $configuration, array $expected) /** * @return array */ - public function cacheDataProvider() + public static function cacheDataProvider() { return [ [ diff --git a/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php b/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php index 7450a9c..62d1b4f 100644 --- a/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php +++ b/Tests/Functional/DataProcessing/TreeMenuProcessorTest.php @@ -19,12 +19,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; -class TreeMenuProcessorTest extends DataProcessingTest +class TreeMenuProcessorTest extends DataProcessing { /** * @return array */ - public function setupDataProvider() + public static function setupDataProvider() { return [ [ @@ -417,7 +417,7 @@ public function processTest(array $tsfe, array $configuration, array $expected): /** * @return array */ - public function cacheDataProvider() + public static function cacheDataProvider() { return [ // entry point 2 diff --git a/Tests/Functional/Frontend/AbstractFrontendTest.php b/Tests/Functional/Frontend/AbstractFrontendTest.php deleted file mode 100644 index 25357ca..0000000 --- a/Tests/Functional/Frontend/AbstractFrontendTest.php +++ /dev/null @@ -1,33 +0,0 @@ - 'typo3conf/sites']; - - protected function executeFrontendRequestWrapper(InternalRequest $request, InternalRequestContext $context = null, bool $followRedirects = false): ResponseInterface - { - if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 11) { - return $this->executeFrontendRequest($request, $context, $followRedirects); - } - return $this->executeFrontendSubRequest($request, $context, $followRedirects); - } -} diff --git a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php index 2b2b628..72f153f 100644 --- a/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/BreadcrumbMenuContentObjectTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class BreadcrumbMenuContentObjectTest extends AbstractFrontendTest +class BreadcrumbMenuContentObjectTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -21,7 +26,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'root'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -34,7 +39,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/page-1')); $expected = 'rootpage-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php index 681665d..a028ab9 100644 --- a/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php +++ b/Tests/Functional/Frontend/BreadcrumbMenuFluidTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class BreadcrumbMenuFluidTest extends AbstractFrontendTest +class BreadcrumbMenuFluidTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -21,7 +26,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'root'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -34,7 +39,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/breadcrumb_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/page-1')); $expected = 'rootpage-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php index 3241972..23fac1c 100644 --- a/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/LanguageMenuContentObjectTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class LanguageMenuContentObjectTest extends AbstractFrontendTest +class LanguageMenuContentObjectTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -22,7 +27,7 @@ public function menuOnRootPage(): void $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -36,7 +41,7 @@ public function menuOnSubpage(): void $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/de/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/de/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/LanguageMenuFluidTest.php b/Tests/Functional/Frontend/LanguageMenuFluidTest.php index 994ba58..181a0f7 100644 --- a/Tests/Functional/Frontend/LanguageMenuFluidTest.php +++ b/Tests/Functional/Frontend/LanguageMenuFluidTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class LanguageMenuFluidTest extends AbstractFrontendTest +class LanguageMenuFluidTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -22,7 +27,7 @@ public function menuOnRootPage(): void $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -36,7 +41,7 @@ public function menuOnSubpage(): void $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/translated_pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/language_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/de/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/de/')); $expected = 'englishgerman'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/ListMenuContentObjectTest.php b/Tests/Functional/Frontend/ListMenuContentObjectTest.php index ae4a8c6..2f8cf88 100644 --- a/Tests/Functional/Frontend/ListMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/ListMenuContentObjectTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class ListMenuContentObjectTest extends AbstractFrontendTest +class ListMenuContentObjectTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -21,7 +26,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -34,7 +39,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/page-1')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/ListMenuFluidTest.php b/Tests/Functional/Frontend/ListMenuFluidTest.php index dbe362f..270851d 100644 --- a/Tests/Functional/Frontend/ListMenuFluidTest.php +++ b/Tests/Functional/Frontend/ListMenuFluidTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class ListMenuFluidTest extends AbstractFrontendTest +class ListMenuFluidTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -21,7 +26,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -34,7 +39,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/list_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/page-1')); $expected = 'page-1'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php index 8a22008..0a979f9 100644 --- a/Tests/Functional/Frontend/TreeMenuContentObjectTest.php +++ b/Tests/Functional/Frontend/TreeMenuContentObjectTest.php @@ -11,9 +11,14 @@ */ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class TreeMenuContentObjectTest extends AbstractFrontendTest +class TreeMenuContentObjectTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -21,7 +26,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -34,7 +39,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_content_object_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/page-1')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); diff --git a/Tests/Functional/Frontend/TreeMenuFluidTest.php b/Tests/Functional/Frontend/TreeMenuFluidTest.php index 6553aa8..c1bf894 100644 --- a/Tests/Functional/Frontend/TreeMenuFluidTest.php +++ b/Tests/Functional/Frontend/TreeMenuFluidTest.php @@ -12,9 +12,14 @@ use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext; +use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -class TreeMenuFluidTest extends AbstractFrontendTest +class TreeMenuFluidTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = ['typo3conf/ext/menus']; + protected array $coreExtensionsToLoad = ['core', 'frontend']; + protected array $pathsToLinkInTestInstance = ['typo3conf/ext/menus/Build/sites' => 'typo3conf/sites']; + /** * @test */ @@ -22,7 +27,7 @@ public function menuOnRootPage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -35,7 +40,7 @@ public function menuOnSubpage(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/pages.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/page-1')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/page-1')); $expected = 'page-1page-2'; $body = (string)$response->getBody(); self::assertStringContainsString($expected, $body); @@ -48,7 +53,7 @@ public function menuWithAccessRestrictionForNotLoggedinUser(): void { $this->importCSVDataSet(__DIR__ . '/Fixtures/access_restriction.csv'); $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); - $response = $this->executeFrontendRequestWrapper(new InternalRequest('http://localhost/')); + $response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/')); $body = (string)$response->getBody(); self::assertStringContainsString('page-1', $body); self::assertStringNotContainsString('page-2', $body); @@ -63,7 +68,7 @@ public function menuWithAccessRestrictionForLoggedinUser(): void $this->importCSVDataSet(__DIR__ . '/Fixtures/tree_menu_fluid_typoscript.csv'); $context = (new InternalRequestContext())->withFrontendUserId(1); $request = new InternalRequest('http://localhost/'); - $response = $this->executeFrontendRequestWrapper($request, $context); + $response = $this->executeFrontendSubRequest($request, $context); $body = (string)$response->getBody(); self::assertStringContainsString('page-1', $body); self::assertStringContainsString('page-2', $body); diff --git a/Tests/Functional/Hooks/DataHandlerTest.php b/Tests/Functional/Hooks/DataHandlerTest.php index 8ed04e0..3887bc1 100644 --- a/Tests/Functional/Hooks/DataHandlerTest.php +++ b/Tests/Functional/Hooks/DataHandlerTest.php @@ -11,10 +11,10 @@ */ use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; -use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; @@ -44,11 +44,11 @@ protected function setUp(): void $this->importCSVDataSet(__DIR__ . '/../Fixtures/caches.csv'); $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv'); $this->backendUser = $GLOBALS['BE_USER'] = $this->setUpBackendUser(1); - Bootstrap::initializeLanguageObject(); + $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']); $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); } - public function cmdmapDataProvider(): array + public static function cmdmapDataProvider(): array { return [ 'copy page' => ['cmdmap' => ['pages' => [ @@ -104,7 +104,7 @@ protected function assertCacheIsEmpty(): void } $rows = $queryBuilder->select('*') ->from('cache_pages') - ->execute() + ->executeQuery() ->fetchAllAssociative(); self::assertSame(0, count($rows)); } diff --git a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php index de54416..4c384ed 100644 --- a/Tests/Unit/Domain/Repository/MenuRepositoryTest.php +++ b/Tests/Unit/Domain/Repository/MenuRepositoryTest.php @@ -17,6 +17,8 @@ use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Domain\Repository\PageRepository; +use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; class MenuRepositoryTest extends UnitTestCase @@ -38,9 +40,11 @@ public function getSubPagesOfPageRestrictQueryToExcludeDoktypes(): void ->getMock(); $excludedDoktypes = [ PageRepository::DOKTYPE_BE_USER_SECTION, - PageRepository::DOKTYPE_RECYCLER, PageRepository::DOKTYPE_SYSFOLDER, ]; + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + $excludedDoktypes[] = PageRepository::DOKTYPE_RECYCLER; + } $pageRepository->expects(self::once())->method('getMenu') ->with(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ') ', false) ->willReturn([]); @@ -63,9 +67,11 @@ public function getSubPagesOfPageMergeExcludeDoktypesFromConfiguration(): void ->getMock(); $excludedDoktypes = [ PageRepository::DOKTYPE_BE_USER_SECTION, - PageRepository::DOKTYPE_RECYCLER, PageRepository::DOKTYPE_SYSFOLDER, ]; + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + $excludedDoktypes[] = PageRepository::DOKTYPE_RECYCLER; + } $pageRepository->expects(self::once())->method('getMenu') ->with(1, '*', 'sorting', 'AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ',99) ', false) ->willReturn([]); @@ -88,20 +94,40 @@ public function getBreadcrumbsMenuRespectConfiguredExcludeDoktypes(): void ->getMock(); $context->expects(self::once())->method('getAspect')->with('language')->willReturn($languageAspect); - $pageRepository = new class() extends PageRepository { - public function getPage($uid, $disableGroupAccessCheck = false) - { - if ($uid === 1) { - // $rootLine[0] - return ['uid' => 1, 'doktype' => 99, 'nav_hide'=> 0]; + if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) { + $pageRepository = new class() extends PageRepository { + public function getPage($uid, $disableGroupAccessCheck = false) + { + if ($uid === 1) { + // $rootLine[0] + return ['uid' => 1, 'doktype' => 99, 'nav_hide'=> 0]; + } + if ($uid === 2) { + // $rootLine[0] + return ['uid' => 2, 'doktype' => 98, 'nav_hide'=> 0]; + } + return []; } - if ($uid === 2) { - // $rootLine[0] - return ['uid' => 2, 'doktype' => 98, 'nav_hide'=> 0]; + }; + } else { + $pageRepository = new class() extends PageRepository { + public function getPage(int $uid, bool $disableGroupAccessCheck = false): array + { + if ($uid === 1) { + // $rootLine[0] + return ['uid' => 1, 'doktype' => 99, 'nav_hide'=> 0]; + } + if ($uid === 2) { + // $rootLine[0] + return ['uid' => 2, 'doktype' => 98, 'nav_hide'=> 0]; + } + return []; } - return []; - } - }; + protected function init(): void + { + } + }; + } $menuRepository = $this->getMockBuilder(MenuRepository::class) ->onlyMethods(['populateAdditionalKeysForPage', 'isPageSuitableForLanguage']) diff --git a/composer.json b/composer.json index 1bb8c01..88b515d 100644 --- a/composer.json +++ b/composer.json @@ -4,18 +4,17 @@ "license": "GPL-2.0-or-later", "description": "Easy and fast menus for TYPO3 Frontends", "require": { - "php": "^7.4 || ~8.0", - "typo3/cms-core": "^10 || ^11 || ^12.4", - "typo3/cms-frontend": "^10 || ^11 || ^12.4" + "typo3/cms-core": "^11 || ^12.4 || ^13.1", + "typo3/cms-frontend": "^11 || ^12.4 || ^13.1" }, "require-dev": { - "phpstan/phpstan": "^1.8.11", - "phpunit/phpunit": "^9.5", - "typo3/cms-fluid-styled-content": "^11.5", - "typo3/cms-install": "^11.5", - "typo3/coding-standards": "^0.5", + "typo3/cms-fluid-styled-content": "^11 || ^12.4 || ^13.1", + "typo3/cms-install": "^11 || ^12.4 || ^13.1", + "typo3/coding-standards": "^0.5.5", + "saschaegerer/phpstan-typo3": "^1.8", "typo3/tailor": "^1.0", - "typo3/testing-framework": "^7" + "typo3/testing-framework": "^7.0 || ^8.0", + "phpunit/phpunit": "9.6 || ^10.5" }, "config": { "vendor-dir": ".Build/vendor", @@ -35,9 +34,6 @@ } }, "scripts": { - "prepare-tests-10": [ - "TYPO3\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare" - ], "prepare-tests": [ "if [ ! -e .Build/Web/typo3conf/sites -a -e .Build/Web/typo3conf ]; then cd .Build/Web/typo3conf && ln -s ../../../Build/sites && cd -; fi" ] From b4d0f9e47e834e5a5e6d856d665365ad08dd6aa0 Mon Sep 17 00:00:00 2001 From: Achim Fritz Date: Thu, 27 Jun 2024 09:06:30 +0200 Subject: [PATCH 21/21] [BUGFIX] use current prefix for language menu cache identifier Fixes: #87 --- Classes/Compiler/LanguageMenuCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Compiler/LanguageMenuCompiler.php b/Classes/Compiler/LanguageMenuCompiler.php index efbe5a7..5ce305a 100644 --- a/Classes/Compiler/LanguageMenuCompiler.php +++ b/Classes/Compiler/LanguageMenuCompiler.php @@ -23,7 +23,7 @@ class LanguageMenuCompiler extends AbstractMenuCompiler */ public function compile(ContentObjectRenderer $contentObjectRenderer, array $configuration): array { - $cacheIdentifier = $this->generateCacheIdentifierForMenu('list', $configuration); + $cacheIdentifier = $this->generateCacheIdentifierForMenu('language', $configuration); $excludedLanguages = $contentObjectRenderer->stdWrap($configuration['excludeLanguages'] ?? '', $configuration['excludeLanguages.'] ?? []); $excludedLanguages = GeneralUtility::trimExplode(',', $excludedLanguages, true);