diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-17 13:46:33 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-17 13:46:33 -0500 |
commit | 1259e911e4316f9f1ae401f4f293da69d9ba9e78 (patch) | |
tree | 9a9d279c989dd04cdc753af4be1fc3fd42886107 | |
parent | d45fa6a33b8ce5258e4eab4c894765f885c16518 (diff) |
Make sure that project daily column stats works when score is null
-rw-r--r-- | app/Model/ProjectDailyColumnStats.php | 9 | ||||
-rw-r--r-- | tests/units/Model/ProjectDailyColumnStatsTest.php | 33 |
2 files changed, 36 insertions, 6 deletions
diff --git a/app/Model/ProjectDailyColumnStats.php b/app/Model/ProjectDailyColumnStats.php index 83475246..cf79be84 100644 --- a/app/Model/ProjectDailyColumnStats.php +++ b/app/Model/ProjectDailyColumnStats.php @@ -186,15 +186,11 @@ class ProjectDailyColumnStats extends Base $columns = array(); foreach ($totals as $column_id => $total) { - $columns[$column_id] = array('total' => $total); + $columns[$column_id] = array('total' => $total, 'score' => 0); } foreach ($scores as $column_id => $score) { - if (isset($columns[$column_id])) { - $columns[$column_id]['score'] = $score; - } else { - $columns[$column_id] = array('score' => $score); - } + $columns[$column_id]['score'] = (int) $score; } return $columns; @@ -213,6 +209,7 @@ class ProjectDailyColumnStats extends Base ->columns('column_id', 'SUM(score) AS score') ->eq('project_id', $project_id) ->eq('is_active', Task::STATUS_OPEN) + ->notNull('score') ->groupBy('column_id') ->findAll(); diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php index f8a64054..5e8ec3e8 100644 --- a/tests/units/Model/ProjectDailyColumnStatsTest.php +++ b/tests/units/Model/ProjectDailyColumnStatsTest.php @@ -11,6 +11,39 @@ use Kanboard\Model\TaskStatus; class ProjectDailyColumnStatsTest extends Base { + public function testUpdateTotalsWithScoreAtNull() + { + $projectModel = new Project($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $task = $this->container['db']->table(Task::TABLE)->findOne(); + $this->assertNull($task['score']); + + $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + ->asc('day') + ->asc('column_id') + ->columns('day', 'project_id', 'column_id', 'total', 'score') + ->findAll(); + + $expected = array( + array( + 'day' => '2016-01-16', + 'project_id' => 1, + 'column_id' => 1, + 'total' => 1, + 'score' => 0, + ), + ); + + $this->assertEquals($expected, $stats); + } + public function testUpdateTotals() { $projectModel = new Project($this->container); |