Skip to content

Commit

Permalink
More UnitTests and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Nov 18, 2024
1 parent 1f22a3b commit 46d3741
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 4 deletions.
1 change: 1 addition & 0 deletions Resources/Private/Build/PhpCsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$finder = Finder::create()
->in($baseDir.'/Classes')
->in($baseDir.'/Configuration')
->in($baseDir.'/Tests/Unit')
;

return (new Config())
Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/Cache/IdentifierBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function testCheckInValidPath(): void
}
}

protected function getIdentifierBuilder(): IdentifierBuilder {
protected function getIdentifierBuilder(): IdentifierBuilder
{
return new IdentifierBuilder(new NoopEventDispatcher());
}
}
1 change: 0 additions & 1 deletion Tests/Unit/Cache/Listener/AbstractListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

abstract class AbstractListenerTest extends AbstractTest
{

protected function emptyCacheRuleEvent(): CacheRuleEvent
{
return new CacheRuleEvent(
Expand Down
1 change: 0 additions & 1 deletion Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class CachingAllowedListenerTest extends AbstractListenerTest
{

public function testNoExplanation(): void
{
$version = $this->getMockBuilder(Typo3Version::class)->disableOriginalConstructor()->getMock();
Expand Down
1 change: 0 additions & 1 deletion Tests/Unit/Cache/Listener/EnableListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class EnableListenerTest extends AbstractListenerTest
{

public function testNoExplanation(): void
{
$configurationService = $this->getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock();
Expand Down
31 changes: 31 additions & 0 deletions Tests/Unit/Cache/Listener/ForceStaticCacheListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use Psr\Http\Message\ServerRequestInterface;
use SFC\Staticfilecache\Cache\Listener\ForceStaticCacheListener;
use SFC\Staticfilecache\Event\CacheRuleEvent;
use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;

class ForceStaticCacheListenerTest extends AbstractListenerTest
{
public function testNoExplanation(): void
{
$listener = new ForceStaticCacheListener(new NoopEventDispatcher());

$cacheRuleEvent = new CacheRuleEvent(
$this->getMockBuilder(ServerRequestInterface::class)->getMock(),
['dummy'],
false
);

$listener($cacheRuleEvent);

self::assertEquals(['dummy'], $cacheRuleEvent->getExplanation());
self::assertEquals(false, $cacheRuleEvent->isSkipProcessing());

}

}
42 changes: 42 additions & 0 deletions Tests/Unit/Cache/Listener/NoAuthorizationListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use Psr\Http\Message\ServerRequestInterface;
use SFC\Staticfilecache\Cache\Listener\NoAuthorizationListener;
use SFC\Staticfilecache\Event\CacheRuleEvent;

class NoAuthorizationListenerTest extends AbstractListenerTest
{
public function testNoExplanation(): void
{
$listener = new NoAuthorizationListener();

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertEquals([], $event->getExplanation());
self::assertEquals(false, $event->isSkipProcessing());
}


public function testAddExplanation(): void
{
$listener = new NoAuthorizationListener();

$request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
$request->method('getHeaderLine')->willReturn('Content');

$event = new CacheRuleEvent(
$request,
[],
false
);
$listener($event);

self::assertNotEquals([], $event->getExplanation());
self::assertEquals(true, $event->isSkipProcessing());
}
}
50 changes: 50 additions & 0 deletions Tests/Unit/Cache/Listener/NoBackendUserListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use SFC\Staticfilecache\Cache\Listener\NoBackendUserListener;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\UserAspect;

class NoBackendUserListenerTest extends AbstractListenerTest
{
public function testNoExplanation(): void
{
$userAuth = new BackendUserAuthentication();

$userAspect = new UserAspect($userAuth);

$context = new Context();
$context->setAspect('backend.user', $userAspect);

$listener = new NoBackendUserListener($context);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertEquals([], $event->getExplanation());
self::assertEquals(false, $event->isSkipProcessing());
}

public function testExplanationAndSkip(): void
{
$userAuth = new BackendUserAuthentication();
$userAuth->user = ['uid' => 5];

$userAspect = new UserAspect($userAuth);

$context = new Context();
$context->setAspect('backend.user', $userAspect);

$listener = new NoBackendUserListener($context);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertNotEquals([], $event->getExplanation());
self::assertEquals(true, $event->isSkipProcessing());
}
}
41 changes: 41 additions & 0 deletions Tests/Unit/Cache/Listener/NoWorkspacePreviewListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use SFC\Staticfilecache\Cache\Listener\NoWorkspacePreviewListener;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\WorkspaceAspect;

class NoWorkspacePreviewListenerTest extends AbstractListenerTest
{
public function testNoExplanation(): void
{
$context = new Context();
$context->setAspect('workspace', new WorkspaceAspect(0));

$listener = new NoWorkspacePreviewListener($context);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertEquals([], $event->getExplanation());
self::assertEquals(false, $event->isSkipProcessing());
}

public function testExplanationAndSkip(): void
{
$context = new Context();
$context->setAspect('workspace', new WorkspaceAspect(1));

$listener = new NoWorkspacePreviewListener($context);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertNotEquals([], $event->getExplanation());
}


}

0 comments on commit 46d3741

Please sign in to comment.