summaryrefslogtreecommitdiff
path: root/tests/units/Analytic/UserDistributionAnalyticTest.php
diff options
context:
space:
mode:
authorGerardo Zamudio <gerardozamudio@users.noreply.github.com>2016-02-24 23:48:50 -0600
committerGerardo Zamudio <gerardozamudio@users.noreply.github.com>2016-02-24 23:48:50 -0600
commite4de6b3898b64b26d29aff31f21df5fda8055686 (patch)
tree575f8a65440f291d70a070d168eafca8c82a6459 /tests/units/Analytic/UserDistributionAnalyticTest.php
parentd9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff)
parenta6540bc604c837d92c9368540c145606723e97f7 (diff)
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'tests/units/Analytic/UserDistributionAnalyticTest.php')
-rw-r--r--tests/units/Analytic/UserDistributionAnalyticTest.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/units/Analytic/UserDistributionAnalyticTest.php b/tests/units/Analytic/UserDistributionAnalyticTest.php
new file mode 100644
index 00000000..bdc136e1
--- /dev/null
+++ b/tests/units/Analytic/UserDistributionAnalyticTest.php
@@ -0,0 +1,83 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectUserRole;
+use Kanboard\Model\User;
+use Kanboard\Analytic\UserDistributionAnalytic;
+use Kanboard\Core\Security\Role;
+
+class UserDistributionAnalyticTest extends Base
+{
+ public function testBuild()
+ {
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $userDistributionModel = new UserDistributionAnalytic($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test1')));
+
+ $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($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 5, Role::PROJECT_MEMBER));
+
+ $this->createTasks(0, 10, 1);
+ $this->createTasks(2, 30, 1);
+ $this->createTasks(3, 40, 1);
+ $this->createTasks(4, 10, 1);
+ $this->createTasks(5, 10, 1);
+
+ $expected = array(
+ array(
+ 'user' => 'Unassigned',
+ 'nb_tasks' => 10,
+ 'percentage' => 10.0,
+ ),
+ array(
+ 'user' => 'user1',
+ 'nb_tasks' => 30,
+ 'percentage' => 30.0,
+ ),
+ array(
+ 'user' => 'user2',
+ 'nb_tasks' => 40,
+ 'percentage' => 40.0,
+ ),
+ array(
+ 'user' => 'user3',
+ 'nb_tasks' => 10,
+ 'percentage' => 10.0,
+ ),
+ array(
+ 'user' => 'user4',
+ 'nb_tasks' => 10,
+ 'percentage' => 10.0,
+ )
+ );
+
+ $this->assertEquals($expected, $userDistributionModel->build(1));
+ }
+
+ private function createTasks($user_id, $nb_active, $nb_inactive)
+ {
+ $taskCreationModel = new TaskCreation($this->container);
+
+ for ($i = 0; $i < $nb_active; $i++) {
+ $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => $user_id, 'is_active' => 1)));
+ }
+
+ for ($i = 0; $i < $nb_inactive; $i++) {
+ $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => $user_id, 'is_active' => 0)));
+ }
+ }
+}