From 3e594a0d152118717cfbdb11245f2a9000890ce4 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 10 Aug 2023 08:34:14 +0200 Subject: [PATCH] Support MM Relations (#8) Those don't have a hash or uid field. We use a quick check whether a table is part of TCA in order to determine those tables. --- CHANGELOG.md | 6 +++ Classes/TestingFramework.php | 2 +- Tests/Functional/AssertTest.php | 49 +++++++++++++++---- Tests/Functional/Fixtures/MmRelation.php | 24 +++++++++ .../Functional/Fixtures/MmRelationBroken.php | 24 +++++++++ 5 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 Tests/Functional/Fixtures/MmRelation.php create mode 100644 Tests/Functional/Fixtures/MmRelationBroken.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f69720..1fe0560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v1.3.1 - 2023-08-10 + +### Added + +- Add Support for mm relations in assertions. + ## v1.3.0 - 2023-05-11 ### Added diff --git a/Classes/TestingFramework.php b/Classes/TestingFramework.php index 5eef4a9..5c9e2c6 100644 --- a/Classes/TestingFramework.php +++ b/Classes/TestingFramework.php @@ -54,7 +54,7 @@ protected function assertPHPDataSet(string $filePath): void $failMessages = []; foreach ($dataSet as $tableName => $expectedRecords) { - $records = $this->getAllRecords($tableName, true); + $records = $this->getAllRecords($tableName, (isset($GLOBALS['TCA'][$tableName]))); foreach ($expectedRecords as $assertion) { $result = $this->assertInRecords($assertion, $records); diff --git a/Tests/Functional/AssertTest.php b/Tests/Functional/AssertTest.php index 6d6f0e3..52a461d 100644 --- a/Tests/Functional/AssertTest.php +++ b/Tests/Functional/AssertTest.php @@ -60,6 +60,15 @@ public function canAssertAgainstDifferentSetOfColumns(): void $this->assertPHPDataSet(__DIR__ . '/Fixtures/WithDifferentColumns.php'); } + /** + * @test + */ + public function canAssertMmRelation(): void + { + $this->importPHPDataSet(__DIR__ . '/Fixtures/MmRelation.php'); + $this->assertPHPDataSet(__DIR__ . '/Fixtures/MmRelation.php'); + } + /** * @test */ @@ -78,14 +87,11 @@ public function failsForDifferingAssertionWithUid(): void $this->importPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php'); $this->expectException(AssertionFailedError::class); - $this->expectExceptionMessage( - 'Assertion in data-set failed for "pages:1":' - . PHP_EOL - . 'Fields|Assertion |Record ' - . PHP_EOL - . 'title |Rootpage without match|Rootpage' - . PHP_EOL - ); + $this->expectExceptionMessage(implode(PHP_EOL, [ + 'Assertion in data-set failed for "pages:1":', + 'Fields|Assertion |Record ', + 'title |Rootpage without match|Rootpage', + ])); $this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithUid.php'); } @@ -103,10 +109,35 @@ public function failsForAssertionWithoutUid(): void ' \'pid\' => \'0\', ', ' \'title\' => \'Rootpage without match\'', ')', - ]) . PHP_EOL); + '', + ])); $this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithoutUid.php'); } + /** + * @test + */ + public function failsForAssertionForMmRelation(): void + { + $this->importPHPDataSet(__DIR__ . '/Fixtures/MmRelation.php'); + + $this->expectException(AssertionFailedError::class); + $this->expectExceptionMessage(implode(PHP_EOL, [ + 'Assertion in data-set failed for "sys_category_record_mm":', + 'array(', + ' \'uid_local\' => \'1\', ', + ' \'uid_foreign\' => \'2\', ', + ' \'tablenames\' => \'pages\', ', + ' \'fieldname\' => \'categories\', ', + ' \'sorting\' => \'0\', ', + ' \'sorting_foreign\' => \'3\'', + ')', + '', + 'Not asserted record found for "sys_category_record_mm:".', + ])); + $this->assertPHPDataSet(__DIR__ . '/Fixtures/MmRelationBroken.php'); + } + /** * @test */ diff --git a/Tests/Functional/Fixtures/MmRelation.php b/Tests/Functional/Fixtures/MmRelation.php new file mode 100644 index 0000000..6a29e9f --- /dev/null +++ b/Tests/Functional/Fixtures/MmRelation.php @@ -0,0 +1,24 @@ + [ + [ + 'uid_local' => 1, + 'uid_foreign' => 1, + 'tablenames' => 'pages', + 'fieldname' => 'categories', + 'sorting' => 0, + 'sorting_foreign' => 1, + ], + // A single one would work. + // But a 2nd would have the same internal index, an empty key. + [ + 'uid_local' => 1, + 'uid_foreign' => 2, + 'tablenames' => 'pages', + 'fieldname' => 'categories', + 'sorting' => 0, + 'sorting_foreign' => 2, + ], + ], +]; diff --git a/Tests/Functional/Fixtures/MmRelationBroken.php b/Tests/Functional/Fixtures/MmRelationBroken.php new file mode 100644 index 0000000..cf55042 --- /dev/null +++ b/Tests/Functional/Fixtures/MmRelationBroken.php @@ -0,0 +1,24 @@ + [ + [ + 'uid_local' => 1, + 'uid_foreign' => 1, + 'tablenames' => 'pages', + 'fieldname' => 'categories', + 'sorting' => 0, + 'sorting_foreign' => 1, + ], + // A single one would work. + // But a 2nd would have the same internal index, an empty key. + [ + 'uid_local' => 1, + 'uid_foreign' => 2, + 'tablenames' => 'pages', + 'fieldname' => 'categories', + 'sorting' => 0, + 'sorting_foreign' => 3, + ], + ], +];