diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-07-02 14:44:26 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-07-02 14:44:26 -0400 |
commit | 3fcc0cb9183f9ff32ce7a3c615258bcf53c385ed (patch) | |
tree | 219a6d8270d2067a250ead4096c754ceb0eb1589 /tests/units/Model/TaskRecurrenceModelTest.php | |
parent | 853189a43fff8b8b64f18029a35ac910b14932e8 (diff) |
Handle tags and tasks move/duplication to another project
Diffstat (limited to 'tests/units/Model/TaskRecurrenceModelTest.php')
-rw-r--r-- | tests/units/Model/TaskRecurrenceModelTest.php | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/units/Model/TaskRecurrenceModelTest.php b/tests/units/Model/TaskRecurrenceModelTest.php new file mode 100644 index 00000000..6970e30f --- /dev/null +++ b/tests/units/Model/TaskRecurrenceModelTest.php @@ -0,0 +1,90 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Core\DateParser; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskRecurrenceModel; + +class TaskRecurrenceModelTest extends Base +{ + public function testCalculateRecurringTaskDueDate() + { + $taskRecurrenceModel = new TaskRecurrenceModel($this->container); + + $values = array('date_due' => 0); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(0, $values['date_due']); + + $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(0, $values['date_due']); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(time() + 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1436561776, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1494449776, $values['date_due'], '', 1); + } + + public function testDuplicateRecurringTask() + { + $taskRecurrenceModel = new TaskRecurrenceModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $dateParser = new DateParser($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(1, $taskCreationModel->create(array( + 'title' => 'test', + 'project_id' => 1, + 'date_due' => 1436561776, + 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING, + 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE, + 'recurrence_factor' => 2, + 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS, + 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, + ))); + + $this->assertEquals(2, $taskRecurrenceModel->duplicateRecurringTask(1)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); + $this->assertEquals(2, $task['recurrence_child']); + $this->assertEquals(1436486400, $task['date_due'], '', 2); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); + $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); + $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); + $this->assertEquals(1, $task['recurrence_parent']); + $this->assertEquals(2, $task['recurrence_factor']); + $this->assertEquals($dateParser->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2); + } +} |