diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-05-10 17:39:00 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-05-10 17:39:00 -0400 |
commit | d75e2fcaa7ac6ce4bfb222e9bc91a85023bf1649 (patch) | |
tree | 192364b616ebbe3f1f46f6a129d50e8cff096be8 | |
parent | 6f77a4033f7feb2785e0e242d50b78e824c892cd (diff) |
Recurring tasks (#847): add unit test
-rw-r--r-- | app/Integration/Base.php | 1 | ||||
-rwxr-xr-x | app/Model/TaskDuplication.php | 6 | ||||
-rw-r--r-- | tests/units/TaskDuplicationTest.php | 77 |
3 files changed, 81 insertions, 3 deletions
diff --git a/app/Integration/Base.php b/app/Integration/Base.php index 53f0ae8a..dbb0349a 100644 --- a/app/Integration/Base.php +++ b/app/Integration/Base.php @@ -12,6 +12,7 @@ use Pimple\Container; * * @property \Model\ProjectActivity $projectActivity * @property \Model\ProjectIntegration $projectIntegration + * @property \Model\ProjectPermission $projectPermission * @property \Model\Task $task * @property \Model\TaskFinder $taskFinder * @property \Model\User $user diff --git a/app/Model/TaskDuplication.php b/app/Model/TaskDuplication.php index 42777335..afcac4c7 100755 --- a/app/Model/TaskDuplication.php +++ b/app/Model/TaskDuplication.php @@ -174,10 +174,10 @@ class TaskDuplication extends Base /** * Calculate new due date for new recurrence task * - * @access private - * @param array $values + * @access public + * @param array $values Task fields */ - private function calculateRecurringTaskDueDate(array &$values) + public function calculateRecurringTaskDueDate(array &$values) { if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php index bc455873..f991efd6 100644 --- a/tests/units/TaskDuplicationTest.php +++ b/tests/units/TaskDuplicationTest.php @@ -483,4 +483,81 @@ class TaskDuplicationTest extends Base $this->assertEquals(2, $task['project_id']); $this->assertEquals('test', $task['title']); } + + public function testCalculateRecurringTaskDueDate() + { + $td = new TaskDuplication($this->container); + + $values = array('date_due' => 0); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(0, $values['date_due']); + + $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(0, $values['date_due']); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(time() + 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_MONTHS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(1436561776, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_YEARS); + $td->calculateRecurringTaskDueDate($values); + $this->assertEquals(1494449776, $values['date_due'], '', 1); + } + + public function testDuplicateRecurringTask() + { + $td = new TaskDuplication($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + + $this->assertEquals(1, $tc->create(array( + 'title' => 'test', + 'project_id' => 1, + 'date_due' => 1436561776, + 'recurrence_status' => Task::RECURRING_STATUS_PENDING, + 'recurrence_trigger' => Task::RECURRING_TRIGGER_CLOSE, + 'recurrence_factor' => 2, + 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS, + 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, + ))); + + $this->assertEquals(2, $td->duplicateRecurringTask(1)); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); + $this->assertEquals(2, $task['recurrence_child']); + $this->assertEquals(1436561776, $task['date_due']); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(Task::RECURRING_STATUS_PENDING, $task['recurrence_status']); + $this->assertEquals(Task::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); + $this->assertEquals(Task::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); + $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); + $this->assertEquals(1, $task['recurrence_parent']); + $this->assertEquals(2, $task['recurrence_factor']); + $this->assertEquals(strtotime('+2 days'), $task['date_due']); + } } |