diff --git a/.gitignore b/.gitignore index 75b642d..348b987 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ /Documentation-GENERATED-temp/ +/.Build/ +/vendor/ +/composer.lock diff --git a/Classes/Collection/RecordCollectionRepository.php b/Classes/Collection/RecordCollectionRepository.php index 0a4daad..866d7c5 100644 --- a/Classes/Collection/RecordCollectionRepository.php +++ b/Classes/Collection/RecordCollectionRepository.php @@ -17,6 +17,8 @@ declare(strict_types=1); namespace FriendsOfTYPO3\LegacyCollections\Collection; +use TYPO3\CMS\Core\Collection\AbstractRecordCollection; +use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer; @@ -54,7 +56,7 @@ class RecordCollectionRepository * Finds a record collection by uid. * * @param int $uid The uid to be looked up - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection|null + * @return AbstractRecordCollection|null */ public function findByUid($uid) { @@ -70,9 +72,7 @@ class RecordCollectionRepository } $data = $queryBuilder->select('*') - ->from($this->table) - ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))) - ->execute() + ->from($this->table)->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))->executeQuery() ->fetch(); if (is_array($data)) { $result = $this->createDomainObject($data); @@ -83,7 +83,7 @@ class RecordCollectionRepository /** * Finds all record collections. * - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection[]|null + * @return AbstractRecordCollection[]|null */ public function findAll() { @@ -94,7 +94,7 @@ class RecordCollectionRepository * Finds record collections by table name. * * @param string $tableName Name of the table to be looked up - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection[] + * @return AbstractRecordCollection[] */ public function findByTableName($tableName) { @@ -111,7 +111,7 @@ class RecordCollectionRepository * Finds record collection by type. * * @param string $type Type to be looked up - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection[]|null + * @return AbstractRecordCollection[]|null */ public function findByType($type) { @@ -129,7 +129,7 @@ class RecordCollectionRepository * * @param string $type Type to be looked up * @param string $tableName Name of the table to be looked up - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection[]|null + * @return AbstractRecordCollection[]|null */ public function findByTypeAndTableName($type, $tableName) { @@ -154,7 +154,7 @@ class RecordCollectionRepository ->getConnectionForTable($this->table) ->update( $this->table, - ['deleted' => 1, 'tstamp' => (int)$GLOBALS['EXEC_TIME']], + ['deleted' => 1, 'tstamp' => (int)GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('date', 'timestamp')], ['uid' => (int)$uid] ); } @@ -163,7 +163,7 @@ class RecordCollectionRepository * Queries for multiple records for the given conditions. * * @param array $conditions Conditions concatenated with AND for query - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection[]|null + * @return AbstractRecordCollection[]|null */ protected function queryMultipleRecords(array $conditions = []) { @@ -181,7 +181,7 @@ class RecordCollectionRepository $queryBuilder->where(...$conditions); } - $data = $queryBuilder->execute()->fetchAll(); + $data = $queryBuilder->executeQuery()->fetchAll(); if (!empty($data)) { $result = $this->createMultipleDomainObjects($data); } @@ -193,7 +193,7 @@ class RecordCollectionRepository * Creates a record collection domain object. * * @param array $record Database record to be reconstituted - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection + * @return AbstractRecordCollection * @throws \RuntimeException */ protected function createDomainObject(array $record) @@ -212,7 +212,7 @@ class RecordCollectionRepository * Creates multiple record collection domain objects. * * @param array $data Array of multiple database records to be reconstituted - * @return \TYPO3\CMS\Core\Collection\AbstractRecordCollection[] + * @return AbstractRecordCollection[] */ protected function createMultipleDomainObjects(array $data) { diff --git a/Classes/Collection/StaticRecordCollection.php b/Classes/Collection/StaticRecordCollection.php index 2a0d5fb..2c85a38 100644 --- a/Classes/Collection/StaticRecordCollection.php +++ b/Classes/Collection/StaticRecordCollection.php @@ -194,7 +194,7 @@ class StaticRecordCollection extends AbstractRecordCollection implements Editabl ) ) ->orderBy('sys_collection_entries.sorting') - ->execute(); + ->executeQuery(); $relatedRecords = []; while ($record = $statement->fetch()) { $relatedRecords[] = $record; diff --git a/Configuration/TCA/sys_collection.php b/Configuration/TCA/sys_collection.php index 1782fc0..a9ddaff 100644 --- a/Configuration/TCA/sys_collection.php +++ b/Configuration/TCA/sys_collection.php @@ -5,7 +5,6 @@ return [ 'label' => 'title', 'tstamp' => 'tstamp', 'crdate' => 'crdate', - 'cruser_id' => 'cruser_id', 'descriptionColumn' => 'description', 'versioningWS' => true, 'origUid' => 't3_origuid', @@ -34,21 +33,7 @@ return [ 'sys_language_uid' => [ 'exclude' => true, 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language', - 'config' => [ - 'type' => 'select', - 'renderType' => 'selectSingle', - 'foreign_table' => 'sys_language', - 'items' => [ - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages', -1], - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.default_value', 0] - ], - 'default' => 0, - 'fieldWizard' => [ - 'selectIcons' => [ - 'disabled' => false, - ], - ], - ] + 'config' => ['type' => 'language'] ], 'l10n_parent' => [ 'displayCond' => 'FIELD:sys_language_uid:>:0', @@ -57,7 +42,7 @@ return [ 'type' => 'select', 'renderType' => 'selectSingle', 'items' => [ - ['', 0] + ['label' => '', 'value' => 0] ], 'foreign_table' => 'sys_file_collection', 'foreign_table_where' => 'AND sys_file_collection.pid=###CURRENT_PID### AND sys_file_collection.sys_language_uid IN (-1,0)' @@ -78,7 +63,7 @@ return [ 'default' => 0, 'items' => [ [ - 0 => '', + 'label' => '', 1 => '', 'invertStateDisplay' => true ] @@ -89,9 +74,7 @@ return [ 'exclude' => true, 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.starttime', 'config' => [ - 'type' => 'input', - 'renderType' => 'inputDateTime', - 'eval' => 'date,int', + 'type' => 'datetime', 'default' => 0, ] ], @@ -99,9 +82,7 @@ return [ 'exclude' => true, 'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.endtime', 'config' => [ - 'type' => 'input', - 'renderType' => 'inputDateTime', - 'eval' => 'date,int', + 'type' => 'datetime', 'default' => 0, 'range' => [ 'upper' => mktime(0, 0, 0, 1, 1, 2038), @@ -115,10 +96,10 @@ return [ 'type' => 'select', 'renderType' => 'selectSingle', 'items' => [ - ['', 0], - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.hide_at_login', -1], - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.any_login', -2], - ['LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.usergroups', '--div--'] + ['label' => '', 'value' => 0], + ['label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.hide_at_login', 'value' => -1], + ['label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.any_login', 'value' => -2], + ['label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.usergroups', 'value' => '--div--'] ], 'foreign_table' => 'fe_groups' ] @@ -135,7 +116,6 @@ return [ 'label' => 'LLL:EXT:legacy_collections/Resources/Private/Language/locallang_tca.xlf:sys_collection.items', 'config' => [ 'type' => 'group', - 'internal_type' => 'db', 'prepend_tname' => true, 'allowed' => '*', 'MM' => 'sys_collection_entries', @@ -149,7 +129,7 @@ return [ 'config' => [ 'type' => 'input', 'size' => 60, - 'eval' => 'required' + 'required' => true ] ], 'description' => [ @@ -166,7 +146,7 @@ return [ 'type' => 'select', 'renderType' => 'selectSingle', 'items' => [ - ['LLL:EXT:legacy_collections/Resources/Private/Language/locallang_tca.xlf:sys_collection.type.static', 'static'] + ['label' => 'LLL:EXT:legacy_collections/Resources/Private/Language/locallang_tca.xlf:sys_collection.type.static', 'value' => 'static'] ], 'default' => 'static' ] diff --git a/Migrations/Code/ClassAliasMap.php b/Migrations/Code/ClassAliasMap.php deleted file mode 100644 index e3354be..0000000 --- a/Migrations/Code/ClassAliasMap.php +++ /dev/null @@ -1,5 +0,0 @@ - \FriendsOfTYPO3\LegacyCollections\Collection\StaticRecordCollection::class, - 'TYPO3\\CMS\\Core\\Collection\\RecordCollectionRepository' => \FriendsOfTYPO3\LegacyCollections\Collection\RecordCollectionRepository::class, -]; diff --git a/Tests/Functional/Collection/RecordCollectionRepositoryTest.php b/Tests/Functional/Collection/RecordCollectionRepositoryTest.php index 3f03bad..badab39 100644 --- a/Tests/Functional/Collection/RecordCollectionRepositoryTest.php +++ b/Tests/Functional/Collection/RecordCollectionRepositoryTest.php @@ -17,6 +17,7 @@ declare(strict_types=1); namespace FriendsOfTYPO3\LegacyCollections\Tests\Functional\Collection; +use PHPUnit\Framework\MockObject\MockObject; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\SQLServerPlatform; use FriendsOfTYPO3\LegacyCollections\Collection\RecordCollectionRepository; @@ -31,8 +32,12 @@ use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; */ class RecordCollectionRepositoryTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = [ + 'typo3conf/ext/legacy_collections', + ]; + /** - * @var RecordCollectionRepository|\PHPUnit\Framework\MockObject\MockObject + * @var RecordCollectionRepository|MockObject */ protected $subject; @@ -49,7 +54,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase parent::setUp(); $this->subject = $this->getMockBuilder(RecordCollectionRepository::class) - ->setMethods(['getEnvironmentMode']) + ->onlyMethods(['getEnvironmentMode']) ->getMock(); $this->testTableName = StringUtility::getUniqueId('tx_testtable'); } @@ -66,7 +71,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByTypeReturnNull() + public function doesFindByTypeReturnNull(): void { $type = RecordCollectionRepository::TYPE_Static; $objects = $this->subject->findByType($type); @@ -76,7 +81,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByTypeReturnObjects() + public function doesFindByTypeReturnObjects(): void { $type = RecordCollectionRepository::TYPE_Static; $this->insertTestData([ @@ -93,7 +98,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByTableNameReturnNull() + public function doesFindByTableNameReturnNull(): void { $objects = $this->subject->findByTableName($this->testTableName); self::assertNull($objects); @@ -102,7 +107,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByTableNameReturnObjects() + public function doesFindByTableNameReturnObjects(): void { $type = RecordCollectionRepository::TYPE_Static; $this->insertTestData([ @@ -119,7 +124,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByTypeAndTableNameReturnNull() + public function doesFindByTypeAndTableNameReturnNull(): void { $type = RecordCollectionRepository::TYPE_Static; $objects = $this->subject->findByTypeAndTableName($type, $this->testTableName); @@ -130,7 +135,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByTypeAndTableNameReturnObjects() + public function doesFindByTypeAndTableNameReturnObjects(): void { $type = RecordCollectionRepository::TYPE_Static; $this->insertTestData([ @@ -147,7 +152,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByUidReturnAnObjectInBackendMode() + public function doesFindByUidReturnAnObjectInBackendMode(): void { $this->subject->method('getEnvironmentMode')->willReturn('BE'); $type = RecordCollectionRepository::TYPE_Static; @@ -170,7 +175,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByUidRespectDeletedFieldInBackendMode() + public function doesFindByUidRespectDeletedFieldInBackendMode(): void { $this->subject->method('getEnvironmentMode')->willReturn('BE'); $type = RecordCollectionRepository::TYPE_Static; @@ -193,7 +198,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByUidIgnoreOtherEnableFieldsInBackendMode() + public function doesFindByUidIgnoreOtherEnableFieldsInBackendMode(): void { $this->subject->method('getEnvironmentMode')->willReturn('BE'); $type = RecordCollectionRepository::TYPE_Static; @@ -229,7 +234,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByUidReturnAnObjectInFrontendMode() + public function doesFindByUidReturnAnObjectInFrontendMode(): void { $this->subject->method('getEnvironmentMode')->willReturn('FE'); $type = RecordCollectionRepository::TYPE_Static; @@ -252,7 +257,7 @@ class RecordCollectionRepositoryTest extends FunctionalTestCase /** * @test */ - public function doesFindByUidRespectEnableFieldsInFrontendMode() + public function doesFindByUidRespectEnableFieldsInFrontendMode(): void { $this->subject->method('getEnvironmentMode')->willReturn('FE'); $type = RecordCollectionRepository::TYPE_Static; diff --git a/Tests/Functional/Fixtures/BackendUser.csv b/Tests/Functional/Fixtures/BackendUser.csv new file mode 100644 index 0000000..53a96db --- /dev/null +++ b/Tests/Functional/Fixtures/BackendUser.csv @@ -0,0 +1,3 @@ +be_users +,uid,pid,username,password,admin +,1,0,admin,$1$tCrlLajZ$C0sikFQQ3SWaFAZ1Me0Z/1,1,1 diff --git a/Tests/Functional/Tca/CollectionVisibleFieldsTest.php b/Tests/Functional/Tca/CollectionVisibleFieldsTest.php index b83c647..231ba76 100644 --- a/Tests/Functional/Tca/CollectionVisibleFieldsTest.php +++ b/Tests/Functional/Tca/CollectionVisibleFieldsTest.php @@ -18,12 +18,16 @@ declare(strict_types=1); namespace FriendsOfTYPO3\LegacyCollections\Tests\Functional\Tca; use TYPO3\CMS\Backend\Tests\Functional\Form\FormTestService; -use TYPO3\CMS\Core\Localization\LanguageService; +use TYPO3\CMS\Core\Localization\LanguageServiceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; class CollectionVisibleFieldsTest extends FunctionalTestCase { + protected array $testExtensionsToLoad = [ + 'typo3conf/ext/legacy_collections', + ]; + protected static $collectionFields = [ 'title', 'sys_language_uid', @@ -39,12 +43,13 @@ class CollectionVisibleFieldsTest extends FunctionalTestCase /** * @test */ - public function collectionFormContainsExpectedFields() + public function collectionFormContainsExpectedFields(): void { - $this->setUpBackendUserFromFixture(1); - $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageService::class); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/BackendUser.csv'); + $this->setUpBackendUser(1); + $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->create('en_EN'); - $formEngineTestService = GeneralUtility::makeInstance(FormTestService::class); + $formEngineTestService = new FormTestService(); $formResult = $formEngineTestService->createNewRecordForm('sys_collection'); foreach (static::$collectionFields as $expectedField) { diff --git a/composer.json b/composer.json index 1027b98..c8a1259 100644 --- a/composer.json +++ b/composer.json @@ -10,21 +10,18 @@ }, "license": ["GPL-2.0+"], "require": { - "php": "^7.2 || ^8.0", - "typo3/cms-core": "^10.0 || ^11.5", - "typo3/cms-frontend": "^10.0 || ^11.5" + "php": "8.1.*", + "typo3/cms-core": "^12.4", + "typo3/cms-frontend": "^12.4" }, "require-dev": { - "typo3/testing-framework": "^6.3.2" + "typo3/testing-framework": "^8.0" }, "extra": { - "typo3/class-alias-loader": { - "class-alias-maps": [ - "Migrations/Code/ClassAliasMap.php" - ] - }, "typo3/cms": { - "extension-key": "legacy_collections" + "extension-key": "legacy_collections", + "app-dir": ".Build", + "web-dir": ".Build/Web" } }, "autoload": { @@ -34,7 +31,17 @@ }, "autoload-dev": { "psr-4": { - "FriendsOfTYPO3\\LegacyCollections\\Tests\\": "Tests/" + "FriendsOfTYPO3\\LegacyCollections\\Tests\\": "Tests/", + "TYPO3\\CMS\\Backend\\Tests\\": "vendor/typo3/cms-backend/Tests/" + } + }, + "config": { + "preferred-install": { + "typo3/cms-backend": "source" + }, + "allow-plugins": { + "typo3/class-alias-loader": true, + "typo3/cms-composer-installers": true } } } diff --git a/ext_emconf.php b/ext_emconf.php index 027e434..643c001 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,11 +9,11 @@ $EM_CONF[$_EXTKEY] = [ 'author' => 'Benni Mack', 'author_email' => 'benni@typo3.org', 'author_company' => '', - 'version' => '1.0.1', + 'version' => '2.0.0', 'constraints' => [ 'depends' => [ - 'typo3' => '10.4.0-11.5.99', - 'frontend' => '10.4.0-11.5.99', + 'typo3' => '12.4.0-12.4.99', + 'frontend' => '12.4.0-12.4.99', ], 'conflicts' => [], 'suggests' => [], diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..de94235 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + Tests/Functional/ + + + + + +