summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-16 17:01:56 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-16 17:01:56 -0500
commit73ff5ec89b711791b3993f9158dc9554a623602c (patch)
tree8899efba69125c7117754134ffe17bef7257be20 /tests
parentb77fecc7d942c5cf606110f865caadfcab431155 (diff)
Remove ProjectAnalytic class
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php73
-rw-r--r--tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php116
2 files changed, 189 insertions, 0 deletions
diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php
new file mode 100644
index 00000000..9c445dca
--- /dev/null
+++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php
@@ -0,0 +1,73 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+use Kanboard\Model\Task;
+use Kanboard\Analytic\AverageLeadCycleTimeAnalytic;
+
+class AverageLeadCycleTimeAnalyticTest extends Base
+{
+ public function testBuild()
+ {
+ $taskCreationModel = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container);
+ $now = time();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ // LT=3600 CT=1800
+ $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800));
+
+ // LT=1800 CT=900
+ $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900));
+
+ // LT=3600 CT=0
+ $this->container['db']->table(Task::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600));
+
+ // LT=2*3600 CT=0
+ $this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600));
+
+ $stats = $averageLeadCycleTimeAnalytic->build(1);
+ $expected = array(
+ 'count' => 4,
+ 'total_lead_time' => 3600 + 1800 + 3600 + 2*3600,
+ 'total_cycle_time' => 1800 + 900,
+ 'avg_lead_time' => (3600 + 1800 + 3600 + 2*3600) / 4,
+ 'avg_cycle_time' => (1800 + 900) / 4,
+ );
+
+ $this->assertEquals($expected, $stats);
+ }
+
+ public function testBuildWithNoTasks()
+ {
+ $taskCreationModel = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container);
+ $now = time();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test1')));
+
+ $stats = $averageLeadCycleTimeAnalytic->build(1);
+
+ $expected = array(
+ 'count' => 0,
+ 'total_lead_time' => 0,
+ 'total_cycle_time' => 0,
+ 'avg_lead_time' => 0,
+ 'avg_cycle_time' => 0,
+ );
+
+ $this->assertEquals($expected, $stats);
+ }
+}
diff --git a/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php
new file mode 100644
index 00000000..75cb181d
--- /dev/null
+++ b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php
@@ -0,0 +1,116 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+use Kanboard\Model\Transition;
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Analytic\AverageTimeSpentColumnAnalytic;
+
+class AverageTimeSpentColumnAnalyticTest extends Base
+{
+ public function testAverageWithNoTransitions()
+ {
+ $taskCreationModel = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container);
+ $now = time();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600));
+ $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800));
+
+ $stats = $averageLeadCycleTimeAnalytic->build(1);
+ $expected = array(
+ 1 => array(
+ 'count' => 2,
+ 'time_spent' => 3600+1800,
+ 'average' => (int) ((3600+1800)/2),
+ 'title' => 'Backlog',
+ ),
+ 2 => array(
+ 'count' => 0,
+ 'time_spent' => 0,
+ 'average' => 0,
+ 'title' => 'Ready',
+ ),
+ 3 => array(
+ 'count' => 0,
+ 'time_spent' => 0,
+ 'average' => 0,
+ 'title' => 'Work in progress',
+ ),
+ 4 => array(
+ 'count' => 0,
+ 'time_spent' => 0,
+ 'average' => 0,
+ 'title' => 'Done',
+ )
+ );
+
+ $this->assertEquals($expected, $stats);
+ }
+
+ public function testAverageWithTransitions()
+ {
+ $transitionModel = new Transition($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $projectModel = new Project($this->container);
+ $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container);
+ $now = time();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600));
+ $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800));
+
+ foreach (array(1, 2) as $task_id) {
+ $task = $taskFinderModel->getById($task_id);
+ $task['task_id'] = $task['id'];
+ $task['date_moved'] = $now - 900;
+ $task['src_column_id'] = 3;
+ $task['dst_column_id'] = 1;
+ $this->assertTrue($transitionModel->save(1, $task));
+ }
+
+ $stats = $averageLeadCycleTimeAnalytic->build(1);
+ $expected = array(
+ 1 => array(
+ 'count' => 2,
+ 'time_spent' => 3600+1800,
+ 'average' => (int) ((3600+1800)/2),
+ 'title' => 'Backlog',
+ ),
+ 2 => array(
+ 'count' => 0,
+ 'time_spent' => 0,
+ 'average' => 0,
+ 'title' => 'Ready',
+ ),
+ 3 => array(
+ 'count' => 2,
+ 'time_spent' => 1800,
+ 'average' => 900,
+ 'title' => 'Work in progress',
+ ),
+ 4 => array(
+ 'count' => 0,
+ 'time_spent' => 0,
+ 'average' => 0,
+ 'title' => 'Done',
+ )
+ );
+
+ $this->assertEquals($expected, $stats);
+ }
+}