diff options
Diffstat (limited to 'tests')
133 files changed, 4025 insertions, 2788 deletions
diff --git a/tests/integration.mysql.xml b/tests/integration.mysql.xml index 30769371..9d87f77e 100644 --- a/tests/integration.mysql.xml +++ b/tests/integration.mysql.xml @@ -13,5 +13,8 @@ <const name="DB_USERNAME" value="root" /> <const name="DB_PASSWORD" value="" /> <const name="DB_PORT" value="" /> + <const name="DB_SSL_KEY" value="" /> + <const name="DB_SSL_CA" value="" /> + <const name="DB_SSL_CERT" value="" /> </php> -</phpunit>
\ No newline at end of file +</phpunit> diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php index 5fed0368..f552bea9 100644 --- a/tests/integration/ApiTest.php +++ b/tests/integration/ApiTest.php @@ -51,9 +51,9 @@ class Api extends PHPUnit_Framework_TestCase if ($projects) { foreach ($projects as $project) { - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); $this->assertTrue($this->client->removeProject($project['id'])); } } @@ -71,9 +71,9 @@ class Api extends PHPUnit_Framework_TestCase $project = $this->client->getProjectById(1); $this->assertNotEmpty($project); $this->assertEquals(1, $project['id']); - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); } public function testGetProjectByName() @@ -81,9 +81,9 @@ class Api extends PHPUnit_Framework_TestCase $project = $this->client->getProjectByName('API test'); $this->assertNotEmpty($project); $this->assertEquals(1, $project['id']); - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); $project = $this->client->getProjectByName(array('name' => 'API test')); $this->assertNotEmpty($project); @@ -100,9 +100,9 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotEmpty($projects); foreach ($projects as $project) { - $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); - $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); - $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertEquals('http://127.0.0.1:8000/?controller=BoardViewController&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=CalendarController&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskListController&action=show&project_id='.$project['id'], $project['url']['list']); } } @@ -235,7 +235,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotFalse($task); $this->assertTrue(is_array($task)); $this->assertEquals('Task #1', $task['title']); - $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskViewController&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } public function testGetAllTasks() @@ -245,7 +245,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotFalse($tasks); $this->assertTrue(is_array($tasks)); $this->assertEquals('Task #1', $tasks[0]['title']); - $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$tasks[0]['id'].'&project_id='.$tasks[0]['project_id'], $tasks[0]['url']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskViewController&action=show&task_id='.$tasks[0]['id'].'&project_id='.$tasks[0]['project_id'], $tasks[0]['url']); $tasks = $this->client->getAllTasks(2, 0); @@ -896,7 +896,7 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotEmpty($task); $this->assertEquals('Task with external ticket number', $task['title']); $this->assertEquals('TICKET-1234', $task['reference']); - $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); + $this->assertEquals('http://127.0.0.1:8000/?controller=TaskViewController&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); } public function testCreateOverdueTask() diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php index 6464639e..5eaf515e 100644 --- a/tests/units/Action/CommentCreationMoveTaskColumnTest.php +++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php @@ -3,10 +3,10 @@ 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; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\CommentCreationMoveTaskColumn; class CommentCreationMoveTaskColumnTest extends Base @@ -15,9 +15,9 @@ class CommentCreationMoveTaskColumnTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -28,7 +28,7 @@ class CommentCreationMoveTaskColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); @@ -39,9 +39,8 @@ class CommentCreationMoveTaskColumnTest extends Base public function testWithUserNotLogged() { - $projectModel = new Project($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -52,6 +51,6 @@ class CommentCreationMoveTaskColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php index 042a8f8b..4a2fc386 100644 --- a/tests/units/Action/CommentCreationTest.php +++ b/tests/units/Action/CommentCreationTest.php @@ -3,11 +3,11 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Comment; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Kanboard\Action\CommentCreation; use Kanboard\Core\Security\Role; @@ -15,11 +15,11 @@ class CommentCreationTest extends Base { public function testSuccess() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -44,11 +44,10 @@ class CommentCreationTest extends Base public function testWithUserNotAssignable() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -72,11 +71,9 @@ class CommentCreationTest extends Base public function testWithNoComment() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $commentModel = new Comment($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php index bd8181e8..09c08264 100644 --- a/tests/units/Action/TaskAssignCategoryColorTest.php +++ b/tests/units/Action/TaskAssignCategoryColorTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignCategoryColor; class TaskAssignCategoryColorTest extends Base { public function testChangeCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -30,7 +30,7 @@ class TaskAssignCategoryColorTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,10 +39,9 @@ class TaskAssignCategoryColorTest extends Base public function testWithWrongColor() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -55,6 +54,6 @@ class TaskAssignCategoryColorTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignCategoryLabelTest.php b/tests/units/Action/TaskAssignCategoryLabelTest.php index bf8bdb5b..1ddb1f7a 100644 --- a/tests/units/Action/TaskAssignCategoryLabelTest.php +++ b/tests/units/Action/TaskAssignCategoryLabelTest.php @@ -3,20 +3,20 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskAssignCategoryLabel; class TaskAssignCategoryLabelTest extends Base { public function testChangeCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -39,10 +39,9 @@ class TaskAssignCategoryLabelTest extends Base public function testWithWrongLabel() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -61,10 +60,9 @@ class TaskAssignCategoryLabelTest extends Base public function testWithExistingCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php index da83d541..712c3c02 100644 --- a/tests/units/Action/TaskAssignCategoryLinkTest.php +++ b/tests/units/Action/TaskAssignCategoryLinkTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\TaskLink; -use Kanboard\Model\Category; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskLinkModel; +use Kanboard\Model\CategoryModel; use Kanboard\Event\TaskLinkEvent; use Kanboard\Action\TaskAssignCategoryLink; @@ -14,10 +14,10 @@ class TaskAssignCategoryLinkTest extends Base { public function testAssignCategory() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $action = new TaskAssignCategoryLink($this->container); $action->setProjectId(1); @@ -35,7 +35,7 @@ class TaskAssignCategoryLinkTest extends Base 'link_id' => 2, )); - $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); $task = $tf->getById(1); $this->assertEquals(1, $task['category_id']); @@ -43,10 +43,10 @@ class TaskAssignCategoryLinkTest extends Base public function testWhenLinkDontMatch() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $action = new TaskAssignCategoryLink($this->container); $action->setProjectId(1); @@ -64,15 +64,14 @@ class TaskAssignCategoryLinkTest extends Base 'link_id' => 2, )); - $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); } public function testThatExistingCategoryWillNotChange() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $action = new TaskAssignCategoryLink($this->container); $action->setProjectId(1); @@ -91,6 +90,6 @@ class TaskAssignCategoryLinkTest extends Base 'link_id' => 2, )); - $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php index 9f188645..6502035f 100644 --- a/tests/units/Action/TaskAssignColorCategoryTest.php +++ b/tests/units/Action/TaskAssignColorCategoryTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorCategory; class TaskAssignColorCategoryTest extends Base { public function testChangeColor() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -30,7 +30,7 @@ class TaskAssignColorCategoryTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,10 +39,8 @@ class TaskAssignColorCategoryTest extends Base public function testWithWrongCategory() { - $categoryModel = new Category($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -54,6 +52,6 @@ class TaskAssignColorCategoryTest extends Base $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php index e5858b19..d4ba8e01 100644 --- a/tests/units/Action/TaskAssignColorColumnTest.php +++ b/tests/units/Action/TaskAssignColorColumnTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorColumn; class TaskAssignColorColumnTest extends Base { public function testChangeColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignColorColumnTest extends Base $action->setParam('color_id', 'red'); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,9 +36,8 @@ class TaskAssignColorColumnTest extends Base public function testWithWrongCategory() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -50,6 +49,6 @@ class TaskAssignColorColumnTest extends Base $action->setParam('color_id', 'red'); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php index d89c8b06..07d0969b 100644 --- a/tests/units/Action/TaskAssignColorLinkTest.php +++ b/tests/units/Action/TaskAssignColorLinkTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\TaskLink; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskLinkModel; use Kanboard\Action\TaskAssignColorLink; class TaskAssignColorLinkTest extends Base { public function testChangeColor() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignColorLinkTest extends Base $action->setParam('color_id', 'red'); $action->setParam('link_id', 1); - $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,9 +36,8 @@ class TaskAssignColorLinkTest extends Base public function testWithWrongLink() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -50,6 +49,6 @@ class TaskAssignColorLinkTest extends Base $action->setParam('color_id', 'red'); $action->setParam('link_id', 1); - $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + $this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorPriorityTest.php b/tests/units/Action/TaskAssignColorPriorityTest.php new file mode 100644 index 00000000..2fce8e66 --- /dev/null +++ b/tests/units/Action/TaskAssignColorPriorityTest.php @@ -0,0 +1,57 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; +use Kanboard\Action\TaskAssignColorPriority; + +class TaskAssignColorPriorityTest extends Base +{ + public function testChangeColor() + { + $categoryModel = new CategoryModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'priority' => 1)); + + $action = new TaskAssignColorPriority($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('priority', 1); + + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('red', $task['color_id']); + } + + public function testWithWrongPriority() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'priority' => 2)); + + $action = new TaskAssignColorPriority($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('priority', 1); + + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE_UPDATE)); + } +} diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php index e2656cc0..370f9070 100644 --- a/tests/units/Action/TaskAssignColorUserTest.php +++ b/tests/units/Action/TaskAssignColorUserTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignColorUser; class TaskAssignColorUserTest extends Base { public function testChangeColor() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignColorUserTest extends Base $action->setParam('color_id', 'red'); $action->setParam('user_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,9 +36,8 @@ class TaskAssignColorUserTest extends Base public function testWithWrongUser() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -50,6 +49,6 @@ class TaskAssignColorUserTest extends Base $action->setParam('color_id', 'red'); $action->setParam('user_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php index 41576ee4..6fdbda63 100644 --- a/tests/units/Action/TaskAssignCurrentUserColumnTest.php +++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php @@ -3,10 +3,10 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignCurrentUserColumn; class TaskAssignCurrentUserColumnTest extends Base @@ -15,9 +15,9 @@ class TaskAssignCurrentUserColumnTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -28,7 +28,7 @@ class TaskAssignCurrentUserColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,9 +39,8 @@ class TaskAssignCurrentUserColumnTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -52,14 +51,13 @@ class TaskAssignCurrentUserColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } public function testWithNoUserSession() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -70,6 +68,6 @@ class TaskAssignCurrentUserColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php index 2fe84a5d..5569a191 100644 --- a/tests/units/Action/TaskAssignCurrentUserTest.php +++ b/tests/units/Action/TaskAssignCurrentUserTest.php @@ -3,10 +3,10 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignCurrentUser; class TaskAssignCurrentUserTest extends Base @@ -15,9 +15,9 @@ class TaskAssignCurrentUserTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -27,7 +27,7 @@ class TaskAssignCurrentUserTest extends Base $action = new TaskAssignCurrentUser($this->container); $action->setProjectId(1); - $this->assertTrue($action->execute($event, Task::EVENT_CREATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,9 +36,8 @@ class TaskAssignCurrentUserTest extends Base public function testWithNoUserSession() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -48,6 +47,6 @@ class TaskAssignCurrentUserTest extends Base $action = new TaskAssignCurrentUser($this->container); $action->setProjectId(1); - $this->assertFalse($action->execute($event, Task::EVENT_CREATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CREATE)); } } diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php index 67b2c397..78ec314f 100644 --- a/tests/units/Action/TaskAssignSpecificUserTest.php +++ b/tests/units/Action/TaskAssignSpecificUserTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskAssignSpecificUser; class TaskAssignSpecificUserTest extends Base { public function testChangeUser() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0))); @@ -27,7 +27,7 @@ class TaskAssignSpecificUserTest extends Base $action->setParam('column_id', 2); $action->setParam('user_id', 1); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -36,9 +36,8 @@ class TaskAssignSpecificUserTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -50,6 +49,6 @@ class TaskAssignSpecificUserTest extends Base $action->setParam('column_id', 2); $action->setParam('user_id', 1); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignUserTest.php b/tests/units/Action/TaskAssignUserTest.php index 31404c0b..060128eb 100644 --- a/tests/units/Action/TaskAssignUserTest.php +++ b/tests/units/Action/TaskAssignUserTest.php @@ -3,11 +3,11 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Kanboard\Action\TaskAssignUser; use Kanboard\Core\Security\Role; @@ -15,11 +15,11 @@ class TaskAssignUserTest extends Base { public function testChangeUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0))); @@ -41,11 +41,8 @@ class TaskAssignUserTest extends Base public function testWithNotAssignableUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php index ce41bb41..f9a938f0 100644 --- a/tests/units/Action/TaskCloseColumnTest.php +++ b/tests/units/Action/TaskCloseColumnTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskCloseColumn; class TaskCloseColumnTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -26,7 +26,7 @@ class TaskCloseColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -35,9 +35,8 @@ class TaskCloseColumnTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -48,6 +47,6 @@ class TaskCloseColumnTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskCloseNoActivityTest.php b/tests/units/Action/TaskCloseNoActivityTest.php index b6e04c47..707d8585 100644 --- a/tests/units/Action/TaskCloseNoActivityTest.php +++ b/tests/units/Action/TaskCloseNoActivityTest.php @@ -3,25 +3,25 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\TaskListEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskCloseNoActivity; class TaskCloseNoActivityTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); $tasks = $taskFinderModel->getAll(1); $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); @@ -30,7 +30,7 @@ class TaskCloseNoActivityTest extends Base $action->setProjectId(1); $action->setParam('duration', 2); - $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php index 536d79ca..3df10cb8 100644 --- a/tests/units/Action/TaskCloseTest.php +++ b/tests/units/Action/TaskCloseTest.php @@ -3,18 +3,18 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskClose; class TaskCloseTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -34,8 +34,8 @@ class TaskCloseTest extends Base public function testWithNoTaskId() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskCreationTest.php b/tests/units/Action/TaskCreationTest.php index 57c2995d..fb3d334f 100644 --- a/tests/units/Action/TaskCreationTest.php +++ b/tests/units/Action/TaskCreationTest.php @@ -3,16 +3,16 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskCreation as TaskCreationAction; class TaskCreationActionTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -33,8 +33,7 @@ class TaskCreationActionTest extends Base public function testWithNoTitle() { - $projectModel = new Project($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php index d9491dd9..98ff187f 100644 --- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php +++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskDuplicateAnotherProject; class TaskDuplicateAnotherProjectTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskDuplicateAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE)); $task = $taskFinderModel->getById(2); $this->assertNotEmpty($task); @@ -38,8 +38,7 @@ class TaskDuplicateAnotherProjectTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -51,6 +50,6 @@ class TaskDuplicateAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskEmailNoActivityTest.php b/tests/units/Action/TaskEmailNoActivityTest.php index af4baed5..c4d489d8 100644 --- a/tests/units/Action/TaskEmailNoActivityTest.php +++ b/tests/units/Action/TaskEmailNoActivityTest.php @@ -3,28 +3,28 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\TaskListEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; use Kanboard\Action\TaskEmailNoActivity; class TaskEmailNoActivityTest extends Base { public function testSendEmail() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); $tasks = $taskFinderModel->getAll(1); $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); @@ -40,22 +40,22 @@ class TaskEmailNoActivityTest extends Base ->method('send') ->with('chuck@norris', 'Chuck Norris', 'Old tasks', $this->anything()); - $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); } public function testUserWithNoEmail() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'name' => 'Chuck Norris'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); $tasks = $taskFinderModel->getAll(1); $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); @@ -70,15 +70,15 @@ class TaskEmailNoActivityTest extends Base ->expects($this->never()) ->method('send'); - $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); } public function testTooRecent() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -98,6 +98,6 @@ class TaskEmailNoActivityTest extends Base ->expects($this->never()) ->method('send'); - $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB)); } } diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php index ef32a296..df71aaf8 100644 --- a/tests/units/Action/TaskEmailTest.php +++ b/tests/units/Action/TaskEmailTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\User; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; use Kanboard\Action\TaskEmail; class TaskEmailTest extends Base { public function testSuccess() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -38,13 +38,12 @@ class TaskEmailTest extends Base $this->stringContains('test') ); - $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE)); } public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -56,6 +55,6 @@ class TaskEmailTest extends Base $action->setParam('user_id', 1); $action->setParam('subject', 'My email subject'); - $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php index dfabe5f8..d36df47b 100644 --- a/tests/units/Action/TaskMoveAnotherProjectTest.php +++ b/tests/units/Action/TaskMoveAnotherProjectTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveAnotherProject; class TaskMoveAnotherProjectTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskMoveAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -39,8 +39,7 @@ class TaskMoveAnotherProjectTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -52,6 +51,6 @@ class TaskMoveAnotherProjectTest extends Base $action->setParam('project_id', 2); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php index f0eec894..f8982969 100644 --- a/tests/units/Action/TaskMoveColumnAssignedTest.php +++ b/tests/units/Action/TaskMoveColumnAssignedTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveColumnAssigned; class TaskMoveColumnAssignedTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskMoveColumnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -38,8 +38,7 @@ class TaskMoveColumnAssignedTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -51,6 +50,6 @@ class TaskMoveColumnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php index 1f0768c1..c42383f8 100644 --- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php +++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php @@ -3,21 +3,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Category; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveColumnCategoryChange; class TaskMoveColumnCategoryChangeTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -31,7 +31,7 @@ class TaskMoveColumnCategoryChangeTest extends Base $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_UPDATE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_UPDATE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -41,10 +41,9 @@ class TaskMoveColumnCategoryChangeTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -58,15 +57,14 @@ class TaskMoveColumnCategoryChangeTest extends Base $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_UPDATE)); } public function testWithWrongCategory() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -81,6 +79,6 @@ class TaskMoveColumnCategoryChangeTest extends Base $action->setParam('category_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_UPDATE)); } } diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php index 0b54b781..befae36b 100644 --- a/tests/units/Action/TaskMoveColumnUnAssignedTest.php +++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskMoveColumnUnAssigned; class TaskMoveColumnUnAssignedTest extends Base { public function testSuccess() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -28,7 +28,7 @@ class TaskMoveColumnUnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -38,8 +38,7 @@ class TaskMoveColumnUnAssignedTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -51,13 +50,12 @@ class TaskMoveColumnUnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } public function testWithWrongUser() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -69,6 +67,6 @@ class TaskMoveColumnUnAssignedTest extends Base $action->setParam('src_column_id', 1); $action->setParam('dest_column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php index 01290a64..1018e2ea 100644 --- a/tests/units/Action/TaskOpenTest.php +++ b/tests/units/Action/TaskOpenTest.php @@ -3,18 +3,18 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Action\TaskOpen; class TaskOpenTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0))); @@ -34,8 +34,8 @@ class TaskOpenTest extends Base public function testWithNoTaskId() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php index adf5bd9d..ddd9eafd 100644 --- a/tests/units/Action/TaskUpdateStartDateTest.php +++ b/tests/units/Action/TaskUpdateStartDateTest.php @@ -3,19 +3,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Action\TaskUpdateStartDate; class TaskUpdateStartDateTest extends Base { public function testClose() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -26,7 +26,7 @@ class TaskUpdateStartDateTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); @@ -35,8 +35,8 @@ class TaskUpdateStartDateTest extends Base public function testWithWrongColumn() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -47,6 +47,6 @@ class TaskUpdateStartDateTest extends Base $action->setProjectId(1); $action->setParam('column_id', 2); - $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php index b87e9573..831ec960 100644 --- a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php +++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\Task; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; use Kanboard\Analytic\AverageLeadCycleTimeAnalytic; class AverageLeadCycleTimeAnalyticTest extends Base { public function testBuild() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); $now = time(); @@ -26,19 +26,19 @@ class AverageLeadCycleTimeAnalyticTest extends Base $this->assertEquals(5, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); // LT=3600 CT=1800 - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800)); // LT=1800 CT=900 - $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900)); // LT=3600 CT=0 - $this->container['db']->table(Task::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600)); // LT=2*3600 CT=0 - $this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); // CT=0 - $this->container['db']->table(Task::TABLE)->eq('id', 5)->update(array('date_started' => $now + 900)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 5)->update(array('date_started' => $now + 900)); $stats = $averageLeadCycleTimeAnalytic->build(1); @@ -51,7 +51,7 @@ class AverageLeadCycleTimeAnalyticTest extends Base public function testBuildWithNoTasks() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php index 4e01bfa9..1da425fb 100644 --- a/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php +++ b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\Transition; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TransitionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; use Kanboard\Analytic\AverageTimeSpentColumnAnalytic; class AverageTimeSpentColumnAnalyticTest extends Base { public function testAverageWithNoTransitions() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -24,8 +24,8 @@ class AverageTimeSpentColumnAnalyticTest extends Base $now = time(); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); - $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); $stats = $averageLeadCycleTimeAnalytic->build(1); @@ -52,10 +52,10 @@ class AverageTimeSpentColumnAnalyticTest extends Base public function testAverageWithTransitions() { - $transitionModel = new Transition($this->container); - $taskFinderModel = new TaskFinder($this->container); - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $transitionModel = new TransitionModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -64,8 +64,8 @@ class AverageTimeSpentColumnAnalyticTest extends Base $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $now = time(); - $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); - $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(TaskModel::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); foreach (array(1, 2) as $task_id) { $task = $taskFinderModel->getById($task_id); diff --git a/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php index 2ca631b1..29bf88a3 100644 --- a/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php +++ b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php @@ -2,16 +2,16 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Analytic\EstimatedTimeComparisonAnalytic; class EstimatedTimeComparisonAnalyticTest extends Base { public function testBuild() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -41,8 +41,8 @@ class EstimatedTimeComparisonAnalyticTest extends Base public function testBuildWithNoClosedTask() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -70,8 +70,8 @@ class EstimatedTimeComparisonAnalyticTest extends Base public function testBuildWithOnlyClosedTask() { - $taskCreationModel = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Analytic/TaskDistributionAnalyticTest.php b/tests/units/Analytic/TaskDistributionAnalyticTest.php index 531101ef..0d600b8b 100644 --- a/tests/units/Analytic/TaskDistributionAnalyticTest.php +++ b/tests/units/Analytic/TaskDistributionAnalyticTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Analytic\TaskDistributionAnalytic; class TaskDistributionAnalyticTest extends Base { public function testBuild() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $taskDistributionModel = new TaskDistributionAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -49,7 +49,7 @@ class TaskDistributionAnalyticTest extends Base private function createTasks($column_id, $nb_active, $nb_inactive) { - $taskCreationModel = new TaskCreation($this->container); + $taskCreationModel = new TaskCreationModel($this->container); for ($i = 0; $i < $nb_active; $i++) { $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'is_active' => 1))); diff --git a/tests/units/Analytic/UserDistributionAnalyticTest.php b/tests/units/Analytic/UserDistributionAnalyticTest.php index bdc136e1..f4514899 100644 --- a/tests/units/Analytic/UserDistributionAnalyticTest.php +++ b/tests/units/Analytic/UserDistributionAnalyticTest.php @@ -2,10 +2,10 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserModel; use Kanboard\Analytic\UserDistributionAnalytic; use Kanboard\Core\Security\Role; @@ -13,9 +13,9 @@ class UserDistributionAnalyticTest extends Base { public function testBuild() { - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); $userDistributionModel = new UserDistributionAnalytic($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); @@ -70,7 +70,7 @@ class UserDistributionAnalyticTest extends Base private function createTasks($user_id, $nb_active, $nb_inactive) { - $taskCreationModel = new TaskCreation($this->container); + $taskCreationModel = new TaskCreationModel($this->container); for ($i = 0; $i < $nb_active; $i++) { $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => $user_id, 'is_active' => 1))); diff --git a/tests/units/Auth/DatabaseAuthTest.php b/tests/units/Auth/DatabaseAuthTest.php index ac099a7e..97c75bd2 100644 --- a/tests/units/Auth/DatabaseAuthTest.php +++ b/tests/units/Auth/DatabaseAuthTest.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Auth\DatabaseAuth; -use Kanboard\Model\User; +use Kanboard\Model\UserModel; class DatabaseAuthTest extends Base { @@ -41,7 +41,7 @@ class DatabaseAuthTest extends Base public function testIsvalidSession() { - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $provider = new DatabaseAuth($this->container); $this->assertFalse($provider->isValidSession()); diff --git a/tests/units/Base.php b/tests/units/Base.php index 5125ffb9..c7e066d1 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -3,11 +3,11 @@ require __DIR__.'/../../vendor/autoload.php'; require __DIR__.'/../../app/constants.php'; +use Composer\Autoload\ClassLoader; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; use SimpleLogger\Logger; -use SimpleLogger\File; use Kanboard\Core\Session\FlashMessage; use Kanboard\Core\Session\SessionStorage; use Kanboard\ServiceProvider\ActionProvider; @@ -33,14 +33,15 @@ abstract class Base extends PHPUnit_Framework_TestCase } $this->container = new Pimple\Container; - $this->container->register(new Kanboard\ServiceProvider\HelperProvider); - $this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider); - $this->container->register(new Kanboard\ServiceProvider\DatabaseProvider); - $this->container->register(new Kanboard\ServiceProvider\ClassProvider); - $this->container->register(new Kanboard\ServiceProvider\NotificationProvider); - $this->container->register(new Kanboard\ServiceProvider\RouteProvider); - $this->container->register(new Kanboard\ServiceProvider\AvatarProvider); - $this->container->register(new Kanboard\ServiceProvider\FilterProvider); + $this->container->register(new Kanboard\ServiceProvider\HelperProvider()); + $this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider()); + $this->container->register(new Kanboard\ServiceProvider\DatabaseProvider()); + $this->container->register(new Kanboard\ServiceProvider\ClassProvider()); + $this->container->register(new Kanboard\ServiceProvider\NotificationProvider()); + $this->container->register(new Kanboard\ServiceProvider\RouteProvider()); + $this->container->register(new Kanboard\ServiceProvider\AvatarProvider()); + $this->container->register(new Kanboard\ServiceProvider\FilterProvider()); + $this->container->register(new Kanboard\ServiceProvider\QueueProvider()); $this->container['dispatcher'] = new TraceableEventDispatcher( new EventDispatcher, @@ -48,9 +49,7 @@ abstract class Base extends PHPUnit_Framework_TestCase ); $this->container['db']->logQueries = true; - $this->container['logger'] = new Logger; - $this->container['logger']->setLogger(new File($this->isWindows() ? 'NUL' : '/dev/null')); $this->container['httpClient'] = $this ->getMockBuilder('\Kanboard\Core\Http\Client') @@ -64,8 +63,8 @@ abstract class Base extends PHPUnit_Framework_TestCase ->setMethods(array('send')) ->getMock(); - $this->container['userNotificationType'] = $this - ->getMockBuilder('\Kanboard\Model\UserNotificationType') + $this->container['userNotificationTypeModel'] = $this + ->getMockBuilder('\Kanboard\Model\UserNotificationTypeModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('getType', 'getSelectedTypes')) ->getMock(); @@ -82,15 +81,14 @@ abstract class Base extends PHPUnit_Framework_TestCase $this->container['flash'] = function ($c) { return new FlashMessage($c); }; + + $loader = new ClassLoader(); + $loader->addPsr4('Kanboard\Plugin\\', PLUGINS_DIR); + $loader->register(); } public function tearDown() { $this->container['db']->closeConnection(); } - - public function isWindows() - { - return substr(PHP_OS, 0, 3) === 'WIN'; - } } diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php index aae5bd2d..e7c2071f 100644 --- a/tests/units/Core/Action/ActionManagerTest.php +++ b/tests/units/Core/Action/ActionManagerTest.php @@ -7,10 +7,10 @@ use Kanboard\Action\TaskAssignColorColumn; use Kanboard\Action\TaskClose; use Kanboard\Action\TaskCloseColumn; use Kanboard\Action\TaskUpdateStartDate; -use Kanboard\Model\Action; -use Kanboard\Model\Task; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ActionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Core\Security\Role; class ActionManagerTest extends Base @@ -79,16 +79,16 @@ class ActionManagerTest extends Base $events = $actionManager->getCompatibleEvents('\\'.get_class($actionTaskAssignColorColumn)); $this->assertCount(2, $events); - $this->assertArrayHasKey(Task::EVENT_CREATE, $events); - $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events); - $this->assertNotEmpty($events[Task::EVENT_CREATE]); - $this->assertNotEmpty($events[Task::EVENT_MOVE_COLUMN]); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE, $events); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN, $events); + $this->assertNotEmpty($events[TaskModel::EVENT_CREATE]); + $this->assertNotEmpty($events[TaskModel::EVENT_MOVE_COLUMN]); } public function testAttachEventsWithoutUserSession() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); $actionManager->register($actionTaskAssignColorColumn); @@ -101,13 +101,13 @@ class ActionManagerTest extends Base $this->assertEquals(1, $projectModel->create(array('name' =>'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_CREATE); + $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE); $this->assertCount(1, $listeners); $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); @@ -118,9 +118,9 @@ class ActionManagerTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); $actionManager->register($actionTaskAssignColorColumn); @@ -134,21 +134,21 @@ class ActionManagerTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN); + $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN); $this->assertCount(1, $listeners); $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); @@ -157,9 +157,9 @@ class ActionManagerTest extends Base public function testThatEachListenerAreDifferentInstance() { - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); $actionManager->register($actionTaskAssignColorColumn); @@ -169,21 +169,21 @@ class ActionManagerTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => key($actions), 'params' => array('column_id' => 2, 'color_id' => 'green'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => key($actions), 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN); + $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN); $this->assertCount(2, $listeners); $this->assertFalse($listeners[0][0] === $listeners[1][0]); diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php index ac5315bb..23726f32 100644 --- a/tests/units/Core/Filter/LexerBuilderTest.php +++ b/tests/units/Core/Filter/LexerBuilderTest.php @@ -5,17 +5,17 @@ require_once __DIR__.'/../../Base.php'; use Kanboard\Core\Filter\LexerBuilder; use Kanboard\Filter\TaskAssigneeFilter; use Kanboard\Filter\TaskTitleFilter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; class LexerBuilderTest extends Base { public function testBuilderThatReturnResult() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -33,9 +33,9 @@ class LexerBuilderTest extends Base public function testBuilderThatReturnNothing() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -52,9 +52,9 @@ class LexerBuilderTest extends Base public function testBuilderWithEmptyInput() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -71,9 +71,9 @@ class LexerBuilderTest extends Base public function testBuilderWithMultipleMatches() { - $project = new Project($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $project->create(array('name' => 'Project'))); @@ -91,7 +91,7 @@ class LexerBuilderTest extends Base public function testClone() { - $taskFinder = new TaskFinder($this->container); + $taskFinder = new TaskFinderModel($this->container); $query = $taskFinder->getExtendedQuery(); $builder = new LexerBuilder(); diff --git a/tests/units/Core/Filter/LexerTest.php b/tests/units/Core/Filter/LexerTest.php index 3f3e368e..c72231c4 100644 --- a/tests/units/Core/Filter/LexerTest.php +++ b/tests/units/Core/Filter/LexerTest.php @@ -77,24 +77,129 @@ class LexerTest extends Base public function testTokenizeWithStringDate() { $lexer = new Lexer(); - $lexer->addToken("/^(date:)/", 'T_DATE'); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); $expected = array( - 'T_DATE' => array('today'), + 'T_MY_DATE' => array('today'), ); $this->assertSame($expected, $lexer->tokenize('date:today something else')); } + public function testTokenizeWithStringDateWithSpaces() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('last month'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:"last month" something else')); + } + + public function testTokenizeWithStringDateWithSpacesAndOperator() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<=last month'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<="last month" something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('>=next month'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:>="next month" something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<+2 days'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<"+2 days" something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<-1 hour'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<"-1 hour" something else')); + } + + public function testTokenizeWithStringDateAndOperator() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('<=today'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<=today something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('>now'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:>now something else')); + + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); + + $expected = array( + 'T_MY_DATE' => array('>=now'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:>=now something else')); + } + public function testTokenizeWithIsoDate() { $lexer = new Lexer(); - $lexer->addToken("/^(date:)/", 'T_DATE'); + $lexer->addToken("/^(date:)/", 'T_MY_DATE'); $expected = array( - 'T_DATE' => array('<=2016-01-01'), + 'T_MY_DATE' => array('<=2016-01-01'), ); $this->assertSame($expected, $lexer->tokenize('date:<=2016-01-01 something else')); } + + public function testTokenizeWithUtf8Letters() + { + $lexer = new Lexer(); + $lexer->setDefaultToken('myDefaultToken'); + + $expected = array( + 'myDefaultToken' => array('àa éçùe'), + ); + + $this->assertSame($expected, $lexer->tokenize('àa éçùe')); + } + + public function testTokenizeWithUtf8Numbers() + { + $lexer = new Lexer(); + $lexer->setDefaultToken('myDefaultToken'); + + $expected = array( + 'myDefaultToken' => array('६Δↈ五一'), + ); + + $this->assertSame($expected, $lexer->tokenize('६Δↈ五一')); + } } diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php index 787d3461..a46726c3 100644 --- a/tests/units/Core/Filter/OrCriteriaTest.php +++ b/tests/units/Core/Filter/OrCriteriaTest.php @@ -3,10 +3,10 @@ use Kanboard\Core\Filter\OrCriteria; use Kanboard\Filter\TaskAssigneeFilter; use Kanboard\Filter\TaskTitleFilter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\User; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\UserModel; require_once __DIR__.'/../../Base.php'; @@ -14,10 +14,10 @@ class OrCriteriaTest extends Base { public function testWithSameFilter() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); @@ -36,10 +36,10 @@ class OrCriteriaTest extends Base public function testWithDifferentFilter() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); diff --git a/tests/units/Core/Group/GroupManagerTest.php b/tests/units/Core/Group/GroupManagerTest.php index faf5501f..e89ad15b 100644 --- a/tests/units/Core/Group/GroupManagerTest.php +++ b/tests/units/Core/Group/GroupManagerTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../../Base.php'; -use Kanboard\Model\Group; +use Kanboard\Model\GroupModel; use Kanboard\Core\Group\GroupManager; use Kanboard\Group\DatabaseBackendGroupProvider; @@ -10,7 +10,7 @@ class GroupManagerTest extends Base { public function testFind() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $groupManager = new GroupManager; $this->assertEquals(1, $groupModel->create('Group 1')); diff --git a/tests/units/Core/Http/RouteTest.php b/tests/units/Core/Http/RouteTest.php index 5e44ad00..86920970 100644 --- a/tests/units/Core/Http/RouteTest.php +++ b/tests/units/Core/Http/RouteTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/../../Base.php'; use Kanboard\Core\Http\Route; +use Kanboard\Core\Http\Router; class RouteTest extends Base { @@ -34,7 +35,7 @@ class RouteTest extends Base ); $this->assertEquals( - array('controller' => 'app', 'action' => 'index', 'plugin' => ''), + array('controller' => Router::DEFAULT_CONTROLLER, 'action' => Router::DEFAULT_METHOD, 'plugin' => ''), $route->findRoute('/notfound') ); diff --git a/tests/units/Core/Http/RouterTest.php b/tests/units/Core/Http/RouterTest.php index 75a3ba4f..6f124d33 100644 --- a/tests/units/Core/Http/RouterTest.php +++ b/tests/units/Core/Http/RouterTest.php @@ -1,207 +1,147 @@ <?php -namespace Kanboard\Controller { +require_once __DIR__.'/../../Base.php'; - class FakeController { - public function beforeAction() {} - public function myAction() {} - } -} +use Kanboard\Core\Http\Route; +use Kanboard\Core\Http\Router; +use Kanboard\Core\Http\Request; -namespace Kanboard\Plugin\Myplugin\Controller { +class RouterTest extends Base +{ + public function testSanitize() + { + $dispatcher = new Router($this->container); - class FakeController { - public function beforeAction() {} - public function myAction() {} + $this->assertEquals('PloP', $dispatcher->sanitize('PloP', 'default')); + $this->assertEquals('default', $dispatcher->sanitize('', 'default')); + $this->assertEquals('default', $dispatcher->sanitize('123-AB', 'default')); + $this->assertEquals('default', $dispatcher->sanitize('R&D', 'default')); + $this->assertEquals('Test123', $dispatcher->sanitize('Test123', 'default')); + $this->assertEquals('Test_123', $dispatcher->sanitize('Test_123', 'default')); + $this->assertEquals('userImport', $dispatcher->sanitize('userImport', 'default')); } -} - -namespace { - - require_once __DIR__.'/../../Base.php'; - - use Kanboard\Core\Helper; - use Kanboard\Core\Http\Route; - use Kanboard\Core\Http\Router; - use Kanboard\Core\Http\Request; - class RouterTest extends Base + public function testGetPathWithFolder() { - public function testSanitize() - { - $dispatcher = new Router($this->container); - - $this->assertEquals('PloP', $dispatcher->sanitize('PloP', 'default')); - $this->assertEquals('default', $dispatcher->sanitize('', 'default')); - $this->assertEquals('default', $dispatcher->sanitize('123-AB', 'default')); - $this->assertEquals('default', $dispatcher->sanitize('R&D', 'default')); - $this->assertEquals('Test123', $dispatcher->sanitize('Test123', 'default')); - $this->assertEquals('Test_123', $dispatcher->sanitize('Test_123', 'default')); - $this->assertEquals('userImport', $dispatcher->sanitize('userImport', 'default')); - } - - public function testGetPathWithFolder() - { - $router = new Router($this->container); - $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/c', 'REQUEST_METHOD' => 'GET')); - $this->assertEquals('a/b/c', $router->getPath()); - } - - public function testGetPathWithQueryString() - { - $router = new Router($this->container); - $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); - $this->assertEquals('a/b/something', $router->getPath()); - } - - public function testGetPathWithSubFolderAndQueryString() - { - $router = new Router($this->container); - $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/a/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); - $this->assertEquals('b/something', $router->getPath()); - } - - public function testDispatcherWithControllerNotFound() - { - $this->container['request'] = new Request($this->container, array( - 'PHP_SELF' => '/kanboard/index.php', - 'REQUEST_URI' => '/kanboard/?controller=FakeControllerNotFound&action=myAction&myvar=value1', - 'QUERY_STRING' => 'controller=FakeControllerNotFound&action=myAction&myvar=value1', - 'REQUEST_METHOD' => 'GET' - ), - array( - 'controller' => 'FakeControllerNotFound', - 'action' => 'myAction', - 'myvar' => 'value1', - ) - ); - - $this->setExpectedException('RuntimeException', 'Controller not found'); + $router = new Router($this->container); + $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/c', 'REQUEST_METHOD' => 'GET')); + $this->assertEquals('a/b/c', $router->getPath()); + } - $dispatcher = new Router($this->container); - $dispatcher->dispatch(); - } + public function testGetPathWithQueryString() + { + $router = new Router($this->container); + $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); + $this->assertEquals('a/b/something', $router->getPath()); + } - public function testDispatcherWithActionNotFound() - { - $this->container['request'] = new Request($this->container, array( - 'PHP_SELF' => '/kanboard/index.php', - 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myActionNotFound&myvar=value1', - 'QUERY_STRING' => 'controller=FakeController&action=myActionNotFound&myvar=value1', - 'REQUEST_METHOD' => 'GET' - ), - array( - 'controller' => 'FakeController', - 'action' => 'myActionNotFound', - 'myvar' => 'value1', - ) - ); + public function testGetPathWithSubFolderAndQueryString() + { + $router = new Router($this->container); + $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/a/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); + $this->assertEquals('b/something', $router->getPath()); + } - $this->setExpectedException('RuntimeException', 'Action not implemented'); + public function testDispatcherWithNoUrlRewrite() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myAction&myvar=value1', + 'QUERY_STRING' => 'controller=FakeController&action=myAction&myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'controller' => 'FakeController', + 'action' => 'myAction', + 'myvar' => 'value1', + ) + ); - $dispatcher = new Router($this->container); - $dispatcher->dispatch(); - } + $dispatcher = new Router($this->container); + $dispatcher->dispatch(); - public function testDispatcherWithNoUrlRewrite() - { - $this->container['request'] = new Request($this->container, array( - 'PHP_SELF' => '/kanboard/index.php', - 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myAction&myvar=value1', - 'QUERY_STRING' => 'controller=FakeController&action=myAction&myvar=value1', - 'REQUEST_METHOD' => 'GET' - ), - array( - 'controller' => 'FakeController', - 'action' => 'myAction', - 'myvar' => 'value1', - ) - ); + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + } - $dispatcher = new Router($this->container); - $this->assertInstanceOf('\Kanboard\Controller\FakeController', $dispatcher->dispatch()); - $this->assertEquals('FakeController', $dispatcher->getController()); - $this->assertEquals('myAction', $dispatcher->getAction()); - $this->assertEquals('', $dispatcher->getPlugin()); - $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); - } + public function testDispatcherWithNoUrlRewriteAndPlugin() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myAction&myvar=value1&plugin=myplugin', + 'QUERY_STRING' => 'controller=FakeController&action=myAction&myvar=value1&plugin=myplugin', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'controller' => 'FakeController', + 'action' => 'myAction', + 'myvar' => 'value1', + 'plugin' => 'myplugin', + ) + ); - public function testDispatcherWithNoUrlRewriteAndPlugin() - { - $this->container['request'] = new Request($this->container, array( - 'PHP_SELF' => '/kanboard/index.php', - 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myAction&myvar=value1&plugin=myplugin', - 'QUERY_STRING' => 'controller=FakeController&action=myAction&myvar=value1&plugin=myplugin', - 'REQUEST_METHOD' => 'GET' - ), - array( - 'controller' => 'FakeController', - 'action' => 'myAction', - 'myvar' => 'value1', - 'plugin' => 'myplugin', - ) - ); + $dispatcher = new Router($this->container); + $dispatcher->dispatch(); - $dispatcher = new Router($this->container); - $this->assertInstanceOf('\Kanboard\Plugin\Myplugin\Controller\FakeController', $dispatcher->dispatch()); - $this->assertEquals('FakeController', $dispatcher->getController()); - $this->assertEquals('myAction', $dispatcher->getAction()); - $this->assertEquals('Myplugin', $dispatcher->getPlugin()); - $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); - } + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('Myplugin', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + } - public function testDispatcherWithUrlRewrite() - { - $this->container['request'] = new Request($this->container, array( - 'PHP_SELF' => '/kanboard/index.php', - 'REQUEST_URI' => '/kanboard/my/route/123?myvar=value1', - 'QUERY_STRING' => 'myvar=value1', - 'REQUEST_METHOD' => 'GET' - ), - array( - 'myvar' => 'value1', - ) - ); + public function testDispatcherWithUrlRewrite() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/my/route/123?myvar=value1', + 'QUERY_STRING' => 'myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'myvar' => 'value1', + ) + ); - $this->container['route'] = new Route($this->container); - $this->container['route']->enable(); - $dispatcher = new Router($this->container); + $this->container['route'] = new Route($this->container); + $this->container['route']->enable(); + $this->container['route']->addRoute('/my/route/:param', 'FakeController', 'myAction'); - $this->container['route']->addRoute('/my/route/:param', 'FakeController', 'myAction'); + $dispatcher = new Router($this->container); + $dispatcher->dispatch(); - $this->assertInstanceOf('\Kanboard\Controller\FakeController', $dispatcher->dispatch()); - $this->assertEquals('FakeController', $dispatcher->getController()); - $this->assertEquals('myAction', $dispatcher->getAction()); - $this->assertEquals('', $dispatcher->getPlugin()); - $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); - $this->assertEquals('123', $this->container['request']->getStringParam('param')); - } + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + $this->assertEquals('123', $this->container['request']->getStringParam('param')); + } - public function testDispatcherWithUrlRewriteWithPlugin() - { - $this->container['request'] = new Request($this->container, array( - 'PHP_SELF' => '/kanboard/index.php', - 'REQUEST_URI' => '/kanboard/my/plugin/route/123?myvar=value1', - 'QUERY_STRING' => 'myvar=value1', - 'REQUEST_METHOD' => 'GET' - ), - array( - 'myvar' => 'value1', - ) - ); + public function testDispatcherWithUrlRewriteWithPlugin() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/my/plugin/route/123?myvar=value1', + 'QUERY_STRING' => 'myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'myvar' => 'value1', + ) + ); - $this->container['route'] = new Route($this->container); - $this->container['route']->enable(); - $dispatcher = new Router($this->container); + $this->container['route'] = new Route($this->container); + $this->container['route']->enable(); + $this->container['route']->addRoute('/my/plugin/route/:param', 'fakeController', 'myAction', 'Myplugin'); - $this->container['route']->addRoute('/my/plugin/route/:param', 'fakeController', 'myAction', 'Myplugin'); + $dispatcher = new Router($this->container); + $dispatcher->dispatch(); - $this->assertInstanceOf('\Kanboard\Plugin\Myplugin\Controller\FakeController', $dispatcher->dispatch()); - $this->assertEquals('FakeController', $dispatcher->getController()); - $this->assertEquals('myAction', $dispatcher->getAction()); - $this->assertEquals('Myplugin', $dispatcher->getPlugin()); - $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); - $this->assertEquals('123', $this->container['request']->getStringParam('param')); - } + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('Myplugin', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + $this->assertEquals('123', $this->container['request']->getStringParam('param')); } } diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php index b4b63053..505b8a03 100644 --- a/tests/units/Core/Ldap/LdapUserTest.php +++ b/tests/units/Core/Ldap/LdapUserTest.php @@ -2,15 +2,18 @@ require_once __DIR__.'/../../Base.php'; +use Kanboard\Core\Ldap\Query; use Kanboard\Core\Ldap\User; use Kanboard\Core\Ldap\Entries; use Kanboard\Core\Security\Role; +use Kanboard\Group\LdapGroupProvider; class LdapUserTest extends Base { private $query; private $client; private $user; + private $group; public function setUp() { @@ -33,14 +36,24 @@ class LdapUserTest extends Base )) ->getMock(); + $this->group = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Group') + ->setConstructorArgs(array(new Query($this->client))) + ->setMethods(array( + 'find', + )) + ->getMock(); + $this->user = $this ->getMockBuilder('\Kanboard\Core\Ldap\User') - ->setConstructorArgs(array($this->query)) + ->setConstructorArgs(array($this->query, $this->group)) ->setMethods(array( 'getAttributeUsername', 'getAttributeEmail', 'getAttributeName', 'getAttributeGroup', + 'getAttributePhoto', + 'getGroupUserFilter', 'getGroupAdminDn', 'getGroupManagerDn', 'getBasDn', @@ -48,7 +61,7 @@ class LdapUserTest extends Base ->getMock(); } - public function testGetUser() + public function testGetUserWithNoGroupConfigured() { $entries = new Entries(array( 'count' => 1, @@ -123,11 +136,80 @@ class LdapUserTest extends Base $this->assertEquals('my_ldap_user', $user->getUsername()); $this->assertEquals('My LDAP user', $user->getName()); $this->assertEquals('user1@localhost', $user->getEmail()); - $this->assertEquals(Role::APP_USER, $user->getRole()); + $this->assertEquals(null, $user->getRole()); + $this->assertSame('', $user->getPhoto()); $this->assertEquals(array(), $user->getExternalGroupIds()); $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); } + public function testGetUserWithPhoto() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 'jpegPhoto' => array( + 'count' => 1, + 0 => 'my photo', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + ) + )); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributePhoto') + ->will($this->returnValue('jpegPhoto')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('my photo', $user->getPhoto()); + } + public function testGetUserWithAdminRole() { $entries = new Entries(array( @@ -367,6 +449,333 @@ class LdapUserTest extends Base $this->assertEquals(null, $user); } + public function testGetUserWithAdminRoleAndPosixGroups() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=Users,dc=kanboard,dc=local', + 'cn' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'uid' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 0 => 'cn', + 1 => 'mail', + 2 => 'uid', + ) + )); + + $groups = array( + new LdapGroupProvider('CN=Kanboard Admins,OU=Groups,DC=kanboard,DC=local', 'Kanboard Admins') + ); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('OU=Users,DC=kanboard,DC=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('uid')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('cn')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getAttributeGroup') + ->will($this->returnValue('')); + + $this->user + ->expects($this->any()) + ->method('getGroupUserFilter') + ->will($this->returnValue('(&(objectClass=posixGroup)(memberUid=%s))')); + + $this->user + ->expects($this->any()) + ->method('getGroupAdminDn') + ->will($this->returnValue('cn=Kanboard Admins,ou=Groups,dc=kanboard,dc=local')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('OU=Users,DC=kanboard,DC=local')); + + $this->group + ->expects($this->once()) + ->method('find') + ->with('(&(objectClass=posixGroup)(memberUid=my_ldap_user))') + ->will($this->returnValue($groups)); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('uid=my_ldap_user,ou=Users,dc=kanboard,dc=local', $user->getDn()); + $this->assertEquals('my_ldap_user', $user->getUsername()); + $this->assertEquals('My LDAP user', $user->getName()); + $this->assertEquals('user1@localhost', $user->getEmail()); + $this->assertEquals(array('CN=Kanboard Admins,OU=Groups,DC=kanboard,DC=local'), $user->getExternalGroupIds()); + $this->assertEquals(Role::APP_ADMIN, $user->getRole()); + $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); + } + + public function testGetUserWithManagerRoleAndPosixGroups() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=Users,dc=kanboard,dc=local', + 'cn' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'uid' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 0 => 'cn', + 1 => 'mail', + 2 => 'uid', + ) + )); + + $groups = array( + new LdapGroupProvider('CN=Kanboard Users,OU=Groups,DC=kanboard,DC=local', 'Kanboard Users'), + new LdapGroupProvider('CN=Kanboard Managers,OU=Groups,DC=kanboard,DC=local', 'Kanboard Managers'), + ); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('OU=Users,DC=kanboard,DC=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('uid')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('cn')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getAttributeGroup') + ->will($this->returnValue('')); + + $this->user + ->expects($this->any()) + ->method('getGroupUserFilter') + ->will($this->returnValue('(&(objectClass=posixGroup)(memberUid=%s))')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('cn=Kanboard Managers,ou=Groups,dc=kanboard,dc=local')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('OU=Users,DC=kanboard,DC=local')); + + $this->group + ->expects($this->once()) + ->method('find') + ->with('(&(objectClass=posixGroup)(memberUid=my_ldap_user))') + ->will($this->returnValue($groups)); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('uid=my_ldap_user,ou=Users,dc=kanboard,dc=local', $user->getDn()); + $this->assertEquals('my_ldap_user', $user->getUsername()); + $this->assertEquals('My LDAP user', $user->getName()); + $this->assertEquals('user1@localhost', $user->getEmail()); + $this->assertEquals( + array( + 'CN=Kanboard Users,OU=Groups,DC=kanboard,DC=local', + 'CN=Kanboard Managers,OU=Groups,DC=kanboard,DC=local', + ), + $user->getExternalGroupIds() + ); + $this->assertEquals(Role::APP_MANAGER, $user->getRole()); + $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); + } + + public function testGetUserWithUserRoleAndPosixGroups() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=Users,dc=kanboard,dc=local', + 'cn' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'uid' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 0 => 'cn', + 1 => 'mail', + 2 => 'uid', + ) + )); + + $groups = array( + new LdapGroupProvider('CN=Kanboard Users,OU=Groups,DC=kanboard,DC=local', 'Kanboard Users'), + ); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('OU=Users,DC=kanboard,DC=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('uid')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('cn')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getAttributeGroup') + ->will($this->returnValue('')); + + $this->user + ->expects($this->any()) + ->method('getGroupUserFilter') + ->will($this->returnValue('(&(objectClass=posixGroup)(memberUid=%s))')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('cn=Kanboard Managers,ou=Groups,dc=kanboard,dc=local')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('OU=Users,DC=kanboard,DC=local')); + + $this->group + ->expects($this->once()) + ->method('find') + ->with('(&(objectClass=posixGroup)(memberUid=my_ldap_user))') + ->will($this->returnValue($groups)); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('uid=my_ldap_user,ou=Users,dc=kanboard,dc=local', $user->getDn()); + $this->assertEquals('my_ldap_user', $user->getUsername()); + $this->assertEquals('My LDAP user', $user->getName()); + $this->assertEquals('user1@localhost', $user->getEmail()); + $this->assertEquals( + array( + 'CN=Kanboard Users,OU=Groups,DC=kanboard,DC=local', + ), + $user->getExternalGroupIds() + ); + $this->assertEquals(Role::APP_USER, $user->getRole()); + $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); + } + public function testGetBaseDnNotConfigured() { $this->setExpectedException('\LogicException'); @@ -400,4 +809,40 @@ class LdapUserTest extends Base $user = new User($this->query); $this->assertEquals($expected, $user->getLdapUserPattern('test', $filter)); } + + public function testGetGroupUserFilter() + { + $user = new User($this->query); + $this->assertSame('', $user->getGroupUserFilter()); + } + + public function testHasGroupUserFilterWithEmptyString() + { + $this->user + ->expects($this->any()) + ->method('getGroupUserFilter') + ->will($this->returnValue('')); + + $this->assertFalse($this->user->hasGroupUserFilter()); + } + + public function testHasGroupUserFilterWithNull() + { + $this->user + ->expects($this->any()) + ->method('getGroupUserFilter') + ->will($this->returnValue(null)); + + $this->assertFalse($this->user->hasGroupUserFilter()); + } + + public function testHasGroupUserFilterWithValue() + { + $this->user + ->expects($this->any()) + ->method('getGroupUserFilter') + ->will($this->returnValue('foobar')); + + $this->assertTrue($this->user->hasGroupUserFilter()); + } } diff --git a/tests/units/Core/Plugin/DirectoryTest.php b/tests/units/Core/Plugin/DirectoryTest.php new file mode 100644 index 00000000..13aef4b9 --- /dev/null +++ b/tests/units/Core/Plugin/DirectoryTest.php @@ -0,0 +1,44 @@ +<?php + +use Kanboard\Core\Plugin\Directory; + +require_once __DIR__.'/../../Base.php'; + +class DirectoryTest extends Base +{ + public function testIsCompatible() + { + $pluginDirectory = new Directory($this->container); + $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234')); + } + + public function testGetAvailablePlugins() + { + $plugins = array( + array( + 'title' => 'Plugin A', + 'compatible_version' => '1.0.30', + 'remote_install' => true, + ), + array( + 'title' => 'Plugin B', + 'compatible_version' => '1.0.29', + 'remote_install' => false, + ), + ); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('getJson') + ->with('api_url') + ->will($this->returnValue($plugins)); + + $pluginDirectory = new Directory($this->container); + $availablePlugins = $pluginDirectory->getAvailablePlugins('api_url'); + + $this->assertCount(1, $availablePlugins); + $this->assertEquals('Plugin A', $availablePlugins[0]['title']); + } +} diff --git a/tests/units/Core/Plugin/LoaderTest.php b/tests/units/Core/Plugin/SchemaHandlerTest.php index 448723d8..98a00e0b 100644 --- a/tests/units/Core/Plugin/LoaderTest.php +++ b/tests/units/Core/Plugin/SchemaHandlerTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../../Base.php'; -use Kanboard\Core\Plugin\Loader; +use Kanboard\Core\Plugin\SchemaHandler; -class LoaderTest extends Base +class SchemaHandlerTest extends Base { public function testGetSchemaVersion() { - $p = new Loader($this->container); + $p = new SchemaHandler($this->container); $this->assertEquals(0, $p->getSchemaVersion('not_found')); $this->assertTrue($p->setSchemaVersion('plugin1', 1)); diff --git a/tests/units/Core/ToolTest.php b/tests/units/Core/ToolTest.php deleted file mode 100644 index 2422d73c..00000000 --- a/tests/units/Core/ToolTest.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Core\Tool; - -class ToolTest extends Base -{ - public function testMailboxHash() - { - $this->assertEquals('test1', Tool::getMailboxHash('a+test1@localhost')); - $this->assertEquals('', Tool::getMailboxHash('test1@localhost')); - $this->assertEquals('', Tool::getMailboxHash('test1')); - } -} diff --git a/tests/units/Core/User/GroupSyncTest.php b/tests/units/Core/User/GroupSyncTest.php index e22b86d4..d3df71bb 100644 --- a/tests/units/Core/User/GroupSyncTest.php +++ b/tests/units/Core/User/GroupSyncTest.php @@ -3,15 +3,15 @@ require_once __DIR__.'/../../Base.php'; use Kanboard\Core\User\GroupSync; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; class GroupSyncTest extends Base { - public function testSynchronize() + public function testAddGroups() { - $group = new Group($this->container); - $groupMember = new GroupMember($this->container); + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); $groupSync = new GroupSync($this->container); $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); @@ -27,4 +27,63 @@ class GroupSyncTest extends Base $this->assertTrue($groupMember->isMember(1, 1)); $this->assertTrue($groupMember->isMember(2, 1)); } + + public function testRemoveGroups() + { + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); + $groupSync = new GroupSync($this->container); + + $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); + $this->assertEquals(2, $group->create('My Group 2', 'externalId2')); + + $this->assertTrue($groupMember->addUser(1, 1)); + + $this->assertTrue($groupMember->isMember(1, 1)); + $this->assertFalse($groupMember->isMember(2, 1)); + + $groupSync->synchronize(1, array('externalId3')); + + $this->assertFalse($groupMember->isMember(1, 1)); + $this->assertFalse($groupMember->isMember(2, 1)); + } + + public function testBoth() + { + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); + $groupSync = new GroupSync($this->container); + + $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); + $this->assertEquals(2, $group->create('My Group 2', 'externalId2')); + $this->assertEquals(3, $group->create('My Group 3', 'externalId3')); + + $this->assertTrue($groupMember->addUser(1, 1)); + $this->assertTrue($groupMember->addUser(2, 1)); + + $this->assertTrue($groupMember->isMember(1, 1)); + $this->assertTrue($groupMember->isMember(2, 1)); + $this->assertFalse($groupMember->isMember(3, 1)); + + $groupSync->synchronize(1, array('externalId1', 'externalId3')); + + $this->assertTrue($groupMember->isMember(1, 1)); + $this->assertFalse($groupMember->isMember(2, 1)); + $this->assertTrue($groupMember->isMember(3, 1)); + } + + public function testThatInternalGroupsAreNotTouched() + { + $group = new GroupModel($this->container); + $groupMember = new GroupMemberModel($this->container); + $groupSync = new GroupSync($this->container); + + $this->assertEquals(1, $group->create('My Group 1')); + $this->assertTrue($groupMember->addUser(1, 1)); + $this->assertTrue($groupMember->isMember(1, 1)); + + $groupSync->synchronize(1, array('externalId3')); + + $this->assertTrue($groupMember->isMember(1, 1)); + } } diff --git a/tests/units/Core/User/UserProfileTest.php b/tests/units/Core/User/UserProfileTest.php index 4886a945..6dc627b7 100644 --- a/tests/units/Core/User/UserProfileTest.php +++ b/tests/units/Core/User/UserProfileTest.php @@ -58,6 +58,6 @@ class UserProfileTest extends Base $this->assertEquals('admin', $this->container['sessionStorage']->user['username']); $this->assertEquals('Bob', $this->container['sessionStorage']->user['name']); $this->assertEquals('', $this->container['sessionStorage']->user['email']); - $this->assertEquals(Role::APP_ADMIN, $this->container['sessionStorage']->user['role']); + $this->assertEquals(Role::APP_MANAGER, $this->container['sessionStorage']->user['role']); } } diff --git a/tests/units/Core/User/UserPropertyTest.php b/tests/units/Core/User/UserPropertyTest.php index 170eab4c..30e651cb 100644 --- a/tests/units/Core/User/UserPropertyTest.php +++ b/tests/units/Core/User/UserPropertyTest.php @@ -31,7 +31,7 @@ class UserPropertyTest extends Base $this->assertEquals($expected, UserProperty::getProperties($user)); } - public function testFilterProperties() + public function testFilterPropertiesDoNotOverrideExistingValue() { $profile = array( 'id' => 123, @@ -56,5 +56,83 @@ class UserPropertyTest extends Base ); $this->assertEquals($expected, UserProperty::filterProperties($profile, $properties)); + + $profile = array( + 'id' => 123, + 'username' => 'bob', + 'name' => null, + 'email' => '', + 'other_column' => 'myvalue', + 'role' => Role::APP_ADMIN, + ); + + $properties = array( + 'external_id' => '456', + 'username' => 'bobby', + 'name' => 'Bobby', + 'email' => 'admin@localhost', + 'role' => null, + ); + + $expected = array( + 'name' => 'Bobby', + 'email' => 'admin@localhost', + ); + + $this->assertEquals($expected, UserProperty::filterProperties($profile, $properties)); + } + + public function testFilterPropertiesOverrideExistingValueWhenNecessary() + { + $profile = array( + 'id' => 123, + 'username' => 'bob', + 'name' => null, + 'email' => '', + 'other_column' => 'myvalue', + 'role' => Role::APP_USER, + ); + + $properties = array( + 'external_id' => '456', + 'username' => 'bobby', + 'name' => 'Bobby', + 'email' => 'admin@localhost', + 'role' => Role::APP_MANAGER, + ); + + $expected = array( + 'name' => 'Bobby', + 'email' => 'admin@localhost', + 'role' => Role::APP_MANAGER, + ); + + $this->assertEquals($expected, UserProperty::filterProperties($profile, $properties)); + } + + public function testFilterPropertiesDoNotOverrideSameValue() + { + $profile = array( + 'id' => 123, + 'username' => 'bob', + 'name' => 'Bobby', + 'email' => 'admin@example.org', + 'other_column' => 'myvalue', + 'role' => Role::APP_MANAGER, + ); + + $properties = array( + 'external_id' => '456', + 'username' => 'bobby', + 'name' => 'Bobby', + 'email' => 'admin@localhost', + 'role' => Role::APP_MANAGER, + ); + + $expected = array( + 'email' => 'admin@localhost', + ); + + $this->assertEquals($expected, UserProperty::filterProperties($profile, $properties)); } } diff --git a/tests/units/Export/TaskExportTest.php b/tests/units/Export/TaskExportTest.php index f0637c25..c142cde9 100644 --- a/tests/units/Export/TaskExportTest.php +++ b/tests/units/Export/TaskExportTest.php @@ -2,21 +2,21 @@ require_once __DIR__ . '/../Base.php'; -use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskCreationModel; use Kanboard\Export\TaskExport; -use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\Swimlane; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\SwimlaneModel; class TaskExportTest extends Base { public function testExport() { - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); $e = new TaskExport($this->container); - $s = new Swimlane($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Export Project'))); diff --git a/tests/units/Export/TransitionExportTest.php b/tests/units/Export/TransitionExportTest.php index 7ff3082e..ee195ad1 100644 --- a/tests/units/Export/TransitionExportTest.php +++ b/tests/units/Export/TransitionExportTest.php @@ -2,18 +2,18 @@ require_once __DIR__ . '/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Transition; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TransitionModel; use Kanboard\Export\TransitionExport; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; class TransitionExportTest extends Base { public function testExport() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $transitionExportModel = new TransitionExport($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); diff --git a/tests/units/ExternalLink/AttachmentLinkProviderTest.php b/tests/units/ExternalLink/AttachmentLinkProviderTest.php index fe374664..9f56629e 100644 --- a/tests/units/ExternalLink/AttachmentLinkProviderTest.php +++ b/tests/units/ExternalLink/AttachmentLinkProviderTest.php @@ -28,13 +28,13 @@ class AttachmentLinkProviderTest extends Base { $attachmentLinkProvider = new AttachmentLinkProvider($this->container); - $attachmentLinkProvider->setUserTextInput('http://kanboard.net/FILE.DOC'); + $attachmentLinkProvider->setUserTextInput('https://kanboard.net/FILE.DOC'); $this->assertTrue($attachmentLinkProvider->match()); - $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.PDF'); + $attachmentLinkProvider->setUserTextInput('https://kanboard.net/folder/document.PDF'); $this->assertTrue($attachmentLinkProvider->match()); - $attachmentLinkProvider->setUserTextInput('http://kanboard.net/archive.zip'); + $attachmentLinkProvider->setUserTextInput('https://kanboard.net/archive.zip'); $this->assertTrue($attachmentLinkProvider->match()); $attachmentLinkProvider->setUserTextInput(' https://kanboard.net/folder/archive.tar '); @@ -46,13 +46,13 @@ class AttachmentLinkProviderTest extends Base $attachmentLinkProvider->setUserTextInput(''); $this->assertFalse($attachmentLinkProvider->match()); - $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.html'); + $attachmentLinkProvider->setUserTextInput('https://kanboard.net/folder/document.html'); $this->assertFalse($attachmentLinkProvider->match()); - $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/DOC.HTML'); + $attachmentLinkProvider->setUserTextInput('https://kanboard.net/folder/DOC.HTML'); $this->assertFalse($attachmentLinkProvider->match()); - $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.do'); + $attachmentLinkProvider->setUserTextInput('https://kanboard.net/folder/document.do'); $this->assertFalse($attachmentLinkProvider->match()); } diff --git a/tests/units/ExternalLink/WebLinkProviderTest.php b/tests/units/ExternalLink/WebLinkProviderTest.php index 95110ed8..8fc5766f 100644 --- a/tests/units/ExternalLink/WebLinkProviderTest.php +++ b/tests/units/ExternalLink/WebLinkProviderTest.php @@ -28,10 +28,10 @@ class WebLinkProviderTest extends Base { $webLinkProvider = new WebLinkProvider($this->container); - $webLinkProvider->setUserTextInput('http://kanboard.net/'); + $webLinkProvider->setUserTextInput('https://kanboard.net/'); $this->assertTrue($webLinkProvider->match()); - $webLinkProvider->setUserTextInput('http://kanboard.net/mypage'); + $webLinkProvider->setUserTextInput('https://kanboard.net/mypage'); $this->assertTrue($webLinkProvider->match()); $webLinkProvider->setUserTextInput(' https://kanboard.net/ '); diff --git a/tests/units/ExternalLink/WebLinkTest.php b/tests/units/ExternalLink/WebLinkTest.php index 85487e15..54046006 100644 --- a/tests/units/ExternalLink/WebLinkTest.php +++ b/tests/units/ExternalLink/WebLinkTest.php @@ -8,7 +8,7 @@ class WebLinkTest extends Base { public function testGetTitleFromHtml() { - $url = 'http://kanboard.net/something'; + $url = 'https://kanboard.net/something'; $title = 'My title'; $html = '<!DOCTYPE html><html><head><title> '.$title.' </title></head><body>Test</body></html>'; @@ -27,7 +27,7 @@ class WebLinkTest extends Base public function testGetTitleFromUrl() { - $url = 'http://kanboard.net/something'; + $url = 'https://kanboard.net/something'; $html = '<!DOCTYPE html><html><head></head><body>Test</body></html>'; $webLink = new WebLink($this->container); diff --git a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php index d679f285..716d58bd 100644 --- a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php +++ b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityCreationDateFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,14 +13,14 @@ class ProjectActivityCreationDateFilterTest extends Base { public function testWithToday() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('today'); @@ -33,14 +33,14 @@ class ProjectActivityCreationDateFilterTest extends Base public function testWithYesterday() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('yesterday'); @@ -51,16 +51,36 @@ class ProjectActivityCreationDateFilterTest extends Base $this->assertCount(0, $events); } + public function testWithStrtotimeString() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('<=last week'); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + } + public function testWithIsoDate() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter(date('Y-m-d')); @@ -73,14 +93,14 @@ class ProjectActivityCreationDateFilterTest extends Base public function testWithOperatorAndIsoDate() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreationDateFilter('>='.date('Y-m-d')); diff --git a/tests/units/Filter/ProjectActivityCreatorFilterTest.php b/tests/units/Filter/ProjectActivityCreatorFilterTest.php index 99c70322..65281d06 100644 --- a/tests/units/Filter/ProjectActivityCreatorFilterTest.php +++ b/tests/units/Filter/ProjectActivityCreatorFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityCreatorFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,14 +13,14 @@ class ProjectActivityCreatorFilterTest extends Base { public function testWithUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('admin'); @@ -32,14 +32,14 @@ class ProjectActivityCreatorFilterTest extends Base public function testWithAnotherUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('John Doe'); @@ -51,14 +51,14 @@ class ProjectActivityCreatorFilterTest extends Base public function testWithCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('me'); @@ -71,14 +71,14 @@ class ProjectActivityCreatorFilterTest extends Base public function testWithAnotherCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); $query = $projectActivityModel->getQuery(); $filter = new ProjectActivityCreatorFilter('me'); diff --git a/tests/units/Filter/ProjectActivityProjectIdFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php index 193852e1..75e6fa70 100644 --- a/tests/units/Filter/ProjectActivityProjectIdFilterTest.php +++ b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityProjectIdFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,10 +13,10 @@ class ProjectActivityProjectIdFilterTest extends Base { public function testFilterByProjectId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -25,8 +25,8 @@ class ProjectActivityProjectIdFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityProjectIdFilter(1); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php index e99d2e2f..b5c4683d 100644 --- a/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php +++ b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityProjectIdsFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,10 +13,10 @@ class ProjectActivityProjectIdsFilterTest extends Base { public function testFilterByProjectIds() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -27,9 +27,9 @@ class ProjectActivityProjectIdsFilterTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); - $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); $filter = new ProjectActivityProjectIdsFilter(array(1, 2)); $filter->withQuery($query)->apply(); @@ -38,10 +38,10 @@ class ProjectActivityProjectIdsFilterTest extends Base public function testWithEmptyArgument() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -52,9 +52,9 @@ class ProjectActivityProjectIdsFilterTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, $taskFinder->getById(1))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, $taskFinder->getById(2))); - $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, $taskFinder->getById(3))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, $taskFinder->getById(1))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, $taskFinder->getById(2))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, TaskModel::EVENT_CREATE, $taskFinder->getById(3))); $filter = new ProjectActivityProjectIdsFilter(array()); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityProjectNameFilterTest.php b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php index de9d7d59..3ec01bc0 100644 --- a/tests/units/Filter/ProjectActivityProjectNameFilterTest.php +++ b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityProjectNameFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,10 +13,10 @@ class ProjectActivityProjectNameFilterTest extends Base { public function testFilterByProjectName() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -25,8 +25,8 @@ class ProjectActivityProjectNameFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityProjectNameFilter('P1'); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityTaskIdFilterTest.php b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php index 646cab1b..940d1c6f 100644 --- a/tests/units/Filter/ProjectActivityTaskIdFilterTest.php +++ b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityTaskIdFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,10 +13,10 @@ class ProjectActivityTaskIdFilterTest extends Base { public function testFilterByTaskId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -24,8 +24,8 @@ class ProjectActivityTaskIdFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskIdFilter(1); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php index b8df6338..673a4990 100644 --- a/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php +++ b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php @@ -1,12 +1,12 @@ <?php use Kanboard\Filter\ProjectActivityTaskStatusFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; -use Kanboard\Model\TaskStatus; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskStatusModel; require_once __DIR__.'/../Base.php'; @@ -14,19 +14,19 @@ class ProjectActivityTaskStatusFilterTest extends Base { public function testFilterByTaskStatus() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $taskStatus = new TaskStatus($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskStatus = new TaskStatusModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $this->assertTrue($taskStatus->close(1)); diff --git a/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php index 925a1ab2..f6217dba 100644 --- a/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php +++ b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Filter\ProjectActivityTaskTitleFilter; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Task; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskModel; require_once __DIR__.'/../Base.php'; @@ -13,10 +13,10 @@ class ProjectActivityTaskTitleFilterTest extends Base { public function testWithFullTitle() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -24,8 +24,8 @@ class ProjectActivityTaskTitleFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskTitleFilter('test2'); $filter->withQuery($query)->apply(); @@ -34,10 +34,10 @@ class ProjectActivityTaskTitleFilterTest extends Base public function testWithPartialTitle() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -45,8 +45,8 @@ class ProjectActivityTaskTitleFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskTitleFilter('test'); $filter->withQuery($query)->apply(); @@ -55,10 +55,10 @@ class ProjectActivityTaskTitleFilterTest extends Base public function testWithId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $query = $projectActivityModel->getQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -66,8 +66,8 @@ class ProjectActivityTaskTitleFilterTest extends Base $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $filter = new ProjectActivityTaskTitleFilter('#2'); $filter->withQuery($query)->apply(); diff --git a/tests/units/Filter/TaskAssigneeFilterTest.php b/tests/units/Filter/TaskAssigneeFilterTest.php index 356342c5..dec3824e 100644 --- a/tests/units/Filter/TaskAssigneeFilterTest.php +++ b/tests/units/Filter/TaskAssigneeFilterTest.php @@ -1,10 +1,10 @@ <?php use Kanboard\Filter\TaskAssigneeFilter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\User; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\UserModel; require_once __DIR__.'/../Base.php'; @@ -12,9 +12,9 @@ class TaskAssigneeFilterTest extends Base { public function testWithIntegerAssigneeId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -37,9 +37,9 @@ class TaskAssigneeFilterTest extends Base public function testWithStringAssigneeId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -62,9 +62,9 @@ class TaskAssigneeFilterTest extends Base public function testWithUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -87,10 +87,10 @@ class TaskAssigneeFilterTest extends Base public function testWithName() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); @@ -114,9 +114,9 @@ class TaskAssigneeFilterTest extends Base public function testWithNobody() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -132,9 +132,9 @@ class TaskAssigneeFilterTest extends Base public function testWithCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); diff --git a/tests/units/Filter/TaskCommentFilterTest.php b/tests/units/Filter/TaskCommentFilterTest.php index 8d1b7f44..95ffb32f 100644 --- a/tests/units/Filter/TaskCommentFilterTest.php +++ b/tests/units/Filter/TaskCommentFilterTest.php @@ -1,10 +1,10 @@ <?php use Kanboard\Filter\TaskCommentFilter; -use Kanboard\Model\Comment; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\CommentModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; require_once __DIR__.'/../Base.php'; @@ -12,10 +12,10 @@ class TaskCommentFilterTest extends Base { public function testMatch() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $commentModel = new Comment($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $commentModel = new CommentModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -32,10 +32,10 @@ class TaskCommentFilterTest extends Base public function testNoMatch() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $commentModel = new Comment($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $commentModel = new CommentModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); diff --git a/tests/units/Filter/TaskCreatorFilterTest.php b/tests/units/Filter/TaskCreatorFilterTest.php index 1c344de7..b5abe6cf 100644 --- a/tests/units/Filter/TaskCreatorFilterTest.php +++ b/tests/units/Filter/TaskCreatorFilterTest.php @@ -1,10 +1,10 @@ <?php use Kanboard\Filter\TaskCreatorFilter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\User; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\UserModel; require_once __DIR__.'/../Base.php'; @@ -12,9 +12,9 @@ class TaskCreatorFilterTest extends Base { public function testWithIntegerAssigneeId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -37,9 +37,9 @@ class TaskCreatorFilterTest extends Base public function testWithStringAssigneeId() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -62,9 +62,9 @@ class TaskCreatorFilterTest extends Base public function testWithUsername() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -87,10 +87,10 @@ class TaskCreatorFilterTest extends Base public function testWithName() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); @@ -114,9 +114,9 @@ class TaskCreatorFilterTest extends Base public function testWithNobody() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -132,9 +132,9 @@ class TaskCreatorFilterTest extends Base public function testWithCurrentUser() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); $query = $taskFinder->getExtendedQuery(); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); diff --git a/tests/units/Helper/AssetHelperTest.php b/tests/units/Helper/AssetHelperTest.php index 6ef5accd..da780c4b 100644 --- a/tests/units/Helper/AssetHelperTest.php +++ b/tests/units/Helper/AssetHelperTest.php @@ -3,14 +3,14 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\AssetHelper; -use Kanboard\Model\Config; +use Kanboard\Model\ConfigModel; class AssetHelperTest extends Base { public function testCustomCss() { $h = new AssetHelper($this->container); - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEmpty($h->customCss()); diff --git a/tests/units/Helper/MailHelperTest.php b/tests/units/Helper/MailHelperTest.php new file mode 100644 index 00000000..b2d4ba6e --- /dev/null +++ b/tests/units/Helper/MailHelperTest.php @@ -0,0 +1,35 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Helper\MailHelper; + +class MailHelperTest extends Base +{ + public function testMailboxHash() + { + $helper = new MailHelper($this->container); + $this->assertEquals('test1', $helper->getMailboxHash('a+test1@localhost')); + $this->assertEquals('', $helper->getMailboxHash('test1@localhost')); + $this->assertEquals('', $helper->getMailboxHash('test1')); + } + + public function testFilterSubject() + { + $helper = new MailHelper($this->container); + $this->assertEquals('Test', $helper->filterSubject('Test')); + $this->assertEquals('Test', $helper->filterSubject('RE: Test')); + $this->assertEquals('Test', $helper->filterSubject('FW: Test')); + } + + public function testGetSenderAddress() + { + $helper = new MailHelper($this->container); + $this->assertEquals('notifications@kanboard.local', $helper->getMailSenderAddress()); + + $this->container['configModel']->save(array('mail_sender_address' => 'me@here')); + $this->container['memoryCache']->flush(); + + $this->assertEquals('me@here', $helper->getMailSenderAddress()); + } +} diff --git a/tests/units/Helper/ProjectActivityHelperTest.php b/tests/units/Helper/ProjectActivityHelperTest.php index 88b2d352..1ad95699 100644 --- a/tests/units/Helper/ProjectActivityHelperTest.php +++ b/tests/units/Helper/ProjectActivityHelperTest.php @@ -1,11 +1,11 @@ <?php use Kanboard\Helper\ProjectActivityHelper; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; require_once __DIR__.'/../Base.php'; @@ -13,10 +13,10 @@ class ProjectActivityHelperTest extends Base { public function testGetProjectEvents() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); @@ -24,9 +24,9 @@ class ProjectActivityHelperTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 3, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); $helper = new ProjectActivityHelper($this->container); $events = $helper->getProjectEvents(1); @@ -41,10 +41,10 @@ class ProjectActivityHelperTest extends Base public function testGetProjectsEvents() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); @@ -54,9 +54,9 @@ class ProjectActivityHelperTest extends Base $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); - $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); $helper = new ProjectActivityHelper($this->container); $events = $helper->getProjectsEvents(array(1, 2)); @@ -71,18 +71,18 @@ class ProjectActivityHelperTest extends Base public function testGetTaskEvents() { - $taskFinder = new TaskFinder($this->container); - $taskCreation = new TaskCreation($this->container); - $projectModel = new Project($this->container); - $projectActivityModel = new ProjectActivity($this->container); + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectActivityModel = new ProjectActivityModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); - $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, TaskModel::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); $helper = new ProjectActivityHelper($this->container); $events = $helper->getTaskEvents(1); diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index d7324dfd..c9447abb 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -3,30 +3,43 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\TextHelper; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; class TextHelperTest extends Base { public function testMarkdownTaskLink() { - $h = new TextHelper($this->container); + $helper = new TextHelper($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertTrue($projectModel->enablePublicAccess(1)); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1))); + $project = $projectModel->getById(1); - $this->assertEquals('<p>Test</p>', $h->markdown('Test')); + $this->assertEquals('<p>Test</p>', $helper->markdown('Test')); + + $this->assertEquals( + '<p>Task <a href="?controller=TaskViewController&action=show&task_id=123">#123</a></p>', + $helper->markdown('Task #123') + ); $this->assertEquals( '<p>Task #123</p>', - $h->markdown('Task #123') + $helper->markdown('Task #123', true) ); $this->assertEquals( - '<p>Task <a href="?controller=a&action=b&c=d&task_id=123">#123</a></p>', - $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))) + '<p>Task <a href="?controller=TaskViewController&action=readonly&token='.$project['token'].'&task_id=1">#1</a></p>', + $helper->markdown('Task #1', true) ); $this->assertEquals( '<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>', - $h->markdown( - 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454', - array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')) + $helper->markdown( + 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454' ) ); } @@ -34,7 +47,16 @@ class TextHelperTest extends Base public function testMarkdownUserLink() { $h = new TextHelper($this->container); - $this->assertEquals('<p>Text <a href="?controller=user&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound')); + $this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound')); + $this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true)); + } + + public function testMarkdownAttribute() + { + $helper = new TextHelper($this->container); + $this->assertEquals('<p>Ça marche</p>', $helper->markdownAttribute('Ça marche')); + $this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $helper->markdownAttribute('Test with "double quotes"')); + $this->assertEquals('<p>Test with 'single quotes'</p>', $helper->markdownAttribute("Test with 'single quotes'")); } public function testFormatBytes() diff --git a/tests/units/Helper/UrlHelperTest.php b/tests/units/Helper/UrlHelperTest.php index 34ab7604..b1f0a032 100644 --- a/tests/units/Helper/UrlHelperTest.php +++ b/tests/units/Helper/UrlHelperTest.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\UrlHelper; -use Kanboard\Model\Config; +use Kanboard\Model\ConfigModel; use Kanboard\Core\Http\Request; class UrlHelperTest extends Base @@ -115,7 +115,7 @@ class UrlHelperTest extends Base $h = new UrlHelper($this->container); $this->assertEquals('http://kb:1234/', $h->base()); - $c = new Config($this->container); + $c = new ConfigModel($this->container); $c->save(array('application_url' => 'https://mykanboard/')); $this->container['memoryCache']->flush(); diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index 9a9832b2..10bbc58e 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -2,11 +2,14 @@ require_once __DIR__.'/../Base.php'; +use Kanboard\Core\User\UserSession; use Kanboard\Helper\UserHelper; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\User as UserModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; use Kanboard\Core\Security\Role; +use Kanboard\Model\UserModel; class UserHelperTest extends Base { @@ -17,6 +20,7 @@ class UserHelperTest extends Base $this->assertEquals('CN', $helper->getInitials('chuck norris')); $this->assertEquals('CN', $helper->getInitials('chuck norris #2')); $this->assertEquals('A', $helper->getInitials('admin')); + $this->assertEquals('Ü君', $helper->getInitials('Ü 君が代')); } public function testGetRoleName() @@ -36,9 +40,9 @@ class UserHelperTest extends Base 'role' => Role::APP_ADMIN, ); - $this->assertTrue($helper->hasAccess('user', 'create')); - $this->assertTrue($helper->hasAccess('ProjectCreation', 'create')); - $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + $this->assertTrue($helper->hasAccess('UserCreationController', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreationController', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate')); } public function testHasAccessForManagers() @@ -50,9 +54,9 @@ class UserHelperTest extends Base 'role' => Role::APP_MANAGER, ); - $this->assertFalse($helper->hasAccess('user', 'create')); - $this->assertTrue($helper->hasAccess('ProjectCreation', 'create')); - $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + $this->assertFalse($helper->hasAccess('UserCreationController', 'show')); + $this->assertTrue($helper->hasAccess('ProjectCreationController', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate')); } public function testHasAccessForUsers() @@ -64,15 +68,15 @@ class UserHelperTest extends Base 'role' => Role::APP_USER, ); - $this->assertFalse($helper->hasAccess('user', 'create')); - $this->assertFalse($helper->hasAccess('ProjectCreation', 'create')); - $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + $this->assertFalse($helper->hasAccess('UserCreationController', 'show')); + $this->assertFalse($helper->hasAccess('ProjectCreationController', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate')); } public function testHasProjectAccessForAdmins() { $helper = new UserHelper($this->container); - $project = new Project($this->container); + $project = new ProjectModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -81,14 +85,14 @@ class UserHelperTest extends Base $this->assertEquals(1, $project->create(array('name' => 'My project'))); - $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('BoardViewController', 'show', 1)); } public function testHasProjectAccessForManagers() { $helper = new UserHelper($this->container); - $project = new Project($this->container); + $project = new ProjectModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -97,14 +101,14 @@ class UserHelperTest extends Base $this->assertEquals(1, $project->create(array('name' => 'My project'))); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 1)); } public function testHasProjectAccessForUsers() { $helper = new UserHelper($this->container); - $project = new Project($this->container); + $project = new ProjectModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -113,16 +117,16 @@ class UserHelperTest extends Base $this->assertEquals(1, $project->create(array('name' => 'My project'))); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 1)); } public function testHasProjectAccessForAppManagerAndProjectManagers() { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -134,23 +138,23 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); - $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + $this->assertTrue($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('BoardViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('TaskViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreationcontroller', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); - $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); } public function testHasProjectAccessForProjectManagers() { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -162,23 +166,23 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); - $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + $this->assertTrue($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('BoardViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('TaskViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('TaskCreationController', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); - $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); } public function testHasProjectAccessForProjectMembers() { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -190,23 +194,23 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('BoardViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('TaskViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('TaskCreationController', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); - $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); } public function testHasProjectAccessForProjectViewers() { $helper = new UserHelper($this->container); $user = new UserModel($this->container); - $project = new Project($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $project = new ProjectModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -218,14 +222,104 @@ class UserHelperTest extends Base $this->assertEquals(2, $user->create(array('username' => 'user'))); $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); - $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); - $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); - $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 1)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('BoardViewController', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('TaskViewController', 'show', 1)); + $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 1)); - $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); - $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); - $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); + $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('BoardViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskViewController', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); + } + + public function testCanRemoveTask() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $helper = new UserHelper($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userSessionModel = new UserSession($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456'))); + $this->assertNotFalse($userModel->create(array('username' => 'toto2', 'password' => '123456'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'TaskViewController #1', 'project_id' => 1, 'creator_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'TaskViewController #2', 'project_id' => 1, 'creator_id' => 2))); + $this->assertEquals(3, $taskCreationModel->create(array('title' => 'TaskViewController #3', 'project_id' => 1, 'creator_id' => 3))); + $this->assertEquals(4, $taskCreationModel->create(array('title' => 'TaskViewController #4', 'project_id' => 1))); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertTrue($helper->canRemoveTask($task)); + + // User #2 can't remove the TaskViewController #1 + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertFalse($helper->canRemoveTask($task)); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertTrue($helper->canRemoveTask($task)); + + // User #2 can remove his own TaskViewController + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertTrue($helper->canRemoveTask($task)); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(3); + $this->assertNotEmpty($task); + $this->assertTrue($helper->canRemoveTask($task)); + + // User #2 can't remove the TaskViewController #3 + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(3); + $this->assertNotEmpty($task); + $this->assertFalse($helper->canRemoveTask($task)); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(4); + $this->assertNotEmpty($task); + $this->assertTrue($helper->canRemoveTask($task)); + + // User #2 can't remove the TaskViewController #4 + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(4); + $this->assertNotEmpty($task); + $this->assertFalse($helper->canRemoveTask($task)); } } diff --git a/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php b/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php new file mode 100644 index 00000000..0a0c8783 --- /dev/null +++ b/tests/units/Middleware/ApplicationAuthorizationMiddlewareTest.php @@ -0,0 +1,65 @@ +<?php + +use Kanboard\Middleware\ApplicationAuthorizationMiddleware; + +require_once __DIR__.'/../Base.php'; + +class ApplicationAuthorizationMiddlewareMiddlewareTest extends Base +{ + /** + * @var ApplicationAuthorizationMiddleware + */ + private $middleware; + private $nextMiddleware; + + public function setUp() + { + parent::setUp(); + + $this->container['helper'] = new stdClass(); + + $this->container['helper']->user = $this + ->getMockBuilder('Kanboard\Helper\UserHelper') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('hasAccess')) + ->getMock(); + + $this->nextMiddleware = $this + ->getMockBuilder('Kanboard\Middleware\ApplicationAuthorizationMiddleware') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('execute')) + ->getMock(); + + $this->middleware = new ApplicationAuthorizationMiddleware($this->container); + $this->middleware->setNextMiddleware($this->nextMiddleware); + } + + public function testWithAccessDenied() + { + $this->container['helper']->user + ->expects($this->once()) + ->method('hasAccess') + ->will($this->returnValue(false)); + + $this->nextMiddleware + ->expects($this->never()) + ->method('execute'); + + $this->setExpectedException('Kanboard\Core\Controller\AccessForbiddenException'); + $this->middleware->execute(); + } + + public function testWithAccessGranted() + { + $this->container['helper']->user + ->expects($this->once()) + ->method('hasAccess') + ->will($this->returnValue(true)); + + $this->nextMiddleware + ->expects($this->once()) + ->method('execute'); + + $this->middleware->execute(); + } +} diff --git a/tests/units/Middleware/AuthenticationMiddlewareTest.php b/tests/units/Middleware/AuthenticationMiddlewareTest.php new file mode 100644 index 00000000..b6819adc --- /dev/null +++ b/tests/units/Middleware/AuthenticationMiddlewareTest.php @@ -0,0 +1,141 @@ +<?php + +use Kanboard\Middleware\AuthenticationMiddleware; + +require_once __DIR__.'/../Base.php'; + +class AuthenticationMiddlewareTest extends Base +{ + /** + * @var AuthenticationMiddleware + */ + private $middleware; + private $nextMiddleware; + + public function setUp() + { + parent::setUp(); + + $this->container['authenticationManager'] = $this + ->getMockBuilder('Kanboard\Core\Security\AuthenticationManager') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('checkCurrentSession')) + ->getMock(); + + $this->container['applicationAuthorization'] = $this + ->getMockBuilder('Kanboard\Core\Security\AccessMap') + ->setMethods(array('isAllowed')) + ->getMock(); + + $this->container['response'] = $this + ->getMockBuilder('Kanboard\Core\Http\Response') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('redirect')) + ->getMock(); + + $this->container['userSession'] = $this + ->getMockBuilder('Kanboard\Core\User\UserSession') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('isLogged')) + ->getMock(); + + $this->nextMiddleware = $this + ->getMockBuilder('Kanboard\Middleware\AuthenticationMiddleware') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('execute')) + ->getMock(); + + $this->middleware = new AuthenticationMiddleware($this->container); + $this->middleware->setNextMiddleware($this->nextMiddleware); + } + + public function testWithBadSession() + { + $this->container['authenticationManager'] + ->expects($this->once()) + ->method('checkCurrentSession') + ->will($this->returnValue(false)); + + $this->nextMiddleware + ->expects($this->never()) + ->method('execute'); + + $this->setExpectedException('Kanboard\Core\Controller\AccessForbiddenException'); + $this->middleware->execute(); + } + + public function testWithPublicAction() + { + $this->container['authenticationManager'] + ->expects($this->once()) + ->method('checkCurrentSession') + ->will($this->returnValue(true)); + + $this->container['applicationAuthorization'] + ->expects($this->once()) + ->method('isAllowed') + ->will($this->returnValue(true)); + + $this->nextMiddleware + ->expects($this->never()) + ->method('execute'); + + $this->middleware->execute(); + } + + public function testWithNotAuthenticatedUser() + { + $this->container['authenticationManager'] + ->expects($this->once()) + ->method('checkCurrentSession') + ->will($this->returnValue(true)); + + $this->container['applicationAuthorization'] + ->expects($this->once()) + ->method('isAllowed') + ->will($this->returnValue(false)); + + $this->container['userSession'] + ->expects($this->once()) + ->method('isLogged') + ->will($this->returnValue(false)); + + $this->container['response'] + ->expects($this->once()) + ->method('redirect'); + + $this->nextMiddleware + ->expects($this->never()) + ->method('execute'); + + $this->middleware->execute(); + } + + public function testWithAuthenticatedUser() + { + $this->container['authenticationManager'] + ->expects($this->once()) + ->method('checkCurrentSession') + ->will($this->returnValue(true)); + + $this->container['applicationAuthorization'] + ->expects($this->once()) + ->method('isAllowed') + ->will($this->returnValue(false)); + + $this->container['userSession'] + ->expects($this->once()) + ->method('isLogged') + ->will($this->returnValue(true)); + + $this->container['response'] + ->expects($this->never()) + ->method('redirect'); + + $this->nextMiddleware + ->expects($this->once()) + ->method('execute'); + + $this->middleware->execute(); + } +} diff --git a/tests/units/Middleware/ProjectAuthorizationMiddlewareTest.php b/tests/units/Middleware/ProjectAuthorizationMiddlewareTest.php new file mode 100644 index 00000000..256f0a4d --- /dev/null +++ b/tests/units/Middleware/ProjectAuthorizationMiddlewareTest.php @@ -0,0 +1,81 @@ +<?php + +use Kanboard\Middleware\ProjectAuthorizationMiddleware; + +require_once __DIR__.'/../Base.php'; + +class ProjectAuthorizationMiddlewareMiddlewareTest extends Base +{ + /** + * @var ProjectAuthorizationMiddleware + */ + private $middleware; + private $nextMiddleware; + + public function setUp() + { + parent::setUp(); + + $this->container['helper'] = new stdClass(); + + $this->container['helper']->user = $this + ->getMockBuilder('Kanboard\Helper\UserHelper') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('hasProjectAccess')) + ->getMock(); + + $this->container['request'] = $this + ->getMockBuilder('Kanboard\Core\Http\Request') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getIntegerParam')) + ->getMock(); + + $this->nextMiddleware = $this + ->getMockBuilder('Kanboard\Middleware\ProjectAuthorizationMiddleware') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('execute')) + ->getMock(); + + $this->middleware = new ProjectAuthorizationMiddleware($this->container); + $this->middleware->setNextMiddleware($this->nextMiddleware); + } + + public function testWithAccessDenied() + { + $this->container['request'] + ->expects($this->any()) + ->method('getIntegerParam') + ->will($this->returnValue(123)); + + $this->container['helper']->user + ->expects($this->once()) + ->method('hasProjectAccess') + ->will($this->returnValue(false)); + + $this->nextMiddleware + ->expects($this->never()) + ->method('execute'); + + $this->setExpectedException('Kanboard\Core\Controller\AccessForbiddenException'); + $this->middleware->execute(); + } + + public function testWithAccessGranted() + { + $this->container['request'] + ->expects($this->any()) + ->method('getIntegerParam') + ->will($this->returnValue(123)); + + $this->container['helper']->user + ->expects($this->once()) + ->method('hasProjectAccess') + ->will($this->returnValue(true)); + + $this->nextMiddleware + ->expects($this->once()) + ->method('execute'); + + $this->middleware->execute(); + } +} diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php index ed687846..5db18983 100644 --- a/tests/units/Model/ActionTest.php +++ b/tests/units/Model/ActionTest.php @@ -2,27 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Action; -use Kanboard\Model\Project; -use Kanboard\Model\Task; -use Kanboard\Model\User; -use Kanboard\Model\Column; -use Kanboard\Model\Category; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ActionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Core\Security\Role; class ActionTest extends Base { public function testCreate() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -30,14 +30,14 @@ class ActionTest extends Base public function testRemove() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -49,14 +49,14 @@ class ActionTest extends Base public function testGetById() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -65,28 +65,28 @@ class ActionTest extends Base $this->assertNotEmpty($action); $this->assertEquals(1, $action['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $action['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $action['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']); } public function testGetAll() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 6, 'color_id' => 'blue'), ))); @@ -96,33 +96,33 @@ class ActionTest extends Base $this->assertEquals(1, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); $this->assertEquals(2, $actions[1]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[1]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[1]['event_name']); $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']); } public function testGetAllByProject() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 6, 'color_id' => 'blue'), ))); @@ -132,7 +132,7 @@ class ActionTest extends Base $this->assertEquals(1, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); @@ -141,16 +141,16 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); } public function testGetAllByUser() { - $projectModel = new Project($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -165,21 +165,21 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 2, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 6, 'color_id' => 'blue'), ))); $this->assertEquals(3, $actionModel->create(array( 'project_id' => 3, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 10, 'color_id' => 'green'), ))); @@ -192,7 +192,7 @@ class ActionTest extends Base $this->assertEquals(1, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); $actions = $actionModel->getAllByUser(3); @@ -200,21 +200,21 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); } public function testDuplicateWithColumnAndColorParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); @@ -226,21 +226,21 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); } public function testDuplicateWithColumnsParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3), ))); @@ -252,15 +252,15 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']); } public function testDuplicateWithColumnParameterNotfound() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -269,14 +269,14 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE, + 'event_name' => TaskModel::EVENT_CREATE, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); $this->assertEquals(2, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', 'params' => array('column_id' => 2, 'color_id' => 'green'), ))); @@ -288,14 +288,14 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); } public function testDuplicateWithProjectParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -303,7 +303,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CLOSE, + 'event_name' => TaskModel::EVENT_CLOSE, 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', 'params' => array('column_id' => 1, 'project_id' => 3), ))); @@ -315,21 +315,21 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CLOSE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CLOSE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']); } public function testDuplicateWithProjectParameterIdenticalToDestination() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CLOSE, + 'event_name' => TaskModel::EVENT_CLOSE, 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', 'params' => array('column_id' => 1, 'project_id' => 2), ))); @@ -342,10 +342,10 @@ class ActionTest extends Base public function testDuplicateWithUserParameter() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -357,7 +357,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2), ))); @@ -369,16 +369,16 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_MOVE_COLUMN, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']); } public function testDuplicateWithUserParameterButNotAssignable() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -390,7 +390,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2), ))); @@ -403,10 +403,10 @@ class ActionTest extends Base public function testDuplicateWithUserParameterButNotAvailable() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -417,7 +417,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'owner_id' => 2), ))); @@ -430,9 +430,9 @@ class ActionTest extends Base public function testDuplicateWithCategoryParameter() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -442,7 +442,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1), ))); @@ -454,15 +454,15 @@ class ActionTest extends Base $this->assertEquals(2, $actions[0]['project_id']); $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']); - $this->assertEquals(Task::EVENT_CREATE_UPDATE, $actions[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CREATE_UPDATE, $actions[0]['event_name']); $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']); } public function testDuplicateWithCategoryParameterButDifferentName() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -472,7 +472,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1), ))); @@ -485,9 +485,9 @@ class ActionTest extends Base public function testDuplicateWithCategoryParameterButNotFound() { - $projectModel = new Project($this->container); - $actionModel = new Action($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); @@ -496,7 +496,7 @@ class ActionTest extends Base $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', 'params' => array('column_id' => 1, 'category_id' => 1), ))); diff --git a/tests/units/Model/BoardTest.php b/tests/units/Model/BoardTest.php index bb0778ce..80587d89 100644 --- a/tests/units/Model/BoardTest.php +++ b/tests/units/Model/BoardTest.php @@ -2,22 +2,21 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\Board; -use Kanboard\Model\Column; -use Kanboard\Model\Config; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Swimlane; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\BoardModel; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\SwimlaneModel; class BoardTest extends Base { public function testCreation() { - $p = new Project($this->container); - $b = new Board($this->container); - $columnModel = new Column($this->container); - $c = new Config($this->container); + $p = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); + $c = new ConfigModel($this->container); // Default columns @@ -49,8 +48,8 @@ class BoardTest extends Base public function testGetBoard() { - $p = new Project($this->container); - $b = new Board($this->container); + $p = new ProjectModel($this->container); + $b = new BoardModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); @@ -70,11 +69,11 @@ class BoardTest extends Base public function testGetBoardWithSwimlane() { - $b = new Board($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $b = new BoardModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1'))); diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php index 600007d0..1fdc51f6 100644 --- a/tests/units/Model/CategoryTest.php +++ b/tests/units/Model/CategoryTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Category; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; class CategoryTest extends Base { public function testCreation() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -33,8 +33,8 @@ class CategoryTest extends Base public function testExists() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -44,8 +44,8 @@ class CategoryTest extends Base public function testGetById() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($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'))); @@ -59,8 +59,8 @@ class CategoryTest extends Base public function testGetNameById() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($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'))); @@ -71,8 +71,8 @@ class CategoryTest extends Base public function testGetIdByName() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($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'))); @@ -83,8 +83,8 @@ class CategoryTest extends Base public function testGetList() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($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'))); @@ -117,8 +117,8 @@ class CategoryTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($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'))); @@ -140,9 +140,9 @@ class CategoryTest extends Base public function testCreateDefaultCategories() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); - $configModel = new Config($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + $configModel = new ConfigModel($this->container); $this->assertTrue($configModel->save(array('project_categories' => 'C1, C2, C3'))); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); @@ -157,8 +157,8 @@ class CategoryTest extends Base public function testUpdate() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -172,10 +172,10 @@ class CategoryTest extends Base public function testRemove() { - $taskCreationModel = new TaskCreation($this->container); - $taskFinderModel = new TaskFinder($this->container); - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); @@ -195,8 +195,8 @@ class CategoryTest extends Base public function testDuplicate() { - $projectModel = new Project($this->container); - $categoryModel = new Category($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); diff --git a/tests/units/Model/ColorTest.php b/tests/units/Model/ColorTest.php index e96ecb6b..2a2c4b87 100644 --- a/tests/units/Model/ColorTest.php +++ b/tests/units/Model/ColorTest.php @@ -2,14 +2,14 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Color; -use Kanboard\Model\Config; +use Kanboard\Model\ColorModel; +use Kanboard\Model\ConfigModel; class ColorTest extends Base { public function testFind() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $this->assertEquals('yellow', $colorModel->find('yellow')); $this->assertEquals('yellow', $colorModel->find('Yellow')); $this->assertEquals('dark_grey', $colorModel->find('Dark Grey')); @@ -18,7 +18,7 @@ class ColorTest extends Base public function testGetColorProperties() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $expected = array( 'name' => 'Light Green', 'background' => '#dcedc8', @@ -38,7 +38,7 @@ class ColorTest extends Base public function testGetList() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $colors = $colorModel->getList(); $this->assertCount(16, $colors); @@ -52,8 +52,8 @@ class ColorTest extends Base public function testGetDefaultColor() { - $colorModel = new Color($this->container); - $configModel = new Config($this->container); + $colorModel = new ColorModel($this->container); + $configModel = new ConfigModel($this->container); $this->assertEquals('yellow', $colorModel->getDefaultColor()); @@ -64,7 +64,7 @@ class ColorTest extends Base public function testGetDefaultColors() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $colors = $colorModel->getDefaultColors(); $this->assertCount(16, $colors); @@ -72,19 +72,19 @@ class ColorTest extends Base public function testGetBorderColor() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $this->assertEquals('rgb(74, 227, 113)', $colorModel->getBorderColor('green')); } public function testGetBackgroundColor() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $this->assertEquals('rgb(189, 244, 203)', $colorModel->getBackgroundColor('green')); } public function testGetCss() { - $colorModel = new Color($this->container); + $colorModel = new ColorModel($this->container); $css = $colorModel->getCss(); $this->assertStringStartsWith('div.color-yellow {', $css); diff --git a/tests/units/Model/ColumnTest.php b/tests/units/Model/ColumnTest.php index e40f89c6..7340a274 100644 --- a/tests/units/Model/ColumnTest.php +++ b/tests/units/Model/ColumnTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\Column; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ColumnModel; class ColumnTest extends Base { public function testGetColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -24,8 +24,8 @@ class ColumnTest extends Base public function testGetFirstColumnId() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $columnModel->getFirstColumnId(1)); @@ -33,8 +33,8 @@ class ColumnTest extends Base public function testGetLastColumnId() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(4, $columnModel->getLastColumnId(1)); @@ -42,8 +42,8 @@ class ColumnTest extends Base public function testGetLastColumnPosition() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(4, $columnModel->getLastColumnPosition(1)); @@ -51,8 +51,8 @@ class ColumnTest extends Base public function testGetColumnIdByTitle() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $columnModel->getColumnIdByTitle(1, 'Ready')); @@ -60,8 +60,8 @@ class ColumnTest extends Base public function testGetTitleByColumnId() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals('Work in progress', $columnModel->getColumnTitleById(3)); @@ -69,8 +69,8 @@ class ColumnTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -96,8 +96,8 @@ class ColumnTest extends Base public function testGetList() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -119,8 +119,8 @@ class ColumnTest extends Base public function testAddColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertNotFalse($columnModel->create(1, 'another column')); @@ -142,8 +142,8 @@ class ColumnTest extends Base public function testUpdateColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -163,8 +163,8 @@ class ColumnTest extends Base public function testRemoveColumn() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($columnModel->remove(3)); @@ -177,8 +177,8 @@ class ColumnTest extends Base public function testChangePosition() { - $projectModel = new Project($this->container); - $columnModel = new Column($this->container); + $projectModel = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php index bb96e4f4..7250ae0b 100644 --- a/tests/units/Model/CommentTest.php +++ b/tests/units/Model/CommentTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\Comment; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CommentModel; class CommentTest extends Base { public function testCreate() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); @@ -38,9 +38,9 @@ class CommentTest extends Base public function testGetAll() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); @@ -61,9 +61,9 @@ class CommentTest extends Base public function testUpdate() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); @@ -77,9 +77,9 @@ class CommentTest extends Base public function validateRemove() { - $c = new Comment($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); + $c = new CommentModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php index 6ccdbef9..3345ee3e 100644 --- a/tests/units/Model/ConfigTest.php +++ b/tests/units/Model/ConfigTest.php @@ -2,73 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; +use Kanboard\Model\ConfigModel; class ConfigTest extends Base { - public function testGetTimezones() - { - $configModel = new Config($this->container); - $this->assertNotEmpty($configModel->getTimezones()); - $this->assertArrayHasKey('Europe/Paris', $configModel->getTimezones()); - $this->assertContains('Europe/Paris', $configModel->getTimezones()); - $this->assertArrayNotHasKey('', $configModel->getTimezones()); - - $this->assertArrayHasKey('', $configModel->getTimezones(true)); - $this->assertContains('Application default', $configModel->getTimezones(true)); - } - - public function testGetLanguages() - { - $configModel = new Config($this->container); - $this->assertNotEmpty($configModel->getLanguages()); - $this->assertArrayHasKey('fr_FR', $configModel->getLanguages()); - $this->assertContains('Français', $configModel->getLanguages()); - $this->assertArrayNotHasKey('', $configModel->getLanguages()); - - $this->assertArrayHasKey('', $configModel->getLanguages(true)); - $this->assertContains('Application default', $configModel->getLanguages(true)); - } - - public function testGetJsLanguage() - { - $configModel = new Config($this->container); - $this->assertEquals('en', $configModel->getJsLanguageCode()); - - $this->container['sessionStorage']->user = array('language' => 'fr_FR'); - $this->assertEquals('fr', $configModel->getJsLanguageCode()); - - $this->container['sessionStorage']->user = array('language' => 'xx_XX'); - $this->assertEquals('en', $configModel->getJsLanguageCode()); - } - - public function testGetCurrentLanguage() - { - $configModel = new Config($this->container); - $this->assertEquals('en_US', $configModel->getCurrentLanguage()); - - $this->container['sessionStorage']->user = array('language' => 'fr_FR'); - $this->assertEquals('fr_FR', $configModel->getCurrentLanguage()); - - $this->container['sessionStorage']->user = array('language' => 'xx_XX'); - $this->assertEquals('xx_XX', $configModel->getCurrentLanguage()); - } - - public function testGetCurrentTimezone() - { - $configModel = new Config($this->container); - $this->assertEquals('UTC', $configModel->getCurrentTimezone()); - - $this->container['sessionStorage']->user = array('timezone' => 'Europe/Paris'); - $this->assertEquals('Europe/Paris', $configModel->getCurrentTimezone()); - - $this->container['sessionStorage']->user = array('timezone' => 'Something'); - $this->assertEquals('Something', $configModel->getCurrentTimezone()); - } - public function testRegenerateToken() { - $configModel = new Config($this->container); + $configModel = new ConfigModel($this->container); $token = $configModel->getOption('api_token'); $this->assertTrue($configModel->regenerateToken('api_token')); $this->assertNotEquals($token, $configModel->getOption('api_token')); @@ -76,7 +16,7 @@ class ConfigTest extends Base public function testCRUDOperations() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertTrue($c->save(array('key1' => 'value1'))); $this->assertTrue($c->save(array('key1' => 'value2'))); @@ -101,7 +41,7 @@ class ConfigTest extends Base public function testSaveApplicationUrl() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertTrue($c->save(array('application_url' => 'http://localhost/'))); $this->assertEquals('http://localhost/', $c->getOption('application_url')); @@ -115,7 +55,7 @@ class ConfigTest extends Base public function testDefaultValues() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEquals(172800, $c->getOption('board_highlight_period')); $this->assertEquals(60, $c->getOption('board_public_refresh_interval')); @@ -152,7 +92,7 @@ class ConfigTest extends Base public function testGetOption() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEquals('', $c->getOption('board_columns')); $this->assertEquals('test', $c->getOption('board_columns', 'test')); @@ -161,7 +101,7 @@ class ConfigTest extends Base public function testGetWithCaching() { - $c = new Config($this->container); + $c = new ConfigModel($this->container); $this->assertEquals('UTC', $c->get('application_timezone')); $this->assertTrue($c->save(array('application_timezone' => 'Europe/Paris'))); diff --git a/tests/units/Model/CurrencyTest.php b/tests/units/Model/CurrencyTest.php index 0bc71da6..162cdfc1 100644 --- a/tests/units/Model/CurrencyTest.php +++ b/tests/units/Model/CurrencyTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Currency; +use Kanboard\Model\CurrencyModel; class CurrencyTest extends Base { public function testGetCurrencies() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $currencies = $currencyModel->getCurrencies(); $this->assertArrayHasKey('EUR', $currencies); } public function testGetAll() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $currencies = $currencyModel->getAll(); $this->assertCount(0, $currencies); @@ -28,21 +28,21 @@ class CurrencyTest extends Base public function testCreate() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $this->assertNotFalse($currencyModel->create('EUR', 1.2)); $this->assertNotFalse($currencyModel->create('EUR', 1.5)); } public function testUpdate() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $this->assertNotFalse($currencyModel->create('EUR', 1.1)); $this->assertNotFalse($currencyModel->update('EUR', 2.2)); } public function testGetPrice() { - $currencyModel = new Currency($this->container); + $currencyModel = new CurrencyModel($this->container); $this->assertEquals(123, $currencyModel->getPrice('USD', 123)); diff --git a/tests/units/Model/CustomFilterTest.php b/tests/units/Model/CustomFilterTest.php index a73bc401..463a1c91 100644 --- a/tests/units/Model/CustomFilterTest.php +++ b/tests/units/Model/CustomFilterTest.php @@ -2,16 +2,16 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\CustomFilter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\CustomFilterModel; class CustomFilterTest extends Base { public function testCreation() { - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); @@ -36,8 +36,8 @@ class CustomFilterTest extends Base public function testModification() { - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); @@ -54,9 +54,9 @@ class CustomFilterTest extends Base public function testGetAll() { - $u = new User($this->container); - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest 1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest 2'))); @@ -128,8 +128,8 @@ class CustomFilterTest extends Base public function testRemove() { - $p = new Project($this->container); - $cf = new CustomFilter($this->container); + $p = new ProjectModel($this->container); + $cf = new CustomFilterModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); diff --git a/tests/units/Model/GroupMemberTest.php b/tests/units/Model/GroupMemberTest.php index 0ff9fdf6..edc9d98c 100644 --- a/tests/units/Model/GroupMemberTest.php +++ b/tests/units/Model/GroupMemberTest.php @@ -2,16 +2,16 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Group; -use Kanboard\Model\User; -use Kanboard\Model\GroupMember; +use Kanboard\Model\GroupModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupMemberModel; class GroupMemberTest extends Base { public function testAddRemove() { - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); @@ -32,9 +32,9 @@ class GroupMemberTest extends Base public function testMembers() { - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $groupModel->create('Group A')); $this->assertEquals(2, $groupModel->create('Group B')); diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupTest.php index 36b47dc5..85c2c5d9 100644 --- a/tests/units/Model/GroupTest.php +++ b/tests/units/Model/GroupTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Group; +use Kanboard\Model\GroupModel; class GroupTest extends Base { public function testCreation() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $this->assertFalse($groupModel->create('Test')); } public function testGetById() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $group = $groupModel->getById(1); @@ -27,7 +27,7 @@ class GroupTest extends Base public function testGetAll() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('B')); $this->assertEquals(2, $groupModel->create('A', 'uuid')); @@ -41,7 +41,7 @@ class GroupTest extends Base public function testUpdate() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $this->assertTrue($groupModel->update(array('id' => 1, 'name' => 'My group', 'external_id' => 'test'))); @@ -52,7 +52,7 @@ class GroupTest extends Base public function testRemove() { - $groupModel = new Group($this->container); + $groupModel = new GroupModel($this->container); $this->assertEquals(1, $groupModel->create('Test')); $this->assertTrue($groupModel->remove(1)); $this->assertEmpty($groupModel->getById(1)); diff --git a/tests/units/Model/LanguageTest.php b/tests/units/Model/LanguageTest.php new file mode 100644 index 00000000..4330c3c8 --- /dev/null +++ b/tests/units/Model/LanguageTest.php @@ -0,0 +1,58 @@ +<?php + +use Kanboard\Model\LanguageModel; + +require_once __DIR__.'/../Base.php'; + +class LanguageTest extends Base +{ + public function testGetCodes() + { + $codes = LanguageModel::getCodes(); + $this->assertContains('fr_FR', $codes); + $this->assertContains('en_US', $codes); + } + + public function testFindCode() + { + $this->assertSame('', LanguageModel::findCode('xx-XX')); + $this->assertSame('fr_FR', LanguageModel::findCode('fr-FR')); + $this->assertSame('en_US', LanguageModel::findCode('en-US')); + } + + public function testGetJsLanguage() + { + $languageModel = new LanguageModel($this->container); + $this->assertEquals('en', $languageModel->getJsLanguageCode()); + + $this->container['sessionStorage']->user = array('language' => 'fr_FR'); + $this->assertEquals('fr', $languageModel->getJsLanguageCode()); + + $this->container['sessionStorage']->user = array('language' => 'xx_XX'); + $this->assertEquals('en', $languageModel->getJsLanguageCode()); + } + + public function testGetCurrentLanguage() + { + $languageModel = new LanguageModel($this->container); + $this->assertEquals('en_US', $languageModel->getCurrentLanguage()); + + $this->container['sessionStorage']->user = array('language' => 'fr_FR'); + $this->assertEquals('fr_FR', $languageModel->getCurrentLanguage()); + + $this->container['sessionStorage']->user = array('language' => 'xx_XX'); + $this->assertEquals('xx_XX', $languageModel->getCurrentLanguage()); + } + + public function testGetLanguages() + { + $languageModel = new LanguageModel($this->container); + $this->assertNotEmpty($languageModel->getLanguages()); + $this->assertArrayHasKey('fr_FR', $languageModel->getLanguages()); + $this->assertContains('Français', $languageModel->getLanguages()); + $this->assertArrayNotHasKey('', $languageModel->getLanguages()); + + $this->assertArrayHasKey('', $languageModel->getLanguages(true)); + $this->assertContains('Application default', $languageModel->getLanguages(true)); + } +} diff --git a/tests/units/Model/LastLoginTest.php b/tests/units/Model/LastLoginTest.php index fc5ea1e5..8c291e15 100644 --- a/tests/units/Model/LastLoginTest.php +++ b/tests/units/Model/LastLoginTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\LastLogin; +use Kanboard\Model\LastLoginModel; class LastLoginTest extends Base { public function testCreate() { - $lastLoginModel = new LastLogin($this->container); + $lastLoginModel = new LastLoginModel($this->container); $this->assertTrue($lastLoginModel->create('Test1', 1, '127.0.0.1', 'My browser')); $this->assertTrue($lastLoginModel->create('Test2', 1, '127.0.0.1', str_repeat('Too long', 50))); @@ -29,7 +29,7 @@ class LastLoginTest extends Base public function testCleanup() { - $lastLoginModel = new LastLogin($this->container); + $lastLoginModel = new LastLoginModel($this->container); for ($i = 0; $i < $lastLoginModel::NB_LOGINS + 5; $i++) { $this->assertTrue($lastLoginModel->create('Test' . $i, 1, '127.0.0.1', 'My browser')); diff --git a/tests/units/Model/LinkTest.php b/tests/units/Model/LinkTest.php index b102646d..600c09f3 100644 --- a/tests/units/Model/LinkTest.php +++ b/tests/units/Model/LinkTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Link; +use Kanboard\Model\LinkModel; class LinkTest extends Base { public function testCreateLink() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $this->assertNotFalse($l->create('Link A')); $this->assertFalse($l->create('Link A')); @@ -38,7 +38,7 @@ class LinkTest extends Base public function testGetOppositeLinkId() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $this->assertNotFalse($l->create('Link A')); $this->assertNotFalse($l->create('Link B', 'Link C')); @@ -50,7 +50,7 @@ class LinkTest extends Base public function testUpdate() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0))); @@ -62,7 +62,7 @@ class LinkTest extends Base public function testRemove() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $link = $l->getById(3); $this->assertNotEmpty($link); @@ -82,7 +82,7 @@ class LinkTest extends Base public function testGetMergedList() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $links = $l->getMergedList(); $this->assertNotEmpty($links); @@ -93,7 +93,7 @@ class LinkTest extends Base public function testGetList() { - $l = new Link($this->container); + $l = new LinkModel($this->container); $links = $l->getList(); $this->assertNotEmpty($links); diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php index d5ec7735..96ee5f4e 100644 --- a/tests/units/Model/NotificationTest.php +++ b/tests/units/Model/NotificationTest.php @@ -2,27 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; -use Kanboard\Model\TaskFile; -use Kanboard\Model\Task; -use Kanboard\Model\Project; -use Kanboard\Model\Notification; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\NotificationModel; use Kanboard\Subscriber\NotificationSubscriber; class NotificationTest extends Base { public function testGetTitle() { - $wn = new Notification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $c = new Comment($this->container); - $f = new TaskFile($this->container); + $wn = new NotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $c = new CommentModel($this->container); + $f = new TaskFileModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -62,7 +62,7 @@ class NotificationTest extends Base $this->assertNotEmpty($title); } - $this->assertNotEmpty($wn->getTitleWithoutAuthor(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); + $this->assertNotEmpty($wn->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); $this->assertNotEmpty($wn->getTitleWithoutAuthor('unkown', array())); } } diff --git a/tests/units/Model/PasswordResetTest.php b/tests/units/Model/PasswordResetTest.php index f88d24fb..01ca1d12 100644 --- a/tests/units/Model/PasswordResetTest.php +++ b/tests/units/Model/PasswordResetTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\PasswordReset; +use Kanboard\Model\UserModel; +use Kanboard\Model\PasswordResetModel; class PasswordResetTest extends Base { public function testCreate() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -22,8 +22,8 @@ class PasswordResetTest extends Base public function testGetUserIdByToken() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -33,8 +33,8 @@ class PasswordResetTest extends Base public function testGetUserIdByTokenWhenExpired() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -44,8 +44,8 @@ class PasswordResetTest extends Base public function testDisableTokens() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); @@ -63,8 +63,8 @@ class PasswordResetTest extends Base public function testGetAll() { - $userModel = new User($this->container); - $passwordResetModel = new PasswordReset($this->container); + $userModel = new UserModel($this->container); + $passwordResetModel = new PasswordResetModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); $this->assertNotFalse($passwordResetModel->create('user2')); diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php index a624cd86..0b87b515 100644 --- a/tests/units/Model/ProjectActivityTest.php +++ b/tests/units/Model/ProjectActivityTest.php @@ -2,53 +2,53 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\ProjectActivity; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectActivityModel; +use Kanboard\Model\ProjectModel; class ProjectActivityTest extends Base { public function testCreation() { - $projectActivity = new ProjectActivity($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); - $projectModel = new Project($this->container); + $projectActivity = new ProjectActivityModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1))); $this->assertEquals(2, $taskCreation->create(array('title' => 'Task #2', 'project_id' => 1))); - $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $taskFinder->getbyId(1)))); - $this->assertTrue($projectActivity->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $taskFinder->getById(2)))); - $this->assertFalse($projectActivity->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $taskFinder->getbyId(1)))); + $this->assertTrue($projectActivity->createEvent(1, 1, 1, TaskModel::EVENT_CLOSE, array('task' => $taskFinder->getById(1)))); + $this->assertTrue($projectActivity->createEvent(1, 2, 1, TaskModel::EVENT_UPDATE, array('task' => $taskFinder->getById(2)))); + $this->assertFalse($projectActivity->createEvent(1, 1, 0, TaskModel::EVENT_OPEN, array('task' => $taskFinder->getById(1)))); $events = $projectActivity->getQuery()->desc('id')->findAll(); $this->assertCount(2, $events); $this->assertEquals(time(), $events[0]['date_creation'], '', 1); - $this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']); - $this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']); + $this->assertEquals(TaskModel::EVENT_UPDATE, $events[0]['event_name']); + $this->assertEquals(TaskModel::EVENT_CLOSE, $events[1]['event_name']); } public function testCleanup() { - $projectActivity = new ProjectActivity($this->container); - $taskCreation = new TaskCreation($this->container); - $taskFinder = new TaskFinder($this->container); - $projectModel = new Project($this->container); + $projectActivity = new ProjectActivityModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1))); $max = 15; $nb_events = 100; - $task = $taskFinder->getbyId(1); + $task = $taskFinder->getById(1); for ($i = 0; $i < $nb_events; $i++) { - $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task))); + $this->assertTrue($projectActivity->createEvent(1, 1, 1, TaskModel::EVENT_CLOSE, array('task' => $task))); } $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count()); diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php index 4f92ad2b..5e500340 100644 --- a/tests/units/Model/ProjectDailyColumnStatsTest.php +++ b/tests/units/Model/ProjectDailyColumnStatsTest.php @@ -2,29 +2,29 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectDailyColumnStats; -use Kanboard\Model\Config; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectDailyColumnStatsModel; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; class ProjectDailyColumnStatsTest extends Base { public function testUpdateTotalsWithScoreAtNull() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $projectDailyColumnStats->updateTotals(1, '2016-01-16'); - $task = $this->container['db']->table(Task::TABLE)->findOne(); + $task = $this->container['db']->table(TaskModel::TABLE)->findOne(); $this->assertNull($task['score']); - $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + $stats = $this->container['db']->table(ProjectDailyColumnStatsModel::TABLE) ->asc('day') ->asc('column_id') ->columns('day', 'project_id', 'column_id', 'total', 'score') @@ -45,8 +45,8 @@ class ProjectDailyColumnStatsTest extends Base public function testUpdateTotals() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->createTasks(1, 2, 1); @@ -68,7 +68,7 @@ class ProjectDailyColumnStatsTest extends Base $projectDailyColumnStats->updateTotals(1, '2016-01-17'); - $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + $stats = $this->container['db']->table(ProjectDailyColumnStatsModel::TABLE) ->asc('day') ->asc('column_id') ->columns('day', 'project_id', 'column_id', 'total', 'score') @@ -117,9 +117,9 @@ class ProjectDailyColumnStatsTest extends Base public function testUpdateTotalsWithOnlyOpenTasks() { - $configModel = new Config($this->container); - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $configModel = new ConfigModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->assertTrue($configModel->save(array('cfd_include_closed_tasks' => 0))); @@ -144,7 +144,7 @@ class ProjectDailyColumnStatsTest extends Base $projectDailyColumnStats->updateTotals(1, '2016-01-17'); - $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + $stats = $this->container['db']->table(ProjectDailyColumnStatsModel::TABLE) ->asc('day') ->asc('column_id') ->columns('day', 'project_id', 'column_id', 'total', 'score') @@ -193,8 +193,8 @@ class ProjectDailyColumnStatsTest extends Base public function testCountDays() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -208,8 +208,8 @@ class ProjectDailyColumnStatsTest extends Base public function testGetAggregatedMetrics() { - $projectModel = new Project($this->container); - $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $projectModel = new ProjectModel($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStatsModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); $this->createTasks(1, 2, 1); @@ -258,7 +258,7 @@ class ProjectDailyColumnStatsTest extends Base private function createTasks($column_id, $score, $is_active) { - $taskCreationModel = new TaskCreation($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'score' => $score, 'is_active' => $is_active))); } } diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php index 60afc4c3..851af985 100644 --- a/tests/units/Model/ProjectDailyStatsTest.php +++ b/tests/units/Model/ProjectDailyStatsTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectDailyStats; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskStatus; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectDailyStatsModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskStatusModel; class ProjectDailyStatsTest extends Base { public function testUpdateTotals() { - $p = new Project($this->container); - $pds = new ProjectDailyStats($this->container); - $tc = new TaskCreation($this->container); - $ts = new TaskStatus($this->container); + $p = new ProjectModel($this->container); + $pds = new ProjectDailyStatsModel($this->container); + $tc = new TaskCreationModel($this->container); + $ts = new TaskStatusModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); @@ -45,10 +45,10 @@ class ProjectDailyStatsTest extends Base $this->assertEquals($expected[0]['day'], $metrics[0]['day']); $this->assertEquals($expected[1]['day'], $metrics[1]['day']); - $this->assertSame($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], '', 2); - $this->assertSame($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], '', 2); + $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->assertSame($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], '', 2); - $this->assertSame($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_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/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php index ee5b4ce4..312c7168 100644 --- a/tests/units/Model/ProjectDuplicationTest.php +++ b/tests/units/Model/ProjectDuplicationTest.php @@ -2,33 +2,33 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Action; -use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectDuplication; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\Swimlane; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; +use Kanboard\Model\ActionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectDuplicationModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; use Kanboard\Core\Security\Role; class ProjectDuplicationTest extends Base { public function testGetSelections() { - $projectDuplicationModel = new ProjectDuplication($this->container); - $this->assertCount(5, $projectDuplicationModel->getOptionalSelection()); - $this->assertCount(6, $projectDuplicationModel->getPossibleSelection()); + $projectDuplicationModel = new ProjectDuplicationModel($this->container); + $this->assertCount(6, $projectDuplicationModel->getOptionalSelection()); + $this->assertCount(7, $projectDuplicationModel->getPossibleSelection()); } public function testGetClonedProjectName() { - $pd = new ProjectDuplication($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals('test (Clone)', $pd->getClonedProjectName('test')); @@ -41,8 +41,8 @@ class ProjectDuplicationTest extends Base public function testClonePublicProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Public'))); $this->assertEquals(2, $pd->duplicate(1)); @@ -59,9 +59,9 @@ class ProjectDuplicationTest extends Base public function testClonePrivateProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $pp = new ProjectUserRole($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $pp = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true)); $this->assertEquals(2, $pd->duplicate(1)); @@ -80,8 +80,8 @@ class ProjectDuplicationTest extends Base public function testCloneSharedProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Shared'))); $this->assertTrue($p->update(array('id' => 1, 'is_public' => 1, 'token' => 'test'))); @@ -101,8 +101,8 @@ class ProjectDuplicationTest extends Base public function testCloneInactiveProject() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Inactive'))); $this->assertTrue($p->update(array('id' => 1, 'is_active' => 0))); @@ -120,16 +120,16 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithOwner() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Owner'))); $project = $p->getById(1); $this->assertEquals(0, $project['owner_id']); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -141,15 +141,15 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithDifferentName() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Owner'))); $project = $p->getById(1); $this->assertEquals(0, $project['owner_id']); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar')); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar')); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -159,8 +159,8 @@ class ProjectDuplicationTest extends Base public function testCloneProjectAndForceItToBePrivate() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Owner'))); @@ -168,7 +168,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(0, $project['owner_id']); $this->assertEquals(0, $project['is_private']); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar', true)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true)); $project = $p->getById(2); $this->assertNotEmpty($project); @@ -179,9 +179,9 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithCategories() { - $p = new Project($this->container); - $c = new Category($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -204,11 +204,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithUsers() { - $p = new Project($this->container); - $c = new Category($this->container); - $pp = new ProjectUserRole($this->container); - $u = new User($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $u = new UserModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(3, $u->create(array('username' => 'user2'))); @@ -230,11 +229,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithUsersAndOverrideOwner() { - $p = new Project($this->container); - $c = new Category($this->container); - $pp = new ProjectUserRole($this->container); - $u = new User($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $u = new UserModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(1, $p->create(array('name' => 'P1'), 2)); @@ -245,7 +243,7 @@ class ProjectDuplicationTest extends Base $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1)); $this->assertCount(2, $pp->getUsers(2)); $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2)); @@ -257,11 +255,10 @@ class ProjectDuplicationTest extends Base public function testCloneTeamProjectToPrivatProject() { - $p = new Project($this->container); - $c = new Category($this->container); - $pp = new ProjectUserRole($this->container); - $u = new User($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $u = new UserModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(3, $u->create(array('username' => 'user2'))); @@ -274,7 +271,7 @@ class ProjectDuplicationTest extends Base $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 3, 'My private project', true)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true)); $this->assertCount(1, $pp->getUsers(2)); $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3)); @@ -286,14 +283,13 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithGroups() { - $p = new Project($this->container); - $c = new Category($this->container); - $pd = new ProjectDuplication($this->container); - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $projectGroupRoleModel = new ProjectGroupRole($this->container); - $projectUserRoleModel = new ProjectUserRole($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $projectGroupRoleModel = new ProjectGroupRoleModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -323,15 +319,15 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithActionTaskAssignCurrentUser() { - $p = new Project($this->container); - $a = new Action($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $a = new ActionModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); $this->assertEquals(1, $a->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_MOVE_COLUMN, + 'event_name' => TaskModel::EVENT_MOVE_COLUMN, 'action_name' => 'TaskAssignCurrentUser', 'params' => array('column_id' => 2), ))); @@ -348,10 +344,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithActionTaskAssignColorCategory() { - $p = new Project($this->container); - $a = new Action($this->container); - $c = new Category($this->container); - $pd = new ProjectDuplication($this->container); + $p = new ProjectModel($this->container); + $a = new ActionModel($this->container); + $c = new CategoryModel($this->container); + $pd = new ProjectDuplicationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -361,7 +357,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(1, $a->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, + 'event_name' => TaskModel::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignColorCategory', 'params' => array('color_id' => 'blue', 'category_id' => 2), ))); @@ -379,11 +375,11 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithSwimlanes() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $s = new SwimlaneModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); @@ -398,7 +394,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(3, $tc->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2))); $this->assertEquals(4, $tc->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3))); - $this->assertEquals(2, $pd->duplicate(1, array('category', 'swimlane'))); + $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'swimlaneModel'))); $swimlanes = $s->getAll(2); $this->assertCount(3, $swimlanes); @@ -418,11 +414,10 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithTasks() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); @@ -431,7 +426,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3))); - $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'task'))); + $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'actionModel', 'taskModel'))); // Check if Tasks have been duplicated $tasks = $tf->getAll(2); @@ -443,11 +438,11 @@ class ProjectDuplicationTest extends Base public function testCloneProjectWithSwimlanesAndTasks() { - $p = new Project($this->container); - $pd = new ProjectDuplication($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $pd = new ProjectDuplicationModel($this->container); + $s = new SwimlaneModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); @@ -461,7 +456,7 @@ class ProjectDuplicationTest extends Base $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertEquals(2, $pd->duplicate(1, array('projectPermission', 'swimlane', 'task'))); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel'))); // Check if Swimlanes have been duplicated $swimlanes = $s->getAll(2); diff --git a/tests/units/Model/ProjectFileTest.php b/tests/units/Model/ProjectFileTest.php index 0d7a9377..116dd3d2 100644 --- a/tests/units/Model/ProjectFileTest.php +++ b/tests/units/Model/ProjectFileTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\ProjectFile; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectFileModel; +use Kanboard\Model\ProjectModel; class ProjectFileTest extends Base { public function testCreation() { - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); @@ -34,8 +34,8 @@ class ProjectFileTest extends Base public function testCreationWithFileNameTooLong() { - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -54,8 +54,8 @@ class ProjectFileTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); @@ -67,8 +67,8 @@ class ProjectFileTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $fileModel = new ProjectFile($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -100,13 +100,13 @@ class ProjectFileTest extends Base public function testGetThumbnailPath() { - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); } public function testGeneratePath() { - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertStringStartsWith('projects'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); @@ -115,12 +115,12 @@ class ProjectFileTest extends Base public function testUploadFiles() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->getMockBuilder('\Kanboard\Model\ProjectFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -181,7 +181,7 @@ class ProjectFileTest extends Base public function testUploadFilesWithEmptyFiles() { - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, array())); } @@ -206,7 +206,7 @@ class ProjectFileTest extends Base ), ); - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } @@ -237,19 +237,19 @@ class ProjectFileTest extends Base ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - $fileModel = new ProjectFile($this->container); + $fileModel = new ProjectFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } public function testUploadFileContent() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->getMockBuilder('\Kanboard\Model\ProjectFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -276,12 +276,12 @@ class ProjectFileTest extends Base public function testUploadImageContent() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->getMockBuilder('\Kanboard\Model\ProjectFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromData')) ->getMock(); - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); diff --git a/tests/units/Model/ProjectGroupRoleTest.php b/tests/units/Model/ProjectGroupRoleTest.php index e38e812a..e703d4a9 100644 --- a/tests/units/Model/ProjectGroupRoleTest.php +++ b/tests/units/Model/ProjectGroupRoleTest.php @@ -2,21 +2,21 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; use Kanboard\Core\Security\Role; class ProjectGroupRoleTest extends Base { public function testGetUserRole() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Group A')); @@ -30,9 +30,9 @@ class ProjectGroupRoleTest extends Base public function testAddGroup() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Test')); @@ -49,9 +49,9 @@ class ProjectGroupRoleTest extends Base public function testRemoveGroup() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Test')); @@ -65,9 +65,9 @@ class ProjectGroupRoleTest extends Base public function testChangeRole() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Test')); @@ -84,9 +84,9 @@ class ProjectGroupRoleTest extends Base public function testGetGroups() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Group C')); @@ -115,11 +115,11 @@ class ProjectGroupRoleTest extends Base public function testGetUsers() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -164,11 +164,11 @@ class ProjectGroupRoleTest extends Base public function testGetAssignableUsers() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -206,11 +206,11 @@ class ProjectGroupRoleTest extends Base public function testGetAssignableUsersWithDisabledUsers() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -244,11 +244,11 @@ class ProjectGroupRoleTest extends Base public function testGetProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -290,11 +290,11 @@ class ProjectGroupRoleTest extends Base public function testGetActiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -317,27 +317,27 @@ class ProjectGroupRoleTest extends Base $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); - $projects = $groupRoleModel->getProjectsByUser(2, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(2, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $groupRoleModel->getProjectsByUser(3, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(3, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $groupRoleModel->getProjectsByUser(4, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(4, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $groupRoleModel->getProjectsByUser(5, array(Project::ACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(5, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); } public function testGetInactiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -360,29 +360,29 @@ class ProjectGroupRoleTest extends Base $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); - $projects = $groupRoleModel->getProjectsByUser(2, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(2, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $groupRoleModel->getProjectsByUser(3, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(3, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $groupRoleModel->getProjectsByUser(4, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(4, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $groupRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); + $projects = $groupRoleModel->getProjectsByUser(5, array(ProjectModel::INACTIVE)); $this->assertCount(0, $projects); } public function testUserInMultipleGroupsShouldReturnHighestRole() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(2, $userModel->create(array('username' => 'My user'))); diff --git a/tests/units/Model/ProjectMetadataTest.php b/tests/units/Model/ProjectMetadataTest.php index 5814987d..2f6d111a 100644 --- a/tests/units/Model/ProjectMetadataTest.php +++ b/tests/units/Model/ProjectMetadataTest.php @@ -2,51 +2,65 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectMetadata; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectMetadataModel; class ProjectMetadataTest extends Base { public function testOperations() { - $p = new Project($this->container); - $pm = new ProjectMetadata($this->container); + $projectModel = new ProjectModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'project #1'))); - $this->assertEquals(2, $p->create(array('name' => 'project #2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'project #1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'project #2'))); - $this->assertTrue($pm->save(1, array('key1' => 'value1'))); - $this->assertTrue($pm->save(1, array('key1' => 'value2'))); - $this->assertTrue($pm->save(2, array('key1' => 'value1'))); - $this->assertTrue($pm->save(2, array('key2' => 'value2'))); + $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1'))); + $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value2'))); + $this->assertTrue($projectMetadataModel->save(2, array('key1' => 'value1'))); + $this->assertTrue($projectMetadataModel->save(2, array('key2' => 'value2'))); - $this->assertEquals('value2', $pm->get(1, 'key1')); - $this->assertEquals('value1', $pm->get(2, 'key1')); - $this->assertEquals('', $pm->get(2, 'key3')); - $this->assertEquals('default', $pm->get(2, 'key3', 'default')); + $this->assertEquals('value2', $projectMetadataModel->get(1, 'key1')); + $this->assertEquals('value1', $projectMetadataModel->get(2, 'key1')); + $this->assertEquals('', $projectMetadataModel->get(2, 'key3')); + $this->assertEquals('default', $projectMetadataModel->get(2, 'key3', 'default')); - $this->assertTrue($pm->exists(2, 'key1')); - $this->assertFalse($pm->exists(2, 'key3')); + $this->assertTrue($projectMetadataModel->exists(2, 'key1')); + $this->assertFalse($projectMetadataModel->exists(2, 'key3')); - $this->assertEquals(array('key1' => 'value2'), $pm->getAll(1)); - $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $pm->getAll(2)); + $this->assertEquals(array('key1' => 'value2'), $projectMetadataModel->getAll(1)); + $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $projectMetadataModel->getAll(2)); - $this->assertTrue($pm->remove(2, 'key1')); - $this->assertFalse($pm->remove(2, 'key1')); + $this->assertTrue($projectMetadataModel->remove(2, 'key1')); + $this->assertFalse($projectMetadataModel->remove(2, 'key1')); - $this->assertEquals(array('key2' => 'value2'), $pm->getAll(2)); + $this->assertEquals(array('key2' => 'value2'), $projectMetadataModel->getAll(2)); } public function testAutomaticRemove() { - $p = new Project($this->container); - $pm = new ProjectMetadata($this->container); + $projectModel = new ProjectModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'project #1'))); - $this->assertTrue($pm->save(1, array('key1' => 'value1'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'project #1'))); + $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1'))); - $this->assertTrue($pm->exists(1, 'key1')); - $this->assertTrue($p->remove(1)); - $this->assertFalse($pm->exists(1, 'key1')); + $this->assertTrue($projectMetadataModel->exists(1, 'key1')); + $this->assertTrue($projectModel->remove(1)); + $this->assertFalse($projectMetadataModel->exists(1, 'key1')); + } + + public function testDuplicate() + { + $projectModel = new ProjectModel($this->container); + $projectMetadataModel = new ProjectMetadataModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'project #1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'project #2'))); + + $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1', 'key2' => 'value2'))); + $this->assertTrue($projectMetadataModel->duplicate(1, 2)); + + $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $projectMetadataModel->getAll(2)); } } diff --git a/tests/units/Model/ProjectNotificationTypeTest.php b/tests/units/Model/ProjectNotificationTypeTest.php index 71e2b964..7f735828 100644 --- a/tests/units/Model/ProjectNotificationTypeTest.php +++ b/tests/units/Model/ProjectNotificationTypeTest.php @@ -2,14 +2,14 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectNotificationType; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectNotificationTypeModel; class ProjectNotificationTypeTest extends Base { public function testGetTypes() { - $nt = new ProjectNotificationType($this->container); + $nt = new ProjectNotificationTypeModel($this->container); $this->assertEmpty($nt->getTypes()); $nt->setType('foo', 'Foo', 'Something1'); @@ -22,8 +22,8 @@ class ProjectNotificationTypeTest extends Base public function testGetSelectedTypes() { - $nt = new ProjectNotificationType($this->container); - $p = new Project($this->container); + $nt = new ProjectNotificationTypeModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php index 10fcdcc2..c9e0a481 100644 --- a/tests/units/Model/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -2,26 +2,26 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectPermissionModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Core\Security\Role; class ProjectPermissionTest extends Base { public function testFindByUsernames() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermissionModel = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermissionModel = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); @@ -42,13 +42,10 @@ class ProjectPermissionTest extends Base public function testGetQueryByRole() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -108,8 +105,8 @@ class ProjectPermissionTest extends Base public function testEverybodyAllowed() { - $projectModel = new Project($this->container); - $projectPermission = new ProjectPermission($this->container); + $projectModel = new ProjectModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_everybody_allowed' => 1))); @@ -120,13 +117,13 @@ class ProjectPermissionTest extends Base public function testIsUserAllowed() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -157,13 +154,13 @@ class ProjectPermissionTest extends Base public function testIsAssignable() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -194,13 +191,10 @@ class ProjectPermissionTest extends Base public function testIsAssignableWhenUserIsDisabled() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2', 'is_active' => 0))); @@ -216,13 +210,13 @@ class ProjectPermissionTest extends Base public function testIsMember() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -253,13 +247,10 @@ class ProjectPermissionTest extends Base public function testGetActiveProjectIds() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); @@ -278,13 +269,13 @@ class ProjectPermissionTest extends Base public function testDuplicate() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $projectPermission = new ProjectPermission($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 5478fa40..472d7351 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -4,21 +4,21 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\Translator; use Kanboard\Subscriber\ProjectModificationDateSubscriber; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Config; -use Kanboard\Model\Category; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\CategoryModel; class ProjectTest extends Base { public function testCreationForAllLanguages() { - $c = new Config($this->container); - $p = new Project($this->container); + $p = new ProjectModel($this->container); - foreach ($c->getLanguages() as $locale => $language) { + foreach ($this->container['languageModel']->getLanguages() as $locale => $language) { + Translator::unload(); Translator::load($locale); $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); } @@ -28,7 +28,7 @@ class ProjectTest extends Base public function testCreation() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); @@ -43,7 +43,7 @@ class ProjectTest extends Base public function testCreationWithDuplicateName() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); @@ -51,7 +51,7 @@ class ProjectTest extends Base public function testCreationWithStartAndDate() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31'))); @@ -63,9 +63,9 @@ class ProjectTest extends Base public function testCreationWithDefaultCategories() { - $p = new Project($this->container); - $c = new Config($this->container); - $cat = new Category($this->container); + $p = new ProjectModel($this->container); + $c = new ConfigModel($this->container); + $cat = new CategoryModel($this->container); // Multiple categories correctly formatted @@ -124,7 +124,7 @@ class ProjectTest extends Base public function testUpdateLastModifiedDate() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $now = time(); @@ -143,7 +143,7 @@ class ProjectTest extends Base public function testGetAllIds() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); @@ -154,8 +154,8 @@ class ProjectTest extends Base public function testIsLastModified() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $now = time(); @@ -168,12 +168,12 @@ class ProjectTest extends Base sleep(1); $listener = new ProjectModificationDateSubscriber($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($listener, 'execute')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute')); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called); $project = $p->getById(1); $this->assertNotEmpty($project); @@ -182,7 +182,7 @@ class ProjectTest extends Base public function testRemove() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->remove(1)); @@ -191,7 +191,7 @@ class ProjectTest extends Base public function testEnable() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->disable(1)); @@ -205,7 +205,7 @@ class ProjectTest extends Base public function testDisable() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->disable(1)); @@ -220,7 +220,7 @@ class ProjectTest extends Base public function testEnablePublicAccess() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->enablePublicAccess(1)); @@ -235,7 +235,7 @@ class ProjectTest extends Base public function testDisablePublicAccess() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($p->enablePublicAccess(1)); @@ -251,7 +251,7 @@ class ProjectTest extends Base public function testIdentifier() { - $p = new Project($this->container); + $p = new ProjectModel($this->container); // Creation $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); @@ -282,8 +282,8 @@ class ProjectTest extends Base public function testThatProjectCreatorAreAlsoOwner() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'Me'))); $this->assertEquals(1, $projectModel->create(array('name' => 'My project 1'), 2)); @@ -306,7 +306,7 @@ class ProjectTest extends Base public function testPriority() { - $projectModel = new Project($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2'))); $project = $projectModel->getById(1); @@ -315,6 +315,11 @@ class ProjectTest extends Base $this->assertEquals(0, $project['priority_start']); $this->assertEquals(3, $project['priority_end']); + $this->assertEquals( + array(0 => 0, 1 => 1, 2 => 2, 3 => 3), + $projectModel->getPriorities($project) + ); + $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4))); $project = $projectModel->getById(1); @@ -322,5 +327,10 @@ class ProjectTest extends Base $this->assertEquals(4, $project['priority_default']); $this->assertEquals(2, $project['priority_start']); $this->assertEquals(5, $project['priority_end']); + + $this->assertEquals( + array(2 => 2, 3 => 3, 4 => 4, 5 => 5), + $projectModel->getPriorities($project) + ); } } diff --git a/tests/units/Model/ProjectUserRoleTest.php b/tests/units/Model/ProjectUserRoleTest.php index 06cd1b70..d59b15c9 100644 --- a/tests/units/Model/ProjectUserRoleTest.php +++ b/tests/units/Model/ProjectUserRoleTest.php @@ -2,21 +2,21 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\ProjectPermission; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectPermissionModel; use Kanboard\Core\Security\Role; class ProjectUserRoleTest extends Base { public function testAddUser() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -33,8 +33,8 @@ class ProjectUserRoleTest extends Base public function testRemoveUser() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -47,8 +47,8 @@ class ProjectUserRoleTest extends Base public function testChangeRole() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -65,8 +65,8 @@ class ProjectUserRoleTest extends Base public function testGetRole() { - $projectModel = new Project($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEmpty($userRoleModel->getUserRole(1, 1)); @@ -85,11 +85,11 @@ class ProjectUserRoleTest extends Base public function testGetRoleWithGroups() { - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $groupModel->create('Group A')); @@ -101,11 +101,31 @@ class ProjectUserRoleTest extends Base $this->assertEquals('', $userRoleModel->getUserRole(1, 2)); } + public function testGetRoleWithPublicProject() + { + $projectModel = new ProjectModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'), 2, true)); + + $this->assertEquals(Role::PROJECT_MANAGER, $userRoleModel->getUserRole(1, 2)); + $this->assertEquals(null, $userRoleModel->getUserRole(1, 3)); + + $this->assertTrue($projectModel->update(array('id' => 1, 'is_everybody_allowed' => 1))); + + $this->assertEquals(Role::PROJECT_MANAGER, $userRoleModel->getUserRole(1, 2)); + $this->assertEquals(Role::PROJECT_MEMBER, $userRoleModel->getUserRole(1, 3)); + } + public function testGetAssignableUsersWithDisabledUsers() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); @@ -133,9 +153,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithoutGroups() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); @@ -154,12 +174,12 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithGroups() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $userRoleModel = new ProjectUserRole($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $groupMemberModel = new GroupMember($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); @@ -191,9 +211,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersList() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Test2'))); @@ -229,9 +249,9 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithEverybodyAllowed() { - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test', 'is_everybody_allowed' => 1))); @@ -252,10 +272,10 @@ class ProjectUserRoleTest extends Base public function testGetAssignableUsersWithDisabledUsersAndEverybodyAllowed() { - $projectModel = new Project($this->container); - $projectPermission = new ProjectPermission($this->container); - $userModel = new User($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $projectModel = new ProjectModel($this->container); + $projectPermission = new ProjectPermissionModel($this->container); + $userModel = new UserModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); @@ -282,12 +302,12 @@ class ProjectUserRoleTest extends Base public function testGetProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -344,12 +364,12 @@ class ProjectUserRoleTest extends Base public function testGetActiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -378,36 +398,36 @@ class ProjectUserRoleTest extends Base $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); - $projects = $userRoleModel->getProjectsByUser(2, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(2, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(3, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(3, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(4, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(4, array(ProjectModel::ACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(5, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(5, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); - $projects = $userRoleModel->getProjectsByUser(6, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(6, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); - $projects = $userRoleModel->getProjectsByUser(7, array(Project::ACTIVE)); + $projects = $userRoleModel->getProjectsByUser(7, array(ProjectModel::ACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 2', $projects[2]); } public function testGetInactiveProjectsByUser() { - $userModel = new User($this->container); - $projectModel = new Project($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $groupRoleModel = new ProjectGroupRole($this->container); - $userRoleModel = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $projectModel = new ProjectModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $groupRoleModel = new ProjectGroupRoleModel($this->container); + $userRoleModel = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); @@ -436,26 +456,26 @@ class ProjectUserRoleTest extends Base $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); - $projects = $userRoleModel->getProjectsByUser(2, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(2, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(3, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(3, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(4, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(4, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(5, array(ProjectModel::INACTIVE)); $this->assertCount(0, $projects); - $projects = $userRoleModel->getProjectsByUser(6, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(6, array(ProjectModel::INACTIVE)); $this->assertCount(1, $projects); $this->assertEquals('Project 1', $projects[1]); - $projects = $userRoleModel->getProjectsByUser(7, array(Project::INACTIVE)); + $projects = $userRoleModel->getProjectsByUser(7, array(ProjectModel::INACTIVE)); $this->assertCount(0, $projects); } } diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php index eb9747d4..b65ee609 100644 --- a/tests/units/Model/SubtaskTest.php +++ b/tests/units/Model/SubtaskTest.php @@ -2,10 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\ProjectModel; use Kanboard\Core\User\UserSession; +use Kanboard\Model\TaskFinderModel; class SubtaskTest extends Base { @@ -45,7 +46,7 @@ class SubtaskTest extends Base $this->assertArrayHasKey('user_id', $data['changes']); $this->assertArrayHasKey('status', $data['changes']); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $data['changes']['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']); $this->assertEquals(1, $data['changes']['user_id']); } @@ -69,14 +70,14 @@ class SubtaskTest extends Base public function testCreation() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Subtask::EVENT_CREATE, array($this, 'onSubtaskCreated')); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated')); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); @@ -85,7 +86,7 @@ class SubtaskTest extends Base $this->assertEquals(1, $subtask['id']); $this->assertEquals(1, $subtask['task_id']); $this->assertEquals('subtask #1', $subtask['title']); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['time_estimated']); $this->assertEquals(0, $subtask['time_spent']); $this->assertEquals(0, $subtask['user_id']); @@ -94,24 +95,24 @@ class SubtaskTest extends Base public function testModification() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Subtask::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => Subtask::STATUS_INPROGRESS))); + $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS))); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); $this->assertEquals(1, $subtask['id']); $this->assertEquals(1, $subtask['task_id']); $this->assertEquals('subtask #1', $subtask['title']); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); $this->assertEquals(0, $subtask['time_estimated']); $this->assertEquals(0, $subtask['time_spent']); $this->assertEquals(1, $subtask['user_id']); @@ -120,15 +121,15 @@ class SubtaskTest extends Base public function testRemove() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->container['dispatcher']->addListener(Subtask::EVENT_DELETE, array($this, 'onSubtaskDeleted')); + $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted')); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -141,9 +142,9 @@ class SubtaskTest extends Base public function testToggleStatusWithoutSession() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); @@ -152,40 +153,40 @@ class SubtaskTest extends Base $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_DONE, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_TODO, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); } public function testToggleStatusWithSession() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $us = new UserSession($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -195,43 +196,43 @@ class SubtaskTest extends Base $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); // Set the current logged user $this->container['sessionStorage']->user = array('id' => 1); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']); $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_DONE, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertEquals(Subtask::STATUS_TODO, $s->toggleStatus(1)); + $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); - $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']); $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); } public function testCloseAll() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); @@ -245,15 +246,15 @@ class SubtaskTest extends Base $this->assertNotEmpty($subtasks); foreach ($subtasks as $subtask) { - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); } } public function testDuplicate() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); // We create a project $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -298,9 +299,9 @@ class SubtaskTest extends Base public function testChangePosition() { - $taskCreationModel = new TaskCreation($this->container); - $subtaskModel = new Subtask($this->container); - $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); @@ -360,4 +361,28 @@ class SubtaskTest extends Base $this->assertFalse($subtaskModel->changePosition(1, 2, 0)); $this->assertFalse($subtaskModel->changePosition(1, 2, 4)); } + + public function testConvertToTask() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $subtaskModel = new SubtaskModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3))); + $task_id = $subtaskModel->convertToTask(1, 1); + + $this->assertNotFalse($task_id); + $this->assertEmpty($subtaskModel->getById(1)); + + $task = $taskFinderModel->getById($task_id); + $this->assertEquals('subtask #1', $task['title']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(2, $task['time_spent']); + $this->assertEquals(3, $task['time_estimated']); + } } diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index 2545dcb2..d5ae62ae 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\SubtaskTimeTracking; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\SubtaskTimeTrackingModel; +use Kanboard\Model\ProjectModel; class SubtaskTimeTrackingTest extends Base { public function testHasTimer() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -31,10 +31,10 @@ class SubtaskTimeTrackingTest extends Base public function testGetTimerStatus() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->container['sessionStorage']->user = array('id' => 1); @@ -48,7 +48,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(0, $subtasks[0]['timer_start_date']); $this->assertFalse($subtasks[0]['is_timer_started']); - $subtask = $s->getbyId(1, true); + $subtask = $s->getById(1, true); $this->assertNotEmpty($subtask); $this->assertEquals(0, $subtask['timer_start_date']); $this->assertFalse($subtask['is_timer_started']); @@ -61,7 +61,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3); $this->assertTrue($subtasks[0]['is_timer_started']); - $subtask = $s->getbyId(1, true); + $subtask = $s->getById(1, true); $this->assertNotEmpty($subtask); $this->assertEquals(time(), $subtask['timer_start_date'], '', 3); $this->assertTrue($subtask['is_timer_started']); @@ -73,7 +73,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(0, $subtasks[0]['timer_start_date']); $this->assertFalse($subtasks[0]['is_timer_started']); - $subtask = $s->getbyId(1, true); + $subtask = $s->getById(1, true); $this->assertNotEmpty($subtask); $this->assertEquals(0, $subtask['timer_start_date']); $this->assertFalse($subtask['is_timer_started']); @@ -81,10 +81,10 @@ class SubtaskTimeTrackingTest extends Base public function testLogStartTime() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -103,10 +103,10 @@ class SubtaskTimeTrackingTest extends Base public function testLogStartEnd() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -134,10 +134,10 @@ class SubtaskTimeTrackingTest extends Base public function testCalculateSubtaskTime() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -145,7 +145,6 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4))); $time = $st->calculateSubtaskTime(1); - $this->assertNotempty($time); $this->assertCount(2, $time); $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01); $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01); @@ -153,10 +152,10 @@ class SubtaskTimeTrackingTest extends Base public function testUpdateSubtaskTimeSpent() { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); @@ -167,7 +166,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertTrue($st->logStartTime(2, 1)); // Fake start time - $this->container['db']->table(SubtaskTimeTracking::TABLE)->update(array('start' => time() - 3600)); + $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600)); $this->assertTrue($st->logEndTime(1, 1)); $this->assertTrue($st->logEndTime(2, 1)); @@ -179,23 +178,21 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1); $time = $st->calculateSubtaskTime(1); - $this->assertNotempty($time); $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01); $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01); $time = $st->calculateSubtaskTime(2); - $this->assertNotempty($time); $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01); $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01); } public function testUpdateTaskTimeTracking() { - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $st = new SubtaskTimeTrackingModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php index 71c13e40..cf0be169 100644 --- a/tests/units/Model/SwimlaneTest.php +++ b/tests/units/Model/SwimlaneTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Swimlane; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\SwimlaneModel; class SwimlaneTest extends Base { public function testCreation() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -30,10 +30,23 @@ class SwimlaneTest extends Base $this->assertEquals('', $s->getNameById(23)); } + public function testGetFirstActiveSwimlane() + { + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1', 'is_active' => 0))); + $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2'))); + + $swimlane = $swimlaneModel->getFirstActiveSwimlane(1); + $this->assertEquals(2, $swimlane['id']); + } + public function testGetList() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -47,8 +60,8 @@ class SwimlaneTest extends Base public function testUpdate() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -66,8 +79,8 @@ class SwimlaneTest extends Base public function testUpdateDefaultSwimlane() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertTrue($s->updateDefault(array('id' => 1, 'default_swimlane' => 'foo', 'show_default_swimlane' => 1))); @@ -87,8 +100,8 @@ class SwimlaneTest extends Base public function testDisableEnableDefaultSwimlane() { - $projectModel = new Project($this->container); - $swimlaneModel = new Swimlane($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); @@ -103,8 +116,8 @@ class SwimlaneTest extends Base public function testDisableEnable() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -143,22 +156,22 @@ class SwimlaneTest extends Base public function testRemove() { - $p = new Project($this->container); - $s = new Swimlane($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'swimlane_id' => 1))); - $task = $tf->getbyId(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['swimlane_id']); $this->assertTrue($s->remove(1, 1)); - $task = $tf->getbyId(1); + $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(0, $task['swimlane_id']); @@ -167,8 +180,8 @@ class SwimlaneTest extends Base public function testUpdatePositions() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -227,8 +240,8 @@ class SwimlaneTest extends Base public function testDuplicateSwimlane() { - $p = new Project($this->container); - $s = new Swimlane($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'P1'))); $this->assertEquals(2, $p->create(array('name' => 'P2'))); @@ -258,8 +271,8 @@ class SwimlaneTest extends Base public function testChangePosition() { - $projectModel = new Project($this->container); - $swimlaneModel = new Swimlane($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); @@ -321,8 +334,8 @@ class SwimlaneTest extends Base public function testChangePositionWithInactiveSwimlane() { - $projectModel = new Project($this->container); - $swimlaneModel = new Swimlane($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php index 04d23930..aba52ae2 100644 --- a/tests/units/Model/TaskCreationTest.php +++ b/tests/units/Model/TaskCreationTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; class TaskCreationTest extends Base { @@ -22,36 +22,36 @@ class TaskCreationTest extends Base public function testNoProjectId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayNotHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayNotHasKey(TaskModel::EVENT_CREATE.'.closure', $called); } public function testNoTitle() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -62,19 +62,19 @@ class TaskCreationTest extends Base public function testMinimum() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, array($this, 'onCreate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, array($this, 'onCreate')); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.TaskCreationTest::onCreate', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.TaskCreationTest::onCreate', $called); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -108,16 +108,15 @@ class TaskCreationTest extends Base public function testColorId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue'))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals('blue', $task['color_id']); @@ -125,16 +124,15 @@ class TaskCreationTest extends Base public function testOwnerId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['owner_id']); @@ -142,16 +140,15 @@ class TaskCreationTest extends Base public function testCategoryId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['category_id']); @@ -159,16 +156,15 @@ class TaskCreationTest extends Base public function testCreatorId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['creator_id']); @@ -176,9 +172,9 @@ class TaskCreationTest extends Base public function testThatCreatorIsDefined() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->container['sessionStorage']->user = array('id' => 1); @@ -187,7 +183,6 @@ class TaskCreationTest extends Base $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['creator_id']); @@ -195,16 +190,15 @@ class TaskCreationTest extends Base public function testColumnId() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); @@ -213,16 +207,15 @@ class TaskCreationTest extends Base public function testPosition() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['column_id']); @@ -232,7 +225,6 @@ class TaskCreationTest extends Base $task = $tf->getById(2); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(2, $task['id']); $this->assertEquals(2, $task['column_id']); @@ -241,16 +233,15 @@ class TaskCreationTest extends Base public function testDescription() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test'))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals('test', $task['description']); @@ -258,16 +249,15 @@ class TaskCreationTest extends Base public function testReference() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test'))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals('test', $task['reference']); @@ -277,9 +267,9 @@ class TaskCreationTest extends Base { $date = '2014-11-23'; $timestamp = strtotime('+2days'); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date))); @@ -303,9 +293,9 @@ class TaskCreationTest extends Base public function testDateStarted() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); @@ -341,16 +331,15 @@ class TaskCreationTest extends Base public function testTime() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); $this->assertEquals(1, $task['id']); $this->assertEquals(1.5, $task['time_estimated']); @@ -359,23 +348,22 @@ class TaskCreationTest extends Base public function testStripColumn() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1'))); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertNotFalse($task); } public function testScore() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'score' => '3'))); @@ -388,10 +376,10 @@ class TaskCreationTest extends Base public function testDefaultColor() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $c = new Config($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $c = new ConfigModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test1'))); @@ -412,9 +400,9 @@ class TaskCreationTest extends Base public function testDueDateYear2038TimestampBug() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => strtotime('2050-01-10 12:30')))); diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php index c4b36e45..79b75e54 100644 --- a/tests/units/Model/TaskDuplicationTest.php +++ b/tests/units/Model/TaskDuplicationTest.php @@ -3,25 +3,25 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\DateParser; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskDuplication; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\Category; -use Kanboard\Model\User; -use Kanboard\Model\Swimlane; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskDuplicationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\CategoryModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\SwimlaneModel; use Kanboard\Core\Security\Role; class TaskDuplicationTest extends Base { public function testThatDuplicateDefineCreator() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -45,11 +45,11 @@ class TaskDuplicationTest extends Base public function testDuplicateSameProject() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create a task and a project $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -73,20 +73,20 @@ class TaskDuplicationTest extends Base $this->assertEquals(2, $task['category_id']); $this->assertEquals(4.4, $task['time_spent']); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); // We duplicate our task $this->assertEquals(2, $td->duplicate(1)); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); // Check the values of the duplicated task $task = $tf->getById(2); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(1, $task['project_id']); $this->assertEquals(1, $task['owner_id']); $this->assertEquals(2, $task['category_id']); @@ -99,11 +99,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProject() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -115,15 +115,15 @@ class TaskDuplicationTest extends Base // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); // We duplicate our task to the 2nd project $this->assertEquals(2, $td->duplicateToProject(1, 2)); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); // Check the values of the duplicated task $task = $tf->getById(2); @@ -139,11 +139,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithCategory() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -174,11 +174,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedCategory() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -213,11 +213,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -246,11 +246,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithoutSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -279,11 +279,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -307,10 +307,10 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedColumn() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -330,11 +330,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -356,7 +356,7 @@ class TaskDuplicationTest extends Base $this->assertEquals('test', $task['title']); // We create a new user for our project - $user = new User($this->container); + $user = new UserModel($this->container); $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); @@ -386,11 +386,11 @@ class TaskDuplicationTest extends Base public function testDuplicateAnotherProjectWithPredefinedUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pr = new ProjectUserRole($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pr = new ProjectUserRoleModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -421,11 +421,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProject() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $user = new User($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $user = new UserModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -434,13 +434,13 @@ class TaskDuplicationTest extends Base // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_PROJECT, array($this, 'onMoveProject')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject')); // We duplicate our task to the 2nd project $this->assertTrue($td->moveToProject(1, 2)); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called); // Check the values of the moved task $task = $tf->getById(1); @@ -456,11 +456,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithCategory() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $c = new CategoryModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -491,12 +491,12 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $user = new User($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $user = new UserModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -524,12 +524,12 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithForbiddenUser() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $pp = new ProjectUserRole($this->container); - $user = new User($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $pp = new ProjectUserRoleModel($this->container); + $user = new UserModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -557,11 +557,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -590,11 +590,11 @@ class TaskDuplicationTest extends Base public function testMoveAnotherProjectWithoutSwimlane() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -623,48 +623,47 @@ class TaskDuplicationTest extends Base public function testCalculateRecurringTaskDueDate() { - $td = new TaskDuplication($this->container); + $td = new TaskDuplicationModel($this->container); $values = array('date_due' => 0); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(0, $values['date_due']); - $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(0, $values['date_due']); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(time() + 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_MONTHS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1436561776, $values['date_due'], '', 1); - $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_YEARS); + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS); $td->calculateRecurringTaskDueDate($values); $this->assertEquals(1494449776, $values['date_due'], '', 1); } public function testDuplicateRecurringTask() { - $td = new TaskDuplication($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $td = new TaskDuplicationModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $dp = new DateParser($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -673,27 +672,27 @@ class TaskDuplicationTest extends Base 'title' => 'test', 'project_id' => 1, 'date_due' => 1436561776, - 'recurrence_status' => Task::RECURRING_STATUS_PENDING, - 'recurrence_trigger' => Task::RECURRING_TRIGGER_CLOSE, + 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING, + 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE, 'recurrence_factor' => 2, - 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS, - 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, + 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS, + 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, ))); $this->assertEquals(2, $td->duplicateRecurringTask(1)); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); $this->assertEquals(2, $task['recurrence_child']); $this->assertEquals(1436486400, $task['date_due'], '', 2); $task = $tf->getById(2); $this->assertNotEmpty($task); - $this->assertEquals(Task::RECURRING_STATUS_PENDING, $task['recurrence_status']); - $this->assertEquals(Task::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); - $this->assertEquals(Task::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); - $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); + $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); + $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); + $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); $this->assertEquals(1, $task['recurrence_parent']); $this->assertEquals(2, $task['recurrence_factor']); $this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2); diff --git a/tests/units/Model/TaskExternalLinkTest.php b/tests/units/Model/TaskExternalLinkTest.php index 28ccab83..1327b6e1 100644 --- a/tests/units/Model/TaskExternalLinkTest.php +++ b/tests/units/Model/TaskExternalLinkTest.php @@ -2,9 +2,9 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\TaskExternalLink; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskExternalLinkModel; use Kanboard\Core\ExternalLink\ExternalLinkManager; use Kanboard\ExternalLink\WebLinkProvider; @@ -12,18 +12,18 @@ class TaskExternalLinkTest extends Base { public function testCreate() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); $link = $taskExternalLinkModel->getById(1); $this->assertNotEmpty($link); $this->assertEquals('My website', $link['title']); - $this->assertEquals('http://kanboard.net/', $link['url']); + $this->assertEquals('https://kanboard.net/', $link['url']); $this->assertEquals('related', $link['dependency']); $this->assertEquals('weblink', $link['link_type']); $this->assertEquals(0, $link['creator_id']); @@ -35,18 +35,18 @@ class TaskExternalLinkTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); $link = $taskExternalLinkModel->getById(1); $this->assertNotEmpty($link); $this->assertEquals('My website', $link['title']); - $this->assertEquals('http://kanboard.net/', $link['url']); + $this->assertEquals('https://kanboard.net/', $link['url']); $this->assertEquals('related', $link['dependency']); $this->assertEquals('weblink', $link['link_type']); $this->assertEquals(1, $link['creator_id']); @@ -56,13 +56,13 @@ class TaskExternalLinkTest extends Base public function testModification() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); sleep(1); @@ -76,13 +76,13 @@ class TaskExternalLinkTest extends Base public function testRemove() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); - $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); $this->assertTrue($taskExternalLinkModel->remove(1)); $this->assertFalse($taskExternalLinkModel->remove(1)); @@ -95,9 +95,9 @@ class TaskExternalLinkTest extends Base $this->container['sessionStorage']->user = array('id' => 1); $this->container['externalLinkManager'] = new ExternalLinkManager($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $taskExternalLinkModel = new TaskExternalLink($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskExternalLinkModel = new TaskExternalLinkModel($this->container); $webLinkProvider = new WebLinkProvider($this->container); $this->container['externalLinkManager']->register($webLinkProvider); @@ -105,7 +105,7 @@ class TaskExternalLinkTest extends Base $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'https://miniflux.net/', 'title' => 'MX', 'link_type' => 'weblink', 'dependency' => 'related'))); - $this->assertEquals(2, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'http://kanboard.net/', 'title' => 'KB', 'link_type' => 'weblink', 'dependency' => 'related'))); + $this->assertEquals(2, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'https://kanboard.net/', 'title' => 'KB', 'link_type' => 'weblink', 'dependency' => 'related'))); $links = $taskExternalLinkModel->getAll(1); $this->assertCount(2, $links); diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileTest.php index e44e092d..2faee95c 100644 --- a/tests/units/Model/TaskFileTest.php +++ b/tests/units/Model/TaskFileTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFile; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskFileTest extends Base { public function testCreation() { - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -38,9 +38,9 @@ class TaskFileTest extends Base public function testCreationWithFileNameTooLong() { - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -60,9 +60,9 @@ class TaskFileTest extends Base { $this->container['sessionStorage']->user = array('id' => 1); - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -75,9 +75,9 @@ class TaskFileTest extends Base public function testGetAll() { - $projectModel = new Project($this->container); - $fileModel = new TaskFile($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $fileModel = new TaskFileModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -110,7 +110,7 @@ class TaskFileTest extends Base public function testIsImage() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertTrue($fileModel->isImage('test.png')); $this->assertTrue($fileModel->isImage('test.jpeg')); @@ -125,13 +125,13 @@ class TaskFileTest extends Base public function testGetThumbnailPath() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); } public function testGeneratePath() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertStringStartsWith('tasks'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); @@ -140,13 +140,13 @@ class TaskFileTest extends Base public function testUploadFiles() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -208,7 +208,7 @@ class TaskFileTest extends Base public function testUploadFilesWithEmptyFiles() { - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, array())); } @@ -233,7 +233,7 @@ class TaskFileTest extends Base ), ); - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } @@ -264,20 +264,20 @@ class TaskFileTest extends Base ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); - $fileModel = new TaskFile($this->container); + $fileModel = new TaskFileModel($this->container); $this->assertFalse($fileModel->uploadFiles(1, $files)); } public function testUploadFileContent() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -305,13 +305,13 @@ class TaskFileTest extends Base public function testUploadFileContentWithObjectStorageError() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromFile')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -329,13 +329,13 @@ class TaskFileTest extends Base public function testUploadScreenshot() { $fileModel = $this - ->getMockBuilder('\Kanboard\Model\TaskFile') + ->getMockBuilder('\Kanboard\Model\TaskFileModel') ->setConstructorArgs(array($this->container)) ->setMethods(array('generateThumbnailFromData')) ->getMock(); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $data = 'test'; $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); @@ -366,9 +366,9 @@ class TaskFileTest extends Base public function testRemove() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -384,9 +384,9 @@ class TaskFileTest extends Base public function testRemoveWithObjectStorageError() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -403,9 +403,9 @@ class TaskFileTest extends Base public function testRemoveImage() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -426,9 +426,9 @@ class TaskFileTest extends Base public function testRemoveAll() { - $fileModel = new TaskFile($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); + $fileModel = new TaskFileModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php index 0ed211ed..46792baf 100644 --- a/tests/units/Model/TaskFinderTest.php +++ b/tests/units/Model/TaskFinderTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; class TaskFinderTest extends Base { public function testGetOverdueTasks() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day')))); @@ -29,9 +29,9 @@ class TaskFinderTest extends Base public function testGetOverdueTasksByProject() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); @@ -44,15 +44,15 @@ class TaskFinderTest extends Base $tasks = $tf->getOverdueTasksByProject(1); $this->assertNotEmpty($tasks); $this->assertTrue(is_array($tasks)); - $this->assertcount(1, $tasks); + $this->assertCount(1, $tasks); $this->assertEquals('Task #1', $tasks[0]['title']); } public function testGetOverdueTasksByUser() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); @@ -80,9 +80,9 @@ class TaskFinderTest extends Base public function testCountByProject() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); @@ -93,4 +93,23 @@ class TaskFinderTest extends Base $this->assertEquals(1, $tf->countByProjectId(1)); $this->assertEquals(2, $tf->countByProjectId(2)); } + + public function testGetProjectToken() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2'))); + + $this->assertTrue($projectModel->enablePublicAccess(1)); + + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2))); + + $project = $projectModel->getById(1); + $this->assertEquals($project['token'], $taskFinderModel->getProjectToken(1)); + $this->assertEmpty($taskFinderModel->getProjectToken(2)); + } } diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php index 8dd71830..bc574731 100644 --- a/tests/units/Model/TaskLinkTest.php +++ b/tests/units/Model/TaskLinkTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskLink; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskLinkModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskLinkTest extends Base { // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression" public function testGetTaskWithMultipleMilestoneLink() { - $tf = new TaskFinder($this->container); - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tf = new TaskFinderModel($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -31,9 +31,9 @@ class TaskLinkTest extends Base public function testCreateTaskLinkWithNoOpposite() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -73,9 +73,9 @@ class TaskLinkTest extends Base public function testCreateTaskLinkWithOpposite() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -115,9 +115,9 @@ class TaskLinkTest extends Base public function testGroupByLabel() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); @@ -139,9 +139,9 @@ class TaskLinkTest extends Base public function testUpdate() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2'))); @@ -172,9 +172,9 @@ class TaskLinkTest extends Base public function testRemove() { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); diff --git a/tests/units/Model/TaskMetadataTest.php b/tests/units/Model/TaskMetadataTest.php index 2683c297..b1e7eee8 100644 --- a/tests/units/Model/TaskMetadataTest.php +++ b/tests/units/Model/TaskMetadataTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskMetadata; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskMetadataModel; class TaskMetadataTest extends Base { public function testOperations() { - $p = new Project($this->container); - $tm = new TaskMetadata($this->container); - $tc = new TaskCreation($this->container); + $p = new ProjectModel($this->container); + $tm = new TaskMetadataModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'task #1', 'project_id' => 1))); diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php index 315125d5..022fb49b 100644 --- a/tests/units/Model/TaskModificationTest.php +++ b/tests/units/Model/TaskModificationTest.php @@ -2,11 +2,11 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskModification; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskModificationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; class TaskModificationTest extends Base { @@ -42,16 +42,16 @@ class TaskModificationTest extends Base public function testThatNoEventAreFiredWhenNoChanges() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); - $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate')); $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test'))); @@ -60,22 +60,22 @@ class TaskModificationTest extends Base public function testChangeTitle() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); - $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate')); $this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1'))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called); - $this->assertArrayHasKey(Task::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called); + $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called); $task = $tf->getById(1); $this->assertEquals('Task #1', $task['title']); @@ -83,10 +83,10 @@ class TaskModificationTest extends Base public function testChangeAssignee() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -94,12 +94,12 @@ class TaskModificationTest extends Base $task = $tf->getById(1); $this->assertEquals(0, $task['owner_id']); - $this->container['dispatcher']->addListener(Task::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange')); $this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1))); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called); + $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called); $task = $tf->getById(1); $this->assertEquals(1, $task['owner_id']); @@ -107,10 +107,10 @@ class TaskModificationTest extends Base public function testChangeDescription() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -126,10 +126,10 @@ class TaskModificationTest extends Base public function testChangeCategory() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -145,10 +145,10 @@ class TaskModificationTest extends Base public function testChangeColor() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -164,10 +164,10 @@ class TaskModificationTest extends Base public function testChangeScore() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -183,10 +183,10 @@ class TaskModificationTest extends Base public function testChangeDueDate() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -207,10 +207,10 @@ class TaskModificationTest extends Base public function testChangeStartedDate() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -245,10 +245,10 @@ class TaskModificationTest extends Base public function testChangeTimeEstimated() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -264,10 +264,10 @@ class TaskModificationTest extends Base public function testChangeTimeSpent() { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $tf = new TaskFinder($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tm = new TaskModificationModel($this->container); + $tf = new TaskFinderModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); diff --git a/tests/units/Model/TaskPermissionTest.php b/tests/units/Model/TaskPermissionTest.php deleted file mode 100644 index 82cd581e..00000000 --- a/tests/units/Model/TaskPermissionTest.php +++ /dev/null @@ -1,103 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskPermission; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Core\User\UserSession; - -class TaskPermissionTest extends Base -{ - public function testPrepareCreation() - { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $tp = new TaskPermission($this->container); - $p = new Project($this->container); - $u = new User($this->container); - $us = new UserSession($this->container); - - $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456'))); - $this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456'))); - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2))); - $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3))); - $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1))); - - // User #1 can remove everything - $user = $u->getbyId(1); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(1); - $this->assertNotEmpty($task); - $this->assertTrue($tp->canRemoveTask($task)); - - // User #2 can't remove the task #1 - $user = $u->getbyId(2); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(1); - $this->assertNotEmpty($task); - $this->assertFalse($tp->canRemoveTask($task)); - - // User #1 can remove everything - $user = $u->getbyId(1); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(2); - $this->assertNotEmpty($task); - $this->assertTrue($tp->canRemoveTask($task)); - - // User #2 can remove his own task - $user = $u->getbyId(2); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(2); - $this->assertNotEmpty($task); - $this->assertTrue($tp->canRemoveTask($task)); - - // User #1 can remove everything - $user = $u->getbyId(1); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(3); - $this->assertNotEmpty($task); - $this->assertTrue($tp->canRemoveTask($task)); - - // User #2 can't remove the task #3 - $user = $u->getbyId(2); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(3); - $this->assertNotEmpty($task); - $this->assertFalse($tp->canRemoveTask($task)); - - // User #1 can remove everything - $user = $u->getbyId(1); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(4); - $this->assertNotEmpty($task); - $this->assertTrue($tp->canRemoveTask($task)); - - // User #2 can't remove the task #4 - $user = $u->getbyId(2); - $this->assertNotEmpty($user); - $us->initialize($user); - - $task = $tf->getbyId(4); - $this->assertNotEmpty($task); - $this->assertFalse($tp->canRemoveTask($task)); - } -} diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionTest.php index 28145a66..7ab6950e 100644 --- a/tests/units/Model/TaskPositionTest.php +++ b/tests/units/Model/TaskPositionTest.php @@ -2,26 +2,26 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\Column; -use Kanboard\Model\TaskStatus; -use Kanboard\Model\TaskPosition; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Swimlane; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ColumnModel; +use Kanboard\Model\TaskStatusModel; +use Kanboard\Model\TaskPositionModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\SwimlaneModel; class TaskPositionTest extends Base { public function testGetTaskProgression() { - $t = new Task($this->container); - $ts = new TaskStatus($this->container); - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $columnModel = new Column($this->container); + $t = new TaskModel($this->container); + $ts = new TaskStatusModel($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $columnModel = new ColumnModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); @@ -42,10 +42,10 @@ class TaskPositionTest extends Base public function testMoveTaskToWrongPosition() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -69,10 +69,10 @@ class TaskPositionTest extends Base public function testMoveTaskToGreaterPosition() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -96,10 +96,10 @@ class TaskPositionTest extends Base public function testMoveTaskToEmptyColumn() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -123,10 +123,10 @@ class TaskPositionTest extends Base public function testMoveTaskToAnotherColumn() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -186,10 +186,10 @@ class TaskPositionTest extends Base public function testMoveTaskTop() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); @@ -224,10 +224,10 @@ class TaskPositionTest extends Base public function testMoveTaskBottom() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); @@ -262,10 +262,10 @@ class TaskPositionTest extends Base public function testMovePosition() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $counter = 1; @@ -283,7 +283,6 @@ class TaskPositionTest extends Base $this->assertEquals($counter, $tc->create($task)); $task = $tf->getById($counter); - $this->assertNotFalse($task); $this->assertNotEmpty($task); $this->assertEquals($i, $task['position']); } @@ -416,11 +415,11 @@ class TaskPositionTest extends Base public function testMoveTaskSwimlane() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1'))); @@ -523,11 +522,11 @@ class TaskPositionTest extends Base public function testEvents() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $tp = new TaskPositionModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1'))); @@ -535,9 +534,9 @@ class TaskPositionTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2))); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn')); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_POSITION, array($this, 'onMovePosition')); - $this->container['dispatcher']->addListener(Task::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, array($this, 'onMovePosition')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane')); // We move the task 1 to the column 2 $this->assertTrue($tp->movePosition(1, 1, 2, 1)); @@ -553,7 +552,7 @@ class TaskPositionTest extends Base $this->assertEquals(2, $task['position']); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called); $this->assertEquals(1, count($called)); // We move the task 1 to the position 2 @@ -570,7 +569,7 @@ class TaskPositionTest extends Base $this->assertEquals(1, $task['position']); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called); $this->assertEquals(2, count($called)); // Move to another swimlane @@ -589,7 +588,7 @@ class TaskPositionTest extends Base $this->assertEquals(0, $task['swimlane_id']); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called); $this->assertEquals(3, count($called)); } diff --git a/tests/units/Model/TaskStatusTest.php b/tests/units/Model/TaskStatusTest.php index 86f31d70..f011409d 100644 --- a/tests/units/Model/TaskStatusTest.php +++ b/tests/units/Model/TaskStatusTest.php @@ -2,23 +2,23 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Swimlane; -use Kanboard\Model\Subtask; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskStatus; -use Kanboard\Model\Project; +use Kanboard\Model\SwimlaneModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskStatusModel; +use Kanboard\Model\ProjectModel; class TaskStatusTest extends Base { public function testCloseBySwimlaneAndColumn() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $ts = new TaskStatus($this->container); - $p = new Project($this->container); - $s = new Swimlane($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $ts = new TaskStatusModel($this->container); + $p = new ProjectModel($this->container); + $s = new SwimlaneModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $s->create(array('name' => 'test', 'project_id' => 1))); @@ -26,6 +26,9 @@ class TaskStatusTest extends Base $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertEquals(3, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2))); $this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'swimlane_id' => 1))); + $this->assertEquals(5, $tc->create(array('title' => 'test', 'project_id' => 1, 'is_active' => 0, 'date_completed' => strtotime('2015-01-01')))); + + $taskBefore = $tf->getById(5); $this->assertEquals(2, $tf->countByColumnAndSwimlaneId(1, 1, 0)); $this->assertEquals(1, $tf->countByColumnAndSwimlaneId(1, 1, 1)); @@ -45,14 +48,18 @@ class TaskStatusTest extends Base $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 0)); $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 1)); $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 2, 0)); + + $taskAfter = $tf->getById(5); + $this->assertEquals(strtotime('2015-01-01'), $taskAfter['date_completed']); + $this->assertEquals($taskBefore['date_modification'], $taskAfter['date_modification']); } public function testStatus() { - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $ts = new TaskStatus($this->container); - $p = new Project($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $ts = new TaskStatusModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -63,21 +70,21 @@ class TaskStatusTest extends Base $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(0, $task['date_completed']); $this->assertEquals(time(), $task['date_modification'], '', 1); // We close the task - $this->container['dispatcher']->addListener(Task::EVENT_CLOSE, array($this, 'onTaskClose')); - $this->container['dispatcher']->addListener(Task::EVENT_OPEN, array($this, 'onTaskOpen')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CLOSE, array($this, 'onTaskClose')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_OPEN, array($this, 'onTaskOpen')); $this->assertTrue($ts->close(1)); $this->assertTrue($ts->isClosed(1)); $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_CLOSED, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_CLOSED, $task['is_active']); $this->assertEquals(time(), $task['date_completed'], 'Bad completion timestamp', 1); $this->assertEquals(time(), $task['date_modification'], 'Bad modification timestamp', 1); @@ -88,7 +95,7 @@ class TaskStatusTest extends Base $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(0, $task['date_completed']); $this->assertEquals(time(), $task['date_modification'], '', 1); @@ -113,10 +120,10 @@ class TaskStatusTest extends Base public function testThatAllSubtasksAreClosed() { - $ts = new TaskStatus($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); + $ts = new TaskStatusModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); @@ -130,7 +137,7 @@ class TaskStatusTest extends Base $this->assertNotEmpty($subtasks); foreach ($subtasks as $subtask) { - $this->assertEquals(Subtask::STATUS_DONE, $subtask['status']); + $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']); } } } diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php index 60e752e5..89fc4dc1 100644 --- a/tests/units/Model/TaskTest.php +++ b/tests/units/Model/TaskTest.php @@ -2,22 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskStatus; -use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\User; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskTest extends Base { public function testRemove() { - $t = new Task($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $t = new TaskModel($this->container); + $tc = new TaskCreationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); @@ -28,36 +23,36 @@ class TaskTest extends Base public function testGetTaskIdFromText() { - $t = new Task($this->container); + $t = new TaskModel($this->container); $this->assertEquals(123, $t->getTaskIdFromText('My task #123')); $this->assertEquals(0, $t->getTaskIdFromText('My task 123')); } public function testRecurrenceSettings() { - $t = new Task($this->container); + $t = new TaskModel($this->container); $statuses = $t->getRecurrenceStatusList(); $this->assertCount(2, $statuses); - $this->assertArrayHasKey(Task::RECURRING_STATUS_NONE, $statuses); - $this->assertArrayHasKey(Task::RECURRING_STATUS_PENDING, $statuses); - $this->assertArrayNotHasKey(Task::RECURRING_STATUS_PROCESSED, $statuses); + $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_NONE, $statuses); + $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_PENDING, $statuses); + $this->assertArrayNotHasKey(TaskModel::RECURRING_STATUS_PROCESSED, $statuses); $triggers = $t->getRecurrenceTriggerList(); $this->assertCount(3, $triggers); - $this->assertArrayHasKey(Task::RECURRING_TRIGGER_FIRST_COLUMN, $triggers); - $this->assertArrayHasKey(Task::RECURRING_TRIGGER_LAST_COLUMN, $triggers); - $this->assertArrayHasKey(Task::RECURRING_TRIGGER_CLOSE, $triggers); + $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $triggers); + $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_LAST_COLUMN, $triggers); + $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_CLOSE, $triggers); $dates = $t->getRecurrenceBasedateList(); $this->assertCount(2, $dates); - $this->assertArrayHasKey(Task::RECURRING_BASEDATE_DUEDATE, $dates); - $this->assertArrayHasKey(Task::RECURRING_BASEDATE_TRIGGERDATE, $dates); + $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_DUEDATE, $dates); + $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $dates); $timeframes = $t->getRecurrenceTimeframeList(); $this->assertCount(3, $timeframes); - $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_DAYS, $timeframes); - $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_MONTHS, $timeframes); - $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_YEARS, $timeframes); + $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_DAYS, $timeframes); + $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_MONTHS, $timeframes); + $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_YEARS, $timeframes); } } diff --git a/tests/units/Model/TimezoneTest.php b/tests/units/Model/TimezoneTest.php new file mode 100644 index 00000000..8e7103d8 --- /dev/null +++ b/tests/units/Model/TimezoneTest.php @@ -0,0 +1,32 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TimezoneModel; + +class TimezoneTest extends Base +{ + public function testGetTimezones() + { + $timezoneModel = new TimezoneModel($this->container); + $this->assertNotEmpty($timezoneModel->getTimezones()); + $this->assertArrayHasKey('Europe/Paris', $timezoneModel->getTimezones()); + $this->assertContains('Europe/Paris', $timezoneModel->getTimezones()); + $this->assertArrayNotHasKey('', $timezoneModel->getTimezones()); + + $this->assertArrayHasKey('', $timezoneModel->getTimezones(true)); + $this->assertContains('Application default', $timezoneModel->getTimezones(true)); + } + + public function testGetCurrentTimezone() + { + $timezoneModel = new TimezoneModel($this->container); + $this->assertEquals('UTC', $timezoneModel->getCurrentTimezone()); + + $this->container['sessionStorage']->user = array('timezone' => 'Europe/Paris'); + $this->assertEquals('Europe/Paris', $timezoneModel->getCurrentTimezone()); + + $this->container['sessionStorage']->user = array('timezone' => 'Something'); + $this->assertEquals('Something', $timezoneModel->getCurrentTimezone()); + } +} diff --git a/tests/units/Model/TransitionTest.php b/tests/units/Model/TransitionTest.php index 0c262e78..2edf9c43 100644 --- a/tests/units/Model/TransitionTest.php +++ b/tests/units/Model/TransitionTest.php @@ -2,17 +2,17 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Transition; -use Kanboard\Model\Project; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TransitionModel; +use Kanboard\Model\ProjectModel; class TransitionTest extends Base { public function testSave() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -40,9 +40,9 @@ class TransitionTest extends Base public function testGetTimeSpentByTask() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); @@ -77,9 +77,9 @@ class TransitionTest extends Base public function testGetAllByProject() { - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $transitionModel = new Transition($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $transitionModel = new TransitionModel($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1'))); diff --git a/tests/units/Model/UserLockingTest.php b/tests/units/Model/UserLockingTest.php index c743f8eb..1fcb97fe 100644 --- a/tests/units/Model/UserLockingTest.php +++ b/tests/units/Model/UserLockingTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\UserLocking; +use Kanboard\Model\UserLockingModel; class UserLockingTest extends Base { public function testFailedLogin() { - $u = new UserLocking($this->container); + $u = new UserLockingModel($this->container); $this->assertEquals(0, $u->getFailedLogin('admin')); $this->assertEquals(0, $u->getFailedLogin('not_found')); @@ -23,7 +23,7 @@ class UserLockingTest extends Base public function testLocking() { - $u = new UserLocking($this->container); + $u = new UserLockingModel($this->container); $this->assertFalse($u->isLocked('admin')); $this->assertFalse($u->isLocked('not_found')); @@ -33,7 +33,7 @@ class UserLockingTest extends Base public function testCaptcha() { - $u = new UserLocking($this->container); + $u = new UserLockingModel($this->container); $this->assertTrue($u->incrementFailedLogin('admin')); $this->assertFalse($u->hasCaptcha('admin', 2)); diff --git a/tests/units/Model/UserMentionTest.php b/tests/units/Model/UserMentionTest.php index d50c9285..b41c92cd 100644 --- a/tests/units/Model/UserMentionTest.php +++ b/tests/units/Model/UserMentionTest.php @@ -4,19 +4,19 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\Security\Role; use Kanboard\Event\GenericEvent; -use Kanboard\Model\User; -use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\UserMention; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\UserMentionModel; class UserMentionTest extends Base { public function testGetMentionedUsersWithNoMentions() { - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertEmpty($userMentionModel->getMentionedUsers('test')); @@ -24,8 +24,8 @@ class UserMentionTest extends Base public function testGetMentionedUsersWithNotficationDisabled() { - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertEmpty($userMentionModel->getMentionedUsers('test @user1')); @@ -33,8 +33,8 @@ class UserMentionTest extends Base public function testGetMentionedUsersWithNotficationEnabled() { - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); @@ -50,8 +50,8 @@ class UserMentionTest extends Base public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn() { $this->container['sessionStorage']->user = array('id' => 3); - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); @@ -61,10 +61,10 @@ class UserMentionTest extends Base public function testFireEventsWithMultipleMentions() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $projectModel = new Project($this->container); - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $event = new GenericEvent(array('project_id' => 1)); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); @@ -73,21 +73,21 @@ class UserMentionTest extends Base $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); - $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention')); - $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); } public function testFireEventsWithNoProjectId() { - $projectUserRoleModel = new ProjectUserRole($this->container); - $projectModel = new Project($this->container); - $taskCreationModel = new TaskCreation($this->container); - $userModel = new User($this->container); - $userMentionModel = new UserMention($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $userModel = new UserModel($this->container); + $userMentionModel = new UserMentionModel($this->container); $event = new GenericEvent(array('task_id' => 1)); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); @@ -98,12 +98,12 @@ class UserMentionTest extends Base $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1'))); - $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention')); - $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); } public function onUserMention($event) diff --git a/tests/units/Model/UserMetadataTest.php b/tests/units/Model/UserMetadataTest.php index 457f1fb2..fb427371 100644 --- a/tests/units/Model/UserMetadataTest.php +++ b/tests/units/Model/UserMetadataTest.php @@ -2,15 +2,15 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\UserMetadata; +use Kanboard\Model\UserModel; +use Kanboard\Model\UserMetadataModel; class UserMetadataTest extends Base { public function testOperations() { - $m = new UserMetadata($this->container); - $u = new User($this->container); + $m = new UserMetadataModel($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'foobar'))); diff --git a/tests/units/Model/UserNotificationFilterTest.php b/tests/units/Model/UserNotificationFilterTest.php index 924f0883..49c7aa0a 100644 --- a/tests/units/Model/UserNotificationFilterTest.php +++ b/tests/units/Model/UserNotificationFilterTest.php @@ -2,27 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\Project; -use Kanboard\Model\UserNotificationFilter; -use Kanboard\Model\UserNotification; +use Kanboard\Model\UserModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserNotificationFilterModel; +use Kanboard\Model\UserNotificationModel; class UserNotificationFilterTest extends Base { public function testGetFilters() { - $nf = new UserNotificationFilter($this->container); + $nf = new UserNotificationFilterModel($this->container); $filters = $nf->getFilters(); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_NONE, $filters); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_BOTH, $filters); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_CREATOR, $filters); - $this->assertArrayHasKey(UserNotificationFilter::FILTER_ASSIGNEE, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_NONE, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_BOTH, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_CREATOR, $filters); + $this->assertArrayHasKey(UserNotificationFilterModel::FILTER_ASSIGNEE, $filters); } public function testSaveProjectFilter() { - $nf = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $nf = new UserNotificationFilterModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); @@ -35,78 +35,78 @@ class UserNotificationFilterTest extends Base public function testSaveUserFilter() { - $nf = new UserNotificationFilter($this->container); + $nf = new UserNotificationFilterModel($this->container); - $this->assertEquals(UserNotificationFilter::FILTER_BOTH, $nf->getSelectedFilter(1)); - $nf->saveFilter(1, UserNotificationFilter::FILTER_CREATOR); - $this->assertEquals(UserNotificationFilter::FILTER_CREATOR, $nf->getSelectedFilter(1)); + $this->assertEquals(UserNotificationFilterModel::FILTER_BOTH, $nf->getSelectedFilter(1)); + $nf->saveFilter(1, UserNotificationFilterModel::FILTER_CREATOR); + $this->assertEquals(UserNotificationFilterModel::FILTER_CREATOR, $nf->getSelectedFilter(1)); } public function testFilterNone() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); - $this->assertTrue($n->filterNone($u->getById(2), array())); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); + $this->assertTrue($n->filterNone($u->getById(2))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); - $this->assertFalse($n->filterNone($u->getById(3), array())); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); + $this->assertFalse($n->filterNone($u->getById(3))); } public function testFilterCreator() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR))); $this->assertTrue($n->filterCreator($u->getById(2), array('task' => array('creator_id' => 2)))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR))); $this->assertFalse($n->filterCreator($u->getById(3), array('task' => array('creator_id' => 1)))); - $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertFalse($n->filterCreator($u->getById(4), array('task' => array('creator_id' => 2)))); } public function testFilterAssignee() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE))); $this->assertTrue($n->filterAssignee($u->getById(2), array('task' => array('owner_id' => 2)))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE))); $this->assertFalse($n->filterAssignee($u->getById(3), array('task' => array('owner_id' => 1)))); - $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertFalse($n->filterAssignee($u->getById(4), array('task' => array('owner_id' => 2)))); } public function testFilterBoth() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 0, 'creator_id' => 2)))); - $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 1, 'creator_id' => 1)))); $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); - $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertFalse($n->filterBoth($u->getById(4), array('task' => array('owner_id' => 2, 'creator_id' => 1)))); } public function testFilterProject() { - $u = new User($this->container); - $n = new UserNotification($this->container); - $nf = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationModel($this->container); + $nf = new UserNotificationFilterModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); @@ -115,7 +115,7 @@ class UserNotificationFilterTest extends Base $this->assertTrue($nf->filterProject($u->getById(1), array())); // User that select only some projects - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true))); $this->assertFalse($nf->filterProject($u->getById(2), array('task' => array('project_id' => 1)))); @@ -124,22 +124,20 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithNoFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_NONE))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1)))); } public function testFilterUserWithAssigneeFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 2)))); $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 1)))); @@ -147,11 +145,10 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithCreatorFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2)))); $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 1)))); @@ -159,11 +156,10 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithBothFilter() { - $u = new User($this->container); - $n = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationFilterModel($this->container); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3)))); $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2)))); @@ -173,15 +169,15 @@ class UserNotificationFilterTest extends Base public function testFilterUserWithBothFilterAndProjectSelected() { - $u = new User($this->container); - $n = new UserNotification($this->container); - $nf = new UserNotificationFilter($this->container); - $p = new Project($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationModel($this->container); + $nf = new UserNotificationFilterModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); + $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilterModel::FILTER_BOTH))); $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true))); diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php index 53034e20..6ee5c875 100644 --- a/tests/units/Model/UserNotificationTest.php +++ b/tests/units/Model/UserNotificationTest.php @@ -2,29 +2,28 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\User; -use Kanboard\Model\Group; -use Kanboard\Model\GroupMember; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\Task; -use Kanboard\Model\ProjectUserRole; -use Kanboard\Model\ProjectGroupRole; -use Kanboard\Model\UserNotification; -use Kanboard\Model\UserNotificationFilter; -use Kanboard\Subscriber\UserNotificationSubscriber; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\GroupModel; +use Kanboard\Model\GroupMemberModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\ProjectPermissionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectUserRoleModel; +use Kanboard\Model\ProjectGroupRoleModel; +use Kanboard\Model\UserNotificationModel; +use Kanboard\Model\UserNotificationFilterModel; use Kanboard\Core\Security\Role; class UserNotificationTest extends Base { public function testEnableDisableNotification() { - $u = new User($this->container); - $p = new Project($this->container); - $n = new UserNotification($this->container); - $pp = new ProjectUserRole($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $n = new UserNotificationModel($this->container); + $pp = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $u->create(array('username' => 'user1'))); @@ -39,29 +38,29 @@ class UserNotificationTest extends Base public function testReadWriteSettings() { - $n = new UserNotification($this->container); - $p = new Project($this->container); + $n = new UserNotificationModel($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $n->saveSettings(1, array( 'notifications_enabled' => 1, - 'notifications_filter' => UserNotificationFilter::FILTER_CREATOR, + 'notifications_filter' => UserNotificationFilterModel::FILTER_CREATOR, 'notification_types' => array('email' => 1), 'notification_projects' => array(), )); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(0)) ->method('getSelectedTypes') ->will($this->returnValue(array('email'))); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(1)) ->method('getSelectedTypes') ->will($this->returnValue(array('email'))); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(2)) ->method('getSelectedTypes') ->with($this->equalTo(1)) @@ -70,7 +69,7 @@ class UserNotificationTest extends Base $settings = $n->readSettings(1); $this->assertNotEmpty($settings); $this->assertEquals(1, $settings['notifications_enabled']); - $this->assertEquals(UserNotificationFilter::FILTER_CREATOR, $settings['notifications_filter']); + $this->assertEquals(UserNotificationFilterModel::FILTER_CREATOR, $settings['notifications_filter']); $this->assertEquals(array('email'), $settings['notification_types']); $this->assertEmpty($settings['notification_projects']); @@ -84,7 +83,7 @@ class UserNotificationTest extends Base $n->saveSettings(1, array( 'notifications_enabled' => 1, - 'notifications_filter' => UserNotificationFilter::FILTER_ASSIGNEE, + 'notifications_filter' => UserNotificationFilterModel::FILTER_ASSIGNEE, 'notification_types' => array('web' => 1, 'email' => 1), 'notification_projects' => array(1 => 1), )); @@ -92,24 +91,25 @@ class UserNotificationTest extends Base $settings = $n->readSettings(1); $this->assertNotEmpty($settings); $this->assertEquals(1, $settings['notifications_enabled']); - $this->assertEquals(UserNotificationFilter::FILTER_ASSIGNEE, $settings['notifications_filter']); + $this->assertEquals(UserNotificationFilterModel::FILTER_ASSIGNEE, $settings['notifications_filter']); $this->assertEquals(array('email', 'web'), $settings['notification_types']); $this->assertEquals(array(1), $settings['notification_projects']); } public function testGetGroupMembersWithNotificationEnabled() { - $userModel = new User($this->container); - $groupModel = new Group($this->container); - $groupMemberModel = new GroupMember($this->container); - $projectModel = new Project($this->container); - $userNotificationModel = new UserNotification($this->container); - $projectGroupRole = new ProjectGroupRole($this->container); - $projectUserRole = new ProjectUserRole($this->container); + $userModel = new UserModel($this->container); + $groupModel = new GroupModel($this->container); + $groupMemberModel = new GroupMemberModel($this->container); + $projectModel = new ProjectModel($this->container); + $userNotificationModel = new UserNotificationModel($this->container); + $projectGroupRole = new ProjectGroupRoleModel($this->container); + $projectUserRole = new ProjectUserRoleModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); - $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3', 'email' => '', 'notifications_enabled' => 1, 'is_active' => 0))); + $this->assertEquals(5, $userModel->create(array('username' => 'user4'))); $this->assertEquals(1, $groupModel->create('G1')); $this->assertEquals(2, $groupModel->create('G2')); @@ -117,6 +117,7 @@ class UserNotificationTest extends Base $this->assertTrue($groupMemberModel->addUser(1, 2)); $this->assertTrue($groupMemberModel->addUser(1, 3)); $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(1, 5)); $this->assertTrue($groupMemberModel->addUser(2, 2)); $this->assertTrue($groupMemberModel->addUser(2, 3)); @@ -135,34 +136,38 @@ class UserNotificationTest extends Base public function testGetProjectMembersWithNotifications() { - $u = new User($this->container); - $p = new Project($this->container); - $n = new UserNotification($this->container); - $pp = new ProjectUserRole($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $n = new UserNotificationModel($this->container); + $pp = new ProjectUserRoleModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); // No email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + + // User disabled + $this->assertEquals(5, $u->create(array('username' => 'user4', 'email' => 'user3@here', 'notifications_enabled' => 1, 'is_active' => 0))); // No email + notifications disabled - $this->assertNotFalse($u->create(array('username' => 'user4'))); + $this->assertEquals(6, $u->create(array('username' => 'user5'))); // Nobody is member of any projects $this->assertEmpty($pp->getUsers(1)); $this->assertEmpty($n->getUsersWithNotificationEnabled(1)); // We allow all users to be member of our projects - $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 5, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 6, Role::PROJECT_MEMBER)); $this->assertNotEmpty($pp->getUsers(1)); $users = $n->getUsersWithNotificationEnabled(1); @@ -176,25 +181,28 @@ class UserNotificationTest extends Base public function testGetUsersWithNotificationsWhenEverybodyAllowed() { - $u = new User($this->container); - $p = new Project($this->container); - $n = new UserNotification($this->container); - $pp = new ProjectPermission($this->container); + $u = new UserModel($this->container); + $p = new ProjectModel($this->container); + $n = new UserNotificationModel($this->container); + $pp = new ProjectPermissionModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertTrue($pp->isEverybodyAllowed(1)); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); // No email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + + // User disabled + $this->assertEquals(5, $u->create(array('username' => 'user4', 'email' => 'user3@here', 'notifications_enabled' => 1, 'is_active' => 0))); // No email + notifications disabled - $this->assertNotFalse($u->create(array('username' => 'user4'))); + $this->assertEquals(6, $u->create(array('username' => 'user5'))); $users = $n->getUsersWithNotificationEnabled(1); @@ -207,12 +215,12 @@ class UserNotificationTest extends Base public function testSendNotifications() { - $u = new User($this->container); - $n = new UserNotification($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $pp = new ProjectPermission($this->container); + $u = new UserModel($this->container); + $n = new UserNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $pp = new ProjectPermissionModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -221,7 +229,7 @@ class UserNotificationTest extends Base $n->saveSettings(1, array( 'notifications_enabled' => 1, - 'notifications_filter' => UserNotificationFilter::FILTER_NONE, + 'notifications_filter' => UserNotificationFilterModel::FILTER_NONE, 'notification_types' => array('web' => 1, 'email' => 1), )); @@ -234,23 +242,23 @@ class UserNotificationTest extends Base ->expects($this->exactly(2)) ->method('notifyUser'); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(0)) ->method('getSelectedTypes') ->will($this->returnValue(array('email', 'web'))); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(1)) ->method('getType') ->with($this->equalTo('email')) ->will($this->returnValue($notifier)); - $this->container['userNotificationType'] + $this->container['userNotificationTypeModel'] ->expects($this->at(2)) ->method('getType') ->with($this->equalTo('web')) ->will($this->returnValue($notifier)); - $n->sendNotifications(Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $n->sendNotifications(TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); } } diff --git a/tests/units/Model/UserNotificationTypeTest.php b/tests/units/Model/UserNotificationTypeTest.php index da22afef..29223c18 100644 --- a/tests/units/Model/UserNotificationTypeTest.php +++ b/tests/units/Model/UserNotificationTypeTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\UserNotificationType; +use Kanboard\Model\UserNotificationTypeModel; class UserNotificationTypeTest extends Base { public function testGetTypes() { - $nt = new UserNotificationType($this->container); + $nt = new UserNotificationTypeModel($this->container); $this->assertEmpty($nt->getTypes()); $nt->setType('email', 'Email', 'Something'); @@ -18,7 +18,7 @@ class UserNotificationTypeTest extends Base public function testGetSelectedTypes() { - $nt = new UserNotificationType($this->container); + $nt = new UserNotificationTypeModel($this->container); // No type defined $this->assertEmpty($nt->getSelectedTypes(1)); diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php index 7501f2e0..0be6172e 100644 --- a/tests/units/Model/UserTest.php +++ b/tests/units/Model/UserTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\User; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; +use Kanboard\Model\UserModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\ProjectModel; use Kanboard\Core\Security\Role; class UserTest extends Base { public function testGetByEmail() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost'))); $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => ''))); @@ -24,20 +24,20 @@ class UserTest extends Base public function testGetByExternalId() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234'))); $this->assertNotEmpty($u->getByExternalId('gitlab_id', '1234')); $this->assertEmpty($u->getByExternalId('gitlab_id', '')); - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop'))); $this->assertNotFalse($u->create(array('username' => 'user3', 'password' => '123456', 'github_id' => ''))); $this->assertNotEmpty($u->getByExternalId('github_id', 'plop')); $this->assertEmpty($u->getByExternalId('github_id', '')); - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234'))); $this->assertNotFalse($u->create(array('username' => 'user5', 'password' => '123456', 'google_id' => ''))); @@ -47,7 +47,7 @@ class UserTest extends Base public function testGetByToken() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'token' => 'random'))); $this->assertNotFalse($u->create(array('username' => 'user2', 'token' => ''))); @@ -57,7 +57,7 @@ class UserTest extends Base public function testGetByUsername() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1'))); $this->assertNotEmpty($u->getByUsername('user1')); @@ -67,7 +67,7 @@ class UserTest extends Base public function testExists() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1'))); $this->assertTrue($u->exists(1)); @@ -77,14 +77,14 @@ class UserTest extends Base public function testCount() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'user1'))); $this->assertEquals(2, $u->count()); } public function testGetAll() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'you'))); $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me'))); @@ -97,7 +97,7 @@ class UserTest extends Base public function testGetActiveUsersList() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'you'))); $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me too'))); $this->assertEquals(4, $u->create(array('username' => 'foobar', 'is_active' => 0))); @@ -115,10 +115,10 @@ class UserTest extends Base $users = $u->getActiveUsersList(true); $expected = array( - User::EVERYBODY_ID => 'Everybody', - 1 => 'admin', - 3 => 'Me too', - 2 => 'you', + UserModel::EVERYBODY_ID => 'Everybody', + 1 => 'admin', + 3 => 'Me too', + 2 => 'you', ); $this->assertEquals($expected, $users); @@ -126,7 +126,7 @@ class UserTest extends Base public function testGetFullname() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertEquals(3, $u->create(array('username' => 'user2', 'name' => 'User #2'))); @@ -142,7 +142,7 @@ class UserTest extends Base public function testIsAdmin() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user1'))); $this->assertTrue($u->isAdmin(1)); @@ -160,7 +160,7 @@ class UserTest extends Base public function testPrepare() { - $u = new User($this->container); + $u = new UserModel($this->container); $input = array( 'username' => 'user1', @@ -237,7 +237,7 @@ class UserTest extends Base public function testCreate() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User'))); $this->assertEquals(3, $u->create(array('username' => 'user #2', 'is_ldap_user' => 1))); $this->assertEquals(4, $u->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER))); @@ -246,45 +246,33 @@ class UserTest extends Base $this->assertFalse($u->create(array('username' => 'user #1'))); $user = $u->getById(1); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('admin', $user['username']); $this->assertEquals('', $user['name']); $this->assertEquals(Role::APP_ADMIN, $user['role']); $this->assertEquals(0, $user['is_ldap_user']); $user = $u->getById(2); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('user #1', $user['username']); $this->assertEquals('User', $user['name']); $this->assertEquals(Role::APP_USER, $user['role']); $this->assertEquals(0, $user['is_ldap_user']); $user = $u->getById(3); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('user #2', $user['username']); $this->assertEquals('', $user['name']); $this->assertEquals(Role::APP_USER, $user['role']); $this->assertEquals(1, $user['is_ldap_user']); $user = $u->getById(4); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('user #3', $user['username']); $this->assertEquals(Role::APP_MANAGER, $user['role']); $user = $u->getById(5); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('user #4', $user['username']); $this->assertEquals('', $user['gitlab_id']); $this->assertEquals(Role::APP_ADMIN, $user['role']); $user = $u->getById(6); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('user #5', $user['username']); $this->assertEquals('1234', $user['gitlab_id']); $this->assertEquals(Role::APP_USER, $user['role']); @@ -292,7 +280,7 @@ class UserTest extends Base public function testUpdate() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(3, $u->create(array('username' => 'plop', 'gitlab_id' => '123'))); @@ -300,8 +288,6 @@ class UserTest extends Base $this->assertTrue($u->update(array('id' => 3, 'gitlab_id' => ''))); $user = $u->getById(2); - $this->assertNotFalse($user); - $this->assertTrue(is_array($user)); $this->assertEquals('biloute', $user['username']); $this->assertEquals('Toto', $user['name']); $this->assertEquals(Role::APP_USER, $user['role']); @@ -314,12 +300,12 @@ class UserTest extends Base public function testRemove() { - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $s = new Subtask($this->container); - $c = new Comment($this->container); + $u = new UserModel($this->container); + $tc = new TaskCreationModel($this->container); + $tf = new TaskFinderModel($this->container); + $p = new ProjectModel($this->container); + $s = new SubtaskModel($this->container); + $c = new CommentModel($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); @@ -369,7 +355,7 @@ class UserTest extends Base public function testEnableDisablePublicAccess() { - $u = new User($this->container); + $u = new UserModel($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456'))); $user = $u->getById(2); @@ -394,7 +380,7 @@ class UserTest extends Base public function testEnableDisable() { - $userModel = new User($this->container); + $userModel = new UserModel($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'toto'))); $this->assertTrue($userModel->isActive(2)); diff --git a/tests/units/Model/UserUnreadNotificationTest.php b/tests/units/Model/UserUnreadNotificationTest.php index 918ab411..e6716e6c 100644 --- a/tests/units/Model/UserUnreadNotificationTest.php +++ b/tests/units/Model/UserUnreadNotificationTest.php @@ -2,45 +2,42 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\User; -use Kanboard\Model\Task; -use Kanboard\Model\Project; -use Kanboard\Model\UserUnreadNotification; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\UserUnreadNotificationModel; class UserUnreadNotificationTest extends Base { public function testHasNotification() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertFalse($wn->hasNotifications(1)); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertTrue($wn->hasNotifications(1)); } public function testMarkAllAsRead() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertTrue($wn->hasNotifications(1)); $this->assertTrue($wn->markAllAsRead(1)); @@ -51,16 +48,15 @@ class UserUnreadNotificationTest extends Base public function testMarkAsRead() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertTrue($wn->hasNotifications(1)); @@ -73,17 +69,16 @@ class UserUnreadNotificationTest extends Base public function testGetAll() { - $wn = new UserUnreadNotification($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); - $wn->create(1, Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); $this->assertEmpty($wn->getAll(2)); @@ -92,4 +87,24 @@ class UserUnreadNotificationTest extends Base $this->assertArrayHasKey('title', $notifications[0]); $this->assertTrue(is_array($notifications[0]['event_data'])); } + + public function testGetOne() + { + $wn = new UserUnreadNotificationModel($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); + + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $wn->create(1, TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); + + $this->assertEmpty($wn->getAll(2)); + + $notification = $wn->getById(1); + $this->assertArrayHasKey('title', $notification); + $this->assertTrue(is_array($notification['event_data'])); + } } diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php index 7dc6aaef..9f077ac8 100644 --- a/tests/units/Notification/MailTest.php +++ b/tests/units/Notification/MailTest.php @@ -2,28 +2,28 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; -use Kanboard\Model\User; -use Kanboard\Model\TaskFile; -use Kanboard\Model\Project; -use Kanboard\Model\Task; -use Kanboard\Notification\Mail; +use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\SubtaskModel; +use Kanboard\Model\CommentModel; +use Kanboard\Model\UserModel; +use Kanboard\Model\TaskFileModel; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; +use Kanboard\Notification\MailNotification; use Kanboard\Subscriber\NotificationSubscriber; class MailTest extends Base { public function testGetMailContent() { - $en = new Mail($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $c = new Comment($this->container); - $f = new TaskFile($this->container); + $en = new MailNotification($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $s = new SubtaskModel($this->container); + $c = new CommentModel($this->container); + $f = new TaskFileModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -62,11 +62,11 @@ class MailTest extends Base public function testSendWithEmailAddress() { - $en = new Mail($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $en = new MailNotification($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $u = new UserModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -88,16 +88,16 @@ class MailTest extends Base $this->stringContains('test') ); - $en->notifyUser($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); } public function testSendWithoutEmailAddress() { - $en = new Mail($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $u = new User($this->container); + $en = new MailNotification($this->container); + $p = new ProjectModel($this->container); + $tf = new TaskFinderModel($this->container); + $tc = new TaskCreationModel($this->container); + $u = new UserModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); @@ -112,6 +112,6 @@ class MailTest extends Base ->expects($this->never()) ->method('send'); - $en->notifyUser($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); + $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1))); } } diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookTest.php index 5984f303..5a9eb1c7 100644 --- a/tests/units/Notification/WebhookTest.php +++ b/tests/units/Notification/WebhookTest.php @@ -2,18 +2,18 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Config; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\ConfigModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; use Kanboard\Subscriber\NotificationSubscriber; class WebhookTest extends Base { public function testTaskCreation() { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $c = new ConfigModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container)); $c->save(array('webhook_url' => 'http://localhost/?task-creation')); diff --git a/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php b/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php new file mode 100644 index 00000000..41f40844 --- /dev/null +++ b/tests/units/Subscriber/LdapUserPhotoSubscriberTest.php @@ -0,0 +1,83 @@ +<?php + +use Kanboard\Core\Security\Role; +use Kanboard\Event\UserProfileSyncEvent; +use Kanboard\Model\UserModel; +use Kanboard\Subscriber\LdapUserPhotoSubscriber; +use Kanboard\User\DatabaseUserProvider; +use Kanboard\User\LdapUserProvider; + +require_once __DIR__.'/../Base.php'; + +class LdapUserPhotoSubscriberTest extends Base +{ + public function testWhenTheProviderIsNotLdap() + { + $userProvider = new DatabaseUserProvider(array()); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new UserModel($this->container); + + $userModel->update(array('id' => 1, 'avatar_path' => 'my avatar')); + $user = $userModel->getById(1); + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertEquals('my avatar', $user['avatar_path']); + } + + public function testWhenTheUserHaveLdapPhoto() + { + $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo'); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new UserModel($this->container); + $user = $userModel->getById(1); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), 'my photo'); + + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertStringStartsWith('avatars', $user['avatar_path']); + } + + public function testWhenTheUserDoNotHaveLdapPhoto() + { + $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array()); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new UserModel($this->container); + $user = $userModel->getById(1); + + $this->container['objectStorage'] + ->expects($this->never()) + ->method('put'); + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertEmpty($user['avatar_path']); + } + + public function testWhenTheUserAlreadyHaveAvatar() + { + $userProvider = new LdapUserProvider('dn', 'admin', 'Admin', 'admin@localhost', Role::APP_ADMIN, array(), 'my photo'); + $subscriber = new LdapUserPhotoSubscriber($this->container); + $userModel = new UserModel($this->container); + + $userModel->update(array('id' => 1, 'avatar_path' => 'my avatar')); + $user = $userModel->getById(1); + + $this->container['objectStorage'] + ->expects($this->never()) + ->method('put'); + + $subscriber->syncUserPhoto(new UserProfileSyncEvent($user, $userProvider)); + + $user = $userModel->getById(1); + $this->assertEquals('my avatar', $user['avatar_path']); + } +} diff --git a/tests/units/User/Avatar/LetterAvatarProviderTest.php b/tests/units/User/Avatar/LetterAvatarProviderTest.php index 39e51c98..0eb3ef8e 100644 --- a/tests/units/User/Avatar/LetterAvatarProviderTest.php +++ b/tests/units/User/Avatar/LetterAvatarProviderTest.php @@ -34,4 +34,12 @@ class LetterAvatarProviderTest extends Base $expected = '<div class="avatar-letter" style="background-color: rgb(134, 45, 132)" title="admin">A</div>'; $this->assertEquals($expected, $provider->render($user, 48)); } + + public function testRenderWithUTF8() + { + $provider = new LetterAvatarProvider($this->container); + $user = array('id' => 123, 'name' => 'ü', 'username' => 'admin', 'email' => ''); + $expected = '<div class="avatar-letter" style="background-color: rgb(62, 147, 31)" title="ü">Ü</div>'; + $this->assertEquals($expected, $provider->render($user, 48)); + } } diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php index a73e8247..07de6c25 100644 --- a/tests/units/Validator/ProjectValidatorTest.php +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -3,14 +3,14 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Validator\ProjectValidator; -use Kanboard\Model\Project; +use Kanboard\Model\ProjectModel; class ProjectValidatorTest extends Base { public function testValidateCreation() { $validator = new ProjectValidator($this->container); - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); @@ -39,7 +39,7 @@ class ProjectValidatorTest extends Base public function testValidateModification() { $validator = new ProjectValidator($this->container); - $p = new Project($this->container); + $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php index 5ac4588e..5fc50e3e 100644 --- a/tests/units/Validator/TaskLinkValidatorTest.php +++ b/tests/units/Validator/TaskLinkValidatorTest.php @@ -3,18 +3,18 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Validator\TaskLinkValidator; -use Kanboard\Model\TaskLink; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; +use Kanboard\Model\TaskLinkModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\ProjectModel; class TaskLinkValidatorTest extends Base { public function testValidateCreation() { $validator = new TaskLinkValidator($this->container); - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $tl = new TaskLinkModel($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); @@ -46,8 +46,8 @@ class TaskLinkValidatorTest extends Base public function testValidateModification() { $validator = new TaskLinkValidator($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); + $p = new ProjectModel($this->container); + $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); |
