diff options
21 files changed, 371 insertions, 153 deletions
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/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); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $projectModel = new Project($this->container); + $categoryModel = 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))); + $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 = $tf->getById(1); - $this->assertTrue(is_array($task)); + $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); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $projectModel = new Project($this->container); + $categoryModel = 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))); + $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 = $tf->getById(1); - $this->assertTrue(is_array($task)); + $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 |
