diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-12-06 00:00:09 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-12-06 00:00:09 -0500 |
commit | 9bd7985ba41b385c63213970b862ffc06f1096b0 (patch) | |
tree | a181044fca56fd501488c2361971dd883d6d8a89 /tests/units/Auth/GoogleAuthTest.php | |
parent | db5da71f154d34d012d7259d4d627ac7cf0c38fa (diff) |
Add more unit tests
Diffstat (limited to 'tests/units/Auth/GoogleAuthTest.php')
-rw-r--r-- | tests/units/Auth/GoogleAuthTest.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/units/Auth/GoogleAuthTest.php b/tests/units/Auth/GoogleAuthTest.php new file mode 100644 index 00000000..b9a7d811 --- /dev/null +++ b/tests/units/Auth/GoogleAuthTest.php @@ -0,0 +1,89 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Auth\GoogleAuth; +use Kanboard\Model\User; + +class GoogleAuthTest extends Base +{ + public function testGetName() + { + $provider = new GoogleAuth($this->container); + $this->assertEquals('Google', $provider->getName()); + } + + public function testAuthenticationSuccessful() + { + $profile = array( + 'id' => 1234, + 'email' => 'test@localhost', + 'name' => 'Test', + ); + + $provider = $this + ->getMockBuilder('\Kanboard\Auth\GoogleAuth') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'getProfile', + )) + ->getMock(); + + $provider->expects($this->once()) + ->method('getProfile') + ->will($this->returnValue($profile)); + + $this->assertInstanceOf('Kanboard\Auth\GoogleAuth', $provider->setCode('1234')); + + $this->assertTrue($provider->authenticate()); + + $user = $provider->getUser(); + $this->assertInstanceOf('Kanboard\User\GoogleUserProvider', $user); + $this->assertEquals('Test', $user->getName()); + $this->assertEquals('', $user->getInternalId()); + $this->assertEquals(1234, $user->getExternalId()); + $this->assertEquals('', $user->getRole()); + $this->assertEquals('', $user->getUsername()); + $this->assertEquals('test@localhost', $user->getEmail()); + $this->assertEquals('google_id', $user->getExternalIdColumn()); + $this->assertEquals(array(), $user->getExternalGroupIds()); + $this->assertEquals(array(), $user->getExtraAttributes()); + $this->assertFalse($user->isUserCreationAllowed()); + } + + public function testAuthenticationFailed() + { + $provider = $this + ->getMockBuilder('\Kanboard\Auth\GoogleAuth') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'getProfile', + )) + ->getMock(); + + $provider->expects($this->once()) + ->method('getProfile') + ->will($this->returnValue(array())); + + $this->assertFalse($provider->authenticate()); + $this->assertEquals(null, $provider->getUser()); + } + + public function testGetService() + { + $provider = new GoogleAuth($this->container); + $this->assertInstanceOf('Kanboard\Core\Http\OAuth2', $provider->getService()); + } + + public function testUnlink() + { + $userModel = new User($this->container); + $provider = new GoogleAuth($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'test', 'google_id' => '1234'))); + $this->assertNotEmpty($userModel->getByExternalId('google_id', 1234)); + + $this->assertTrue($provider->unlink(2)); + $this->assertEmpty($userModel->getByExternalId('google_id', 1234)); + } +} |