Skip to content

Commit

Permalink
Support MM Relations (#8)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DanielSiepmann authored Aug 10, 2023
1 parent dedec24 commit 3e594a0
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Classes/TestingFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
49 changes: 40 additions & 9 deletions Tests/Functional/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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');
}

Expand All @@ -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
*/
Expand Down
24 changes: 24 additions & 0 deletions Tests/Functional/Fixtures/MmRelation.php
Original file line number Diff line number Diff line change
@@ -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,
],
],
];
24 changes: 24 additions & 0 deletions Tests/Functional/Fixtures/MmRelationBroken.php
Original file line number Diff line number Diff line change
@@ -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,
],
],
];

0 comments on commit 3e594a0

Please sign in to comment.