diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-09-16 19:30:18 +0200 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-09-16 19:30:18 +0200 |
commit | e7a20b9d8f8d7c47173c59782c5bd24a0ba6cac9 (patch) | |
tree | 8d8a65e19cd11e3fa8f6b4cdf5efa81c9ab1a708 /tests | |
parent | eb6dfdca533bc18d8e1b1bdf4d4505c41d9b9c13 (diff) |
Improve API calls for users
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functionals/ApiTest.php | 24 | ||||
-rw-r--r-- | tests/units/UserTest.php | 82 |
2 files changed, 98 insertions, 8 deletions
diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index e633c598..04b22856 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -233,28 +233,26 @@ class Api extends PHPUnit_Framework_TestCase 'username' => 'toto', 'name' => 'Toto', 'password' => '123456', - 'confirmation' => '123456', ); - $this->assertTrue($this->client->createUser($user)); + $this->assertTrue($this->client->execute('createUser', $user)); $user = array( - 'username' => 'titi', 'name' => 'Titi', 'password' => '123456', - 'confirmation' => '789', ); - $this->assertFalse($this->client->createUser($user)); + $this->assertNull($this->client->execute('createUser', $user)); } public function testGetUser() { $user = $this->client->getUser(2); - $this->assertNotFalse($user); $this->assertTrue(is_array($user)); $this->assertEquals('toto', $user['username']); + + $this->assertNull($this->client->getUser(2222)); } public function testUpdateUser() @@ -264,14 +262,24 @@ class Api extends PHPUnit_Framework_TestCase $user['username'] = 'titi'; $user['name'] = 'Titi'; - $this->assertTrue($this->client->updateUser($user)); + $this->assertTrue($this->client->execute('updateUser', $user)); $user = $this->client->getUser(2); - $this->assertNotFalse($user); $this->assertTrue(is_array($user)); $this->assertEquals('titi', $user['username']); $this->assertEquals('Titi', $user['name']); + + $user = array(); + $user['id'] = 2; + $user['email'] = 'titi@localhost'; + + $this->assertTrue($this->client->execute('updateUser', $user)); + + $user = $this->client->getUser(2); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('titi@localhost', $user['email']); } public function testGetAllowedUsers() diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php new file mode 100644 index 00000000..cc0b7c44 --- /dev/null +++ b/tests/units/UserTest.php @@ -0,0 +1,82 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\User; +use Model\Task; +use Model\Project; + +class UserTest extends Base +{ + public function testCreate() + { + $u = new User($this->registry); + $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); + $this->assertTrue($u->create(array('username' => 'titi', 'is_ldap_user' => 1))); + $this->assertFalse($u->create(array('username' => 'toto'))); + + $user = $u->getById(1); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('admin', $user['username']); + $this->assertEquals('', $user['name']); + $this->assertEquals(1, $user['is_admin']); + $this->assertEquals(0, $user['is_ldap_user']); + + $user = $u->getById(2); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('toto', $user['username']); + $this->assertEquals('Toto', $user['name']); + $this->assertEquals(0, $user['is_admin']); + $this->assertEquals(0, $user['is_ldap_user']); + + $user = $u->getById(3); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('titi', $user['username']); + $this->assertEquals('', $user['name']); + $this->assertEquals(0, $user['is_admin']); + $this->assertEquals(1, $user['is_ldap_user']); + } + + public function testUpdate() + { + $u = new User($this->registry); + $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); + $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute'))); + + $user = $u->getById(2); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('biloute', $user['username']); + $this->assertEquals('Toto', $user['name']); + $this->assertEquals(0, $user['is_admin']); + $this->assertEquals(0, $user['is_ldap_user']); + } + + public function testRemove() + { + $u = new User($this->registry); + $t = new Task($this->registry); + $p = new Project($this->registry); + + $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); + + $task = $t->getById(1); + $this->assertEquals(1, $task['id']); + $this->assertEquals(2, $task['owner_id']); + + $this->assertTrue($u->remove(1)); + $this->assertTrue($u->remove(2)); + $this->assertFalse($u->remove(2)); + $this->assertFalse($u->remove(55)); + + // Make sure that assigned tasks are unassigned after removing the user + $task = $t->getById(1); + $this->assertEquals(1, $task['id']); + $this->assertEquals(0, $task['owner_id']); + } +} |