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

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsualko <klaus@jsxc.org>2017-08-02 14:33:33 +0300
committersualko <klaus@jsxc.org>2017-08-02 14:33:33 +0300
commit01f3e627d3e6445dbfafa8c73149a44057dc8c62 (patch)
treef0ba1925850529e48c10221d28834efc74a7f7fa /tests/unit
parent8a7b6e8751fb04b0aa9a5bd79f17bdbdcad97432 (diff)
add more tests for external api controller
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/controller/ExternalApiControllerTest.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/unit/controller/ExternalApiControllerTest.php b/tests/unit/controller/ExternalApiControllerTest.php
index aac2183..eaa17a7 100644
--- a/tests/unit/controller/ExternalApiControllerTest.php
+++ b/tests/unit/controller/ExternalApiControllerTest.php
@@ -4,6 +4,7 @@ namespace OCA\OJSXC\Controller;
use OCA\OJSXC\Controller\ExternalApiController;
use OCA\OJSXC\Controller\SignatureProtectedApiController;
+use OCA\OJSXC\Exceptions\UnprocessableException;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
@@ -49,6 +50,105 @@ class ExternalApiControllerTest extends TestCase
$this->assertInstanceOf(SignatureProtectedApiController::class, $this->externalApiController);
}
+ public function testIndexWithUnsupportedOperation()
+ {
+ $this->expectException(UnprocessableException::class);
+ $this->expectExceptionMessage('Unsupported operation.');
+
+ $this->externalApiController->index('foobar');
+ }
+
+ public function testIndexAuth()
+ {
+ $externalApiController = $this->getMockBuilder(ExternalApiController::class)
+ ->setConstructorArgs([
+ 'ojsxc',
+ $this->request,
+ $this->userManager,
+ $this->userSession,
+ $this->groupManager,
+ $this->logger
+ ])
+ ->setMethods(['checkPassword'])
+ ->getMock();
+
+ $this->request
+ ->expects($this->exactly(3))
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['username', null, 'dummy_username'],
+ ['password', null, 'dummy_password'],
+ ['domain', null, 'dummy_domain']
+ ]));
+
+ $externalApiController
+ ->expects($this->once())
+ ->method('checkPassword')
+ ->with('dummy_username', 'dummy_password', 'dummy_domain');
+
+ $externalApiController->index('auth');
+ }
+
+ public function testIndexIsUser()
+ {
+ $externalApiController = $this->getMockBuilder(ExternalApiController::class)
+ ->setConstructorArgs([
+ 'ojsxc',
+ $this->request,
+ $this->userManager,
+ $this->userSession,
+ $this->groupManager,
+ $this->logger
+ ])
+ ->setMethods(['isUser'])
+ ->getMock();
+
+ $this->request
+ ->expects($this->exactly(2))
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['username', null, 'dummy_username'],
+ ['domain', null, 'dummy_domain']
+ ]));
+
+ $externalApiController
+ ->expects($this->once())
+ ->method('isUser')
+ ->with('dummy_username', 'dummy_domain');
+
+ $externalApiController->index('isuser');
+ }
+
+ public function testIndexSharedRoster()
+ {
+ $externalApiController = $this->getMockBuilder(ExternalApiController::class)
+ ->setConstructorArgs([
+ 'ojsxc',
+ $this->request,
+ $this->userManager,
+ $this->userSession,
+ $this->groupManager,
+ $this->logger
+ ])
+ ->setMethods(['sharedRoster'])
+ ->getMock();
+
+ $this->request
+ ->expects($this->exactly(2))
+ ->method('getParam')
+ ->will($this->returnValueMap([
+ ['username', null, 'dummy_username'],
+ ['domain', null, 'dummy_domain']
+ ]));
+
+ $externalApiController
+ ->expects($this->once())
+ ->method('sharedRoster')
+ ->with('dummy_username', 'dummy_domain');
+
+ $externalApiController->index('sharedroster');
+ }
+
public function testCheckPasswordWithInvalidParams()
{
$this->userSession