diff options
23 files changed, 443 insertions, 224 deletions
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 67216df7..b31c2173 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -85,6 +85,7 @@ Contributors: - [Oliver Jakoubek](https://github.com/jakoubek) - [Olivier Maridat](https://github.com/oliviermaridat) - [Oren Ben-Kiki](https://github.com/orenbenkiki) +- [Patrick Van Elk](https://github.com/patrickvanelk) - Paolo Mainieri - [Pavel Roušar](https://github.com/rousarp) - [Peller Zoltan](https://github.com/PierP) diff --git a/app/Console/Base.php b/app/Console/Base.php index ac89207d..04ee8a21 100644 --- a/app/Console/Base.php +++ b/app/Console/Base.php @@ -14,11 +14,9 @@ use Symfony\Component\Console\Command\Command; * @property \Kanboard\Model\Notification $notification * @property \Kanboard\Model\Project $project * @property \Kanboard\Model\ProjectPermission $projectPermission - * @property \Kanboard\Model\ProjectAnalytic $projectAnalytic * @property \Kanboard\Model\ProjectDailyColumnStats $projectDailyColumnStats * @property \Kanboard\Model\ProjectDailyStats $projectDailyStats * @property \Kanboard\Model\SubtaskExport $subtaskExport - * @property \Kanboard\Model\OverdueNotification $overdueNotification * @property \Kanboard\Model\Task $task * @property \Kanboard\Model\TaskExport $taskExport * @property \Kanboard\Model\TaskFinder $taskFinder diff --git a/app/Console/TaskOverdueNotification.php b/app/Console/TaskOverdueNotification.php index ffb9fab5..43be4df8 100644 --- a/app/Console/TaskOverdueNotification.php +++ b/app/Console/TaskOverdueNotification.php @@ -2,6 +2,7 @@ namespace Kanboard\Console; +use Kanboard\Model\Task; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -19,7 +20,7 @@ class TaskOverdueNotification extends Base protected function execute(InputInterface $input, OutputInterface $output) { - $tasks = $this->overdueNotification->sendOverdueTaskNotifications(); + $tasks = $this->sendOverdueTaskNotifications(); if ($input->getOption('show')) { $this->showTable($output, $tasks); @@ -47,4 +48,69 @@ class TaskOverdueNotification extends Base ->setRows($rows) ->render(); } + + /** + * Send overdue tasks + * + * @access public + */ + public function sendOverdueTaskNotifications() + { + $tasks = $this->taskFinder->getOverdueTasks(); + + foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { + $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); + + foreach ($users as $user) { + $this->sendUserOverdueTaskNotifications($user, $project_tasks); + } + } + + return $tasks; + } + + /** + * Send overdue tasks for a given user + * + * @access public + * @param array $user + * @param array $tasks + */ + public function sendUserOverdueTaskNotifications(array $user, array $tasks) + { + $user_tasks = array(); + + foreach ($tasks as $task) { + if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) { + $user_tasks[] = $task; + } + } + + if (! empty($user_tasks)) { + $this->userNotification->sendUserNotification( + $user, + Task::EVENT_OVERDUE, + array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) + ); + } + } + + /** + * Group a collection of records by a column + * + * @access public + * @param array $collection + * @param string $column + * @return array + */ + public function groupByColumn(array $collection, $column) + { + $result = array(); + + foreach ($collection as $item) { + $result[$item[$column]][] = $item; + } + + return $result; + } } diff --git a/app/Core/Base.php b/app/Core/Base.php index dce3e3dc..14b06b90 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -75,11 +75,9 @@ use Pimple\Container; * @property \Kanboard\Model\LastLogin $lastLogin * @property \Kanboard\Model\Link $link * @property \Kanboard\Model\Notification $notification - * @property \Kanboard\Model\OverdueNotification $overdueNotification * @property \Kanboard\Model\PasswordReset $passwordReset * @property \Kanboard\Model\Project $project * @property \Kanboard\Model\ProjectActivity $projectActivity - * @property \Kanboard\Model\ProjectAnalytic $projectAnalytic * @property \Kanboard\Model\ProjectDuplication $projectDuplication * @property \Kanboard\Model\ProjectDailyColumnStats $projectDailyColumnStats * @property \Kanboard\Model\ProjectDailyStats $projectDailyStats @@ -121,7 +119,6 @@ use Pimple\Container; * @property \Kanboard\Model\UserNotificationFilter $userNotificationFilter * @property \Kanboard\Model\UserUnreadNotification $userUnreadNotification * @property \Kanboard\Model\UserMetadata $userMetadata - * @property \Kanboard\Model\Webhook $webhook * @property \Kanboard\Validator\ActionValidator $actionValidator * @property \Kanboard\Validator\AuthValidator $authValidator * @property \Kanboard\Validator\ColumnValidator $columnValidator @@ -137,7 +134,7 @@ use Pimple\Container; * @property \Kanboard\Validator\SubtaskValidator $subtaskValidator * @property \Kanboard\Validator\SwimlaneValidator $swimlaneValidator * @property \Kanboard\Validator\TaskLinkValidator $taskLinkValidator - * @property \Kanboard\Validator\TaskExternalLinkValidator $taskExternalLinkValidator + * @property \Kanboard\Validator\ExternalLinkValidator $externalLinkValidator * @property \Kanboard\Validator\TaskValidator $taskValidator * @property \Kanboard\Validator\UserValidator $userValidator * @property \Psr\Log\LoggerInterface $logger diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index d1d47a34..51cf95bd 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -1,8 +1,8 @@ <?php return array( - // 'number.decimals_separator' => '', - // 'number.thousands_separator' => '', + 'number.decimals_separator' => ',', + 'number.thousands_separator' => '.', 'None' => 'Geen', 'edit' => 'bewerken', 'Edit' => 'Bewerken', @@ -20,15 +20,15 @@ return array( 'Red' => 'Rood', 'Orange' => 'Oranje', 'Grey' => 'Grijs', - // 'Brown' => '', - // 'Deep Orange' => '', - // 'Dark Grey' => '', - // 'Pink' => '', + 'Brown' => 'Bruin', + 'Deep Orange' => 'Dieporanje', + 'Dark Grey' => 'Donkergrijs', + 'Pink' => 'Roze', // 'Teal' => '', - // 'Cyan' => '', - // 'Lime' => '', - // 'Light Green' => '', - // 'Amber' => '', + 'Cyan' => 'Cyaan', + 'Lime' => 'Limoen', + 'Light Green' => 'Lichtgroen', + 'Amber' => 'Amber', 'Save' => 'Opslaan', 'Login' => 'Inloggen', 'Official website:' => 'Officiële website :', @@ -575,7 +575,7 @@ return array( 'is a milestone of' => 'is een milestone voor', 'fixes' => 'corrigeert', 'is fixed by' => 'word gecorrigeerd door', - 'This task' => 'Deze taal', + 'This task' => 'Deze taak', '<1h' => '<1h', '%dh' => '%dh', 'Expand tasks' => 'Taken uitklappen', @@ -587,42 +587,42 @@ return array( 'Keyboard shortcuts' => 'Keyboard snelkoppelingen', 'Open board switcher' => 'Open bord switcher', 'Application' => 'Applicatie', - // 'Compact view' => '', + 'Compact view' => 'Compacte weergave', // 'Horizontal scrolling' => '', - // 'Compact/wide view' => '', - // 'No results match:' => '', - // 'Currency' => '', - // 'Private project' => '', + 'Compact/wide view' => 'Compacte/breedbeeld-weergave', + 'No results match:' => 'Geen resultaten voor', + 'Currency' => 'Valuta', + 'Private project' => 'Privé project', // 'AUD - Australian Dollar' => '', // 'CAD - Canadian Dollar' => '', // 'CHF - Swiss Francs' => '', // 'Custom Stylesheet' => '', // 'download' => '', - // 'EUR - Euro' => '', + 'EUR - Euro' => 'EUR - Euro', // 'GBP - British Pound' => '', // 'INR - Indian Rupee' => '', // 'JPY - Japanese Yen' => '', // 'NZD - New Zealand Dollar' => '', // 'RSD - Serbian dinar' => '', // 'USD - US Dollar' => '', - // 'Destination column' => '', + 'Destination column' => 'Doel kolom', // 'Move the task to another column when assigned to a user' => '', // 'Move the task to another column when assignee is cleared' => '', - // 'Source column' => '', + 'Source column' => 'Bron kolom', // 'Transitions' => '', // 'Executer' => '', // 'Time spent in the column' => '', // 'Task transitions' => '', // 'Task transitions export' => '', // 'This report contains all column moves for each task with the date, the user and the time spent for each transition.' => '', - // 'Currency rates' => '', - // 'Rate' => '', + 'Currency rates' => 'Wisselkoersen', + 'Rate' => 'Koers', // 'Change reference currency' => '', // 'Add a new currency rate' => '', // 'Reference currency' => '', // 'The currency rate have been added successfully.' => '', // 'Unable to add this currency rate.' => '', - // 'Webhook URL' => '', + 'Webhook URL' => 'Webhook URL', // '%s remove the assignee of the task %s' => '', // 'Enable Gravatar images' => '', // 'Information' => '', @@ -648,7 +648,7 @@ return array( // 'Identifier' => '', // 'Disable two factor authentication' => '', // 'Do you really want to disable the two factor authentication for this user: "%s"?' => '', - // 'Edit link' => '', + 'Edit link' => 'Bewerk link', // 'Start to type task title...' => '', // 'A task cannot be linked to itself' => '', // 'The exact same link already exists' => '', @@ -666,10 +666,10 @@ return array( // 'Action date' => '', // 'Base date to calculate new due date: ' => '', // 'This task has created this child task: ' => '', - // 'Day(s)' => '', + 'Day(s)' => 'Dag(en)', // 'Existing due date' => '', // 'Factor to calculate new due date: ' => '', - // 'Month(s)' => '', + 'Month(s)' => 'Maand(en)', // 'Recurrence' => '', // 'This task has been created by: ' => '', // 'Recurrent task has been generated:' => '', @@ -678,10 +678,10 @@ return array( // 'When task is closed' => '', // 'When task is moved from first column' => '', // 'When task is moved to last column' => '', - // 'Year(s)' => '', - // 'Calendar settings' => '', + 'Year(s)' => 'Jaar/Jaren', + 'Calendar settings' => 'Kalender instellingen', // 'Project calendar view' => '', - // 'Project settings' => '', + 'Project settings' => 'Project instellingen', // 'Show subtasks based on the time tracking' => '', // 'Show tasks based on the creation date' => '', // 'Show tasks based on the start date' => '', @@ -689,19 +689,19 @@ return array( // 'User calendar view' => '', // 'Automatically update the start date' => '', // 'iCal feed' => '', - // 'Preferences' => '', + 'Preferences' => 'Voorkeuren', // 'Security' => '', - // 'Two factor authentication disabled' => '', - // 'Two factor authentication enabled' => '', - // 'Unable to update this user.' => '', + 'Two factor authentication disabled' => 'Authenticatie in twee stappen uitgeschakeld', + 'Two factor authentication enabled' => 'Authenticatie in twee stappen ingeschakeld', + 'Unable to update this user.' => 'Niet mogelijk om deze gebruiker bij te werken', // 'There is no user management for private projects.' => '', - // 'User that will receive the email' => '', - // 'Email subject' => '', - // 'Date' => '', + 'User that will receive the email' => 'Gebruiker die de mail ontvangt', + 'Email subject' => 'Email onderwerp', + 'Date' => 'Datum', // 'Add a comment log when moving the task between columns' => '', // 'Move the task to another column when the category is changed' => '', // 'Send a task by email to someone' => '', - // 'Reopen a task' => '', + 'Reopen a task' => 'Heropen een taak', // 'Column change' => '', // 'Position change' => '', // 'Swimlane change' => '', @@ -710,10 +710,10 @@ return array( // 'Notification' => '', // '%s moved the task #%d to the first swimlane' => '', // '%s moved the task #%d to the swimlane "%s"' => '', - // 'Swimlane' => '', - // 'Gravatar' => '', - // '%s moved the task %s to the first swimlane' => '', - // '%s moved the task %s to the swimlane "%s"' => '', + 'Swimlane' => 'Swimlane', + 'Gravatar' => 'Gravatar', + '%s moved the task %s to the first swimlane' => '%s heeft de taak %s naar de eerste swimlane verplaatst', + '%s moved the task %s to the swimlane "%s"' => '%s heeft taak %s naar swimlane "%s" verplaatst', // 'This report contains all subtasks information for the given date range.' => '', // 'This report contains all tasks information for the given date range.' => '', // 'Project activities for %s' => '', @@ -721,7 +721,7 @@ return array( // 'The task have been moved to the first swimlane' => '', // 'The task have been moved to another swimlane:' => '', // 'Overdue tasks for the project "%s"' => '', - // 'New title: %s' => '', + 'New title: %s' => 'Nieuw titel: %s', // 'The task is not assigned anymore' => '', // 'New assignee: %s' => '', // 'There is no category now' => '', @@ -736,35 +736,35 @@ return array( // 'The field "%s" have been updated' => '', // 'The description have been modified' => '', // 'Do you really want to close the task "%s" as well as all subtasks?' => '', - // 'I want to receive notifications for:' => '', - // 'All tasks' => '', + 'I want to receive notifications for:' => 'Ik wil notificaties ontvangen voor:', + 'All tasks' => 'Alle taken', // 'Only for tasks assigned to me' => '', // 'Only for tasks created by me' => '', // 'Only for tasks created by me and assigned to me' => '', - // '%%Y-%%m-%%d' => '', + '%%Y-%%m-%%d' => '%%d-%%m-%%Y', // 'Total for all columns' => '', // 'You need at least 2 days of data to show the chart.' => '', - // '<15m' => '', - // '<30m' => '', - // 'Stop timer' => '', - // 'Start timer' => '', - // 'Add project member' => '', - // 'Enable notifications' => '', - // 'My activity stream' => '', - // 'My calendar' => '', - // 'Search tasks' => '', - // 'Back to the calendar' => '', - // 'Filters' => '', - // 'Reset filters' => '', + '<15m' => '<15m', + '<30m' => '<30m', + 'Stop timer' => 'Stop timer', + 'Start timer' => 'Start timer', + 'Add project member' => 'Voeg projectlid toe', + 'Enable notifications' => 'Schakel notificaties in', + 'My activity stream' => 'Mijn activiteiten', + 'My calendar' => 'Mijn kalender', + 'Search tasks' => 'Zoek taken', + 'Back to the calendar' => 'Terug naar de kalender', + 'Filters' => 'Filters', + 'Reset filters' => 'Reset filters', // 'My tasks due tomorrow' => '', // 'Tasks due today' => '', // 'Tasks due tomorrow' => '', // 'Tasks due yesterday' => '', - // 'Closed tasks' => '', - // 'Open tasks' => '', + 'Closed tasks' => 'Gesloten taken', + 'Open tasks' => 'Open taken', // 'Not assigned' => '', // 'View advanced search syntax' => '', - // 'Overview' => '', + 'Overview' => 'Overzicht', // 'Board/Calendar/List view' => '', // 'Switch to the board view' => '', // 'Switch to the calendar view' => '', @@ -773,9 +773,9 @@ return array( // 'There is no activity yet.' => '', // 'No tasks found.' => '', // 'Keyboard shortcut: "%s"' => '', - // 'List' => '', - // 'Filter' => '', - // 'Advanced search' => '', + 'List' => 'Lijst', + 'Filter' => 'Filter', + 'Advanced search' => 'Uitgebreid zoeken', // 'Example of query: ' => '', // 'Search by project: ' => '', // 'Search by column: ' => '', @@ -839,12 +839,12 @@ return array( // 'People who are project managers' => '', // 'People who are project members' => '', // 'NOK - Norwegian Krone' => '', - // 'Show this column' => '', - // 'Hide this column' => '', - // 'open file' => '', + 'Show this column' => 'Toon deze kolom', + 'Hide this column' => 'Verberg deze kolom', + 'open file' => 'open bestand', // 'End date' => '', // 'Users overview' => '', - // 'Members' => '', + 'Members' => 'Leden', // 'Shared project' => '', // 'Project managers' => '', // 'Gantt chart for all projects' => '', @@ -857,7 +857,7 @@ return array( // 'Link type' => '', // 'Change task color when using a specific task link' => '', // 'Task link creation or modification' => '', - // 'Milestone' => '', + 'Milestone' => 'Mijlpaal', // 'Documentation: %s' => '', // 'Switch to the Gantt chart view' => '', // 'Reset the search/filter box' => '', diff --git a/app/Model/Base.php b/app/Model/Base.php index 6fe3d74a..635ed09a 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -135,23 +135,4 @@ abstract class Base extends \Kanboard\Core\Base return $start_column.' IS NOT NULL AND '.$start_column.' > 0 AND ('.implode(' OR ', $conditions).')'; } - - /** - * Group a collection of records by a column - * - * @access public - * @param array $collection - * @param string $column - * @return array - */ - public function groupByColumn(array $collection, $column) - { - $result = array(); - - foreach ($collection as $item) { - $result[$item[$column]][] = $item; - } - - return $result; - } } diff --git a/app/Model/Category.php b/app/Model/Category.php index 883fc282..6368f507 100644 --- a/app/Model/Category.php +++ b/app/Model/Category.php @@ -22,12 +22,11 @@ class Category extends Base * * @access public * @param integer $category_id Category id - * @param integer $project_id Project id * @return boolean */ - public function exists($category_id, $project_id) + public function exists($category_id) { - return $this->db->table(self::TABLE)->eq('id', $category_id)->eq('project_id', $project_id)->exists(); + return $this->db->table(self::TABLE)->eq('id', $category_id)->exists(); } /** @@ -115,25 +114,29 @@ class Category extends Base } /** - * Create default cetegories during project creation (transaction already started in Project::create()) + * Create default categories during project creation (transaction already started in Project::create()) * * @access public * @param integer $project_id + * @return boolean */ public function createDefaultCategories($project_id) { + $results = array(); $categories = explode(',', $this->config->get('project_categories')); foreach ($categories as $category) { $category = trim($category); if (! empty($category)) { - $this->db->table(self::TABLE)->insert(array( + $results[] = $this->db->table(self::TABLE)->insert(array( 'project_id' => $project_id, 'name' => $category, )); } } + + return in_array(false, $results, true); } /** @@ -195,7 +198,7 @@ class Category extends Base { $categories = $this->db ->table(self::TABLE) - ->columns('name') + ->columns('name', 'description') ->eq('project_id', $src_project_id) ->asc('name') ->findAll(); diff --git a/app/Model/Color.php b/app/Model/Color.php index d341dd3c..1b11f175 100644 --- a/app/Model/Color.php +++ b/app/Model/Color.php @@ -177,7 +177,7 @@ class Color extends Base } /** - * Get Bordercolor from string + * Get border color from string * * @access public * @param string $color_id Color id diff --git a/app/Model/OverdueNotification.php b/app/Model/OverdueNotification.php deleted file mode 100644 index 84565548..00000000 --- a/app/Model/OverdueNotification.php +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -namespace Kanboard\Model; - -/** - * Task Overdue Notification model - * - * @package model - * @author Frederic Guillot - */ -class OverdueNotification extends Base -{ - /** - * Send overdue tasks - * - * @access public - */ - public function sendOverdueTaskNotifications() - { - $tasks = $this->taskFinder->getOverdueTasks(); - - foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { - $users = $this->userNotification->getUsersWithNotificationEnabled($project_id); - - foreach ($users as $user) { - $this->sendUserOverdueTaskNotifications($user, $project_tasks); - } - } - - return $tasks; - } - - /** - * Send overdue tasks for a given user - * - * @access public - * @param array $user - * @param array $tasks - */ - public function sendUserOverdueTaskNotifications(array $user, array $tasks) - { - $user_tasks = array(); - - foreach ($tasks as $task) { - if ($this->userNotificationFilter->shouldReceiveNotification($user, array('task' => $task))) { - $user_tasks[] = $task; - } - } - - if (! empty($user_tasks)) { - $this->userNotification->sendUserNotification( - $user, - Task::EVENT_OVERDUE, - array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) - ); - } - } -} diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 4f022571..0ffe7099 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -37,7 +37,6 @@ class ClassProvider implements ServiceProviderInterface 'LastLogin', 'Link', 'Notification', - 'OverdueNotification', 'PasswordReset', 'Project', 'ProjectFile', diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php index 87ee86ea..6464639e 100644 --- a/tests/units/Action/CommentCreationMoveTaskColumnTest.php +++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php @@ -7,7 +7,6 @@ use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\Comment; use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; use Kanboard\Action\CommentCreationMoveTaskColumn; class CommentCreationMoveTaskColumnTest extends Base diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php index 8460a350..042a8f8b 100644 --- a/tests/units/Action/CommentCreationTest.php +++ b/tests/units/Action/CommentCreationTest.php @@ -3,7 +3,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\Comment; use Kanboard\Model\Project; diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php index f638e017..da83d541 100644 --- a/tests/units/Action/TaskAssignCategoryLinkTest.php +++ b/tests/units/Action/TaskAssignCategoryLinkTest.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; diff --git a/tests/units/Action/TaskAssignUserTest.php b/tests/units/Action/TaskAssignUserTest.php index d1cb72b9..31404c0b 100644 --- a/tests/units/Action/TaskAssignUserTest.php +++ b/tests/units/Action/TaskAssignUserTest.php @@ -8,7 +8,6 @@ use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; use Kanboard\Model\ProjectUserRole; use Kanboard\Model\User; -use Kanboard\Model\Task; use Kanboard\Action\TaskAssignUser; use Kanboard\Core\Security\Role; diff --git a/tests/units/Core/Ldap/LdapGroupTest.php b/tests/units/Core/Ldap/LdapGroupTest.php index 3f538249..4341ffc8 100644 --- a/tests/units/Core/Ldap/LdapGroupTest.php +++ b/tests/units/Core/Ldap/LdapGroupTest.php @@ -4,7 +4,6 @@ require_once __DIR__.'/../../Base.php'; use Kanboard\Core\Ldap\Group; use Kanboard\Core\Ldap\Entries; -use Kanboard\Core\Security\Role; class LdapGroupTest extends Base { diff --git a/tests/units/Formatter/TaskFilterCalendarFormatterTest.php b/tests/units/Formatter/TaskFilterCalendarFormatterTest.php index a42e865f..09dd0de6 100644 --- a/tests/units/Formatter/TaskFilterCalendarFormatterTest.php +++ b/tests/units/Formatter/TaskFilterCalendarFormatterTest.php @@ -3,14 +3,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Formatter\TaskFilterCalendarFormatter; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\TaskCreation; -use Kanboard\Core\DateParser; -use Kanboard\Model\Category; -use Kanboard\Model\Subtask; -use Kanboard\Model\Config; -use Kanboard\Model\Swimlane; class TaskFilterCalendarFormatterTest extends Base { diff --git a/tests/units/Formatter/TaskFilterICalendarFormatterTest.php b/tests/units/Formatter/TaskFilterICalendarFormatterTest.php index 915cdda2..6de9cf0f 100644 --- a/tests/units/Formatter/TaskFilterICalendarFormatterTest.php +++ b/tests/units/Formatter/TaskFilterICalendarFormatterTest.php @@ -8,10 +8,7 @@ use Kanboard\Model\Project; use Kanboard\Model\User; use Kanboard\Model\TaskCreation; use Kanboard\Core\DateParser; -use Kanboard\Model\Category; -use Kanboard\Model\Subtask; use Kanboard\Model\Config; -use Kanboard\Model\Swimlane; class TaskFilterICalendarFormatterTest extends Base { diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php index 3a64e26c..600007d0 100644 --- a/tests/units/Model/CategoryTest.php +++ b/tests/units/Model/CategoryTest.php @@ -2,6 +2,7 @@ require_once __DIR__.'/../Base.php'; +use Kanboard\Model\Config; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; @@ -11,55 +12,206 @@ class CategoryTest extends Base { public function testCreation() { - $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' => 'Project #1'))); - $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); - - $task = $tf->getById(1); - $this->assertTrue(is_array($task)); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); + + $task = $taskFinderModel->getById(1); $this->assertEquals(2, $task['category_id']); - $category = $c->getById(2); - $this->assertTrue(is_array($category)); + $category = $categoryModel->getById(2); $this->assertEquals(2, $category['id']); $this->assertEquals('Category #2', $category['name']); $this->assertEquals(1, $category['project_id']); + } + + public function testExists() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertFalse($categoryModel->exists(2)); + } + + public function testGetById() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $category = $categoryModel->getById(1); + $this->assertEquals(1, $category['id']); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(1, $category['project_id']); + $this->assertEquals('test', $category['description']); + } + + public function testGetNameById() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertEquals('Category #1', $categoryModel->getNameById(1)); + $this->assertEquals('', $categoryModel->getNameById(2)); + } + + public function testGetIdByName() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertSame(1, $categoryModel->getIdByName(1, 'Category #1')); + $this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2')); + } + + public function testGetList() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + + $categories = $categoryModel->getList(1, false, false); + $this->assertCount(2, $categories); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); + + $categories = $categoryModel->getList(1, true, false); + $this->assertCount(3, $categories); + $this->assertEquals('No category', $categories[0]); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); - $this->assertEquals(2, $c->getIdByName(1, 'Category #2')); - $this->assertEquals(0, $c->getIdByName(2, 'Category #2')); + $categories = $categoryModel->getList(1, false, true); + $this->assertCount(3, $categories); + $this->assertEquals('All categories', $categories[-1]); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); - $this->assertEquals('Category #2', $c->getNameById(2)); - $this->assertEquals('', $c->getNameById(23)); + $categories = $categoryModel->getList(1, true, true); + $this->assertCount(4, $categories); + $this->assertEquals('All categories', $categories[-1]); + $this->assertEquals('No category', $categories[0]); + $this->assertEquals('Category #1', $categories[1]); + $this->assertEquals('Category #2', $categories[2]); + } + + public function testGetAll() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + + $categories = $categoryModel->getAll(1); + $this->assertCount(2, $categories); + + $this->assertEquals('Category #1', $categories[0]['name']); + $this->assertEquals('test', $categories[0]['description']); + $this->assertEquals(1, $categories[0]['project_id']); + $this->assertEquals(1, $categories[0]['id']); + + $this->assertEquals('Category #2', $categories[1]['name']); + $this->assertEquals('', $categories[1]['description']); + $this->assertEquals(1, $categories[1]['project_id']); + $this->assertEquals(2, $categories[1]['id']); + } + + public function testCreateDefaultCategories() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + $configModel = new Config($this->container); + + $this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertTrue($categoryModel->createDefaultCategories(1)); + + $categories = $categoryModel->getAll(1); + $this->assertCount(3, $categories); + $this->assertEquals('C1', $categories[0]['name']); + $this->assertEquals('C2', $categories[1]['name']); + $this->assertEquals('C3', $categories[2]['name']); + } + + public function testUpdate() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertTrue($categoryModel->update(array('id' => 1, 'description' => 'test'))); + + $category = $categoryModel->getById(1); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(1, $category['project_id']); + $this->assertEquals('test', $category['description']); } public function testRemove() { - $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' => 'Project #1'))); - $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); - - $task = $tf->getById(1); - $this->assertTrue(is_array($task)); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); + + $task = $taskFinderModel->getById(1); $this->assertEquals(2, $task['category_id']); - $this->assertTrue($c->remove(1)); - $this->assertTrue($c->remove(2)); + $this->assertTrue($categoryModel->remove(1)); + $this->assertTrue($categoryModel->remove(2)); // Make sure tasks assigned with that category are reseted - $task = $tf->getById(1); - $this->assertTrue(is_array($task)); + $task = $taskFinderModel->getById(1); $this->assertEquals(0, $task['category_id']); } + + public function testDuplicate() + { + $projectModel = new Project($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test'))); + + $this->assertTrue($categoryModel->duplicate(1, 2)); + + $category = $categoryModel->getById(1); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(1, $category['project_id']); + $this->assertEquals('test', $category['description']); + + $category = $categoryModel->getById(2); + $this->assertEquals('Category #1', $category['name']); + $this->assertEquals(2, $category['project_id']); + $this->assertEquals('test', $category['description']); + } } diff --git a/tests/units/Model/ColorTest.php b/tests/units/Model/ColorTest.php new file mode 100644 index 00000000..e96ecb6b --- /dev/null +++ b/tests/units/Model/ColorTest.php @@ -0,0 +1,93 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Color; +use Kanboard\Model\Config; + +class ColorTest extends Base +{ + public function testFind() + { + $colorModel = new Color($this->container); + $this->assertEquals('yellow', $colorModel->find('yellow')); + $this->assertEquals('yellow', $colorModel->find('Yellow')); + $this->assertEquals('dark_grey', $colorModel->find('Dark Grey')); + $this->assertEquals('dark_grey', $colorModel->find('dark_grey')); + } + + public function testGetColorProperties() + { + $colorModel = new Color($this->container); + $expected = array( + 'name' => 'Light Green', + 'background' => '#dcedc8', + 'border' => '#689f38', + ); + + $this->assertEquals($expected, $colorModel->getColorProperties('light_green')); + + $expected = array( + 'name' => 'Yellow', + 'background' => 'rgb(245, 247, 196)', + 'border' => 'rgb(223, 227, 45)', + ); + + $this->assertEquals($expected, $colorModel->getColorProperties('foobar')); + } + + public function testGetList() + { + $colorModel = new Color($this->container); + + $colors = $colorModel->getList(); + $this->assertCount(16, $colors); + $this->assertEquals('Yellow', $colors['yellow']); + + $colors = $colorModel->getList(true); + $this->assertCount(17, $colors); + $this->assertEquals('All colors', $colors['']); + $this->assertEquals('Yellow', $colors['yellow']); + } + + public function testGetDefaultColor() + { + $colorModel = new Color($this->container); + $configModel = new Config($this->container); + + $this->assertEquals('yellow', $colorModel->getDefaultColor()); + + $this->container['memoryCache']->flush(); + $this->assertTrue($configModel->save(array('default_color' => 'red'))); + $this->assertEquals('red', $colorModel->getDefaultColor()); + } + + public function testGetDefaultColors() + { + $colorModel = new Color($this->container); + + $colors = $colorModel->getDefaultColors(); + $this->assertCount(16, $colors); + } + + public function testGetBorderColor() + { + $colorModel = new Color($this->container); + $this->assertEquals('rgb(74, 227, 113)', $colorModel->getBorderColor('green')); + } + + public function testGetBackgroundColor() + { + $colorModel = new Color($this->container); + $this->assertEquals('rgb(189, 244, 203)', $colorModel->getBackgroundColor('green')); + } + + public function testGetCss() + { + $colorModel = new Color($this->container); + $css = $colorModel->getCss(); + + $this->assertStringStartsWith('div.color-yellow {', $css); + $this->assertStringEndsWith('td.color-amber { background-color: #ffe082}', $css); + } +} diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php index 573878c2..c3b20cb9 100644 --- a/tests/units/Model/ProjectDailyStatsTest.php +++ b/tests/units/Model/ProjectDailyStatsTest.php @@ -42,6 +42,13 @@ class ProjectDailyStatsTest extends Base ) ); - $this->assertEquals($expected, $metrics); + $this->assertEquals($expected[0]['day'], $metrics[0]['day']); + $this->assertEquals($expected[1]['day'], $metrics[1]['day']); + + $this->assertEquals($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], '', 2); + $this->assertEquals($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], '', 2); + + $this->assertEquals($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], '', 2); + $this->assertEquals($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_time'], '', 2); } } diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php index 5ceb357e..c4b36e45 100644 --- a/tests/units/Model/TaskDuplicationTest.php +++ b/tests/units/Model/TaskDuplicationTest.php @@ -57,8 +57,8 @@ class TaskDuplicationTest extends Base // Some categories $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertTrue($c->exists(1, 1)); - $this->assertTrue($c->exists(2, 1)); + $this->assertTrue($c->exists(1)); + $this->assertTrue($c->exists(2)); $this->assertEquals( 1, @@ -110,7 +110,7 @@ class TaskDuplicationTest extends Base $this->assertEquals(2, $p->create(array('name' => 'test2'))); $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertTrue($c->exists(1, 1)); + $this->assertTrue($c->exists(1)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); @@ -151,8 +151,8 @@ class TaskDuplicationTest extends Base $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2))); - $this->assertTrue($c->exists(1, 1)); - $this->assertTrue($c->exists(2, 2)); + $this->assertTrue($c->exists(1)); + $this->assertTrue($c->exists(2)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); @@ -187,9 +187,9 @@ class TaskDuplicationTest extends Base $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2))); $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 2))); - $this->assertTrue($c->exists(1, 1)); - $this->assertTrue($c->exists(2, 2)); - $this->assertTrue($c->exists(3, 2)); + $this->assertTrue($c->exists(1)); + $this->assertTrue($c->exists(2)); + $this->assertTrue($c->exists(3)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); @@ -468,8 +468,8 @@ class TaskDuplicationTest extends Base $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2))); - $this->assertTrue($c->exists(1, 1)); - $this->assertTrue($c->exists(2, 2)); + $this->assertTrue($c->exists(1)); + $this->assertTrue($c->exists(2)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookTest.php index 7215baeb..5984f303 100644 --- a/tests/units/Notification/WebhookTest.php +++ b/tests/units/Notification/WebhookTest.php @@ -3,11 +3,8 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Config; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskModification; use Kanboard\Model\Project; -use Kanboard\Model\Comment; use Kanboard\Subscriber\NotificationSubscriber; class WebhookTest extends Base diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php index 4af6c75e..d26ad422 100644 --- a/tests/units/Validator/PasswordResetValidatorTest.php +++ b/tests/units/Validator/PasswordResetValidatorTest.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; use Kanboard\Validator\PasswordResetValidator; class PasswordResetValidatorTest extends Base |