Skip to content

Commit

Permalink
[TASK] Make tests work in v11
Browse files Browse the repository at this point in the history
Adopt TCA for 11 only
Drop usage of ObjectManager if possiblee
Check for undefined index
  • Loading branch information
georgringer authored Oct 22, 2021
1 parent be26661 commit 9fe96a4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 42 deletions.
8 changes: 7 additions & 1 deletion Classes/Domain/Repository/AbstractDemandedRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace GeorgRinger\News\Domain\Repository;

use GeorgRinger\News\Domain\Model\DemandInterface;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser;
Expand Down Expand Up @@ -86,7 +87,12 @@ public function findDemanded(DemandInterface $demand, $respectEnableFields = tru
public function findDemandedRaw(DemandInterface $demand, $respectEnableFields = true, $disableLanguageOverlayMode = false): string
{
$query = $this->generateQuery($demand, $respectEnableFields, $disableLanguageOverlayMode);
$queryParser = $this->objectManager->get(Typo3DbQueryParser::class);
$versionInformation = GeneralUtility::makeInstance(Typo3Version::class);
if ($versionInformation->getMajorVersion() >= 11) {
$queryParser = GeneralUtility::makeInstance(Typo3DbQueryParser::class);
} else {
$queryParser = $this->objectManager->get(Typo3DbQueryParser::class);
}

$queryBuilder = $queryParser->convertQueryToDoctrineQueryBuilder($query);
$queryParameters = $queryBuilder->getParameters();
Expand Down
5 changes: 3 additions & 2 deletions Classes/Domain/Repository/NewsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ protected function createOrderingsFromDemand(DemandInterface $demand): array
if (!empty($orderList)) {
// go through every order statement
foreach ($orderList as $orderItem) {
list($orderField, $ascDesc) = GeneralUtility::trimExplode(' ', $orderItem, true);
// count == 1 means that no direction is given
$orderSplit = GeneralUtility::trimExplode(' ', $orderItem, true);
$orderField = $orderSplit[0];
$ascDesc = $orderSplit[1] ?? '';
if ($ascDesc) {
$orderings[$orderField] = ((strtolower($ascDesc) === 'desc') ?
QueryInterface::ORDER_DESCENDING :
Expand Down
8 changes: 4 additions & 4 deletions Classes/ViewHelpers/SimplePrevNextViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function initializeArguments()
$this->registerArgument('pidList', 'string', 'pid list', false, '');
$this->registerArgument('sortField', 'string', 'sort field', false, 'datetime');
$this->registerArgument('as', 'string', 'as', true);
$this->registerArgument('includeInternalType', 'boolean', 'Include internal news types');
$this->registerArgument('includeExternalType', 'bool', 'Include external news types');
$this->registerArgument('includeInternalType', 'boolean', 'Include internal news types', false, false);
$this->registerArgument('includeExternalType', 'bool', 'Include external news types', false, false);
}

/**
Expand Down Expand Up @@ -181,10 +181,10 @@ protected function getNeighbours(News $news, string $pidList, string $sortField)
$extraWhere = [
$queryBuilder->expr()->neq('uid', $queryBuilder->createNamedParameter($news->getUid(), \PDO::PARAM_INT))
];
if ((bool)$this->arguments['includeInternalType'] === false) {
if ((bool)($this->arguments['includeInternalType'] ?? false) === false) {
$extraWhere[] = $queryBuilder->expr()->neq('type', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT));
}
if ((bool)$this->arguments['includeExternalType'] === false) {
if ((bool)($this->arguments['includeExternalType'] ?? false) === false) {
$extraWhere[] = $queryBuilder->expr()->neq('type', $queryBuilder->createNamedParameter(2, \PDO::PARAM_INT));
}

Expand Down
2 changes: 0 additions & 2 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
}
}


$newFields = [
'tx_news_related_news' => [
'label' => 'tx_news_related_news',
Expand All @@ -41,4 +40,3 @@
]
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $newFields);

25 changes: 25 additions & 0 deletions Configuration/TCA/Overrides/z_misc_11_adoptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

defined('TYPO3') or die();

call_user_func(static function () {
$versionInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
if ($versionInformation->getMajorVersion() === 11) {
foreach (['link', 'news', 'tag'] as $tableSuffix) {
$GLOBALS['TCA']['tx_news_domain_model_' . $tableSuffix]['columns']['sys_language_uid']['config'] = [
'type' => 'language'
];
}

$showRemovedLocalizationRecordsFields = [
'sys_category' => ['images'],
'tx_news_domain_model_news' => ['related_links', 'content_elements', 'fal_media', 'fal_related_files']
];

foreach ($showRemovedLocalizationRecordsFields as $tableName => $fields) {
foreach ($fields as $field) {
unset($GLOBALS['TCA'][$tableName]['columns'][$field]['config']['appearance']['showRemovedLocalizationRecords']);
}
}
}
});
11 changes: 6 additions & 5 deletions Tests/Functional/Repository/CategoryRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
class CategoryRepositoryTest extends FunctionalTestCase
{

/** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager */
protected $objectManager;

/** @var \GeorgRinger\News\Domain\Repository\CategoryRepository */
protected $categoryRepository;

Expand All @@ -31,8 +28,12 @@ class CategoryRepositoryTest extends FunctionalTestCase
public function setUp(): void
{
parent::setUp();
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->categoryRepository = $this->objectManager->get(CategoryRepository::class);
$versionInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
if ($versionInformation->getMajorVersion() === 11) {
$this->categoryRepository = $this->getContainer()->get(CategoryRepository::class);
} else {
$this->categoryRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(CategoryRepository::class);
}

$this->importDataSet(__DIR__ . '/../Fixtures/sys_category.xml');
}
Expand Down
52 changes: 24 additions & 28 deletions Tests/Functional/Repository/NewsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@
namespace GeorgRinger\News\Tests\Functional\Repository;

use GeorgRinger\News\Domain\Model\Dto\NewsDemand;
use GeorgRinger\News\Domain\Repository\NewsRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use GeorgRinger\News\Domain\Repository\NewsRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

/**
* Functional test for the \GeorgRinger\News\Domain\Repository\NewsRepository
*/
class NewsRepositoryTest extends FunctionalTestCase
{

/** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager */
protected $objectManager;

/** @var \GeorgRinger\News\Domain\Repository\NewsRepository */
protected $newsRepository;

Expand All @@ -35,8 +32,13 @@ class NewsRepositoryTest extends FunctionalTestCase
public function setUp(): void
{
parent::setUp();
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->newsRepository = $this->objectManager->get(NewsRepository::class);

$versionInformation = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Information\Typo3Version::class);
if ($versionInformation->getMajorVersion() === 11) {
$this->newsRepository = $this->getContainer()->get(NewsRepository::class);
} else {
$this->newsRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(NewsRepository::class);
}

$this->importDataSet(__DIR__ . '/../Fixtures/tags.xml');
$this->importDataSet(__DIR__ . '/../Fixtures/tx_news_domain_model_news.xml');
Expand Down Expand Up @@ -79,8 +81,7 @@ public function findRecordsByImportSource(): void
*/
public function findTopNewsRecords(): void
{
/** @var $demand \GeorgRinger\News\Domain\Model\Dto\NewsDemand */
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage(2);

// no matter about top news
Expand All @@ -105,8 +106,7 @@ public function findTopNewsRecords(): void
*/
public function findRecordsByStartingpointRestriction(): void
{
/** @var $demand \GeorgRinger\News\Domain\Model\Dto\NewsDemand */
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();

// simple starting point
$demand->setStoragePage(3);
Expand All @@ -131,23 +131,21 @@ public function findRecordsByStartingpointRestriction(): void
public function findRecordsByArchiveRestriction(): void
{
$GLOBALS['SIM_EXEC_TIME'] = 1396812099;
$newsRepository = $this->objectManager->get(NewsRepository::class);

/** @var $demand \GeorgRinger\News\Domain\Model\Dto\NewsDemand */
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage(7);

// Archived means: archive date must be lower than current time AND != 0
$demand->setArchiveRestriction('archived');
$this->assertEquals((int)$newsRepository->findDemanded($demand)->count(), 3);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 3);

// Active means: archive date must be in future or no archive date
$demand->setArchiveRestriction('active');
$this->assertEquals((int)$newsRepository->findDemanded($demand)->count(), 2);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 2);

// no value means: give all
$demand->setArchiveRestriction('');
$this->assertEquals((int)$newsRepository->findDemanded($demand)->count(), 5);
$this->assertEquals((int)$this->newsRepository->findDemanded($demand)->count(), 5);
}

/**
Expand All @@ -160,7 +158,7 @@ public function findRecordsByArchiveRestriction(): void
public function findRecordsByMonthAndYear(): void
{
$this->markTestSkipped('Does not work in travis');
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage(8);

$demand->setDateField('datetime');
Expand All @@ -178,7 +176,7 @@ public function findRecordsByMonthAndYear(): void
*/
public function findLatestLimitRecords(): void
{
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage(9);

$GLOBALS['SIM_EXEC_TIME'] = strtotime('2014-04-03');
Expand All @@ -201,7 +199,7 @@ public function findLatestLimitRecords(): void
*/
public function findRecordsByTags(): void
{
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage(10);
$demand->setOrder('uid');
$demand->setOrderByAllowed('uid');
Expand Down Expand Up @@ -229,7 +227,7 @@ public function findRecordsByTags(): void
*/
public function findRecordsForDateMenu(): void
{
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage('9');
$demand->setDateField('datetime');
$expected = [
Expand All @@ -256,8 +254,7 @@ public function findRecordsForDateMenu(): void
*/
public function findRecordsByType(): void
{
/** @var \GeorgRinger\News\Domain\Model\Dto\NewsDemand $demand */
$demand = $this->objectManager->get(NewsDemand::class);
$demand = new NewsDemand();
$demand->setStoragePage('1,2');

// given is 1 tag
Expand Down Expand Up @@ -287,6 +284,5 @@ protected function getIdListOfNews(QueryResultInterface $newsList)
public function tearDown(): void
{
unset($this->newsRepository);
unset($this->objectManager);
}
}
3 changes: 3 additions & 0 deletions ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
'type' => 'select',
'itemsProcFunc' => \GeorgRinger\News\Hooks\ItemsProcFunc::class . '->user_categoryOverlay',
];
if (!isset($GLOBALS['TYPO3_USER_SETTINGS']['showitem'])) {
$GLOBALS['TYPO3_USER_SETTINGS']['showitem'] = '';
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToUserSettings('--div--;LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:pi1_title,newsoverlay');

// Add tables to livesearch (e.g. "#news:fo" or "#newscat:fo")
Expand Down

0 comments on commit 9fe96a4

Please sign in to comment.