Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-07-13 23:29:14 +0300
committerMorris Jobke <hey@morrisjobke.de>2020-07-15 15:07:18 +0300
commit7d7ba61625b21984eb01db895081d964a73ea934 (patch)
tree0e4fc65db04eb93be5971ed70dbad6d210d81ce3 /tests
parentda4f3559c5f1ab5db77e2cb06c2d618fb228313b (diff)
Add real events to load additionalscripts
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php55
1 files changed, 46 insertions, 9 deletions
diff --git a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php
index 617ead473c0..5127248215b 100644
--- a/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/AdditionalScriptsMiddlewareTest.php
@@ -27,10 +27,12 @@ namespace Test\AppFramework\Middleware;
use OC\AppFramework\Middleware\AdditionalScriptsMiddleware;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\PublicShareController;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -38,7 +40,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
/** @var EventDispatcherInterface|MockObject */
- private $dispatcher;
+ private $legacyDispatcher;
/** @var IUserSession|MockObject */
private $userSession;
@@ -47,40 +49,48 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
/** @var AdditionalScriptsMiddleware */
private $middleWare;
+ /** @var IEventDispatcher|MockObject */
+ private $dispatcher;
protected function setUp(): void {
parent::setUp();
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$this->userSession = $this->createMock(IUserSession::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->middleWare = new AdditionalScriptsMiddleware(
- $this->dispatcher,
- $this->userSession
+ $this->legacyDispatcher,
+ $this->userSession,
+ $this->dispatcher
);
$this->controller = $this->createMock(Controller::class);
}
public function testNoTemplateResponse() {
- $this->dispatcher->expects($this->never())
+ $this->legacyDispatcher->expects($this->never())
->method($this->anything());
$this->userSession->expects($this->never())
->method($this->anything());
+ $this->dispatcher->expects($this->never())
+ ->method($this->anything());
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(Response::class));
}
public function testPublicShareController() {
- $this->dispatcher->expects($this->never())
+ $this->legacyDispatcher->expects($this->never())
->method($this->anything());
$this->userSession->expects($this->never())
->method($this->anything());
+ $this->dispatcher->expects($this->never())
+ ->method($this->anything());
$this->middleWare->afterController($this->createMock(PublicShareController::class), 'myMethod', $this->createMock(Response::class));
}
public function testStandaloneTemplateResponse() {
- $this->dispatcher->expects($this->once())
+ $this->legacyDispatcher->expects($this->once())
->method('dispatch')
->willReturnCallback(function ($eventName) {
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) {
@@ -91,12 +101,21 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
});
$this->userSession->expects($this->never())
->method($this->anything());
+ $this->dispatcher->expects($this->once())
+ ->method('dispatchTyped')
+ ->willReturnCallback(function ($event) {
+ if ($event instanceof BeforeTemplateRenderedEvent && $event->isLoggedIn() === false) {
+ return;
+ }
+
+ $this->fail('Wrong event dispatched');
+ });
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(StandaloneTemplateResponse::class));
}
public function testTemplateResponseNotLoggedIn() {
- $this->dispatcher->expects($this->once())
+ $this->legacyDispatcher->expects($this->once())
->method('dispatch')
->willReturnCallback(function ($eventName) {
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS) {
@@ -107,6 +126,15 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
});
$this->userSession->method('isLoggedIn')
->willReturn(false);
+ $this->dispatcher->expects($this->once())
+ ->method('dispatchTyped')
+ ->willReturnCallback(function ($event) {
+ if ($event instanceof BeforeTemplateRenderedEvent && $event->isLoggedIn() === false) {
+ return;
+ }
+
+ $this->fail('Wrong event dispatched');
+ });
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(TemplateResponse::class));
}
@@ -114,7 +142,7 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
public function testTemplateResponseLoggedIn() {
$events = [];
- $this->dispatcher->expects($this->exactly(2))
+ $this->legacyDispatcher->expects($this->exactly(2))
->method('dispatch')
->willReturnCallback(function ($eventName) use (&$events) {
if ($eventName === TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS ||
@@ -127,6 +155,15 @@ class AdditionalScriptsMiddlewareTest extends \Test\TestCase {
});
$this->userSession->method('isLoggedIn')
->willReturn(true);
+ $this->dispatcher->expects($this->once())
+ ->method('dispatchTyped')
+ ->willReturnCallback(function ($event) {
+ if ($event instanceof BeforeTemplateRenderedEvent && $event->isLoggedIn() === true) {
+ return;
+ }
+
+ $this->fail('Wrong event dispatched');
+ });
$this->middleWare->afterController($this->controller, 'myMethod', $this->createMock(TemplateResponse::class));