summaryrefslogtreecommitdiff
path: root/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-15 20:56:01 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-15 20:56:01 -0400
commit4eaab1f6da1a56376a840231f7b8a10469308f97 (patch)
tree8f96f9f7562c69b19a2faf53923b5ba9cdb51397 /tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php
parent8a6f02735b628033a3284d06a9f633bd260e19ef (diff)
Added unit tests for middleware
Diffstat (limited to 'tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php')
-rw-r--r--tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php b/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php
new file mode 100644
index 00000000..0a0c8783
--- /dev/null
+++ b/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use Kanboard\Middleware\ApplicationAuthorizationMiddleware;
+
+require_once __DIR__.'/../Base.php';
+
+class ApplicationAuthorizationMiddlewareMiddlewareTest extends Base
+{
+ /**
+ * @var ApplicationAuthorizationMiddleware
+ */
+ private $middleware;
+ private $nextMiddleware;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->container['helper'] = new stdClass();
+
+ $this->container['helper']->user = $this
+ ->getMockBuilder('Kanboard\Helper\UserHelper')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('hasAccess'))
+ ->getMock();
+
+ $this->nextMiddleware = $this
+ ->getMockBuilder('Kanboard\Middleware\ApplicationAuthorizationMiddleware')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('execute'))
+ ->getMock();
+
+ $this->middleware = new ApplicationAuthorizationMiddleware($this->container);
+ $this->middleware->setNextMiddleware($this->nextMiddleware);
+ }
+
+ public function testWithAccessDenied()
+ {
+ $this->container['helper']->user
+ ->expects($this->once())
+ ->method('hasAccess')
+ ->will($this->returnValue(false));
+
+ $this->nextMiddleware
+ ->expects($this->never())
+ ->method('execute');
+
+ $this->setExpectedException('Kanboard\Core\Controller\AccessForbiddenException');
+ $this->middleware->execute();
+ }
+
+ public function testWithAccessGranted()
+ {
+ $this->container['helper']->user
+ ->expects($this->once())
+ ->method('hasAccess')
+ ->will($this->returnValue(true));
+
+ $this->nextMiddleware
+ ->expects($this->once())
+ ->method('execute');
+
+ $this->middleware->execute();
+ }
+}