summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Model/Category.php15
-rw-r--r--tests/units/Action/CommentCreationMoveTaskColumnTest.php1
-rw-r--r--tests/units/Action/CommentCreationTest.php1
-rw-r--r--tests/units/Action/TaskAssignCategoryLinkTest.php1
-rw-r--r--tests/units/Action/TaskAssignUserTest.php1
-rw-r--r--tests/units/Core/Ldap/LdapGroupTest.php1
-rw-r--r--tests/units/Formatter/TaskFilterCalendarFormatterTest.php8
-rw-r--r--tests/units/Formatter/TaskFilterICalendarFormatterTest.php3
-rw-r--r--tests/units/Model/CategoryTest.php220
-rw-r--r--tests/units/Model/TaskDuplicationTest.php20
-rw-r--r--tests/units/Notification/WebhookTest.php3
-rw-r--r--tests/units/Validator/PasswordResetValidatorTest.php1
12 files changed, 205 insertions, 70 deletions
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/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/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