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.
This commit is contained in:
Daniel Siepmann 2023-08-10 08:34:14 +02:00 committed by GitHub
parent dedec24de6
commit 3e594a0d15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 10 deletions

View file

@ -1,5 +1,11 @@
# Changelog # Changelog
## v1.3.1 - 2023-08-10
### Added
- Add Support for mm relations in assertions.
## v1.3.0 - 2023-05-11 ## v1.3.0 - 2023-05-11
### Added ### Added

View file

@ -54,7 +54,7 @@ trait TestingFramework
$failMessages = []; $failMessages = [];
foreach ($dataSet as $tableName => $expectedRecords) { foreach ($dataSet as $tableName => $expectedRecords) {
$records = $this->getAllRecords($tableName, true); $records = $this->getAllRecords($tableName, (isset($GLOBALS['TCA'][$tableName])));
foreach ($expectedRecords as $assertion) { foreach ($expectedRecords as $assertion) {
$result = $this->assertInRecords($assertion, $records); $result = $this->assertInRecords($assertion, $records);

View file

@ -60,6 +60,15 @@ class AssertTest extends AbstractFunctionalTestCase
$this->assertPHPDataSet(__DIR__ . '/Fixtures/WithDifferentColumns.php'); $this->assertPHPDataSet(__DIR__ . '/Fixtures/WithDifferentColumns.php');
} }
/**
* @test
*/
public function canAssertMmRelation(): void
{
$this->importPHPDataSet(__DIR__ . '/Fixtures/MmRelation.php');
$this->assertPHPDataSet(__DIR__ . '/Fixtures/MmRelation.php');
}
/** /**
* @test * @test
*/ */
@ -78,14 +87,11 @@ class AssertTest extends AbstractFunctionalTestCase
$this->importPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php'); $this->importPHPDataSet(__DIR__ . '/Fixtures/SimpleSet.php');
$this->expectException(AssertionFailedError::class); $this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage( $this->expectExceptionMessage(implode(PHP_EOL, [
'Assertion in data-set failed for "pages:1":' 'Assertion in data-set failed for "pages:1":',
. PHP_EOL 'Fields|Assertion |Record ',
. 'Fields|Assertion |Record ' 'title |Rootpage without match|Rootpage',
. PHP_EOL ]));
. 'title |Rootpage without match|Rootpage'
. PHP_EOL
);
$this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithUid.php'); $this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithUid.php');
} }
@ -103,10 +109,35 @@ class AssertTest extends AbstractFunctionalTestCase
' \'pid\' => \'0\', ', ' \'pid\' => \'0\', ',
' \'title\' => \'Rootpage without match\'', ' \'title\' => \'Rootpage without match\'',
')', ')',
]) . PHP_EOL); '',
]));
$this->assertPHPDataSet(__DIR__ . '/Fixtures/AssertDifferingWithoutUid.php'); $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 * @test
*/ */

View file

@ -0,0 +1,24 @@
<?php
return [
'sys_category_record_mm' => [
[
'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,
],
],
];

View file

@ -0,0 +1,24 @@
<?php
return [
'sys_category_record_mm' => [
[
'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,
],
],
];