From 39722b72fbde4441b76a0511de1dd833a303796f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Tue, 28 Apr 2026 16:18:31 +0200 Subject: [PATCH 1/2] IBX-11694: The condition has been corrected to be consistent with the previous one --- .../DisableSiteRootCheckboxIfRootLocationListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php b/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php index 7ffa4e9f05..5dec4eb0f8 100644 --- a/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php +++ b/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php @@ -16,7 +16,7 @@ public function onPreSetData(FormEvent $event): void { $location = $event->getData()->getLocation(); - if (null === $location || 1 >= $location->depth) { + if (null === $location || 1 < $location->depth) { return; } From 6852add27e5bc67ac4d8113c366113782f6ba2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Fri, 8 May 2026 11:20:06 +0200 Subject: [PATCH 2/2] Added test --- ...SiteRootCheckboxIfRootLocationListener.php | 2 +- ...RootCheckboxIfRootLocationListenerTest.php | 116 ++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 tests/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListenerTest.php diff --git a/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php b/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php index 5dec4eb0f8..26187e00a2 100644 --- a/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php +++ b/src/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListener.php @@ -16,7 +16,7 @@ public function onPreSetData(FormEvent $event): void { $location = $event->getData()->getLocation(); - if (null === $location || 1 < $location->depth) { + if (null === $location || 1 < $location->getDepth()) { return; } diff --git a/tests/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListenerTest.php b/tests/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListenerTest.php new file mode 100644 index 0000000000..bac1f5078b --- /dev/null +++ b/tests/lib/Form/EventListener/DisableSiteRootCheckboxIfRootLocationListenerTest.php @@ -0,0 +1,116 @@ +createMock(Location::class); + $location + ->method('getDepth') + ->willReturn(1); + + $data = new CustomUrlAddData($location); + $form = $this->createMock(FormInterface::class); + + $form + ->expects(self::once()) + ->method('add') + ->with( + 'site_root', + CheckboxType::class, + [ + 'required' => false, + 'label' => false, + 'disabled' => true, + ] + ); + + $event = $this->createMock(FormEvent::class); + + $event + ->method('getData') + ->willReturn($data); + + $event + ->method('getForm') + ->willReturn($form); + + $listener = new DisableSiteRootCheckboxIfRootLocationListener(); + + $listener->onPreSetData($event); + } + + public function testDoesNothingWhenLocationIsNull(): void + { + $data = new CustomUrlAddData(); + $form = $this->createMock(FormInterface::class); + + $form + ->expects(self::never()) + ->method('add'); + + $event = $this->createMock(FormEvent::class); + + $event + ->method('getData') + ->willReturn($data); + + $event + ->method('getForm') + ->willReturn($form); + + $listener = new DisableSiteRootCheckboxIfRootLocationListener(); + + $listener->onPreSetData($event); + + $form = $event->getForm(); + + self::assertNotTrue($form->has('site_root')); + } + + public function testDoesNothingWhenLocationDepthIsGreaterThanOne(): void + { + $location = $this->createMock(Location::class); + $location + ->method('getDepth') + ->willReturn(2); + + $data = new CustomUrlAddData($location); + $form = $this->createMock(FormInterface::class); + + $form + ->expects(self::never()) + ->method('add'); + + $event = $this->createMock(FormEvent::class); + + $event + ->method('getData') + ->willReturn($data); + + $event + ->method('getForm') + ->willReturn($form); + + $listener = new DisableSiteRootCheckboxIfRootLocationListener(); + + $listener->onPreSetData($event); + + self::assertNotTrue($form->has('site_root')); + } +}