diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-15 21:03:19 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-15 21:03:19 -0500 |
commit | c58478c0abfb418048d2ee9c6297a30793f10f80 (patch) | |
tree | e4eb461636d87e75c267e3e5f2ff957f3e9e049b /tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php | |
parent | 1bbd4faf56969427b550a4d006f2d5018cf97371 (diff) |
Move analytic logic to separate classes
Diffstat (limited to 'tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php')
-rw-r--r-- | tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php new file mode 100644 index 00000000..2ca631b1 --- /dev/null +++ b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php @@ -0,0 +1,99 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Analytic\EstimatedTimeComparisonAnalytic; + +class EstimatedTimeComparisonAnalyticTest extends Base +{ + public function testBuild() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 5.5))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.75))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.25, 'is_active' => 0))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 8.25))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.25))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.5, 'is_active' => 0))); + + $expected = array( + 'open' => array( + 'time_spent' => 8.5, + 'time_estimated' => 7.25, + ), + 'closed' => array( + 'time_spent' => 0.5, + 'time_estimated' => 1.25, + ) + ); + + $this->assertEquals($expected, $estimatedTimeComparisonAnalytic->build(1)); + } + + public function testBuildWithNoClosedTask() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 5.5))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.75))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 8.25))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.25))); + + $expected = array( + 'open' => array( + 'time_spent' => 8.5, + 'time_estimated' => 7.25, + ), + 'closed' => array( + 'time_spent' => 0, + 'time_estimated' => 0, + ) + ); + + $this->assertEquals($expected, $estimatedTimeComparisonAnalytic->build(1)); + } + + public function testBuildWithOnlyClosedTask() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 5.5, 'is_active' => 0))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.75, 'is_active' => 0))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 8.25, 'is_active' => 0))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.25, 'is_active' => 0))); + + $expected = array( + 'closed' => array( + 'time_spent' => 8.5, + 'time_estimated' => 7.25, + ), + 'open' => array( + 'time_spent' => 0, + 'time_estimated' => 0, + ) + ); + + $this->assertEquals($expected, $estimatedTimeComparisonAnalytic->build(1)); + } +} |