Add more unit tests
This commit is contained in:
parent
db5da71f15
commit
9bd7985ba4
|
|
@ -116,10 +116,10 @@ class GithubAuth extends Base implements OAuthAuthenticationProviderInterface
|
|||
/**
|
||||
* Get Github profile
|
||||
*
|
||||
* @access private
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
private function getProfile()
|
||||
public function getProfile()
|
||||
{
|
||||
$this->getService()->getAccessToken($this->code);
|
||||
|
||||
|
|
|
|||
|
|
@ -116,10 +116,10 @@ class GitlabAuth extends Base implements OAuthAuthenticationProviderInterface
|
|||
/**
|
||||
* Get Gitlab profile
|
||||
*
|
||||
* @access private
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
private function getProfile()
|
||||
public function getProfile()
|
||||
{
|
||||
$this->getService()->getAccessToken($this->code);
|
||||
|
||||
|
|
|
|||
|
|
@ -116,10 +116,10 @@ class GoogleAuth extends Base implements OAuthAuthenticationProviderInterface
|
|||
/**
|
||||
* Get Google profile
|
||||
*
|
||||
* @access private
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
private function getProfile()
|
||||
public function getProfile()
|
||||
{
|
||||
$this->getService()->getAccessToken($this->code);
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,6 @@ class GroupManager
|
|||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return array_values($result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class DatabaseGroupProvider implements GroupProviderInterface
|
|||
*/
|
||||
public function getInternalId()
|
||||
{
|
||||
return $this->group['id'];
|
||||
return (int) $this->group['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Group extends Base
|
|||
*/
|
||||
public function search($input)
|
||||
{
|
||||
return $this->db->table(self::TABLE)->ilike('name', '%'.$input.'%')->findAll();
|
||||
return $this->db->table(self::TABLE)->ilike('name', '%'.$input.'%')->asc('name')->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Auth\GithubAuth;
|
||||
use Kanboard\Model\User;
|
||||
|
||||
class GithubAuthTest extends Base
|
||||
{
|
||||
public function testGetName()
|
||||
{
|
||||
$provider = new GithubAuth($this->container);
|
||||
$this->assertEquals('Github', $provider->getName());
|
||||
}
|
||||
|
||||
public function testAuthenticationSuccessful()
|
||||
{
|
||||
$profile = array(
|
||||
'id' => 1234,
|
||||
'email' => 'test@localhost',
|
||||
'name' => 'Test',
|
||||
);
|
||||
|
||||
$provider = $this
|
||||
->getMockBuilder('\Kanboard\Auth\GithubAuth')
|
||||
->setConstructorArgs(array($this->container))
|
||||
->setMethods(array(
|
||||
'getProfile',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$provider->expects($this->once())
|
||||
->method('getProfile')
|
||||
->will($this->returnValue($profile));
|
||||
|
||||
$this->assertInstanceOf('Kanboard\Auth\GithubAuth', $provider->setCode('1234'));
|
||||
|
||||
$this->assertTrue($provider->authenticate());
|
||||
|
||||
$user = $provider->getUser();
|
||||
$this->assertInstanceOf('Kanboard\User\GithubUserProvider', $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('github_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\GithubAuth')
|
||||
->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 GithubAuth($this->container);
|
||||
$this->assertInstanceOf('Kanboard\Core\Http\OAuth2', $provider->getService());
|
||||
}
|
||||
|
||||
public function testUnlink()
|
||||
{
|
||||
$userModel = new User($this->container);
|
||||
$provider = new GithubAuth($this->container);
|
||||
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'test', 'github_id' => '1234')));
|
||||
$this->assertNotEmpty($userModel->getByExternalId('github_id', 1234));
|
||||
|
||||
$this->assertTrue($provider->unlink(2));
|
||||
$this->assertEmpty($userModel->getByExternalId('github_id', 1234));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Auth\GitlabAuth;
|
||||
use Kanboard\Model\User;
|
||||
|
||||
class GitlabAuthTest extends Base
|
||||
{
|
||||
public function testGetName()
|
||||
{
|
||||
$provider = new GitlabAuth($this->container);
|
||||
$this->assertEquals('Gitlab', $provider->getName());
|
||||
}
|
||||
|
||||
public function testAuthenticationSuccessful()
|
||||
{
|
||||
$profile = array(
|
||||
'id' => 1234,
|
||||
'email' => 'test@localhost',
|
||||
'name' => 'Test',
|
||||
);
|
||||
|
||||
$provider = $this
|
||||
->getMockBuilder('\Kanboard\Auth\GitlabAuth')
|
||||
->setConstructorArgs(array($this->container))
|
||||
->setMethods(array(
|
||||
'getProfile',
|
||||
))
|
||||
->getMock();
|
||||
|
||||
$provider->expects($this->once())
|
||||
->method('getProfile')
|
||||
->will($this->returnValue($profile));
|
||||
|
||||
$this->assertInstanceOf('Kanboard\Auth\GitlabAuth', $provider->setCode('1234'));
|
||||
|
||||
$this->assertTrue($provider->authenticate());
|
||||
|
||||
$user = $provider->getUser();
|
||||
$this->assertInstanceOf('Kanboard\User\GitlabUserProvider', $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('gitlab_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\GitlabAuth')
|
||||
->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 GitlabAuth($this->container);
|
||||
$this->assertInstanceOf('Kanboard\Core\Http\OAuth2', $provider->getService());
|
||||
}
|
||||
|
||||
public function testUnlink()
|
||||
{
|
||||
$userModel = new User($this->container);
|
||||
$provider = new GitlabAuth($this->container);
|
||||
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'test', 'gitlab_id' => '1234')));
|
||||
$this->assertNotEmpty($userModel->getByExternalId('gitlab_id', 1234));
|
||||
|
||||
$this->assertTrue($provider->unlink(2));
|
||||
$this->assertEmpty($userModel->getByExternalId('gitlab_id', 1234));
|
||||
}
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Model\Group;
|
||||
use Kanboard\Core\Group\GroupManager;
|
||||
use Kanboard\Group\DatabaseBackendGroupProvider;
|
||||
|
||||
class GroupManagerTest extends Base
|
||||
{
|
||||
public function testFind()
|
||||
{
|
||||
$groupModel = new Group($this->container);
|
||||
$groupManager = new GroupManager;
|
||||
|
||||
$this->assertEquals(1, $groupModel->create('Group 1'));
|
||||
$this->assertEquals(2, $groupModel->create('Group 2'));
|
||||
|
||||
$this->assertEmpty($groupManager->find('group 1'));
|
||||
|
||||
$groupManager->register(new DatabaseBackendGroupProvider($this->container));
|
||||
$groupManager->register(new DatabaseBackendGroupProvider($this->container));
|
||||
|
||||
$groups = $groupManager->find('group 1');
|
||||
$this->assertCount(1, $groups);
|
||||
$this->assertInstanceOf('Kanboard\Group\DatabaseGroupProvider', $groups[0]);
|
||||
$this->assertEquals('Group 1', $groups[0]->getName());
|
||||
$this->assertEquals('', $groups[0]->getExternalId());
|
||||
$this->assertEquals(1, $groups[0]->getInternalId());
|
||||
|
||||
$groups = $groupManager->find('grou');
|
||||
$this->assertCount(2, $groups);
|
||||
$this->assertInstanceOf('Kanboard\Group\DatabaseGroupProvider', $groups[0]);
|
||||
$this->assertInstanceOf('Kanboard\Group\DatabaseGroupProvider', $groups[1]);
|
||||
$this->assertEquals('Group 1', $groups[0]->getName());
|
||||
$this->assertEquals('Group 2', $groups[1]->getName());
|
||||
$this->assertEquals('', $groups[0]->getExternalId());
|
||||
$this->assertEquals('', $groups[1]->getExternalId());
|
||||
$this->assertEquals(1, $groups[0]->getInternalId());
|
||||
$this->assertEquals(2, $groups[1]->getInternalId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue