diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-07-22 15:44:16 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-05 15:17:32 +0300 |
commit | d9418c105e66028d1399b43bad3c1e0122c2aa25 (patch) | |
tree | b6d42454edaf80907b67fb69830f5b29a35fec45 /apps/files_sharing | |
parent | 4504d7f5e9f416d33946c3364426235c92222448 (diff) |
Add OCSShareAPIMiddleware tests
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php | 1 | ||||
-rw-r--r-- | apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php | 115 |
2 files changed, 115 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php index b42cf6b00ad..04a6545c9a7 100644 --- a/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php +++ b/apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php @@ -29,7 +29,6 @@ class OCSShareAPIMiddleware extends Middleware { */ public function beforeController($controller, $methodName) { if ($controller instanceof Share20OCS) { - /** @var Share20OCS $controller */ if (!$this->shareManager->shareApiEnabled()) { throw new OCSNotFoundException($this->l->t('Share API is disabled')); } diff --git a/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php new file mode 100644 index 00000000000..6a2460396de --- /dev/null +++ b/apps/files_sharing/tests/Middleware/OCSShareAPIMiddlewareTest.php @@ -0,0 +1,115 @@ +<?php + +namespace OCA\Files_Sharing\Tests\Middleware; + +use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware; +use OCP\AppFramework\Controller; +use OCP\AppFramework\OCS\OCSNotFoundException; +use OCP\IL10N; +use OCP\Share\IManager; + +/** + * @package OCA\Files_Sharing\Middleware\SharingCheckMiddleware + */ +class OCSShareAPIMiddlewareTest extends \Test\TestCase { + + /** @var IManager */ + private $shareManager; + /** @var IL10N */ + private $l; + /** @var OCSShareAPIMiddleware */ + private $middleware; + + public function setUp() { + $this->shareManager = $this->getMockBuilder('OCP\Share\IManager')->getMock(); + $this->l = $this->getMockBuilder('OCP\IL10N')->getMock(); + + $this->l->method('t')->will($this->returnArgument(0)); + + $this->middleware = new OCSShareAPIMiddleware($this->shareManager, $this->l); + } + + public function dataBeforeController() { + return [ + [ + $this->getMockBuilder('OCP\AppFramework\Controller')->disableOriginalConstructor()->getMock(), + false, + false + ], + [ + $this->getMockBuilder('OCP\AppFramework\Controller')->disableOriginalConstructor()->getMock(), + true, + false + ], + [ + $this->getMockBuilder('OCP\AppFramework\OCSController')->disableOriginalConstructor()->getMock(), + false, + false + ], + [ + $this->getMockBuilder('OCP\AppFramework\OCSController')->disableOriginalConstructor()->getMock(), + true, + false + ], + [ + $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')->disableOriginalConstructor()->getMock(), + false, + true + ], + [ + $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')->disableOriginalConstructor()->getMock(), + true, + false + ], + ]; + } + + /** + * @dataProvider dataBeforeController + * + * @param Controller $controller + * @param bool $enabled + * @param bool $exception + */ + public function testBeforeController(Controller $controller, $enabled, $exception) { + $this->shareManager->method('shareApiEnabled')->willReturn($enabled); + + try { + $this->middleware->beforeController($controller, 'foo'); + $this->assertFalse($exception); + } catch (OCSNotFoundException $e) { + $this->assertTrue($exception); + } + } + + public function dataAfterController() { + return [ + [ + $this->getMockBuilder('OCP\AppFramework\Controller')->disableOriginalConstructor()->getMock(), + ], + [ + $this->getMockBuilder('OCP\AppFramework\OCSController')->disableOriginalConstructor()->getMock(), + ], + [ + $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS')->disableOriginalConstructor()->getMock(), + ], + ]; + } + + /** + * @dataProvider dataAfterController + * + * @param Controller $controller + * @param bool $called + */ + public function testAfterController(Controller $controller) { + if ($controller instanceof OCA\Files_Sharing\API\Share20OCS) { + $controller->expects($this->once())->method('cleanup'); + } + + $response = $this->getMockBuilder('OCP\AppFramework\Http\Response') + ->disableOriginalConstructor() + ->getMock(); + $this->middleware->afterController($controller, 'foo', $response); + } +} |