From 5beaa2b548f5665b63523d88e773833ef8ef02cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Lochm=C3=BCller?= Date: Wed, 13 Nov 2024 22:42:29 +0100 Subject: [PATCH] First listener tests --- .../Cache/Listener/AbstractListenerTest.php | 23 ++++++++++ .../Listener/CachingAllowedListenerTest.php | 37 ++++++++++++++++ .../Cache/Listener/EnableListenerTest.php | 43 +++++++++++++++++++ Tests/UnitTests.xml | 2 +- 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 Tests/Unit/Cache/Listener/AbstractListenerTest.php create mode 100644 Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php create mode 100644 Tests/Unit/Cache/Listener/EnableListenerTest.php diff --git a/Tests/Unit/Cache/Listener/AbstractListenerTest.php b/Tests/Unit/Cache/Listener/AbstractListenerTest.php new file mode 100644 index 00000000000..ff8048c03cd --- /dev/null +++ b/Tests/Unit/Cache/Listener/AbstractListenerTest.php @@ -0,0 +1,23 @@ +getMockBuilder(ServerRequestInterface::class)->getMock(), + [], + false + ); + } + +} diff --git a/Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php b/Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php new file mode 100644 index 00000000000..9bd88faa02f --- /dev/null +++ b/Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php @@ -0,0 +1,37 @@ +getMockBuilder(Typo3Version::class)->disableOriginalConstructor()->getMock(); + $version->method('getMajorVersion')->willReturn(12); + + $listener = new CachingAllowedListener($version); + + $event = $this->emptyCacheRuleEvent(); + $listener($event); + + self::assertEquals([], $event->getExplanation()); + self::assertEquals(false, $event->isSkipProcessing()); + + } + protected function emptyCacheRuleEvent(): CacheRuleEvent + { + return new CacheRuleEvent( + $this->getMockBuilder(ServerRequestInterface::class)->getMock(), + [], + false + ); + } +} diff --git a/Tests/Unit/Cache/Listener/EnableListenerTest.php b/Tests/Unit/Cache/Listener/EnableListenerTest.php new file mode 100644 index 00000000000..53aaafb4e34 --- /dev/null +++ b/Tests/Unit/Cache/Listener/EnableListenerTest.php @@ -0,0 +1,43 @@ +getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock(); + $configurationService->method('isBool')->willReturn(false); + + $listener = new EnableListener($configurationService); + + $event = $this->emptyCacheRuleEvent(); + $listener($event); + + self::assertEquals([], $event->getExplanation()); + self::assertEquals(false, $event->isSkipProcessing()); + + } + + + public function testAddExplanation(): void + { + $configurationService = $this->getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock(); + $configurationService->method('isBool')->willReturn(true); + + $listener = new EnableListener($configurationService); + + $event = $this->emptyCacheRuleEvent(); + $listener($event); + + self::assertNotEquals([], $event->getExplanation()); + self::assertEquals(false, $event->isSkipProcessing()); + + } +} diff --git a/Tests/UnitTests.xml b/Tests/UnitTests.xml index 09efe93512e..8a6ed925759 100755 --- a/Tests/UnitTests.xml +++ b/Tests/UnitTests.xml @@ -9,8 +9,8 @@ Unit/ Unit/AbstractTest.php - Unit/Cache/Rule/AbstractRuleTest.php Unit/Service/HttpPush/AbstractHttpPushTest.php + Unit/Cache/Listener/AbstractListenerTest.php