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

github.com/nextcloud/user_saml.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-08-04 13:54:59 +0300
committerLukas Reschke <lukas@statuscode.ch>2017-08-04 13:54:59 +0300
commitbc98b466bd7c660589c2aa7cf6df2e0be53ccfae (patch)
tree491224c5a3fad40d3ff1dff33b24465e2ba37746 /tests/unit
parent442fa2b7098e27186a0962afe2d7a47ef7b290f3 (diff)
Set last login after successful login operation
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/UserBackendTest.php116
1 files changed, 108 insertions, 8 deletions
diff --git a/tests/unit/UserBackendTest.php b/tests/unit/UserBackendTest.php
index 5967f4a4..8946251b 100644
--- a/tests/unit/UserBackendTest.php
+++ b/tests/unit/UserBackendTest.php
@@ -26,6 +26,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\ISession;
use OCP\IURLGenerator;
+use OCP\IUser;
use OCP\IUserBackend;
use OCP\IUserManager;
use Test\TestCase;
@@ -41,7 +42,7 @@ class UserBackendTest extends TestCase {
private $db;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
- /** @var IUserBackend */
+ /** @var UserBackend|\PHPUnit_Framework_MockObject_MockObject */
private $userBackend;
public function setUp() {
@@ -52,17 +53,116 @@ class UserBackendTest extends TestCase {
$this->session = $this->createMock(ISession::class);
$this->db = $this->createMock(IDBConnection::class);
$this->userManager = $this->createMock(IUserManager::class);
+ }
- $this->userBackend = new UserBackend(
- $this->config,
- $this->urlGenerator,
- $this->session,
- $this->db,
- $this->userManager
- );
+ public function getMockedBuilder(array $mockedFunctions = []) {
+ if($mockedFunctions !== []) {
+ $this->userBackend = $this->getMockBuilder(UserBackend::class)
+ ->setConstructorArgs([
+ $this->config,
+ $this->urlGenerator,
+ $this->session,
+ $this->db,
+ $this->userManager
+ ])
+ ->setMethods($mockedFunctions)
+ ->getMock();
+ } else {
+ $this->userBackend = new UserBackend(
+ $this->config,
+ $this->urlGenerator,
+ $this->session,
+ $this->db,
+ $this->userManager
+ );
+ }
}
public function testGetBackendName() {
+ $this->getMockedBuilder();
$this->assertSame('user_saml', $this->userBackend->getBackendName());
}
+
+ public function testUpdateAttributesWithoutAttributes() {
+ $this->getMockedBuilder(['getDisplayName']);
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->createMock(IUser::class);
+
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn($user);
+ $user
+ ->expects($this->once())
+ ->method('updateLastLoginTimestamp');
+ $user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn(null);
+ $user
+ ->expects($this->never())
+ ->method('setEMailAddress');
+ $this->userBackend
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->with('ExistingUser')
+ ->willReturn('');
+ $this->userBackend->updateAttributes('ExistingUser', []);
+ }
+
+ public function testUpdateAttributesWithoutValidUser() {
+ $this->getMockedBuilder();
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn(null);
+ $this->userBackend->updateAttributes('ExistingUser', []);
+ }
+
+ public function testUpdateAttributes() {
+ $this->getMockedBuilder(['getDisplayName', 'setDisplayName']);
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->createMock(IUser::class);
+
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('user_saml', 'saml-attribute-mapping-email_mapping', '')
+ ->willReturn('email');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('user_saml', 'saml-attribute-mapping-displayName_mapping', '')
+ ->willReturn('displayname');
+
+
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn($user);
+ $user
+ ->expects($this->once())
+ ->method('updateLastLoginTimestamp');
+ $user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('old@example.com');
+ $user
+ ->expects($this->once())
+ ->method('setEMailAddress')
+ ->with('new@example.com');
+ $this->userBackend
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->with('ExistingUser')
+ ->willReturn('');
+ $this->userBackend
+ ->expects($this->once())
+ ->method('setDisplayName')
+ ->with('ExistingUser', 'New Displayname');
+ $this->userBackend->updateAttributes('ExistingUser', ['email' => 'new@example.com', 'displayname' => 'New Displayname']);
+ }
}