From af28149c9babfc42143064f47c4962ae64671e3b Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 16 Jun 2025 15:06:27 +0200 Subject: [PATCH 1/5] Fix: Ensure last ancestor is valid before comparing paths in TrashItemData --- src/lib/Form/Data/TrashItemData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Form/Data/TrashItemData.php b/src/lib/Form/Data/TrashItemData.php index efc1a00934..a1a197de08 100644 --- a/src/lib/Form/Data/TrashItemData.php +++ b/src/lib/Form/Data/TrashItemData.php @@ -81,7 +81,7 @@ public function isParentInTrash(): bool { $lastAncestor = end($this->ancestors); - return $this->location->path !== array_merge($lastAncestor->path, [(string)$this->location->id]); + return $lastAncestor !== false && $this->location->path !== array_merge($lastAncestor->path, [(string)$this->location->id]); } public function getCreator(): ?User From a2d3f2d931a01d464d37410e0110b034bb716d86 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 16 Jun 2025 15:23:26 +0200 Subject: [PATCH 2/5] Removing error from baseline --- phpstan-baseline.neon | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ee60783b2f..69bce069d2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4230,12 +4230,6 @@ parameters: count: 1 path: src/lib/Form/Data/Section/SectionUpdateData.php - - - message: '#^Cannot access property \$path on Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|false\.$#' - identifier: property.nonObject - count: 1 - path: src/lib/Form/Data/TrashItemData.php - - message: '#^Method Ibexa\\AdminUi\\Form\\Data\\URLWildcard\\URLWildcardDeleteData\:\:__construct\(\) has parameter \$urlWildcardsChoices with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue From 9b18ae8a7c73fe463a08c5e3c60301f2a2448cca Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 23 Jun 2025 12:55:20 +0200 Subject: [PATCH 3/5] Adding unit tests for TrashItemData --- tests/lib/Form/Data/TrashItemDataTest.php | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/lib/Form/Data/TrashItemDataTest.php diff --git a/tests/lib/Form/Data/TrashItemDataTest.php b/tests/lib/Form/Data/TrashItemDataTest.php new file mode 100644 index 0000000000..a283196d61 --- /dev/null +++ b/tests/lib/Form/Data/TrashItemDataTest.php @@ -0,0 +1,53 @@ + ['1', '2', '3'], 'id' => 3]); + $data = new TrashItemData($trashItem, null, []); + + self::assertFalse($data->isParentInTrash()); + } + + public function testIsParentInTrashReturnsFalseWhenPathsMatch(): void + { + $trashItem = new TrashItem(['path' => ['1', '2', '3'], 'id' => 3]); + + $ancestor = new Location(['path' => ['1', '2']]); + $data = new TrashItemData($trashItem, null, [$ancestor]); + + self::assertFalse($data->isParentInTrash()); + } + + public function testIsParentInTrashReturnsTrueWhenPathsDoNotMatch(): void + { + $trashItem = new TrashItem(['path' => ['1', '2', '3'], 'id' => 3]); + $ancestor = new Location(['path' => ['1']]); + + $data = new TrashItemData($trashItem, null, [$ancestor]); + + self::assertTrue($data->isParentInTrash()); + } + + public function testIsParentInTrashWithMultipleAncestors(): void + { + $trashItem = new TrashItem(['path' => ['1', '2', '3', '4'], 'id' => 4]); + + $ancestor1 = new Location(['path' => ['1']]); + $ancestor2 = new Location(['path' => ['1', '2', '3']]); + + $data = new TrashItemData($trashItem, null, [$ancestor1, $ancestor2]); + + self::assertFalse($data->isParentInTrash()); + } +} From 7657f0dc81aaaffce1705baaa656537d0ad57e06 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 23 Jun 2025 12:57:46 +0200 Subject: [PATCH 4/5] Minor Fixes --- tests/lib/Form/Data/TrashItemDataTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/lib/Form/Data/TrashItemDataTest.php b/tests/lib/Form/Data/TrashItemDataTest.php index a283196d61..53b216fa83 100644 --- a/tests/lib/Form/Data/TrashItemDataTest.php +++ b/tests/lib/Form/Data/TrashItemDataTest.php @@ -4,6 +4,10 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); + +namespace Ibexa\Tests\AdminUi\Form\Data; + use Ibexa\AdminUi\Form\Data\TrashItemData; use Ibexa\Core\Repository\Values\Content\Location; use Ibexa\Core\Repository\Values\Content\TrashItem; From 08fc4622bac99f6343de8ab0e88aeb34a982991f Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 23 Jun 2025 13:00:39 +0200 Subject: [PATCH 5/5] Minor Fixes --- tests/lib/Form/Data/TrashItemDataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Form/Data/TrashItemDataTest.php b/tests/lib/Form/Data/TrashItemDataTest.php index 53b216fa83..1c2d1c4e0a 100644 --- a/tests/lib/Form/Data/TrashItemDataTest.php +++ b/tests/lib/Form/Data/TrashItemDataTest.php @@ -13,7 +13,7 @@ use Ibexa\Core\Repository\Values\Content\TrashItem; use PHPUnit\Framework\TestCase; -class TrashItemDataTest extends TestCase +final class TrashItemDataTest extends TestCase { public function testIsParentInTrashReturnsFalseWhenNoAncestors(): void {