summaryrefslogtreecommitdiff
path: root/tests/units/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-11-25 22:06:39 -0500
committerFrederic Guillot <fred@kanboard.net>2015-11-25 22:06:39 -0500
commite582d4047b061f0c17e6366fed2bf1cabd624c10 (patch)
tree4f400b1df198103fb257d468b1aab8c625f32d29 /tests/units/Model
parenta8da794b60029c23424ee330e020d18f5f9ac947 (diff)
Add groups (teams)
Diffstat (limited to 'tests/units/Model')
-rw-r--r--tests/units/Model/GroupMemberTest.php76
-rw-r--r--tests/units/Model/GroupTest.php82
2 files changed, 158 insertions, 0 deletions
diff --git a/tests/units/Model/GroupMemberTest.php b/tests/units/Model/GroupMemberTest.php
new file mode 100644
index 00000000..16f769e8
--- /dev/null
+++ b/tests/units/Model/GroupMemberTest.php
@@ -0,0 +1,76 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Group;
+use Kanboard\Model\User;
+use Kanboard\Model\GroupMember;
+
+class GroupMemberTest extends Base
+{
+ public function testAddRemove()
+ {
+ $groupModel = new Group($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Test'));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+ $this->assertFalse($groupMemberModel->addUser(1, 1));
+
+ $users = $groupMemberModel->getMembers(1);
+ $this->assertCount(1, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+
+ $this->assertEmpty($groupMemberModel->getNotMembers(1));
+
+ $this->assertTrue($groupMemberModel->removeUser(1, 1));
+ $this->assertFalse($groupMemberModel->removeUser(1, 1));
+
+ $this->assertEmpty($groupMemberModel->getMembers(1));
+ }
+
+ public function testMembers()
+ {
+ $userModel = new User($this->container);
+ $groupModel = new Group($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertEquals(2, $groupModel->create('Group B'));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+ $this->assertEquals(5, $userModel->create(array('username' => 'user4')));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+ $this->assertTrue($groupMemberModel->addUser(1, 5));
+ $this->assertTrue($groupMemberModel->addUser(2, 3));
+ $this->assertTrue($groupMemberModel->addUser(2, 4));
+ $this->assertTrue($groupMemberModel->addUser(2, 5));
+
+ $users = $groupMemberModel->getMembers(1);
+ $this->assertCount(3, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('user1', $users[1]['username']);
+ $this->assertEquals('user4', $users[2]['username']);
+
+ $users = $groupMemberModel->getNotMembers(1);
+ $this->assertCount(2, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('user3', $users[1]['username']);
+
+ $users = $groupMemberModel->getMembers(2);
+ $this->assertCount(3, $users);
+ $this->assertEquals('user2', $users[0]['username']);
+ $this->assertEquals('user3', $users[1]['username']);
+ $this->assertEquals('user4', $users[2]['username']);
+
+ $users = $groupMemberModel->getNotMembers(2);
+ $this->assertCount(2, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('user1', $users[1]['username']);
+ }
+}
diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupTest.php
new file mode 100644
index 00000000..2cbb254a
--- /dev/null
+++ b/tests/units/Model/GroupTest.php
@@ -0,0 +1,82 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Group;
+
+class GroupTest extends Base
+{
+ public function testCreation()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+ $this->assertFalse($groupModel->create('Test'));
+ }
+
+ public function testGetById()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+
+ $group = $groupModel->getById(1);
+ $this->assertEquals('Test', $group['name']);
+ $this->assertEquals('', $group['external_id']);
+
+ $this->assertEmpty($groupModel->getById(2));
+ }
+
+ public function testGetAll()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('B'));
+ $this->assertEquals(2, $groupModel->create('A', 'uuid'));
+
+ $groups = $groupModel->getAll();
+ $this->assertCount(2, $groups);
+ $this->assertEquals('A', $groups[0]['name']);
+ $this->assertEquals('uuid', $groups[0]['external_id']);
+ $this->assertEquals('B', $groups[1]['name']);
+ $this->assertEquals('', $groups[1]['external_id']);
+ }
+
+ public function testUpdate()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+ $this->assertTrue($groupModel->update(array('id' => 1, 'name' => 'My group', 'external_id' => 'test')));
+
+ $group = $groupModel->getById(1);
+ $this->assertEquals('My group', $group['name']);
+ $this->assertEquals('test', $group['external_id']);
+ }
+
+ public function testRemove()
+ {
+ $groupModel = new Group($this->container);
+ $this->assertEquals(1, $groupModel->create('Test'));
+ $this->assertTrue($groupModel->remove(1));
+ $this->assertEmpty($groupModel->getById(1));
+ }
+
+ public function testValidateCreation()
+ {
+ $groupModel = new Group($this->container);
+
+ $result = $groupModel->validateCreation(array('name' => 'Test'));
+ $this->assertTrue($result[0]);
+
+ $result = $groupModel->validateCreation(array('name' => ''));
+ $this->assertFalse($result[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $groupModel = new Group($this->container);
+
+ $result = $groupModel->validateModification(array('name' => 'Test', 'id' => 1));
+ $this->assertTrue($result[0]);
+
+ $result = $groupModel->validateModification(array('name' => 'Test'));
+ $this->assertFalse($result[0]);
+ }
+}