summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/configs/config.mysql.php12
-rw-r--r--tests/configs/config.postgres.php12
-rw-r--r--tests/configs/config.sqlite.php8
-rw-r--r--tests/docker/Dockerfile.xenial24
-rw-r--r--tests/docker/compose.integration.mysql.yaml27
-rw-r--r--tests/docker/compose.integration.postgres.yaml26
-rw-r--r--tests/docker/compose.integration.sqlite.yaml16
-rwxr-xr-xtests/docker/entrypoint.sh33
-rw-r--r--tests/docker/supervisord.conf6
-rw-r--r--tests/integration.mysql.xml14
-rw-r--r--tests/integration.postgres.xml13
-rw-r--r--tests/integration.sqlite.xml9
-rw-r--r--tests/integration/ActionProcedureTest.php66
-rw-r--r--tests/integration/ApiTest.php928
-rw-r--r--tests/integration/AppProcedureTest.php (renamed from tests/integration/AppTest.php)24
-rw-r--r--tests/integration/Base.php62
-rw-r--r--tests/integration/BaseProcedureTest.php133
-rw-r--r--tests/integration/BoardProcedureTest.php25
-rw-r--r--tests/integration/BoardTest.php21
-rw-r--r--tests/integration/CategoryProcedureTest.php76
-rw-r--r--tests/integration/ColumnProcedureTest.php69
-rw-r--r--tests/integration/ColumnTest.php65
-rw-r--r--tests/integration/CommentProcedureTest.php63
-rw-r--r--tests/integration/GroupMemberProcedureTest.php53
-rw-r--r--tests/integration/GroupMemberTest.php47
-rw-r--r--tests/integration/GroupProcedureTest.php50
-rw-r--r--tests/integration/GroupTest.php48
-rw-r--r--tests/integration/LinkProcedureTest.php70
-rw-r--r--tests/integration/MeProcedureTest.php68
-rw-r--r--tests/integration/MeTest.php247
-rw-r--r--tests/integration/OverdueTaskProcedureTest.php43
-rw-r--r--tests/integration/ProcedureAuthorizationTest.php306
-rw-r--r--tests/integration/ProjectFileProcedureTest.php66
-rw-r--r--tests/integration/ProjectPermissionProcedureTest.php89
-rw-r--r--tests/integration/ProjectPermissionTest.php64
-rw-r--r--tests/integration/ProjectProcedureTest.php119
-rw-r--r--tests/integration/SubtaskProcedureTest.php53
-rw-r--r--tests/integration/SubtaskTimeTrackingProcedureTest.php46
-rw-r--r--tests/integration/SwimlaneProcedureTest.php93
-rw-r--r--tests/integration/SwimlaneTest.php103
-rw-r--r--tests/integration/TaskExternalLinkProcedureTest.php98
-rw-r--r--tests/integration/TaskFileProcedureTest.php67
-rw-r--r--tests/integration/TaskLinkProcedureTest.php68
-rw-r--r--tests/integration/TaskMetadataProcedureTest.php45
-rw-r--r--tests/integration/TaskProcedureTest.php55
-rw-r--r--tests/integration/TaskTest.php132
-rw-r--r--tests/integration/UserProcedureTest.php63
-rw-r--r--tests/integration/UserTest.php18
-rw-r--r--tests/units/Action/BaseActionTest.php10
-rw-r--r--tests/units/Action/CommentCreationMoveTaskColumnTest.php6
-rw-r--r--tests/units/Action/TaskAssignCategoryColorTest.php18
-rw-r--r--tests/units/Action/TaskAssignCategoryLinkTest.php92
-rw-r--r--tests/units/Action/TaskAssignColorCategoryTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorColumnTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorLinkTest.php45
-rw-r--r--tests/units/Action/TaskAssignColorPriorityTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorUserTest.php18
-rw-r--r--tests/units/Action/TaskAssignCurrentUserColumnTest.php26
-rw-r--r--tests/units/Action/TaskAssignDueDateOnCreationTest.php37
-rw-r--r--tests/units/Action/TaskAssignSpecificUserTest.php17
-rw-r--r--tests/units/Action/TaskCloseColumnTest.php18
-rw-r--r--tests/units/Action/TaskCloseNoActivityColumnTest.php49
-rw-r--r--tests/units/Action/TaskCloseTest.php15
-rw-r--r--tests/units/Action/TaskDuplicateAnotherProjectTest.php18
-rw-r--r--tests/units/Action/TaskEmailTest.php19
-rw-r--r--tests/units/Action/TaskMoveAnotherProjectTest.php17
-rw-r--r--tests/units/Action/TaskMoveColumnAssignedTest.php18
-rw-r--r--tests/units/Action/TaskMoveColumnCategoryChangeTest.php31
-rw-r--r--tests/units/Action/TaskMoveColumnClosedTest.php91
-rw-r--r--tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php50
-rw-r--r--tests/units/Action/TaskMoveColumnUnAssignedTest.php31
-rw-r--r--tests/units/Action/TaskOpenTest.php15
-rw-r--r--tests/units/Action/TaskUpdateStartDateTest.php20
-rw-r--r--tests/units/Auth/ReverseProxyAuthTest.php111
-rw-r--r--tests/units/Auth/TotpAuthTest.php5
-rw-r--r--tests/units/Base.php12
-rw-r--r--tests/units/Core/Action/ActionManagerTest.php40
-rw-r--r--tests/units/Core/Filter/LexerBuilderTest.php46
-rw-r--r--tests/units/Core/Filter/LexerTest.php56
-rw-r--r--tests/units/Core/Filter/OrCriteriaTest.php5
-rw-r--r--tests/units/Core/Http/RequestTest.php3
-rw-r--r--tests/units/Core/Ldap/LdapUserTest.php60
-rw-r--r--tests/units/Core/Plugin/HookTest.php62
-rw-r--r--tests/units/EventBuilder/CommentEventBuilderTest.php37
-rw-r--r--tests/units/EventBuilder/ProjectFileEventBuilderTest.php33
-rw-r--r--tests/units/EventBuilder/SubtaskEventBuilderTest.php62
-rw-r--r--tests/units/EventBuilder/TaskEventBuilderTest.php100
-rw-r--r--tests/units/EventBuilder/TaskFileEventBuilderTest.php36
-rw-r--r--tests/units/EventBuilder/TaskLinkEventBuilderTest.php70
-rw-r--r--tests/units/Filter/TaskMovedDateFilterTest.php43
-rw-r--r--tests/units/Filter/TaskPriorityFilterTest.php47
-rw-r--r--tests/units/Filter/TaskTagFilterTest.php122
-rw-r--r--tests/units/Formatter/BoardFormatterTest.php392
-rw-r--r--tests/units/Formatter/TaskAutoCompleteFormatterTest.php34
-rw-r--r--tests/units/FunctionTest.php123
-rw-r--r--tests/units/Helper/HookHelperTest.php91
-rw-r--r--tests/units/Helper/TaskHelperTest.php1
-rw-r--r--tests/units/Helper/UserHelperTest.php30
-rw-r--r--tests/units/Job/CommentEventJobTest.php52
-rw-r--r--tests/units/Job/ProjectFileEventJobTest.php43
-rw-r--r--tests/units/Job/ProjectMetricJobTest.php47
-rw-r--r--tests/units/Job/SubtaskEventJobTest.php52
-rw-r--r--tests/units/Job/TaskEventJobTest.php189
-rw-r--r--tests/units/Job/TaskFileEventJobTest.php46
-rw-r--r--tests/units/Job/TaskLinkEventJobTest.php65
-rw-r--r--tests/units/Model/ActionModelTest.php (renamed from tests/units/Model/ActionTest.php)20
-rw-r--r--tests/units/Model/BoardTest.php121
-rw-r--r--tests/units/Model/CategoryModelTest.php (renamed from tests/units/Model/CategoryTest.php)14
-rw-r--r--tests/units/Model/CommentModelTest.php106
-rw-r--r--tests/units/Model/CommentTest.php92
-rw-r--r--tests/units/Model/GroupModelTest.php (renamed from tests/units/Model/GroupTest.php)11
-rw-r--r--tests/units/Model/NotificationModelTest.php104
-rw-r--r--tests/units/Model/NotificationTest.php68
-rw-r--r--tests/units/Model/ProjectDuplicationModelTest.php548
-rw-r--r--tests/units/Model/ProjectDuplicationTest.php482
-rw-r--r--tests/units/Model/ProjectModelTest.php (renamed from tests/units/Model/ProjectTest.php)196
-rw-r--r--tests/units/Model/ProjectPermissionTest.php23
-rw-r--r--tests/units/Model/ProjectTaskPriorityModelTest.php84
-rw-r--r--tests/units/Model/SubtaskModelTest.php175
-rw-r--r--tests/units/Model/SubtaskPositionModelTest.php77
-rw-r--r--tests/units/Model/SubtaskStatusModelTest.php123
-rw-r--r--tests/units/Model/SubtaskTaskConversionModelTest.php37
-rw-r--r--tests/units/Model/SubtaskTest.php388
-rw-r--r--tests/units/Model/SubtaskTimeTrackingModelTest.php277
-rw-r--r--tests/units/Model/SubtaskTimeTrackingTest.php240
-rw-r--r--tests/units/Model/SwimlaneTest.php10
-rw-r--r--tests/units/Model/TagDuplicationModelTest.php31
-rw-r--r--tests/units/Model/TagModelTest.php120
-rw-r--r--tests/units/Model/TaskCreationModelTest.php403
-rw-r--r--tests/units/Model/TaskCreationTest.php414
-rw-r--r--tests/units/Model/TaskDuplicationModelTest.php142
-rw-r--r--tests/units/Model/TaskDuplicationTest.php700
-rw-r--r--tests/units/Model/TaskFileModelTest.php (renamed from tests/units/Model/TaskFileTest.php)15
-rw-r--r--tests/units/Model/TaskFinderModelTest.php203
-rw-r--r--tests/units/Model/TaskFinderTest.php115
-rw-r--r--tests/units/Model/TaskLinkModelTest.php239
-rw-r--r--tests/units/Model/TaskLinkTest.php196
-rw-r--r--tests/units/Model/TaskModelTest.php30
-rw-r--r--tests/units/Model/TaskModificationModelTest.php323
-rw-r--r--tests/units/Model/TaskModificationTest.php283
-rw-r--r--tests/units/Model/TaskPositionModelTest.php (renamed from tests/units/Model/TaskPositionTest.php)394
-rw-r--r--tests/units/Model/TaskProjectDuplicationModelTest.php377
-rw-r--r--tests/units/Model/TaskProjectMoveModelTest.php277
-rw-r--r--tests/units/Model/TaskRecurrenceModelTest.php126
-rw-r--r--tests/units/Model/TaskTagModelTest.php148
-rw-r--r--tests/units/Model/TaskTest.php58
-rw-r--r--tests/units/Model/UserModelTest.php384
-rw-r--r--tests/units/Model/UserTest.php400
-rw-r--r--tests/units/Notification/MailNotificationTest.php122
-rw-r--r--tests/units/Notification/MailTest.php117
-rw-r--r--tests/units/Notification/WebhookNotificationTest.php (renamed from tests/units/Notification/WebhookTest.php)14
-rw-r--r--tests/units/Pagination/ProjectPaginationTest.php35
-rw-r--r--tests/units/Pagination/SubtaskPaginationTest.php36
-rw-r--r--tests/units/Pagination/TaskPaginationTest.php30
-rw-r--r--tests/units/Pagination/UserPaginationTest.php27
-rw-r--r--tests/units/Subscriber/RecurringTaskSubscriberTest.php164
-rw-r--r--tests/units/User/Avatar/LetterAvatarProviderTest.php2
-rw-r--r--tests/units/Validator/ProjectValidatorTest.php12
158 files changed, 9879 insertions, 5927 deletions
diff --git a/tests/configs/config.mysql.php b/tests/configs/config.mysql.php
new file mode 100644
index 00000000..27e32744
--- /dev/null
+++ b/tests/configs/config.mysql.php
@@ -0,0 +1,12 @@
+<?php
+
+define('DB_DRIVER', 'mysql');
+define('DB_USERNAME', 'root');
+define('DB_PASSWORD', 'kanboard');
+define('DB_HOSTNAME', 'mysql');
+define('DB_NAME', 'kanboard');
+
+define('DEBUG', true);
+define('LOG_DRIVER', 'stderr');
+
+define('API_AUTHENTICATION_TOKEN', 'test');
diff --git a/tests/configs/config.postgres.php b/tests/configs/config.postgres.php
new file mode 100644
index 00000000..161a2349
--- /dev/null
+++ b/tests/configs/config.postgres.php
@@ -0,0 +1,12 @@
+<?php
+
+define('DB_DRIVER', 'postgres');
+define('DB_USERNAME', 'postgres');
+define('DB_PASSWORD', 'postgres');
+define('DB_HOSTNAME', 'postgres');
+define('DB_NAME', 'kanboard');
+
+define('DEBUG', true);
+define('LOG_DRIVER', 'stderr');
+
+define('API_AUTHENTICATION_TOKEN', 'test');
diff --git a/tests/configs/config.sqlite.php b/tests/configs/config.sqlite.php
new file mode 100644
index 00000000..e969c17c
--- /dev/null
+++ b/tests/configs/config.sqlite.php
@@ -0,0 +1,8 @@
+<?php
+
+define('DB_DRIVER', 'sqlite');
+
+define('DEBUG', true);
+define('LOG_DRIVER', 'file');
+
+define('API_AUTHENTICATION_TOKEN', 'test');
diff --git a/tests/docker/Dockerfile.xenial b/tests/docker/Dockerfile.xenial
new file mode 100644
index 00000000..a48d0525
--- /dev/null
+++ b/tests/docker/Dockerfile.xenial
@@ -0,0 +1,24 @@
+FROM ubuntu:16.04
+
+RUN mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/supervisor
+
+RUN apt-get update -qq && \
+ apt-get install -y apache2 supervisor cron curl unzip \
+ libapache2-mod-php7.0 php7.0-cli php7.0-mbstring php7.0-xml php7.0-mysql php7.0-sqlite3 \
+ php7.0-opcache php7.0-json php7.0-pgsql php7.0-ldap php7.0-gd php7.0-zip && \
+ apt clean && \
+ echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
+ sed -ri 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf && \
+ a2enmod rewrite && \
+ curl -sS https://getcomposer.org/installer | php -- --filename=/usr/local/bin/composer
+
+COPY . /var/www/html
+
+RUN chown -R www-data:www-data /var/www/html/data /var/www/html/plugins
+
+COPY tests/docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
+COPY tests/configs /configs/
+
+EXPOSE 80
+
+ENTRYPOINT ["/var/www/html/tests/docker/entrypoint.sh"]
diff --git a/tests/docker/compose.integration.mysql.yaml b/tests/docker/compose.integration.mysql.yaml
new file mode 100644
index 00000000..6eda5eec
--- /dev/null
+++ b/tests/docker/compose.integration.mysql.yaml
@@ -0,0 +1,27 @@
+version: '2'
+services:
+ mysql:
+ image: mysql:5.7
+ environment:
+ MYSQL_ROOT_PASSWORD: "kanboard"
+ MYSQL_DATABASE: "kanboard"
+ MYSQL_USER: "kanboard"
+ MYSQL_PASSWORD: "kanboard"
+ ports:
+ - "3306:3306"
+ app:
+ build:
+ context: ../..
+ dockerfile: tests/docker/Dockerfile.xenial
+ ports:
+ - "8000:80"
+ depends_on:
+ - mysql
+ command: config-mysql
+ tests:
+ build:
+ context: ../..
+ dockerfile: tests/docker/Dockerfile.xenial
+ depends_on:
+ - app
+ command: integration-test-mysql
diff --git a/tests/docker/compose.integration.postgres.yaml b/tests/docker/compose.integration.postgres.yaml
new file mode 100644
index 00000000..ed095248
--- /dev/null
+++ b/tests/docker/compose.integration.postgres.yaml
@@ -0,0 +1,26 @@
+version: '2'
+services:
+ postgres:
+ image: postgres:9.5
+ environment:
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: postgres
+ POSTGRES_DB: kanboard
+ ports:
+ - "5432:5432"
+ app:
+ build:
+ context: ../..
+ dockerfile: tests/docker/Dockerfile.xenial
+ ports:
+ - "8000:80"
+ depends_on:
+ - postgres
+ command: config-postgres
+ tests:
+ build:
+ context: ../..
+ dockerfile: tests/docker/Dockerfile.xenial
+ depends_on:
+ - app
+ command: integration-test-postgres
diff --git a/tests/docker/compose.integration.sqlite.yaml b/tests/docker/compose.integration.sqlite.yaml
new file mode 100644
index 00000000..6431484e
--- /dev/null
+++ b/tests/docker/compose.integration.sqlite.yaml
@@ -0,0 +1,16 @@
+version: '2'
+services:
+ app:
+ build:
+ context: ../..
+ dockerfile: tests/docker/Dockerfile.xenial
+ ports:
+ - "8000:80"
+ command: config-sqlite
+ tests:
+ build:
+ context: ../..
+ dockerfile: tests/docker/Dockerfile.xenial
+ depends_on:
+ - app
+ command: integration-test-sqlite
diff --git a/tests/docker/entrypoint.sh b/tests/docker/entrypoint.sh
new file mode 100755
index 00000000..5a37ae4e
--- /dev/null
+++ b/tests/docker/entrypoint.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+function wait_schema_creation() {
+ curl -s http://app/login > /dev/null
+ sleep $1
+}
+
+case "$1" in
+"config-sqlite")
+ cp /configs/config.sqlite.php /var/www/html/config.php
+ /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
+ ;;
+"config-postgres")
+ cp /configs/config.postgres.php /var/www/html/config.php
+ /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
+ ;;
+"config-mysql")
+ cp /configs/config.mysql.php /var/www/html/config.php
+ /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
+ ;;
+"integration-test-sqlite")
+ wait_schema_creation 1
+ /var/www/html/vendor/phpunit/phpunit/phpunit -c /var/www/html/tests/integration.sqlite.xml
+ ;;
+"integration-test-postgres")
+ wait_schema_creation 10
+ /var/www/html/vendor/phpunit/phpunit/phpunit -c /var/www/html/tests/integration.postgres.xml
+ ;;
+"integration-test-mysql")
+ wait_schema_creation 15
+ /var/www/html/vendor/phpunit/phpunit/phpunit -c /var/www/html/tests/integration.mysql.xml
+ ;;
+esac
diff --git a/tests/docker/supervisord.conf b/tests/docker/supervisord.conf
new file mode 100644
index 00000000..4d5ee621
--- /dev/null
+++ b/tests/docker/supervisord.conf
@@ -0,0 +1,6 @@
+[supervisord]
+nodaemon=true
+
+[program:apache2]
+command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
+autorestart=true
diff --git a/tests/integration.mysql.xml b/tests/integration.mysql.xml
index 9d87f77e..33813187 100644
--- a/tests/integration.mysql.xml
+++ b/tests/integration.mysql.xml
@@ -5,16 +5,8 @@
</testsuite>
</testsuites>
<php>
- <const name="API_URL" value="http://localhost:8000/jsonrpc.php" />
- <const name="API_KEY" value="19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929" />
- <const name="DB_DRIVER" value="mysql" />
- <const name="DB_NAME" value="kanboard" />
- <const name="DB_HOSTNAME" value="localhost" />
- <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="" />
+ <const name="BASE_URL" value="http://app/" />
+ <const name="API_URL" value="http://app/jsonrpc.php" />
+ <const name="API_KEY" value="test" />
</php>
</phpunit>
diff --git a/tests/integration.postgres.xml b/tests/integration.postgres.xml
index ed8a3de3..33813187 100644
--- a/tests/integration.postgres.xml
+++ b/tests/integration.postgres.xml
@@ -5,13 +5,8 @@
</testsuite>
</testsuites>
<php>
- <const name="API_URL" value="http://localhost:8000/jsonrpc.php" />
- <const name="API_KEY" value="19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929" />
- <const name="DB_DRIVER" value="postgres" />
- <const name="DB_NAME" value="kanboard" />
- <const name="DB_HOSTNAME" value="localhost" />
- <const name="DB_USERNAME" value="postgres" />
- <const name="DB_PASSWORD" value="postgres" />
- <const name="DB_PORT" value="" />
+ <const name="BASE_URL" value="http://app/" />
+ <const name="API_URL" value="http://app/jsonrpc.php" />
+ <const name="API_KEY" value="test" />
</php>
-</phpunit> \ No newline at end of file
+</phpunit>
diff --git a/tests/integration.sqlite.xml b/tests/integration.sqlite.xml
index 1964f822..33813187 100644
--- a/tests/integration.sqlite.xml
+++ b/tests/integration.sqlite.xml
@@ -5,9 +5,8 @@
</testsuite>
</testsuites>
<php>
- <const name="API_URL" value="http://127.0.0.1:8000/jsonrpc.php" />
- <const name="API_KEY" value="19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929" />
- <const name="DB_DRIVER" value="sqlite" />
- <const name="DB_FILENAME" value="data/db.sqlite" />
+ <const name="BASE_URL" value="http://app/" />
+ <const name="API_URL" value="http://app/jsonrpc.php" />
+ <const name="API_KEY" value="test" />
</php>
-</phpunit> \ No newline at end of file
+</phpunit>
diff --git a/tests/integration/ActionProcedureTest.php b/tests/integration/ActionProcedureTest.php
new file mode 100644
index 00000000..432de3d3
--- /dev/null
+++ b/tests/integration/ActionProcedureTest.php
@@ -0,0 +1,66 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ActionProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test actions';
+
+ public function testGetAvailableActions()
+ {
+ $actions = $this->app->getAvailableActions();
+ $this->assertNotEmpty($actions);
+ $this->assertInternalType('array', $actions);
+ $this->assertArrayHasKey('\Kanboard\Action\TaskCloseColumn', $actions);
+ }
+
+ public function testGetAvailableActionEvents()
+ {
+ $events = $this->app->getAvailableActionEvents();
+ $this->assertNotEmpty($events);
+ $this->assertInternalType('array', $events);
+ $this->assertArrayHasKey('task.move.column', $events);
+ }
+
+ public function testGetCompatibleActionEvents()
+ {
+ $events = $this->app->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn');
+ $this->assertNotEmpty($events);
+ $this->assertInternalType('array', $events);
+ $this->assertArrayHasKey('task.move.column', $events);
+ }
+
+ public function testCRUD()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateAction();
+ $this->assertGetActions();
+ $this->assertRemoveAction();
+ }
+
+ public function assertCreateAction()
+ {
+ $actionId = $this->app->createAction($this->projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+ $this->assertTrue($actionId > 0);
+ }
+
+ public function assertGetActions()
+ {
+ $actions = $this->app->getActions($this->projectId);
+ $this->assertNotEmpty($actions);
+ $this->assertInternalType('array', $actions);
+ $this->assertArrayHasKey('id', $actions[0]);
+ $this->assertArrayHasKey('project_id', $actions[0]);
+ $this->assertArrayHasKey('event_name', $actions[0]);
+ $this->assertArrayHasKey('action_name', $actions[0]);
+ $this->assertArrayHasKey('params', $actions[0]);
+ $this->assertArrayHasKey('column_id', $actions[0]['params']);
+ }
+
+ public function assertRemoveAction()
+ {
+ $actionId = $this->app->createAction($this->projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertTrue($this->app->removeAction($actionId));
+ }
+}
diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php
deleted file mode 100644
index f552bea9..00000000
--- a/tests/integration/ApiTest.php
+++ /dev/null
@@ -1,928 +0,0 @@
-<?php
-
-require_once __DIR__.'/../../vendor/autoload.php';
-
-class Api extends PHPUnit_Framework_TestCase
-{
- private $client = null;
-
- public static function setUpBeforeClass()
- {
- if (DB_DRIVER === 'sqlite') {
- @unlink(DB_FILENAME);
- } elseif (DB_DRIVER === 'mysql') {
- $pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
- $pdo->exec('DROP DATABASE '.DB_NAME);
- $pdo->exec('CREATE DATABASE '.DB_NAME);
- $pdo = null;
- } elseif (DB_DRIVER === 'postgres') {
- $pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
- $pdo->exec('DROP DATABASE '.DB_NAME);
- $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
- $pdo = null;
- }
-
- $service = new Kanboard\ServiceProvider\DatabaseProvider;
-
- $db = $service->getInstance();
- $db->table('settings')->eq('option', 'api_token')->update(array('value' => API_KEY));
- $db->table('settings')->eq('option', 'application_timezone')->update(array('value' => 'Europe/Paris'));
- $db->closeConnection();
- }
-
- public function setUp()
- {
- $this->client = new JsonRPC\Client(API_URL);
- $this->client->authentication('jsonrpc', API_KEY);
- // $this->client->debug = true;
- }
-
- private function getTaskId()
- {
- $tasks = $this->client->getAllTasks(1, 1);
- $this->assertNotEmpty($tasks);
-
- return $tasks[0]['id'];
- }
-
- public function testRemoveAll()
- {
- $projects = $this->client->getAllProjects();
-
- if ($projects) {
- foreach ($projects as $project) {
- $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']));
- }
- }
- }
-
- public function testCreateProject()
- {
- $project_id = $this->client->createProject('API test');
- $this->assertNotFalse($project_id);
- $this->assertInternalType('int', $project_id);
- }
-
- public function testGetProjectById()
- {
- $project = $this->client->getProjectById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(1, $project['id']);
- $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()
- {
- $project = $this->client->getProjectByName('API test');
- $this->assertNotEmpty($project);
- $this->assertEquals(1, $project['id']);
- $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);
- $this->assertEquals(1, $project['id']);
-
- $project = $this->client->getProjectByName('None');
- $this->assertEmpty($project);
- $this->assertNull($project);
- }
-
- public function testGetAllProjects()
- {
- $projects = $this->client->getAllProjects();
- $this->assertNotEmpty($projects);
-
- foreach ($projects as $project) {
- $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 testUpdateProject()
- {
- $project = $this->client->getProjectById(1);
- $this->assertNotEmpty($project);
- $this->assertTrue($this->client->execute('updateProject', array('id' => 1, 'name' => 'API test 2')));
-
- $project = $this->client->getProjectById(1);
- $this->assertEquals('API test 2', $project['name']);
-
- $this->assertTrue($this->client->execute('updateProject', array('id' => 1, 'name' => 'API test', 'description' => 'test')));
-
- $project = $this->client->getProjectById(1);
- $this->assertEquals('API test', $project['name']);
- $this->assertEquals('test', $project['description']);
- }
-
- public function testDisableProject()
- {
- $this->assertTrue($this->client->disableProject(1));
- $project = $this->client->getProjectById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(0, $project['is_active']);
- }
-
- public function testEnableProject()
- {
- $this->assertTrue($this->client->enableProject(1));
- $project = $this->client->getProjectById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(1, $project['is_active']);
- }
-
- public function testEnableProjectPublicAccess()
- {
- $this->assertTrue($this->client->enableProjectPublicAccess(1));
- $project = $this->client->getProjectById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(1, $project['is_public']);
- $this->assertNotEmpty($project['token']);
- }
-
- public function testDisableProjectPublicAccess()
- {
- $this->assertTrue($this->client->disableProjectPublicAccess(1));
- $project = $this->client->getProjectById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEmpty($project['token']);
- }
-
- public function testgetProjectActivities()
- {
- $activities = $this->client->getProjectActivities(array('project_ids' => array(1)));
- $this->assertInternalType('array', $activities);
- $this->assertCount(0, $activities);
- }
-
- public function testgetProjectActivity()
- {
- $activities = $this->client->getProjectActivity(1);
- $this->assertInternalType('array', $activities);
- $this->assertCount(0, $activities);
- }
-
- public function testCreateTaskWithWrongMember()
- {
- $task = array(
- 'title' => 'Task #1',
- 'color_id' => 'blue',
- 'owner_id' => 1,
- 'project_id' => 1,
- 'column_id' => 2,
- );
-
- $task_id = $this->client->createTask($task);
-
- $this->assertFalse($task_id);
- }
-
- public function testGetAllowedUsers()
- {
- $users = $this->client->getMembers(1);
- $this->assertNotFalse($users);
- $this->assertEquals(array(), $users);
- }
-
- public function testAddMember()
- {
- $this->assertTrue($this->client->allowUser(1, 1));
- }
-
- public function testCreateTask()
- {
- $task = array(
- 'title' => 'Task #1',
- 'color_id' => 'blue',
- 'owner_id' => 1,
- 'project_id' => 1,
- 'column_id' => 2,
- );
-
- $task_id = $this->client->createTask($task);
-
- $this->assertNotFalse($task_id);
- $this->assertInternalType('int', $task_id);
- $this->assertTrue($task_id > 0);
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testCreateTaskWithBadParams()
- {
- $task = array(
- 'title' => 'Task #1',
- 'color_id' => 'blue',
- 'owner_id' => 1,
- );
-
- $this->client->createTask($task);
- }
-
- public function testGetTask()
- {
- $task = $this->client->getTask(1);
-
- $this->assertNotFalse($task);
- $this->assertTrue(is_array($task));
- $this->assertEquals('Task #1', $task['title']);
- $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()
- {
- $tasks = $this->client->getAllTasks(1, 1);
-
- $this->assertNotFalse($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertEquals('Task #1', $tasks[0]['title']);
- $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);
-
- $this->assertNotFalse($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertEmpty($tasks);
- }
-
- public function testMoveTaskSwimlane()
- {
- $task_id = $this->getTaskId();
-
- $task = $this->client->getTask($task_id);
- $this->assertNotFalse($task);
- $this->assertTrue(is_array($task));
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(0, $task['swimlane_id']);
-
- $moved_timestamp = $task['date_moved'];
- sleep(1);
- $this->assertTrue($this->client->moveTaskPosition(1, $task_id, 4, 1, 2));
-
- $task = $this->client->getTask($task_id);
- $this->assertNotFalse($task);
- $this->assertTrue(is_array($task));
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(4, $task['column_id']);
- $this->assertEquals(2, $task['swimlane_id']);
- $this->assertNotEquals($moved_timestamp, $task['date_moved']);
- }
-
- public function testUpdateTask()
- {
- $task = $this->client->getTask(1);
-
- $values = array();
- $values['id'] = $task['id'];
- $values['color_id'] = 'green';
- $values['description'] = 'test';
- $values['date_due'] = '';
-
- $this->assertTrue($this->client->execute('updateTask', $values));
- }
-
- public function testRemoveTask()
- {
- $this->assertTrue($this->client->removeTask(1));
- }
-
- public function testRemoveUsers()
- {
- $users = $this->client->getAllUsers();
- $this->assertNotFalse($users);
- $this->assertNotEmpty($users);
-
- foreach ($users as $user) {
- if ($user['id'] > 1) {
- $this->assertTrue($this->client->removeUser($user['id']));
- }
- }
- }
-
- public function testCreateUser()
- {
- $user = array(
- 'username' => 'toto',
- 'name' => 'Toto',
- 'password' => '123456',
- );
-
- $user_id = $this->client->execute('createUser', $user);
- $this->assertNotFalse($user_id);
- $this->assertInternalType('int', $user_id);
- $this->assertTrue($user_id > 0);
- }
-
- public function testCreateManagerUser()
- {
- $user = array(
- 'username' => 'manager',
- 'name' => 'Manager',
- 'password' => '123456',
- 'role' => 'app-manager'
- );
-
- $user_id = $this->client->execute('createUser', $user);
- $this->assertNotFalse($user_id);
- $this->assertInternalType('int', $user_id);
- $this->assertTrue($user_id > 0);
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testCreateUserWithBadParams()
- {
- $user = array(
- 'name' => 'Titi',
- 'password' => '123456',
- );
-
- $this->assertNull($this->client->execute('createUser', $user));
- }
-
- public function testGetUser()
- {
- $user = $this->client->getUser(2);
- $this->assertNotFalse($user);
- $this->assertTrue(is_array($user));
- $this->assertEquals('toto', $user['username']);
-
- $user = $this->client->getUser(3);
- $this->assertNotEmpty($user);
- $this->assertEquals('app-manager', $user['role']);
-
- $this->assertNull($this->client->getUser(2222));
- }
-
- public function testGetUserByName()
- {
- $user = $this->client->getUserByName('toto');
- $this->assertNotFalse($user);
- $this->assertTrue(is_array($user));
- $this->assertEquals(2, $user['id']);
-
- $user = $this->client->getUserByName('manager');
- $this->assertNotEmpty($user);
- $this->assertEquals('app-manager', $user['role']);
-
- $this->assertNull($this->client->getUserByName('nonexistantusername'));
- }
-
- public function testUpdateUser()
- {
- $user = array();
- $user['id'] = 2;
- $user['username'] = 'titi';
- $user['name'] = 'Titi';
-
- $this->assertTrue($this->client->execute('updateUser', $user));
-
- $user = $this->client->getUser(2);
- $this->assertNotFalse($user);
- $this->assertTrue(is_array($user));
- $this->assertEquals('titi', $user['username']);
- $this->assertEquals('Titi', $user['name']);
-
- $user = array();
- $user['id'] = 2;
- $user['email'] = 'titi@localhost';
-
- $this->assertTrue($this->client->execute('updateUser', $user));
-
- $user = $this->client->getUser(2);
- $this->assertNotFalse($user);
- $this->assertTrue(is_array($user));
- $this->assertEquals('titi@localhost', $user['email']);
- }
-
- public function testAllowedUser()
- {
- $this->assertTrue($this->client->allowUser(1, 2));
-
- $users = $this->client->getMembers(1);
- $this->assertNotFalse($users);
- $this->assertEquals(array(1 => 'admin', 2 => 'Titi'), $users);
- }
-
- public function testRevokeUser()
- {
- $this->assertTrue($this->client->revokeUser(1, 2));
-
- $users = $this->client->getMembers(1);
- $this->assertNotFalse($users);
- $this->assertEquals(array(1 => 'admin'), $users);
- }
-
- public function testCreateComment()
- {
- $task = array(
- 'title' => 'Task with comment',
- 'color_id' => 'red',
- 'owner_id' => 1,
- 'project_id' => 1,
- 'column_id' => 1,
- );
-
- $this->assertNotFalse($this->client->execute('createTask', $task));
-
- $tasks = $this->client->getAllTasks(1, 1);
- $this->assertNotEmpty($tasks);
- $this->assertEquals(1, count($tasks));
-
- $comment = array(
- 'task_id' => $tasks[0]['id'],
- 'user_id' => 2,
- 'content' => 'boo',
- );
-
- $comment_id = $this->client->execute('createComment', $comment);
-
- $this->assertNotFalse($comment_id);
- $this->assertInternalType('int', $comment_id);
- $this->assertTrue($comment_id > 0);
- }
-
- public function testGetComment()
- {
- $comment = $this->client->getComment(1);
- $this->assertNotFalse($comment);
- $this->assertNotEmpty($comment);
- $this->assertEquals(2, $comment['user_id']);
- $this->assertEquals('boo', $comment['comment']);
- }
-
- public function testUpdateComment()
- {
- $comment = array();
- $comment['id'] = 1;
- $comment['content'] = 'test';
-
- $this->assertTrue($this->client->execute('updateComment', $comment));
-
- $comment = $this->client->getComment(1);
- $this->assertEquals('test', $comment['comment']);
- }
-
- public function testGetAllComments()
- {
- $task_id = $this->getTaskId();
-
- $comment = array(
- 'task_id' => $task_id,
- 'user_id' => 1,
- 'content' => 'blabla',
- );
-
- $comment_id = $this->client->createComment($comment);
-
- $this->assertNotFalse($comment_id);
- $this->assertInternalType('int', $comment_id);
- $this->assertTrue($comment_id > 0);
-
- $comments = $this->client->getAllComments($task_id);
- $this->assertNotFalse($comments);
- $this->assertNotEmpty($comments);
- $this->assertTrue(is_array($comments));
- $this->assertEquals(2, count($comments));
- }
-
- public function testRemoveComment()
- {
- $task_id = $this->getTaskId();
-
- $comments = $this->client->getAllComments($task_id);
- $this->assertNotFalse($comments);
- $this->assertNotEmpty($comments);
- $this->assertTrue(is_array($comments));
-
- foreach ($comments as $comment) {
- $this->assertTrue($this->client->removeComment($comment['id']));
- }
-
- $comments = $this->client->getAllComments($task_id);
- $this->assertNotFalse($comments);
- $this->assertEmpty($comments);
- $this->assertTrue(is_array($comments));
- }
-
- public function testCreateSubtask()
- {
- $subtask = array(
- 'task_id' => $this->getTaskId(),
- 'title' => 'subtask #1',
- );
-
- $subtask_id = $this->client->createSubtask($subtask);
-
- $this->assertNotFalse($subtask_id);
- $this->assertInternalType('int', $subtask_id);
- $this->assertTrue($subtask_id > 0);
- }
-
- public function testGetSubtask()
- {
- $subtask = $this->client->getSubtask(1);
- $this->assertNotFalse($subtask);
- $this->assertNotEmpty($subtask);
- $this->assertEquals($this->getTaskId(), $subtask['task_id']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals('subtask #1', $subtask['title']);
- }
-
- public function testUpdateSubtask()
- {
- $subtask = array();
- $subtask['id'] = 1;
- $subtask['task_id'] = $this->getTaskId();
- $subtask['title'] = 'test';
-
- $this->assertTrue($this->client->execute('updateSubtask', $subtask));
-
- $subtask = $this->client->getSubtask(1);
- $this->assertEquals('test', $subtask['title']);
- }
-
- public function testGetAllSubtasks()
- {
- $subtask = array(
- 'task_id' => $this->getTaskId(),
- 'user_id' => 2,
- 'title' => 'Subtask #2',
- );
-
- $this->assertNotFalse($this->client->execute('createSubtask', $subtask));
-
- $subtasks = $this->client->getAllSubtasks($this->getTaskId());
- $this->assertNotFalse($subtasks);
- $this->assertNotEmpty($subtasks);
- $this->assertTrue(is_array($subtasks));
- $this->assertEquals(2, count($subtasks));
- }
-
- public function testRemoveSubtask()
- {
- $this->assertTrue($this->client->removeSubtask(1));
-
- $subtasks = $this->client->getAllSubtasks($this->getTaskId());
- $this->assertNotFalse($subtasks);
- $this->assertNotEmpty($subtasks);
- $this->assertTrue(is_array($subtasks));
- $this->assertEquals(1, count($subtasks));
- }
-
- public function testMoveTaskPosition()
- {
- $task_id = $this->getTaskId();
- $this->assertTrue($this->client->moveTaskPosition(1, $task_id, 3, 1));
-
- $task = $this->client->getTask($task_id);
- $this->assertNotFalse($task);
- $this->assertTrue(is_array($task));
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(3, $task['column_id']);
- }
-
- public function testCategoryCreation()
- {
- $category = array(
- 'name' => 'Category',
- 'project_id' => 1,
- );
-
- $cat_id = $this->client->execute('createCategory', $category);
- $this->assertNotFalse($cat_id);
- $this->assertInternalType('int', $cat_id);
- $this->assertTrue($cat_id > 0);
-
- // Duplicate
-
- $category = array(
- 'name' => 'Category',
- 'project_id' => 1,
- );
-
- $this->assertFalse($this->client->execute('createCategory', $category));
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testCategoryCreationWithBadParams()
- {
- // Missing project id
- $category = array(
- 'name' => 'Category',
- );
-
- $this->assertNull($this->client->execute('createCategory', $category));
- }
-
- public function testCategoryRead()
- {
- $category = $this->client->getCategory(1);
-
- $this->assertTrue(is_array($category));
- $this->assertNotEmpty($category);
- $this->assertEquals(1, $category['id']);
- $this->assertEquals('Category', $category['name']);
- $this->assertEquals(1, $category['project_id']);
- }
-
- public function testGetAllCategories()
- {
- $categories = $this->client->getAllCategories(1);
-
- $this->assertNotEmpty($categories);
- $this->assertNotFalse($categories);
- $this->assertTrue(is_array($categories));
- $this->assertEquals(1, count($categories));
- $this->assertEquals(1, $categories[0]['id']);
- $this->assertEquals('Category', $categories[0]['name']);
- $this->assertEquals(1, $categories[0]['project_id']);
- }
-
- public function testCategoryUpdate()
- {
- $category = array(
- 'id' => 1,
- 'name' => 'Renamed category',
- );
-
- $this->assertTrue($this->client->execute('updateCategory', $category));
-
- $category = $this->client->getCategory(1);
- $this->assertTrue(is_array($category));
- $this->assertNotEmpty($category);
- $this->assertEquals(1, $category['id']);
- $this->assertEquals('Renamed category', $category['name']);
- $this->assertEquals(1, $category['project_id']);
- }
-
- public function testCategoryRemove()
- {
- $this->assertTrue($this->client->removeCategory(1));
- $this->assertFalse($this->client->removeCategory(1));
- $this->assertFalse($this->client->removeCategory(1111));
- }
-
- public function testGetAvailableActions()
- {
- $actions = $this->client->getAvailableActions();
- $this->assertNotEmpty($actions);
- $this->assertInternalType('array', $actions);
- $this->assertArrayHasKey('\Kanboard\Action\TaskCloseColumn', $actions);
- }
-
- public function testGetAvailableActionEvents()
- {
- $events = $this->client->getAvailableActionEvents();
- $this->assertNotEmpty($events);
- $this->assertInternalType('array', $events);
- $this->assertArrayHasKey('task.move.column', $events);
- }
-
- public function testGetCompatibleActionEvents()
- {
- $events = $this->client->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn');
- $this->assertNotEmpty($events);
- $this->assertInternalType('array', $events);
- $this->assertArrayHasKey('task.move.column', $events);
- }
-
- public function testCreateAction()
- {
- $action_id = $this->client->createAction(1, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
- $this->assertNotFalse($action_id);
- $this->assertEquals(1, $action_id);
- }
-
- public function testGetActions()
- {
- $actions = $this->client->getActions(1);
- $this->assertNotEmpty($actions);
- $this->assertInternalType('array', $actions);
- $this->assertCount(1, $actions);
- $this->assertArrayHasKey('id', $actions[0]);
- $this->assertArrayHasKey('project_id', $actions[0]);
- $this->assertArrayHasKey('event_name', $actions[0]);
- $this->assertArrayHasKey('action_name', $actions[0]);
- $this->assertArrayHasKey('params', $actions[0]);
- $this->assertArrayHasKey('column_id', $actions[0]['params']);
- }
-
- public function testRemoveAction()
- {
- $this->assertTrue($this->client->removeAction(1));
-
- $actions = $this->client->getActions(1);
- $this->assertEmpty($actions);
- $this->assertCount(0, $actions);
- }
-
- public function testGetAllLinks()
- {
- $links = $this->client->getAllLinks();
- $this->assertNotEmpty($links);
- $this->assertArrayHasKey('id', $links[0]);
- $this->assertArrayHasKey('label', $links[0]);
- $this->assertArrayHasKey('opposite_id', $links[0]);
- }
-
- public function testGetOppositeLink()
- {
- $link = $this->client->getOppositeLinkId(1);
- $this->assertEquals(1, $link);
-
- $link = $this->client->getOppositeLinkId(2);
- $this->assertEquals(3, $link);
- }
-
- public function testGetLinkByLabel()
- {
- $link = $this->client->getLinkByLabel('blocks');
- $this->assertNotEmpty($link);
- $this->assertEquals(2, $link['id']);
- $this->assertEquals(3, $link['opposite_id']);
- }
-
- public function testGetLinkById()
- {
- $link = $this->client->getLinkById(4);
- $this->assertNotEmpty($link);
- $this->assertEquals(4, $link['id']);
- $this->assertEquals(5, $link['opposite_id']);
- $this->assertEquals('duplicates', $link['label']);
- }
-
- public function testCreateLink()
- {
- $link_id = $this->client->createLink(array('label' => 'test'));
- $this->assertNotFalse($link_id);
- $this->assertInternalType('int', $link_id);
-
- $link_id = $this->client->createLink(array('label' => 'foo', 'opposite_label' => 'bar'));
- $this->assertNotFalse($link_id);
- $this->assertInternalType('int', $link_id);
- }
-
- public function testUpdateLink()
- {
- $link1 = $this->client->getLinkByLabel('bar');
- $this->assertNotEmpty($link1);
-
- $link2 = $this->client->getLinkByLabel('test');
- $this->assertNotEmpty($link2);
-
- $this->assertNotFalse($this->client->updateLink($link1['id'], $link2['id'], 'boo'));
-
- $link = $this->client->getLinkById($link1['id']);
- $this->assertNotEmpty($link);
- $this->assertEquals($link2['id'], $link['opposite_id']);
- $this->assertEquals('boo', $link['label']);
-
- $this->assertTrue($this->client->removeLink($link1['id']));
- }
-
- public function testCreateTaskLink()
- {
- $task_id1 = $this->client->createTask(array('project_id' => 1, 'title' => 'A'));
- $this->assertNotFalse($task_id1);
-
- $task_id2 = $this->client->createTask(array('project_id' => 1, 'title' => 'B'));
- $this->assertNotFalse($task_id2);
-
- $task_id3 = $this->client->createTask(array('project_id' => 1, 'title' => 'C'));
- $this->assertNotFalse($task_id3);
-
- $task_link_id = $this->client->createTaskLink($task_id1, $task_id2, 1);
- $this->assertNotFalse($task_link_id);
-
- $task_link = $this->client->getTaskLinkById($task_link_id);
- $this->assertNotEmpty($task_link);
- $this->assertEquals($task_id1, $task_link['task_id']);
- $this->assertEquals($task_id2, $task_link['opposite_task_id']);
- $this->assertEquals(1, $task_link['link_id']);
-
- $task_links = $this->client->getAllTaskLinks($task_id1);
- $this->assertNotEmpty($task_links);
- $this->assertCount(1, $task_links);
-
- $this->assertTrue($this->client->updateTaskLink($task_link_id, $task_id1, $task_id3, 2));
-
- $task_link = $this->client->getTaskLinkById($task_link_id);
- $this->assertNotEmpty($task_link);
- $this->assertEquals($task_id1, $task_link['task_id']);
- $this->assertEquals($task_id3, $task_link['opposite_task_id']);
- $this->assertEquals(2, $task_link['link_id']);
-
- $this->assertTrue($this->client->removeTaskLink($task_link_id));
- $this->assertEmpty($this->client->getAllTaskLinks($task_id1));
- }
-
- public function testCreateFile()
- {
- $this->assertNotFalse($this->client->createFile(1, $this->getTaskId(), 'My file', base64_encode('plain text file')));
- }
-
- public function testGetAllFiles()
- {
- $files = $this->client->getAllFiles(array('task_id' => $this->getTaskId()));
-
- $this->assertNotEmpty($files);
- $this->assertCount(1, $files);
- $this->assertEquals('My file', $files[0]['name']);
-
- $file = $this->client->getFile($files[0]['id']);
- $this->assertNotEmpty($file);
- $this->assertEquals('My file', $file['name']);
-
- $content = $this->client->downloadFile($file['id']);
- $this->assertNotEmpty($content);
- $this->assertEquals('plain text file', base64_decode($content));
-
- $content = $this->client->downloadFile(1234567);
- $this->assertEmpty($content);
-
- $this->assertTrue($this->client->removeFile($file['id']));
- $this->assertEmpty($this->client->getAllFiles(1));
- }
-
- public function testRemoveAllFiles()
- {
- $this->assertNotFalse($this->client->createFile(1, $this->getTaskId(), 'My file 1', base64_encode('plain text file')));
- $this->assertNotFalse($this->client->createFile(1, $this->getTaskId(), 'My file 2', base64_encode('plain text file')));
-
- $files = $this->client->getAllFiles(array('task_id' => $this->getTaskId()));
- $this->assertNotEmpty($files);
- $this->assertCount(2, $files);
-
- $this->assertTrue($this->client->removeAllFiles(array('task_id' => $this->getTaskId())));
-
- $files = $this->client->getAllFiles(array('task_id' => $this->getTaskId()));
- $this->assertEmpty($files);
- }
-
- public function testCreateTaskWithReference()
- {
- $task = array(
- 'title' => 'Task with external ticket number',
- 'reference' => 'TICKET-1234',
- 'project_id' => 1,
- 'description' => '[Link to my ticket](http://my-ticketing-system/1234)',
- );
-
- $task_id = $this->client->createTask($task);
-
- $this->assertNotFalse($task_id);
- $this->assertInternalType('int', $task_id);
- $this->assertTrue($task_id > 0);
- }
-
- public function testGetTaskByReference()
- {
- $task = $this->client->getTaskByReference(array('project_id' => 1, 'reference' => 'TICKET-1234'));
-
- $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=TaskViewController&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']);
- }
-
- public function testCreateOverdueTask()
- {
- $this->assertNotFalse($this->client->createTask(array(
- 'title' => 'overdue task',
- 'project_id' => 1,
- 'date_due' => date('Y-m-d', strtotime('-2days')),
- )));
- }
-
- public function testGetOverdueTasksByProject()
- {
- $tasks = $this->client->getOverdueTasksByProject(1);
- $this->assertNotEmpty($tasks);
- $this->assertCount(1, $tasks);
- $this->assertEquals('overdue task', $tasks[0]['title']);
- $this->assertEquals('API test', $tasks[0]['project_name']);
- }
-
- public function testGetOverdueTasks()
- {
- $tasks = $this->client->getOverdueTasks();
- $this->assertNotEmpty($tasks);
- $this->assertCount(1, $tasks);
- $this->assertEquals('overdue task', $tasks[0]['title']);
- $this->assertEquals('API test', $tasks[0]['project_name']);
- }
-}
diff --git a/tests/integration/AppTest.php b/tests/integration/AppProcedureTest.php
index 6575fbb8..06135dac 100644
--- a/tests/integration/AppTest.php
+++ b/tests/integration/AppProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/Base.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class AppTest extends Base
+class AppProcedureTest extends BaseProcedureTest
{
public function testGetTimezone()
{
@@ -31,4 +31,24 @@ class AppTest extends Base
$this->assertEquals('Project Member', $roles['project-member']);
$this->assertEquals('Project Viewer', $roles['project-viewer']);
}
+
+ public function testGetDefaultColor()
+ {
+ $this->assertEquals('yellow', $this->user->getDefaultTaskColor());
+ }
+
+ public function testGetDefaultColors()
+ {
+ $colors = $this->user->getDefaultTaskColors();
+ $this->assertNotEmpty($colors);
+ $this->assertArrayHasKey('red', $colors);
+ }
+
+ public function testGetColorList()
+ {
+ $colors = $this->user->getColorList();
+ $this->assertNotEmpty($colors);
+ $this->assertArrayHasKey('red', $colors);
+ $this->assertEquals('Red', $colors['red']);
+ }
}
diff --git a/tests/integration/Base.php b/tests/integration/Base.php
deleted file mode 100644
index 6f3ae076..00000000
--- a/tests/integration/Base.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-require_once __DIR__.'/../../vendor/autoload.php';
-
-abstract class Base extends PHPUnit_Framework_TestCase
-{
- protected $app = null;
- protected $admin = null;
- protected $user = null;
-
- public static function setUpBeforeClass()
- {
- if (DB_DRIVER === 'sqlite') {
- @unlink(DB_FILENAME);
- } elseif (DB_DRIVER === 'mysql') {
- $pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
- $pdo->exec('DROP DATABASE '.DB_NAME);
- $pdo->exec('CREATE DATABASE '.DB_NAME);
- $pdo = null;
- } elseif (DB_DRIVER === 'postgres') {
- $pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
- $pdo->exec('DROP DATABASE '.DB_NAME);
- $pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
- $pdo = null;
- }
-
- $service = new Kanboard\ServiceProvider\DatabaseProvider;
-
- $db = $service->getInstance();
- $db->table('settings')->eq('option', 'api_token')->update(array('value' => API_KEY));
- $db->closeConnection();
- }
-
- public function setUp()
- {
- $this->app = new JsonRPC\Client(API_URL);
- $this->app->authentication('jsonrpc', API_KEY);
- $this->app->getHttpClient()->withDebug();
-
- $this->admin = new JsonRPC\Client(API_URL);
- $this->admin->authentication('admin', 'admin');
- $this->admin->getHttpClient()->withDebug();
-
- $this->user = new JsonRPC\Client(API_URL);
- $this->user->authentication('user', 'password');
- $this->user->getHttpClient()->withDebug();
- }
-
- protected function getProjectId()
- {
- $projects = $this->app->getAllProjects();
- $this->assertNotEmpty($projects);
- return $projects[0]['id'];
- }
-
- protected function getGroupId()
- {
- $groups = $this->app->getAllGroups();
- $this->assertNotEmpty($groups);
- return $groups[0]['id'];
- }
-}
diff --git a/tests/integration/BaseProcedureTest.php b/tests/integration/BaseProcedureTest.php
new file mode 100644
index 00000000..beb13ff7
--- /dev/null
+++ b/tests/integration/BaseProcedureTest.php
@@ -0,0 +1,133 @@
+<?php
+
+require_once __DIR__.'/../../vendor/autoload.php';
+
+abstract class BaseProcedureTest extends PHPUnit_Framework_TestCase
+{
+ protected $app = null;
+ protected $admin = null;
+ protected $manager = null;
+ protected $user = null;
+
+ protected $adminUserId = 0;
+ protected $managerUserId = 0;
+ protected $userUserId = 0;
+
+ protected $projectName = '';
+ protected $projectId = 0;
+ protected $taskTitle = 'My task';
+ protected $taskId = 0;
+ protected $subtaskId = 0;
+
+ protected $groupName1 = 'My Group A';
+ protected $groupName2 = 'My Group B';
+ protected $groupId1;
+ protected $groupId2;
+
+ protected $username = 'test-user';
+ protected $userId;
+
+ public function setUp()
+ {
+ $this->setUpAppClient();
+ $this->setUpAdminUser();
+ $this->setUpManagerUser();
+ $this->setUpStandardUser();
+ }
+
+ public function setUpAppClient()
+ {
+ $this->app = new JsonRPC\Client(API_URL);
+ $this->app->authentication('jsonrpc', API_KEY);
+ $this->app->getHttpClient()->withDebug()->withTimeout(10);
+ }
+
+ public function setUpAdminUser()
+ {
+ $this->adminUserId = $this->getUserId('superuser');
+
+ if (! $this->adminUserId) {
+ $this->adminUserId = $this->app->createUser('superuser', 'password', 'Admin User', 'user@localhost', 'app-admin');
+ $this->assertNotFalse($this->adminUserId);
+ }
+
+ $this->admin = new JsonRPC\Client(API_URL);
+ $this->admin->authentication('superuser', 'password');
+ $this->admin->getHttpClient()->withDebug();
+ }
+
+ public function setUpManagerUser()
+ {
+ $this->managerUserId = $this->getUserId('manager');
+
+ if (! $this->managerUserId) {
+ $this->managerUserId = $this->app->createUser('manager', 'password', 'Manager User', 'user@localhost', 'app-manager');
+ $this->assertNotFalse($this->managerUserId);
+ }
+
+ $this->manager = new JsonRPC\Client(API_URL);
+ $this->manager->authentication('manager', 'password');
+ $this->manager->getHttpClient()->withDebug();
+ }
+
+ public function setUpStandardUser()
+ {
+ $this->userUserId = $this->getUserId('user');
+
+ if (! $this->userUserId) {
+ $this->userUserId = $this->app->createUser('user', 'password', 'Standard User', 'user@localhost', 'app-user');
+ $this->assertNotFalse($this->userUserId);
+ }
+
+ $this->user = new JsonRPC\Client(API_URL);
+ $this->user->authentication('user', 'password');
+ $this->user->getHttpClient()->withDebug();
+ }
+
+ public function getUserId($username)
+ {
+ $user = $this->app->getUserByName($username);
+
+ if (! empty($user)) {
+ return $user['id'];
+ }
+
+ return 0;
+ }
+
+ public function assertCreateTeamProject()
+ {
+ $this->projectId = $this->app->createProject($this->projectName, 'Description');
+ $this->assertNotFalse($this->projectId);
+ }
+
+ public function assertCreateUser()
+ {
+ $this->userId = $this->app->createUser($this->username, 'password');
+ $this->assertNotFalse($this->userId);
+ }
+
+ public function assertCreateGroups()
+ {
+ $this->groupId1 = $this->app->createGroup($this->groupName1);
+ $this->groupId2 = $this->app->createGroup($this->groupName2, 'External ID');
+ $this->assertNotFalse($this->groupId1);
+ $this->assertNotFalse($this->groupId2);
+ }
+
+ public function assertCreateTask()
+ {
+ $this->taskId = $this->app->createTask(array('title' => $this->taskTitle, 'project_id' => $this->projectId));
+ $this->assertNotFalse($this->taskId);
+ }
+
+ public function assertCreateSubtask()
+ {
+ $this->subtaskId = $this->app->createSubtask(array(
+ 'task_id' => $this->taskId,
+ 'title' => 'subtask #1',
+ ));
+
+ $this->assertNotFalse($this->subtaskId);
+ }
+}
diff --git a/tests/integration/BoardProcedureTest.php b/tests/integration/BoardProcedureTest.php
new file mode 100644
index 00000000..273e93c7
--- /dev/null
+++ b/tests/integration/BoardProcedureTest.php
@@ -0,0 +1,25 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class BoardProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test board';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertGetBoard();
+ }
+
+ public function assertGetBoard()
+ {
+ $board = $this->app->getBoard($this->projectId);
+ $this->assertNotNull($board);
+ $this->assertCount(1, $board);
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals('Ready', $board[0]['columns'][1]['title']);
+ }
+}
diff --git a/tests/integration/BoardTest.php b/tests/integration/BoardTest.php
deleted file mode 100644
index bf8d50b9..00000000
--- a/tests/integration/BoardTest.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class BoardTest extends Base
-{
- public function testCreateProject()
- {
- $this->assertEquals(1, $this->app->createProject('A project'));
- }
-
- public function testGetBoard()
- {
- $board = $this->app->getBoard(1);
- $this->assertCount(1, $board);
- $this->assertEquals('Default swimlane', $board[0]['name']);
-
- $this->assertCount(4, $board[0]['columns']);
- $this->assertEquals('Ready', $board[0]['columns'][1]['title']);
- }
-}
diff --git a/tests/integration/CategoryProcedureTest.php b/tests/integration/CategoryProcedureTest.php
new file mode 100644
index 00000000..2f5294ba
--- /dev/null
+++ b/tests/integration/CategoryProcedureTest.php
@@ -0,0 +1,76 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class CategoryProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test categories';
+ private $categoryId = 0;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateCategory();
+ $this->assertThatCategoriesAreUnique();
+ $this->assertGetCategory();
+ $this->assertGetAllCategories();
+ $this->assertCategoryUpdate();
+ $this->assertRemoveCategory();
+ }
+
+ public function assertCreateCategory()
+ {
+ $this->categoryId = $this->app->createCategory(array(
+ 'name' => 'Category',
+ 'project_id' => $this->projectId,
+ ));
+
+ $this->assertNotFalse($this->categoryId);
+ }
+
+ public function assertThatCategoriesAreUnique()
+ {
+ $this->assertFalse($this->app->execute('createCategory', array(
+ 'name' => 'Category',
+ 'project_id' => $this->projectId,
+ )));
+ }
+
+ public function assertGetCategory()
+ {
+ $category = $this->app->getCategory($this->categoryId);
+
+ $this->assertInternalType('array', $category);
+ $this->assertEquals($this->categoryId, $category['id']);
+ $this->assertEquals('Category', $category['name']);
+ $this->assertEquals($this->projectId, $category['project_id']);
+ }
+
+ public function assertGetAllCategories()
+ {
+ $categories = $this->app->getAllCategories($this->projectId);
+
+ $this->assertCount(1, $categories);
+ $this->assertEquals($this->categoryId, $categories[0]['id']);
+ $this->assertEquals('Category', $categories[0]['name']);
+ $this->assertEquals($this->projectId, $categories[0]['project_id']);
+ }
+
+ public function assertCategoryUpdate()
+ {
+ $this->assertTrue($this->app->execute('updateCategory', array(
+ 'id' => $this->categoryId,
+ 'name' => 'Renamed category',
+ )));
+
+ $category = $this->app->getCategory($this->categoryId);
+ $this->assertEquals('Renamed category', $category['name']);
+ }
+
+ public function assertRemoveCategory()
+ {
+ $this->assertTrue($this->app->removeCategory($this->categoryId));
+ $this->assertFalse($this->app->removeCategory($this->categoryId));
+ $this->assertFalse($this->app->removeCategory(1111));
+ }
+}
diff --git a/tests/integration/ColumnProcedureTest.php b/tests/integration/ColumnProcedureTest.php
new file mode 100644
index 00000000..fb6a27c3
--- /dev/null
+++ b/tests/integration/ColumnProcedureTest.php
@@ -0,0 +1,69 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ColumnProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test columns';
+ private $columns = array();
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertGetColumns();
+ $this->assertUpdateColumn();
+ $this->assertAddColumn();
+ $this->assertRemoveColumn();
+ $this->assertChangeColumnPosition();
+ }
+
+ public function assertGetColumns()
+ {
+ $this->columns = $this->app->getColumns($this->projectId);
+ $this->assertCount(4, $this->columns);
+ $this->assertEquals('Done', $this->columns[3]['title']);
+ }
+
+ public function assertUpdateColumn()
+ {
+ $this->assertTrue($this->app->updateColumn($this->columns[3]['id'], 'Another column', 2));
+
+ $this->columns = $this->app->getColumns($this->projectId);
+ $this->assertEquals('Another column', $this->columns[3]['title']);
+ $this->assertEquals(2, $this->columns[3]['task_limit']);
+ }
+
+ public function assertAddColumn()
+ {
+ $column_id = $this->app->addColumn($this->projectId, 'New column');
+ $this->assertNotFalse($column_id);
+ $this->assertTrue($column_id > 0);
+
+ $this->columns = $this->app->getColumns($this->projectId);
+ $this->assertCount(5, $this->columns);
+ $this->assertEquals('New column', $this->columns[4]['title']);
+ }
+
+ public function assertRemoveColumn()
+ {
+ $this->assertTrue($this->app->removeColumn($this->columns[3]['id']));
+
+ $this->columns = $this->app->getColumns($this->projectId);
+ $this->assertCount(4, $this->columns);
+ }
+
+ public function assertChangeColumnPosition()
+ {
+ $this->assertTrue($this->app->changeColumnPosition($this->projectId, $this->columns[0]['id'], 3));
+
+ $this->columns = $this->app->getColumns($this->projectId);
+ $this->assertEquals('Ready', $this->columns[0]['title']);
+ $this->assertEquals(1, $this->columns[0]['position']);
+ $this->assertEquals('Work in progress', $this->columns[1]['title']);
+ $this->assertEquals(2, $this->columns[1]['position']);
+ $this->assertEquals('Backlog', $this->columns[2]['title']);
+ $this->assertEquals(3, $this->columns[2]['position']);
+ $this->assertEquals('New column', $this->columns[3]['title']);
+ $this->assertEquals(4, $this->columns[3]['position']);
+ }
+}
diff --git a/tests/integration/ColumnTest.php b/tests/integration/ColumnTest.php
deleted file mode 100644
index 6d02afc0..00000000
--- a/tests/integration/ColumnTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class ColumnTest extends Base
-{
- public function testCreateProject()
- {
- $this->assertEquals(1, $this->app->createProject('A project'));
- }
-
- public function testGetColumns()
- {
- $columns = $this->app->getColumns($this->getProjectId());
- $this->assertCount(4, $columns);
- $this->assertEquals('Done', $columns[3]['title']);
- }
-
- public function testUpdateColumn()
- {
- $this->assertTrue($this->app->updateColumn(4, 'Boo', 2));
-
- $columns = $this->app->getColumns($this->getProjectId());
- $this->assertEquals('Boo', $columns[3]['title']);
- $this->assertEquals(2, $columns[3]['task_limit']);
- }
-
- public function testAddColumn()
- {
- $column_id = $this->app->addColumn($this->getProjectId(), 'New column');
-
- $this->assertNotFalse($column_id);
- $this->assertInternalType('int', $column_id);
- $this->assertTrue($column_id > 0);
-
- $columns = $this->app->getColumns($this->getProjectId());
- $this->assertCount(5, $columns);
- $this->assertEquals('New column', $columns[4]['title']);
- }
-
- public function testRemoveColumn()
- {
- $this->assertTrue($this->app->removeColumn(5));
-
- $columns = $this->app->getColumns($this->getProjectId());
- $this->assertCount(4, $columns);
- }
-
- public function testChangeColumnPosition()
- {
- $this->assertTrue($this->app->changeColumnPosition($this->getProjectId(), 1, 3));
-
- $columns = $this->app->getColumns($this->getProjectId());
- $this->assertCount(4, $columns);
-
- $this->assertEquals('Ready', $columns[0]['title']);
- $this->assertEquals(1, $columns[0]['position']);
- $this->assertEquals('Work in progress', $columns[1]['title']);
- $this->assertEquals(2, $columns[1]['position']);
- $this->assertEquals('Backlog', $columns[2]['title']);
- $this->assertEquals(3, $columns[2]['position']);
- $this->assertEquals('Boo', $columns[3]['title']);
- $this->assertEquals(4, $columns[3]['position']);
- }
-}
diff --git a/tests/integration/CommentProcedureTest.php b/tests/integration/CommentProcedureTest.php
new file mode 100644
index 00000000..881d938c
--- /dev/null
+++ b/tests/integration/CommentProcedureTest.php
@@ -0,0 +1,63 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class CommentProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test comments';
+ private $commentId = 0;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertCreateComment();
+ $this->assertUpdateComment();
+ $this->assertGetAllComments();
+ $this->assertRemoveComment();
+ }
+
+ public function assertCreateComment()
+ {
+ $this->commentId = $this->app->execute('createComment', array(
+ 'task_id' => $this->taskId,
+ 'user_id' => 1,
+ 'content' => 'foobar',
+ ));
+
+ $this->assertNotFalse($this->commentId);
+ }
+
+ public function assertGetComment()
+ {
+ $comment = $this->app->getComment($this->commentId);
+ $this->assertNotFalse($comment);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals(1, $comment['user_id']);
+ $this->assertEquals('foobar', $comment['comment']);
+ }
+
+ public function assertUpdateComment()
+ {
+ $this->assertTrue($this->app->execute('updateComment', array(
+ 'id' => $this->commentId,
+ 'content' => 'test',
+ )));
+
+ $comment = $this->app->getComment($this->commentId);
+ $this->assertEquals('test', $comment['comment']);
+ }
+
+ public function assertGetAllComments()
+ {
+ $comments = $this->app->getAllComments($this->taskId);
+ $this->assertCount(1, $comments);
+ $this->assertEquals('test', $comments[0]['comment']);
+ }
+
+ public function assertRemoveComment()
+ {
+ $this->assertTrue($this->app->removeComment($this->commentId));
+ $this->assertFalse($this->app->removeComment($this->commentId));
+ }
+}
diff --git a/tests/integration/GroupMemberProcedureTest.php b/tests/integration/GroupMemberProcedureTest.php
new file mode 100644
index 00000000..fe243533
--- /dev/null
+++ b/tests/integration/GroupMemberProcedureTest.php
@@ -0,0 +1,53 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class GroupMemberProcedureTest extends BaseProcedureTest
+{
+ protected $username = 'user-group-member';
+ protected $groupName1 = 'My group member A';
+ protected $groupName2 = 'My group member B';
+
+ public function testAll()
+ {
+ $this->assertCreateGroups();
+ $this->assertCreateUser();
+ $this->assertAddMember();
+ $this->assertGetMembers();
+ $this->assertIsGroupMember();
+ $this->assertGetGroups();
+ $this->assertRemove();
+ }
+
+ public function assertAddMember()
+ {
+ $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId));
+ }
+
+ public function assertGetMembers()
+ {
+ $members = $this->app->getGroupMembers($this->groupId1);
+ $this->assertCount(1, $members);
+ $this->assertEquals($this->username, $members[0]['username']);
+ }
+
+ public function assertIsGroupMember()
+ {
+ $this->assertTrue($this->app->isGroupMember($this->groupId1, $this->userId));
+ $this->assertFalse($this->app->isGroupMember($this->groupId1, $this->adminUserId));
+ }
+
+ public function assertGetGroups()
+ {
+ $groups = $this->app->getMemberGroups($this->userId);
+ $this->assertCount(1, $groups);
+ $this->assertEquals($this->groupId1, $groups[0]['id']);
+ $this->assertEquals($this->groupName1, $groups[0]['name']);
+ }
+
+ public function assertRemove()
+ {
+ $this->assertTrue($this->app->removeGroupMember($this->groupId1, $this->userId));
+ $this->assertFalse($this->app->isGroupMember($this->groupId1, $this->userId));
+ }
+}
diff --git a/tests/integration/GroupMemberTest.php b/tests/integration/GroupMemberTest.php
deleted file mode 100644
index d49945b5..00000000
--- a/tests/integration/GroupMemberTest.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class GroupMemberTest extends Base
-{
- public function testAddMember()
- {
- $this->assertNotFalse($this->app->createGroup('My Group A'));
- $this->assertNotFalse($this->app->createGroup('My Group B'));
-
- $groupId = $this->getGroupId();
- $this->assertTrue($this->app->addGroupMember($groupId, 1));
- }
-
- public function testGetMembers()
- {
- $groups = $this->app->getAllGroups();
- $members = $this->app->getGroupMembers($groups[0]['id']);
- $this->assertCount(1, $members);
- $this->assertEquals('admin', $members[0]['username']);
-
- $this->assertSame(array(), $this->app->getGroupMembers($groups[1]['id']));
- }
-
- public function testIsGroupMember()
- {
- $groupId = $this->getGroupId();
- $this->assertTrue($this->app->isGroupMember($groupId, 1));
- $this->assertFalse($this->app->isGroupMember($groupId, 2));
- }
-
- public function testGetGroups()
- {
- $groups = $this->app->getMemberGroups(1);
- $this->assertCount(1, $groups);
- $this->assertEquals(1, $groups[0]['id']);
- $this->assertEquals('My Group A', $groups[0]['name']);
- }
-
- public function testRemove()
- {
- $groupId = $this->getGroupId();
- $this->assertTrue($this->app->removeGroupMember($groupId, 1));
- $this->assertFalse($this->app->isGroupMember($groupId, 1));
- }
-}
diff --git a/tests/integration/GroupProcedureTest.php b/tests/integration/GroupProcedureTest.php
new file mode 100644
index 00000000..610c121d
--- /dev/null
+++ b/tests/integration/GroupProcedureTest.php
@@ -0,0 +1,50 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class GroupProcedureTest extends BaseProcedureTest
+{
+ public function testAll()
+ {
+ $this->assertCreateGroups();
+ $this->assertGetAllGroups();
+ $this->assertGetGroup();
+ $this->assertUpdateGroup();
+ $this->assertRemove();
+ }
+
+ public function assertGetAllGroups()
+ {
+ $groups = $this->app->getAllGroups();
+ $this->assertNotEmpty($groups);
+ $this->assertArrayHasKey('name', $groups[0]);
+ $this->assertArrayHasKey('external_id', $groups[0]);
+ }
+
+ public function assertGetGroup()
+ {
+ $group = $this->app->getGroup($this->groupId1);
+ $this->assertNotEmpty($group);
+ $this->assertEquals($this->groupName1, $group['name']);
+ $this->assertEquals('', $group['external_id']);
+ }
+
+ public function assertUpdateGroup()
+ {
+ $this->assertTrue($this->app->updateGroup(array(
+ 'group_id' => $this->groupId2,
+ 'name' => 'My Group C',
+ 'external_id' => 'something else',
+ )));
+
+ $group = $this->app->getGroup($this->groupId2);
+ $this->assertNotEmpty($group);
+ $this->assertEquals('My Group C', $group['name']);
+ $this->assertEquals('something else', $group['external_id']);
+ }
+
+ public function assertRemove()
+ {
+ $this->assertTrue($this->app->removeGroup($this->groupId1));
+ }
+}
diff --git a/tests/integration/GroupTest.php b/tests/integration/GroupTest.php
deleted file mode 100644
index 7a5bccc9..00000000
--- a/tests/integration/GroupTest.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class GroupTest extends Base
-{
- public function testCreateGroup()
- {
- $this->assertNotFalse($this->app->createGroup('My Group A'));
- $this->assertNotFalse($this->app->createGroup('My Group B', '1234'));
- }
-
- public function testGetter()
- {
- $groups = $this->app->getAllGroups();
- $this->assertCount(2, $groups);
- $this->assertEquals('My Group A', $groups[0]['name']);
- $this->assertEquals('', $groups[0]['external_id']);
- $this->assertEquals('My Group B', $groups[1]['name']);
- $this->assertEquals('1234', $groups[1]['external_id']);
-
- $group = $this->app->getGroup($groups[0]['id']);
- $this->assertNotEmpty($group);
- $this->assertEquals('My Group A', $group['name']);
- $this->assertEquals('', $group['external_id']);
- }
-
- public function testUpdate()
- {
- $groups = $this->app->getAllGroups();
-
- $this->assertTrue($this->app->updateGroup(array('group_id' => $groups[0]['id'], 'name' => 'ABC', 'external_id' => 'something')));
- $this->assertTrue($this->app->updateGroup(array('group_id' => $groups[1]['id'], 'external_id' => '')));
-
- $groups = $this->app->getAllGroups();
- $this->assertEquals('ABC', $groups[0]['name']);
- $this->assertEquals('something', $groups[0]['external_id']);
- $this->assertEquals('', $groups[1]['external_id']);
- }
-
- public function testRemove()
- {
- $groups = $this->app->getAllGroups();
- $this->assertTrue($this->app->removeGroup($groups[0]['id']));
- $this->assertTrue($this->app->removeGroup($groups[1]['id']));
- $this->assertSame(array(), $this->app->getAllGroups());
- }
-}
diff --git a/tests/integration/LinkProcedureTest.php b/tests/integration/LinkProcedureTest.php
new file mode 100644
index 00000000..fb07e694
--- /dev/null
+++ b/tests/integration/LinkProcedureTest.php
@@ -0,0 +1,70 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class LinkProcedureTest extends BaseProcedureTest
+{
+ public function testGetAllLinks()
+ {
+ $links = $this->app->getAllLinks();
+ $this->assertNotEmpty($links);
+ $this->assertArrayHasKey('id', $links[0]);
+ $this->assertArrayHasKey('label', $links[0]);
+ $this->assertArrayHasKey('opposite_id', $links[0]);
+ }
+
+ public function testGetOppositeLink()
+ {
+ $link = $this->app->getOppositeLinkId(1);
+ $this->assertEquals(1, $link);
+
+ $link = $this->app->getOppositeLinkId(2);
+ $this->assertEquals(3, $link);
+ }
+
+ public function testGetLinkByLabel()
+ {
+ $link = $this->app->getLinkByLabel('blocks');
+ $this->assertNotEmpty($link);
+ $this->assertEquals(2, $link['id']);
+ $this->assertEquals(3, $link['opposite_id']);
+ }
+
+ public function testGetLinkById()
+ {
+ $link = $this->app->getLinkById(4);
+ $this->assertNotEmpty($link);
+ $this->assertEquals(4, $link['id']);
+ $this->assertEquals(5, $link['opposite_id']);
+ $this->assertEquals('duplicates', $link['label']);
+ }
+
+ public function testCreateLink()
+ {
+ $link_id = $this->app->createLink(array('label' => 'test'));
+ $this->assertNotFalse($link_id);
+ $this->assertInternalType('int', $link_id);
+
+ $link_id = $this->app->createLink(array('label' => 'foo', 'opposite_label' => 'bar'));
+ $this->assertNotFalse($link_id);
+ $this->assertInternalType('int', $link_id);
+ }
+
+ public function testUpdateLink()
+ {
+ $link1 = $this->app->getLinkByLabel('bar');
+ $this->assertNotEmpty($link1);
+
+ $link2 = $this->app->getLinkByLabel('test');
+ $this->assertNotEmpty($link2);
+
+ $this->assertNotFalse($this->app->updateLink($link1['id'], $link2['id'], 'my link'));
+
+ $link = $this->app->getLinkById($link1['id']);
+ $this->assertNotEmpty($link);
+ $this->assertEquals($link2['id'], $link['opposite_id']);
+ $this->assertEquals('my link', $link['label']);
+
+ $this->assertTrue($this->app->removeLink($link1['id']));
+ }
+}
diff --git a/tests/integration/MeProcedureTest.php b/tests/integration/MeProcedureTest.php
new file mode 100644
index 00000000..2106419c
--- /dev/null
+++ b/tests/integration/MeProcedureTest.php
@@ -0,0 +1,68 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class MeProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My private project';
+
+ public function testAll()
+ {
+ $this->assertGetMe();
+ $this->assertCreateMyPrivateProject();
+ $this->assertGetMyProjectsList();
+ $this->assertGetMyProjects();
+ $this->assertCreateTask();
+ $this->assertGetMyDashboard();
+ $this->assertGetMyActivityStream();
+ }
+
+ public function assertGetMe()
+ {
+ $profile = $this->user->getMe();
+ $this->assertEquals('user', $profile['username']);
+ $this->assertEquals('app-user', $profile['role']);
+ }
+
+ public function assertCreateMyPrivateProject()
+ {
+ $this->projectId = $this->user->createMyPrivateProject($this->projectName);
+ $this->assertNotFalse($this->projectId);
+ }
+
+ public function assertGetMyProjectsList()
+ {
+ $projects = $this->user->getMyProjectsList();
+ $this->assertNotEmpty($projects);
+ $this->assertEquals($this->projectName, $projects[$this->projectId]);
+ }
+
+ public function assertGetMyProjects()
+ {
+ $projects = $this->user->getMyProjects();
+ $this->assertNotEmpty($projects);
+ }
+
+ public function assertCreateTask()
+ {
+ $taskId = $this->user->createTask(array('title' => 'My task', 'project_id' => $this->projectId, 'owner_id' => $this->userUserId));
+ $this->assertNotFalse($taskId);
+ }
+
+ public function assertGetMyDashboard()
+ {
+ $dashboard = $this->user->getMyDashboard();
+ $this->assertNotEmpty($dashboard);
+ $this->assertArrayHasKey('projects', $dashboard);
+ $this->assertArrayHasKey('tasks', $dashboard);
+ $this->assertArrayHasKey('subtasks', $dashboard);
+ $this->assertNotEmpty($dashboard['projects']);
+ $this->assertNotEmpty($dashboard['tasks']);
+ }
+
+ public function assertGetMyActivityStream()
+ {
+ $activity = $this->user->getMyActivityStream();
+ $this->assertNotEmpty($activity);
+ }
+}
diff --git a/tests/integration/MeTest.php b/tests/integration/MeTest.php
deleted file mode 100644
index 1b028b84..00000000
--- a/tests/integration/MeTest.php
+++ /dev/null
@@ -1,247 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class MeTest extends Base
-{
- public function testCreateProject()
- {
- $this->assertEquals(1, $this->app->createProject('team project'));
- }
-
- public function testCreateUser()
- {
- $this->assertEquals(2, $this->app->createUser('user', 'password'));
- }
-
- /**
- * @expectedException JsonRPC\Exception\AccessDeniedException
- */
- public function testNotAllowedAppProcedure()
- {
- $this->app->getMe();
- }
-
- /**
- * @expectedException JsonRPC\Exception\AccessDeniedException
- */
- public function testNotAllowedUserProcedure()
- {
- $this->user->getAllProjects();
- }
-
- /**
- * @expectedException JsonRPC\Exception\AccessDeniedException
- */
- public function testNotAllowedProjectForUser()
- {
- $this->user->getProjectById(1);
- }
-
- public function testAllowedProjectForAdmin()
- {
- $this->assertNotEmpty($this->admin->getProjectById(1));
- }
-
- public function testGetTimezone()
- {
- $this->assertEquals('UTC', $this->user->getTimezone());
- }
-
- public function testGetVersion()
- {
- $this->assertEquals('master', $this->user->getVersion());
- }
-
- public function testGetDefaultColor()
- {
- $this->assertEquals('yellow', $this->user->getDefaultTaskColor());
- }
-
- public function testGetDefaultColors()
- {
- $colors = $this->user->getDefaultTaskColors();
- $this->assertNotEmpty($colors);
- $this->assertArrayHasKey('red', $colors);
- }
-
- public function testGetColorList()
- {
- $colors = $this->user->getColorList();
- $this->assertNotEmpty($colors);
- $this->assertArrayHasKey('red', $colors);
- $this->assertEquals('Red', $colors['red']);
- }
-
- public function testGetMe()
- {
- $profile = $this->user->getMe();
- $this->assertNotEmpty($profile);
- $this->assertEquals(2, $profile['id']);
- $this->assertEquals('user', $profile['username']);
- }
-
- public function testCreateMyPrivateProject()
- {
- $this->assertEquals(2, $this->user->createMyPrivateProject('my project'));
- }
-
- public function testGetMyProjectsList()
- {
- $projects = $this->user->getMyProjectsList();
- $this->assertNotEmpty($projects);
- $this->assertArrayNotHasKey(1, $projects);
- $this->assertArrayHasKey(2, $projects);
- $this->assertEquals('my project', $projects[2]);
- }
-
- public function testGetMyProjects()
- {
- $projects = $this->user->getMyProjects();
- $this->assertNotEmpty($projects);
- $this->assertCount(1, $projects);
- $this->assertEquals(2, $projects[0]['id']);
- $this->assertEquals('my project', $projects[0]['name']);
- $this->assertNotEmpty($projects[0]['url']['calendar']);
- $this->assertNotEmpty($projects[0]['url']['board']);
- $this->assertNotEmpty($projects[0]['url']['list']);
- }
-
- public function testGetProjectById()
- {
- $project = $this->user->getProjectById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('my project', $project['name']);
- $this->assertEquals(1, $project['is_private']);
- }
-
- public function testCreateTask()
- {
- $this->assertEquals(1, $this->user->createTask('my user title', 2));
- $this->assertEquals(2, $this->admin->createTask('my admin title', 1));
- }
-
- public function testCreateTaskWithWrongMember()
- {
- $this->assertFalse($this->user->createTask(array('title' => 'something', 'project_id' => 2, 'owner_id' => 1)));
- $this->assertFalse($this->app->createTask(array('title' => 'something', 'project_id' => 1, 'owner_id' => 2)));
- }
-
- public function testGetTask()
- {
- $task = $this->user->getTask(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('my user title', $task['title']);
- $this->assertEquals('yellow', $task['color_id']);
- $this->assertArrayHasKey('color', $task);
- $this->assertArrayHasKey('name', $task['color']);
- $this->assertArrayHasKey('border', $task['color']);
- $this->assertArrayHasKey('background', $task['color']);
- }
-
- /**
- * @expectedException JsonRPC\Exception\AccessDeniedException
- */
- public function testGetAdminTask()
- {
- $this->user->getTask(2);
- }
-
- /**
- * @expectedException JsonRPC\Exception\AccessDeniedException
- */
- public function testGetProjectActivityDenied()
- {
- $this->user->getProjectActivity(1);
- }
-
- public function testGetProjectActivityAllowed()
- {
- $activity = $this->user->getProjectActivity(2);
- $this->assertNotEmpty($activity);
- }
-
- public function testGetMyActivityStream()
- {
- $activity = $this->user->getMyActivityStream();
- $this->assertNotEmpty($activity);
- }
-
- public function testCloseTask()
- {
- $this->assertTrue($this->user->closeTask(1));
- }
-
- public function testOpenTask()
- {
- $this->assertTrue($this->user->openTask(1));
- }
-
- public function testMoveTaskPosition()
- {
- $this->assertTrue($this->user->moveTaskPosition(2, 1, 2, 1));
- }
-
- public function testUpdateTaskWithWrongMember()
- {
- $this->assertFalse($this->user->updateTask(array('id' => 1, 'title' => 'new title', 'reference' => 'test', 'owner_id' => 1)));
- }
-
- public function testUpdateTask()
- {
- $this->assertTrue($this->user->updateTask(array('id' => 1, 'title' => 'new title', 'reference' => 'test', 'owner_id' => 2)));
- }
-
- public function testGetbyReference()
- {
- $task = $this->user->getTaskByReference(2, 'test');
- $this->assertNotEmpty($task);
- $this->assertEquals('new title', $task['title']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- }
-
- public function testGetMyDashboard()
- {
- $dashboard = $this->user->getMyDashboard();
- $this->assertNotEmpty($dashboard);
- $this->assertArrayHasKey('projects', $dashboard);
- $this->assertArrayHasKey('tasks', $dashboard);
- $this->assertArrayHasKey('subtasks', $dashboard);
- $this->assertNotEmpty($dashboard['projects']);
- $this->assertNotEmpty($dashboard['tasks']);
- }
-
- public function testGetBoard()
- {
- $this->assertNotEmpty($this->user->getBoard(2));
- }
-
- public function testCreateOverdueTask()
- {
- $this->assertNotFalse($this->user->createTask(array(
- 'title' => 'overdue task',
- 'project_id' => 2,
- 'date_due' => date('Y-m-d', strtotime('-2days')),
- 'owner_id' => 2,
- )));
- }
-
- public function testGetMyOverdueTasks()
- {
- $tasks = $this->user->getMyOverdueTasks();
- $this->assertNotEmpty($tasks);
- $this->assertCount(1, $tasks);
- $this->assertEquals('overdue task', $tasks[0]['title']);
- $this->assertEquals('my project', $tasks[0]['project_name']);
- }
-
- public function testGetOverdueTasksByProject()
- {
- $tasks = $this->user->getOverdueTasksByProject(2);
- $this->assertNotEmpty($tasks);
- $this->assertCount(1, $tasks);
- $this->assertEquals('overdue task', $tasks[0]['title']);
- $this->assertEquals('my project', $tasks[0]['project_name']);
- }
-}
diff --git a/tests/integration/OverdueTaskProcedureTest.php b/tests/integration/OverdueTaskProcedureTest.php
new file mode 100644
index 00000000..65f52301
--- /dev/null
+++ b/tests/integration/OverdueTaskProcedureTest.php
@@ -0,0 +1,43 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class OverdueTaskProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test overdue tasks';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateOverdueTask();
+ $this->assertGetOverdueTasksByProject();
+ $this->assertGetOverdueTasks();
+ }
+
+ public function assertCreateOverdueTask()
+ {
+ $this->assertNotFalse($this->app->createTask(array(
+ 'title' => 'overdue task',
+ 'project_id' => $this->projectId,
+ 'date_due' => date('Y-m-d', strtotime('-2days')),
+ )));
+ }
+
+ public function assertGetOverdueTasksByProject()
+ {
+ $tasks = $this->app->getOverdueTasksByProject($this->projectId);
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('overdue task', $tasks[0]['title']);
+ $this->assertEquals($this->projectName, $tasks[0]['project_name']);
+ }
+
+ public function assertGetOverdueTasks()
+ {
+ $tasks = $this->app->getOverdueTasks();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('overdue task', $tasks[0]['title']);
+ $this->assertEquals($this->projectName, $tasks[0]['project_name']);
+ }
+}
diff --git a/tests/integration/ProcedureAuthorizationTest.php b/tests/integration/ProcedureAuthorizationTest.php
new file mode 100644
index 00000000..a63e9d8c
--- /dev/null
+++ b/tests/integration/ProcedureAuthorizationTest.php
@@ -0,0 +1,306 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ProcedureAuthorizationTest extends BaseProcedureTest
+{
+ public function testApiCredentialDoNotHaveAccessToUserCredentialProcedure()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->app->getMe();
+ }
+
+ public function testUserCredentialDoNotHaveAccessToAdminProcedures()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->getUser(1);
+ }
+
+ public function testManagerCredentialDoNotHaveAccessToAdminProcedures()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->getAllProjects();
+ }
+
+ public function testUserCredentialDoNotHaveAccessToManagerProcedures()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->createProject('Team project creation are only for app managers');
+ }
+
+ public function testAppManagerCanCreateTeamProject()
+ {
+ $this->assertNotFalse($this->manager->createProject('Team project created by app manager'));
+ }
+
+ public function testAdminManagerCanCreateTeamProject()
+ {
+ $projectId = $this->admin->createProject('Team project created by admin');
+ $this->assertNotFalse($projectId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->assertNotNull($this->manager->getProjectById($projectId));
+ }
+
+ public function testProjectManagerCanUpdateHisProject()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Team project can be updated',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertEquals('project-manager', $this->app->getProjectUserRole($projectId, $this->managerUserId));
+ $this->assertNotNull($this->manager->getProjectById($projectId));
+
+ $this->assertTrue($this->manager->updateProject($projectId, 'My team project have been updated'));
+ }
+
+ public function testProjectAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject('A team project without members');
+ $this->assertNotFalse($projectId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->getProjectById($projectId);
+ }
+
+ public function testProjectAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'A team project with members',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId));
+ $this->assertNotNull($this->user->getProjectById($projectId));
+ }
+
+ public function testActionAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeAction($projectId);
+ }
+
+ public function testActionAuthorizationForbiddenBecauseNotProjectManager()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeAction($actionId);
+ }
+
+ public function testActionAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager'));
+ $this->assertTrue($this->user->removeAction($actionId));
+ }
+
+ public function testCategoryAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $categoryId = $this->manager->createCategory($projectId, 'Test');
+ $this->assertNotFalse($categoryId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeCategory($categoryId);
+ }
+
+ public function testCategoryAuthorizationForbiddenBecauseNotProjectManager()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $categoryId = $this->manager->createCategory($projectId, 'Test');
+ $this->assertNotFalse($categoryId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeCategory($categoryId);
+ }
+
+ public function testCategoryAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $categoryId = $this->manager->createCategory($projectId, 'Test');
+ $this->assertNotFalse($categoryId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager'));
+ $this->assertTrue($this->user->removeCategory($categoryId));
+ }
+
+ public function testColumnAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $columnId = $this->manager->addColumn($projectId, 'Test');
+ $this->assertNotFalse($columnId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeColumn($columnId);
+ }
+
+ public function testColumnAuthorizationForbiddenBecauseNotProjectManager()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $columnId = $this->manager->addColumn($projectId, 'Test');
+ $this->assertNotFalse($columnId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeColumn($columnId);
+ }
+
+ public function testColumnAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $columnId = $this->manager->addColumn($projectId, 'Test');
+ $this->assertNotFalse($columnId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager'));
+ $this->assertTrue($this->user->removeColumn($columnId));
+ }
+
+ public function testCommentAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-viewer'));
+
+ $taskId = $this->manager->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $commentId = $this->manager->createComment($taskId, $this->userUserId, 'My comment');
+ $this->assertNotFalse($commentId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->updateComment($commentId, 'something else');
+ }
+
+ public function testCommentAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+
+ $taskId = $this->user->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $commentId = $this->user->createComment($taskId, $this->userUserId, 'My comment');
+ $this->assertNotFalse($commentId);
+
+ $this->assertTrue($this->user->updateComment($commentId, 'something else'));
+ }
+
+ public function testSubtaskAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-viewer'));
+
+ $taskId = $this->manager->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $subtaskId = $this->manager->createSubtask($taskId, 'My subtask');
+ $this->assertNotFalse($subtaskId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeSubtask($subtaskId);
+ }
+
+ public function testSubtaskAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+
+ $taskId = $this->user->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $subtaskId = $this->manager->createSubtask($taskId, 'My subtask');
+ $this->assertNotFalse($subtaskId);
+
+ $this->assertTrue($this->user->removeSubtask($subtaskId));
+ }
+}
diff --git a/tests/integration/ProjectFileProcedureTest.php b/tests/integration/ProjectFileProcedureTest.php
new file mode 100644
index 00000000..8ac70d87
--- /dev/null
+++ b/tests/integration/ProjectFileProcedureTest.php
@@ -0,0 +1,66 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ProjectFileProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test project files';
+ protected $fileId;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateProjectFile();
+ $this->assertGetProjectFile();
+ $this->assertDownloadProjectFile();
+ $this->assertGetAllFiles();
+ $this->assertRemoveProjectFile();
+ $this->assertRemoveAllProjectFiles();
+ }
+
+ public function assertCreateProjectFile()
+ {
+ $this->fileId = $this->app->createProjectFile($this->projectId, 'My file.txt', base64_encode('plain text file'));
+ $this->assertNotFalse($this->fileId);
+ }
+
+ public function assertGetProjectFile()
+ {
+ $file = $this->app->getProjectFile($this->projectId, $this->fileId);
+ $this->assertNotEmpty($file);
+ $this->assertEquals('My file.txt', $file['name']);
+ }
+
+ public function assertDownloadProjectFile()
+ {
+ $content = $this->app->downloadProjectFile($this->projectId, $this->fileId);
+ $this->assertNotEmpty($content);
+ $this->assertEquals('plain text file', base64_decode($content));
+ }
+
+ public function assertGetAllFiles()
+ {
+ $files = $this->app->getAllProjectFiles($this->projectId);
+ $this->assertCount(1, $files);
+ $this->assertEquals('My file.txt', $files[0]['name']);
+ }
+
+ public function assertRemoveProjectFile()
+ {
+ $this->assertTrue($this->app->removeProjectFile($this->projectId, $this->fileId));
+
+ $files = $this->app->getAllProjectFiles($this->projectId);
+ $this->assertEmpty($files);
+ }
+
+ public function assertRemoveAllProjectFiles()
+ {
+ $this->assertCreateProjectFile();
+ $this->assertCreateProjectFile();
+
+ $this->assertTrue($this->app->removeAllProjectFiles($this->projectId));
+
+ $files = $this->app->getAllProjectFiles($this->projectId);
+ $this->assertEmpty($files);
+ }
+}
diff --git a/tests/integration/ProjectPermissionProcedureTest.php b/tests/integration/ProjectPermissionProcedureTest.php
new file mode 100644
index 00000000..74313dc4
--- /dev/null
+++ b/tests/integration/ProjectPermissionProcedureTest.php
@@ -0,0 +1,89 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ProjectPermissionProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'Project with permission';
+ protected $username = 'user-project-permission';
+ protected $groupName1 = 'My group A for project permission';
+ protected $groupName2 = 'My group B for project permission';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateGroups();
+ $this->assertCreateUser();
+
+ $this->assertAddProjectUser();
+ $this->assertGetProjectUsers();
+ $this->assertGetAssignableUsers();
+ $this->assertChangeProjectUserRole();
+ $this->assertRemoveProjectUser();
+
+ $this->assertAddProjectGroup();
+ $this->assertGetProjectUsers();
+ $this->assertGetAssignableUsers();
+ $this->assertChangeProjectGroupRole();
+ $this->assertRemoveProjectGroup();
+ }
+
+ public function assertAddProjectUser()
+ {
+ $this->assertTrue($this->app->addProjectUser($this->projectId, $this->userId));
+ }
+
+ public function assertGetProjectUsers()
+ {
+ $members = $this->app->getProjectUsers($this->projectId);
+ $this->assertCount(1, $members);
+ $this->assertArrayHasKey($this->userId, $members);
+ $this->assertEquals($this->username, $members[$this->userId]);
+ }
+
+ public function assertGetAssignableUsers()
+ {
+ $members = $this->app->getAssignableUsers($this->projectId);
+ $this->assertCount(1, $members);
+ $this->assertArrayHasKey($this->userId, $members);
+ $this->assertEquals($this->username, $members[$this->userId]);
+ }
+
+ public function assertChangeProjectUserRole()
+ {
+ $this->assertTrue($this->app->changeProjectUserRole($this->projectId, $this->userId, 'project-viewer'));
+
+ $members = $this->app->getAssignableUsers($this->projectId);
+ $this->assertCount(0, $members);
+ }
+
+ public function assertRemoveProjectUser()
+ {
+ $this->assertTrue($this->app->removeProjectUser($this->projectId, $this->userId));
+
+ $members = $this->app->getProjectUsers($this->projectId);
+ $this->assertCount(0, $members);
+ }
+
+ public function assertAddProjectGroup()
+ {
+ $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId));
+ $this->assertTrue($this->app->addProjectGroup($this->projectId, $this->groupId1));
+ }
+
+ public function assertChangeProjectGroupRole()
+ {
+ $this->assertTrue($this->app->changeProjectGroupRole($this->projectId, $this->groupId1, 'project-viewer'));
+
+ $members = $this->app->getAssignableUsers($this->projectId);
+ $this->assertCount(0, $members);
+ }
+
+ public function assertRemoveProjectGroup()
+ {
+ $this->assertTrue($this->app->removeProjectGroup($this->projectId, $this->groupId1));
+
+ $members = $this->app->getProjectUsers($this->projectId);
+ $this->assertCount(0, $members);
+ }
+}
diff --git a/tests/integration/ProjectPermissionTest.php b/tests/integration/ProjectPermissionTest.php
deleted file mode 100644
index b06ad4ad..00000000
--- a/tests/integration/ProjectPermissionTest.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class ProjectPermissionTest extends Base
-{
- public function testGetProjectUsers()
- {
- $this->assertNotFalse($this->app->createProject('Test'));
- $this->assertNotFalse($this->app->createGroup('Test'));
-
- $projectId = $this->getProjectId();
- $groupId = $this->getGroupId();
-
- $this->assertTrue($this->app->addGroupMember($projectId, $groupId));
- $this->assertSame(array(), $this->app->getProjectUsers($projectId));
- }
-
- public function testProjectUser()
- {
- $projectId = $this->getProjectId();
- $this->assertTrue($this->app->addProjectUser($projectId, 1));
-
- $users = $this->app->getProjectUsers($projectId);
- $this->assertCount(1, $users);
- $this->assertEquals('admin', $users[1]);
-
- $users = $this->app->getAssignableUsers($projectId);
- $this->assertCount(1, $users);
- $this->assertEquals('admin', $users[1]);
-
- $this->assertTrue($this->app->changeProjectUserRole($projectId, 1, 'project-viewer'));
-
- $users = $this->app->getAssignableUsers($projectId);
- $this->assertCount(0, $users);
-
- $this->assertTrue($this->app->removeProjectUser($projectId, 1));
- $this->assertSame(array(), $this->app->getProjectUsers($projectId));
- }
-
- public function testProjectGroup()
- {
- $projectId = $this->getProjectId();
- $groupId = $this->getGroupId();
-
- $this->assertTrue($this->app->addProjectGroup($projectId, $groupId));
-
- $users = $this->app->getProjectUsers($projectId);
- $this->assertCount(1, $users);
- $this->assertEquals('admin', $users[1]);
-
- $users = $this->app->getAssignableUsers($projectId);
- $this->assertCount(1, $users);
- $this->assertEquals('admin', $users[1]);
-
- $this->assertTrue($this->app->changeProjectGroupRole($projectId, $groupId, 'project-viewer'));
-
- $users = $this->app->getAssignableUsers($projectId);
- $this->assertCount(0, $users);
-
- $this->assertTrue($this->app->removeProjectGroup($projectId, 1));
- $this->assertSame(array(), $this->app->getProjectUsers($projectId));
- }
-}
diff --git a/tests/integration/ProjectProcedureTest.php b/tests/integration/ProjectProcedureTest.php
new file mode 100644
index 00000000..69c2464f
--- /dev/null
+++ b/tests/integration/ProjectProcedureTest.php
@@ -0,0 +1,119 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ProjectProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My team project';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertGetProjectById();
+ $this->assertGetProjectByName();
+ $this->assertGetAllProjects();
+ $this->assertUpdateProject();
+ $this->assertUpdateProjectIdentifier();
+ $this->assertCreateProjectWithIdentifier();
+ $this->assertGetProjectActivity();
+ $this->assertGetProjectsActivity();
+ $this->assertEnableDisableProject();
+ $this->assertEnableDisablePublicAccess();
+ $this->assertRemoveProject();
+ }
+
+ public function assertGetProjectById()
+ {
+ $project = $this->app->getProjectById($this->projectId);
+ $this->assertNotNull($project);
+ $this->assertEquals($this->projectName, $project['name']);
+ $this->assertEquals('Description', $project['description']);
+ }
+
+ public function assertGetProjectByName()
+ {
+ $project = $this->app->getProjectByName($this->projectName);
+ $this->assertNotNull($project);
+ $this->assertEquals($this->projectId, $project['id']);
+ $this->assertEquals($this->projectName, $project['name']);
+ $this->assertEquals('Description', $project['description']);
+ }
+
+ public function assertGetAllProjects()
+ {
+ $projects = $this->app->getAllProjects();
+ $this->assertNotEmpty($projects);
+ }
+
+ public function assertGetProjectActivity()
+ {
+ $activities = $this->app->getProjectActivity($this->projectId);
+ $this->assertInternalType('array', $activities);
+ $this->assertCount(0, $activities);
+ }
+
+ public function assertGetProjectsActivity()
+ {
+ $activities = $this->app->getProjectActivities(array('project_ids' => array($this->projectId)));
+ $this->assertInternalType('array', $activities);
+ $this->assertCount(0, $activities);
+ }
+
+ public function assertUpdateProject()
+ {
+ $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => 'test', 'description' => 'test')));
+
+ $project = $this->app->getProjectById($this->projectId);
+ $this->assertNotNull($project);
+ $this->assertEquals('test', $project['name']);
+ $this->assertEquals('test', $project['description']);
+
+ $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => $this->projectName)));
+ }
+
+ public function assertUpdateProjectIdentifier()
+ {
+ $this->assertTrue($this->app->updateProject(array(
+ 'project_id' => $this->projectId,
+ 'identifier' => 'MYPROJECT',
+ )));
+
+ $project = $this->app->getProjectById($this->projectId);
+ $this->assertNotNull($project);
+ $this->assertEquals($this->projectName, $project['name']);
+ $this->assertEquals('MYPROJECT', $project['identifier']);
+ }
+
+ public function assertCreateProjectWithIdentifier()
+ {
+ $projectId = $this->app->createProject(array(
+ 'name' => 'My project with an identifier',
+ 'identifier' => 'MYPROJECTWITHIDENTIFIER',
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $project = $this->app->getProjectByIdentifier('MYPROJECTWITHIDENTIFIER');
+ $this->assertEquals($projectId, $project['id']);
+ $this->assertEquals('My project with an identifier', $project['name']);
+ $this->assertEquals('MYPROJECTWITHIDENTIFIER', $project['identifier']);
+ }
+
+ public function assertEnableDisableProject()
+ {
+ $this->assertTrue($this->app->disableProject($this->projectId));
+ $this->assertTrue($this->app->enableProject($this->projectId));
+ }
+
+ public function assertEnableDisablePublicAccess()
+ {
+ $this->assertTrue($this->app->disableProjectPublicAccess($this->projectId));
+ $this->assertTrue($this->app->enableProjectPublicAccess($this->projectId));
+ }
+
+ public function assertRemoveProject()
+ {
+ $this->assertTrue($this->app->removeProject($this->projectId));
+ $this->assertNull($this->app->getProjectById($this->projectId));
+ }
+}
diff --git a/tests/integration/SubtaskProcedureTest.php b/tests/integration/SubtaskProcedureTest.php
new file mode 100644
index 00000000..b9868e6f
--- /dev/null
+++ b/tests/integration/SubtaskProcedureTest.php
@@ -0,0 +1,53 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class SubtaskProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test subtasks';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertCreateSubtask();
+ $this->assertGetSubtask();
+ $this->assertUpdateSubtask();
+ $this->assertGetAllSubtasks();
+ $this->assertRemoveSubtask();
+ }
+
+ public function assertGetSubtask()
+ {
+ $subtask = $this->app->getSubtask($this->subtaskId);
+ $this->assertEquals($this->taskId, $subtask['task_id']);
+ $this->assertEquals('subtask #1', $subtask['title']);
+ }
+
+ public function assertUpdateSubtask()
+ {
+ $this->assertTrue($this->app->execute('updateSubtask', array(
+ 'id' => $this->subtaskId,
+ 'task_id' => $this->taskId,
+ 'title' => 'test',
+ )));
+
+ $subtask = $this->app->getSubtask($this->subtaskId);
+ $this->assertEquals('test', $subtask['title']);
+ }
+
+ public function assertGetAllSubtasks()
+ {
+ $subtasks = $this->app->getAllSubtasks($this->taskId);
+ $this->assertCount(1, $subtasks);
+ $this->assertEquals('test', $subtasks[0]['title']);
+ }
+
+ public function assertRemoveSubtask()
+ {
+ $this->assertTrue($this->app->removeSubtask($this->subtaskId));
+
+ $subtasks = $this->app->getAllSubtasks($this->taskId);
+ $this->assertCount(0, $subtasks);
+ }
+}
diff --git a/tests/integration/SubtaskTimeTrackingProcedureTest.php b/tests/integration/SubtaskTimeTrackingProcedureTest.php
new file mode 100644
index 00000000..6c45c983
--- /dev/null
+++ b/tests/integration/SubtaskTimeTrackingProcedureTest.php
@@ -0,0 +1,46 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class SubtaskTimeTrackingProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test subtask time tracking';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertCreateSubtask();
+ $this->assertHasNoTimer();
+ $this->assertStartTimer();
+ $this->assertHasTimer();
+ $this->assertStopTimer();
+ $this->assertHasNoTimer();
+ $this->assertGetSubtaskTimeSpent();
+ }
+
+ public function assertHasNoTimer()
+ {
+ $this->assertFalse($this->app->hasSubtaskTimer($this->subtaskId, $this->userUserId));
+ }
+
+ public function assertHasTimer()
+ {
+ $this->assertTrue($this->app->hasSubtaskTimer($this->subtaskId, $this->userUserId));
+ }
+
+ public function assertStartTimer()
+ {
+ $this->assertTrue($this->app->setSubtaskStartTime($this->subtaskId, $this->userUserId));
+ }
+
+ public function assertStopTimer()
+ {
+ $this->assertTrue($this->app->setSubtaskEndTime($this->subtaskId, $this->userUserId));
+ }
+
+ public function assertGetSubtaskTimeSpent()
+ {
+ $this->assertEquals(0, $this->app->getSubtaskTimeSpent($this->subtaskId, $this->userUserId));
+ }
+}
diff --git a/tests/integration/SwimlaneProcedureTest.php b/tests/integration/SwimlaneProcedureTest.php
new file mode 100644
index 00000000..e64342b4
--- /dev/null
+++ b/tests/integration/SwimlaneProcedureTest.php
@@ -0,0 +1,93 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class SwimlaneProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test swimlanes';
+ private $swimlaneId = 0;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ }
+
+ public function assertGetDefaultSwimlane()
+ {
+ $swimlane = $this->app->getDefaultSwimlane($this->projectId);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals('Default swimlane', $swimlane['default_swimlane']);
+ }
+
+ public function assertAddSwimlane()
+ {
+ $this->swimlaneId = $this->app->addSwimlane($this->projectId, 'Swimlane 1');
+ $this->assertNotFalse($this->swimlaneId);
+ $this->assertNotFalse($this->app->addSwimlane($this->projectId, 'Swimlane 2'));
+ }
+
+ public function assertGetSwimlane()
+ {
+ $swimlane = $this->app->getSwimlane($this->swimlaneId);
+ $this->assertInternalType('array', $swimlane);
+ $this->assertEquals('Swimlane 1', $swimlane['name']);
+ }
+
+ public function assertUpdateSwimlane()
+ {
+ $this->assertTrue($this->app->updateSwimlane($this->swimlaneId, 'Another swimlane'));
+
+ $swimlane = $this->app->getSwimlaneById($this->swimlaneId);
+ $this->assertEquals('Another swimlane', $swimlane['name']);
+ }
+
+ public function assertDisableSwimlane()
+ {
+ $this->assertTrue($this->app->disableSwimlane($this->projectId, $this->swimlaneId));
+
+ $swimlane = $this->app->getSwimlaneById($this->swimlaneId);
+ $this->assertEquals(0, $swimlane['is_active']);
+ }
+
+ public function assertEnableSwimlane()
+ {
+ $this->assertTrue($this->app->enableSwimlane($this->projectId, $this->swimlaneId));
+
+ $swimlane = $this->app->getSwimlaneById($this->swimlaneId);
+ $this->assertEquals(1, $swimlane['is_active']);
+ }
+
+ public function assertGetAllSwimlanes()
+ {
+ $swimlanes = $this->app->getAllSwimlanes($this->projectId);
+ $this->assertCount(2, $swimlanes);
+ $this->assertEquals('Another swimlane', $swimlanes[0]['name']);
+ $this->assertEquals('Swimlane 2', $swimlanes[1]['name']);
+ }
+
+ public function assertGetActiveSwimlane()
+ {
+ $this->assertTrue($this->app->disableSwimlane($this->projectId, $this->swimlaneId));
+
+ $swimlanes = $this->app->getActiveSwimlanes($this->projectId);
+ $this->assertCount(2, $swimlanes);
+ $this->assertEquals('Default swimlane', $swimlanes[0]['name']);
+ $this->assertEquals('Swimlane 2', $swimlanes[1]['name']);
+ }
+
+ public function assertRemoveSwimlane()
+ {
+ $this->assertTrue($this->app->removeSwimlane($this->projectId, $this->swimlaneId));
+ }
+
+ public function assertChangePosition()
+ {
+ $swimlaneId1 = $this->app->addSwimlane($this->projectId, 'Swimlane A');
+ $this->assertNotFalse($this->app->addSwimlane($this->projectId, 'Swimlane B'));
+
+ $swimlanes = $this->app->getAllSwimlanes($this->projectId);
+ $this->assertCount(3, $swimlanes);
+
+ $this->assertTrue($this->app->changeSwimlanePosition($this->projectId, $swimlaneId1, 3));
+ }
+}
diff --git a/tests/integration/SwimlaneTest.php b/tests/integration/SwimlaneTest.php
deleted file mode 100644
index 88747204..00000000
--- a/tests/integration/SwimlaneTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class SwimlaneTest extends Base
-{
- public function testCreateProject()
- {
- $this->assertEquals(1, $this->app->createProject('A project'));
- }
-
- public function testGetDefaultSwimlane()
- {
- $swimlane = $this->app->getDefaultSwimlane(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals('Default swimlane', $swimlane['default_swimlane']);
- }
-
- public function testAddSwimlane()
- {
- $swimlane_id = $this->app->addSwimlane(1, 'Swimlane 1');
- $this->assertNotFalse($swimlane_id);
- $this->assertInternalType('int', $swimlane_id);
-
- $swimlane = $this->app->getSwimlaneById($swimlane_id);
- $this->assertNotEmpty($swimlane);
- $this->assertInternalType('array', $swimlane);
- $this->assertEquals('Swimlane 1', $swimlane['name']);
- }
-
- public function testGetSwimlane()
- {
- $swimlane = $this->app->getSwimlane(1);
- $this->assertInternalType('array', $swimlane);
- $this->assertEquals('Swimlane 1', $swimlane['name']);
- }
-
- public function testUpdateSwimlane()
- {
- $swimlane = $this->app->getSwimlaneByName(1, 'Swimlane 1');
- $this->assertInternalType('array', $swimlane);
- $this->assertEquals(1, $swimlane['id']);
- $this->assertEquals('Swimlane 1', $swimlane['name']);
-
- $this->assertTrue($this->app->updateSwimlane($swimlane['id'], 'Another swimlane'));
-
- $swimlane = $this->app->getSwimlaneById($swimlane['id']);
- $this->assertEquals('Another swimlane', $swimlane['name']);
- }
-
- public function testDisableSwimlane()
- {
- $this->assertTrue($this->app->disableSwimlane(1, 1));
-
- $swimlane = $this->app->getSwimlaneById(1);
- $this->assertEquals(0, $swimlane['is_active']);
- }
-
- public function testEnableSwimlane()
- {
- $this->assertTrue($this->app->enableSwimlane(1, 1));
-
- $swimlane = $this->app->getSwimlaneById(1);
- $this->assertEquals(1, $swimlane['is_active']);
- }
-
- public function testGetAllSwimlanes()
- {
- $this->assertNotFalse($this->app->addSwimlane(1, 'Swimlane A'));
-
- $swimlanes = $this->app->getAllSwimlanes(1);
- $this->assertCount(2, $swimlanes);
- $this->assertEquals('Another swimlane', $swimlanes[0]['name']);
- $this->assertEquals('Swimlane A', $swimlanes[1]['name']);
- }
-
- public function testGetActiveSwimlane()
- {
- $this->assertTrue($this->app->disableSwimlane(1, 1));
-
- $swimlanes = $this->app->getActiveSwimlanes(1);
- $this->assertCount(2, $swimlanes);
- $this->assertEquals('Default swimlane', $swimlanes[0]['name']);
- $this->assertEquals('Swimlane A', $swimlanes[1]['name']);
- }
-
- public function testRemoveSwimlane()
- {
- $this->assertTrue($this->app->removeSwimlane(1, 2));
- }
-
- public function testChangePosition()
- {
- $this->assertNotFalse($this->app->addSwimlane(1, 'Swimlane 1'));
- $this->assertNotFalse($this->app->addSwimlane(1, 'Swimlane 2'));
-
- $swimlanes = $this->app->getAllSwimlanes(1);
- $this->assertCount(3, $swimlanes);
-
- $this->assertTrue($this->app->changeSwimlanePosition(1, 1, 3));
- $this->assertFalse($this->app->changeSwimlanePosition(1, 1, 6));
- }
-}
diff --git a/tests/integration/TaskExternalLinkProcedureTest.php b/tests/integration/TaskExternalLinkProcedureTest.php
new file mode 100644
index 00000000..47ff53ad
--- /dev/null
+++ b/tests/integration/TaskExternalLinkProcedureTest.php
@@ -0,0 +1,98 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskExternalLinkProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test external links';
+ private $linkId = 0;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertGetExternalTaskLinkTypes();
+ $this->assertGetExternalTaskLinkProviderDependencies();
+ $this->assertGetExternalTaskLinkProviderDependenciesWithProviderNotFound();
+ $this->assertCreateExternalTaskLink();
+ $this->assertUpdateExternalTaskLink();
+ $this->assertGetAllExternalTaskLinks();
+ $this->assertRemoveExternalTaskLink();
+ }
+
+ public function assertGetExternalTaskLinkTypes()
+ {
+ $expected = array(
+ 'auto' => 'Auto',
+ 'attachment' => 'Attachment',
+ 'file' => 'Local File',
+ 'weblink' => 'Web Link',
+ );
+
+ $types = $this->app->getExternalTaskLinkTypes();
+ $this->assertEquals($expected, $types);
+ }
+
+ public function assertGetExternalTaskLinkProviderDependencies()
+ {
+ $expected = array(
+ 'related' => 'Related',
+ );
+
+ $dependencies = $this->app->getExternalTaskLinkProviderDependencies('weblink');
+
+ $this->assertEquals($expected, $dependencies);
+ }
+
+ public function assertGetExternalTaskLinkProviderDependenciesWithProviderNotFound()
+ {
+ $this->assertFalse($this->app->getExternalTaskLinkProviderDependencies('foobar'));
+ }
+
+ public function assertCreateExternalTaskLink()
+ {
+ $url = 'http://localhost/document.pdf';
+ $this->linkId = $this->app->createExternalTaskLink($this->taskId, $url, 'related', 'attachment');
+ $this->assertNotFalse($this->linkId);
+
+ $link = $this->app->getExternalTaskLinkById($this->taskId, $this->linkId);
+ $this->assertEquals($this->linkId, $link['id']);
+ $this->assertEquals($this->taskId, $link['task_id']);
+ $this->assertEquals('document.pdf', $link['title']);
+ $this->assertEquals($url, $link['url']);
+ $this->assertEquals('related', $link['dependency']);
+ $this->assertEquals(0, $link['creator_id']);
+ }
+
+ public function assertUpdateExternalTaskLink()
+ {
+ $this->assertTrue($this->app->updateExternalTaskLink(array(
+ 'task_id' => $this->taskId,
+ 'link_id' => $this->linkId,
+ 'title' => 'New title',
+ )));
+
+ $link = $this->app->getExternalTaskLinkById($this->taskId, $this->linkId);
+ $this->assertEquals($this->linkId, $link['id']);
+ $this->assertEquals($this->taskId, $link['task_id']);
+ $this->assertEquals('New title', $link['title']);
+ $this->assertEquals('related', $link['dependency']);
+ $this->assertEquals(0, $link['creator_id']);
+ }
+
+ public function assertGetAllExternalTaskLinks()
+ {
+ $links = $this->app->getAllExternalTaskLinks($this->taskId);
+ $this->assertCount(1, $links);
+ $this->assertEquals($this->linkId, $links[0]['id']);
+ $this->assertEquals($this->taskId, $links[0]['task_id']);
+ $this->assertEquals('New title', $links[0]['title']);
+ $this->assertEquals('related', $links[0]['dependency']);
+ $this->assertEquals(0, $links[0]['creator_id']);
+ }
+
+ public function assertRemoveExternalTaskLink()
+ {
+ $this->assertTrue($this->app->removeExternalTaskLink($this->taskId, $this->linkId));
+ }
+}
diff --git a/tests/integration/TaskFileProcedureTest.php b/tests/integration/TaskFileProcedureTest.php
new file mode 100644
index 00000000..60909ecd
--- /dev/null
+++ b/tests/integration/TaskFileProcedureTest.php
@@ -0,0 +1,67 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskFileProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test task files';
+ protected $fileId;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertCreateTaskFile();
+ $this->assertGetTaskFile();
+ $this->assertDownloadTaskFile();
+ $this->assertGetAllFiles();
+ $this->assertRemoveTaskFile();
+ $this->assertRemoveAllTaskFiles();
+ }
+
+ public function assertCreateTaskFile()
+ {
+ $this->fileId = $this->app->createTaskFile($this->projectId, $this->taskId, 'My file', base64_encode('plain text file'));
+ $this->assertNotFalse($this->fileId);
+ }
+
+ public function assertGetTaskFile()
+ {
+ $file = $this->app->getTaskFile($this->fileId);
+ $this->assertNotEmpty($file);
+ $this->assertEquals('My file', $file['name']);
+ }
+
+ public function assertDownloadTaskFile()
+ {
+ $content = $this->app->downloadTaskFile($this->fileId);
+ $this->assertNotEmpty($content);
+ $this->assertEquals('plain text file', base64_decode($content));
+ }
+
+ public function assertGetAllFiles()
+ {
+ $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId));
+ $this->assertCount(1, $files);
+ $this->assertEquals('My file', $files[0]['name']);
+ }
+
+ public function assertRemoveTaskFile()
+ {
+ $this->assertTrue($this->app->removeTaskFile($this->fileId));
+
+ $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId));
+ $this->assertEmpty($files);
+ }
+
+ public function assertRemoveAllTaskFiles()
+ {
+ $this->assertCreateTaskFile();
+ $this->assertCreateTaskFile();
+
+ $this->assertTrue($this->app->removeAllTaskFiles($this->taskId));
+
+ $files = $this->app->getAllTaskFiles(array('task_id' => $this->taskId));
+ $this->assertEmpty($files);
+ }
+}
diff --git a/tests/integration/TaskLinkProcedureTest.php b/tests/integration/TaskLinkProcedureTest.php
new file mode 100644
index 00000000..a25fced5
--- /dev/null
+++ b/tests/integration/TaskLinkProcedureTest.php
@@ -0,0 +1,68 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskLinkProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test task links';
+ protected $taskLinkId;
+ protected $taskId1;
+ protected $taskId2;
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+
+ $this->taskId1 = $this->app->createTask(array('project_id' => $this->projectId, 'title' => 'Task 1'));
+ $this->taskId2 = $this->app->createTask(array('project_id' => $this->projectId, 'title' => 'Task 2'));
+
+ $this->assertNotFalse($this->taskId1);
+ $this->assertNotFalse($this->taskId2);
+
+ $this->assertCreateTaskLink();
+ $this->assertGetTaskLink();
+ $this->assertGetAllTaskLinks();
+ $this->assertUpdateTaskLink();
+ $this->assertRemoveTaskLink();
+ }
+
+ public function assertCreateTaskLink()
+ {
+ $this->taskLinkId = $this->app->createTaskLink($this->taskId1, $this->taskId2, 1);
+ $this->assertNotFalse($this->taskLinkId);
+ }
+
+ public function assertGetTaskLink()
+ {
+ $link = $this->app->getTaskLinkById($this->taskLinkId);
+ $this->assertNotNull($link);
+ $this->assertEquals($this->taskId1, $link['task_id']);
+ $this->assertEquals($this->taskId2, $link['opposite_task_id']);
+ $this->assertEquals(1, $link['link_id']);
+ }
+
+ public function assertGetAllTaskLinks()
+ {
+ $links = $this->app->getAllTaskLinks($this->taskId2);
+ $this->assertCount(1, $links);
+ }
+
+ public function assertUpdateTaskLink()
+ {
+ $this->assertTrue($this->app->updateTaskLink($this->taskLinkId, $this->taskId1, $this->taskId2, 3));
+
+ $link = $this->app->getTaskLinkById($this->taskLinkId);
+ $this->assertNotNull($link);
+ $this->assertEquals($this->taskId1, $link['task_id']);
+ $this->assertEquals($this->taskId2, $link['opposite_task_id']);
+ $this->assertEquals(3, $link['link_id']);
+ }
+
+ public function assertRemoveTaskLink()
+ {
+ $this->assertTrue($this->app->removeTaskLink($this->taskLinkId));
+
+ $links = $this->app->getAllTaskLinks($this->taskId2);
+ $this->assertCount(0, $links);
+ }
+}
diff --git a/tests/integration/TaskMetadataProcedureTest.php b/tests/integration/TaskMetadataProcedureTest.php
new file mode 100644
index 00000000..9b9b2f39
--- /dev/null
+++ b/tests/integration/TaskMetadataProcedureTest.php
@@ -0,0 +1,45 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskMetadataProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test tasks metadata';
+ protected $metaKey = 'MyTestMetaKey';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertSaveTaskMetadata();
+ $this->assertGetTaskMetadata();
+ $this->assertGetTaskMetadataByName();
+ $this->assertRemoveTaskMetadata();
+ }
+
+ public function assertSaveTaskMetadata()
+ {
+ $this->assertTrue($this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1')));
+ }
+
+ public function assertGetTaskMetadata()
+ {
+ $metaData = $this->app->getTaskMetadata(($this->taskId));
+ $this->assertArrayHasKey($this->metaKey, $metaData);
+ $this->assertEquals('metaValue1', $metaData[$this->metaKey]);
+ }
+
+ public function assertGetTaskMetadataByName()
+ {
+ $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey);
+ $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value');
+ }
+
+ public function assertRemoveTaskMetadata()
+ {
+ $result = $this->app->removeTaskMetadata($this->taskId, $this->metaKey);
+ $this->assertTrue($result, 'Did not remove metakey with success');
+ $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey);
+ $this->assertEquals('', $metaValue, 'Did not return an empty string due to metadata being deleted');
+ }
+}
diff --git a/tests/integration/TaskProcedureTest.php b/tests/integration/TaskProcedureTest.php
new file mode 100644
index 00000000..f456ae52
--- /dev/null
+++ b/tests/integration/TaskProcedureTest.php
@@ -0,0 +1,55 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class TaskProcedureTest extends BaseProcedureTest
+{
+ protected $projectName = 'My project to test tasks';
+
+ public function testAll()
+ {
+ $this->assertCreateTeamProject();
+ $this->assertCreateTask();
+ $this->assertUpdateTask();
+ $this->assertGetTaskById();
+ $this->assertGetTaskByReference();
+ $this->assertGetAllTasks();
+ $this->assertOpenCloseTask();
+ }
+
+ public function assertUpdateTask()
+ {
+ $this->assertTrue($this->app->updateTask(array('id' => $this->taskId, 'color_id' => 'red')));
+ }
+
+ public function assertGetTaskById()
+ {
+ $task = $this->app->getTask($this->taskId);
+ $this->assertNotNull($task);
+ $this->assertEquals('red', $task['color_id']);
+ $this->assertEquals($this->taskTitle, $task['title']);
+ }
+
+ public function assertGetTaskByReference()
+ {
+ $taskId = $this->app->createTask(array('title' => 'task with reference', 'project_id' => $this->projectId, 'reference' => 'test'));
+ $this->assertNotFalse($taskId);
+
+ $task = $this->app->getTaskByReference($this->projectId, 'test');
+ $this->assertNotNull($task);
+ $this->assertEquals($taskId, $task['id']);
+ }
+
+ public function assertGetAllTasks()
+ {
+ $tasks = $this->app->getAllTasks($this->projectId);
+ $this->assertInternalType('array', $tasks);
+ $this->assertNotEmpty($tasks);
+ }
+
+ public function assertOpenCloseTask()
+ {
+ $this->assertTrue($this->app->closeTask($this->taskId));
+ $this->assertTrue($this->app->openTask($this->taskId));
+ }
+}
diff --git a/tests/integration/TaskTest.php b/tests/integration/TaskTest.php
deleted file mode 100644
index 0c398761..00000000
--- a/tests/integration/TaskTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class TaskTest extends Base
-{
- public function testSearchTasks()
- {
- $project_id1 = $this->app->createProject('My project');
- $project_id2 = $this->app->createProject('My project');
- $this->assertNotFalse($project_id1);
- $this->assertNotFalse($project_id2);
-
- $this->assertNotFalse($this->app->createTask(array('project_id' => $project_id1, 'title' => 'T1')));
- $this->assertNotFalse($this->app->createTask(array('project_id' => $project_id1, 'title' => 'T2')));
- $this->assertNotFalse($this->app->createTask(array('project_id' => $project_id2, 'title' => 'T3')));
-
- $tasks = $this->app->searchTasks($project_id1, 't2');
- $this->assertCount(1, $tasks);
- $this->assertEquals('T2', $tasks[0]['title']);
-
- $tasks = $this->app->searchTasks(array('project_id' => $project_id2, 'query' => 'assignee:nobody'));
- $this->assertCount(1, $tasks);
- $this->assertEquals('T3', $tasks[0]['title']);
- }
-
- public function testPriorityAttribute()
- {
- $project_id = $this->app->createProject('My project');
- $this->assertNotFalse($project_id);
-
- $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task', 'priority' => 2));
-
- $task = $this->app->getTask($task_id);
- $this->assertEquals(2, $task['priority']);
-
- $this->assertTrue($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'priority' => 3)));
-
- $task = $this->app->getTask($task_id);
- $this->assertEquals(3, $task['priority']);
- }
-
- public function testChangeAssigneeToAssignableUser()
- {
- $project_id = $this->app->createProject('My project');
- $this->assertNotFalse($project_id);
-
- $user_id = $this->app->createUser('user0', 'password');
- $this->assertNotFalse($user_id);
-
- $this->assertTrue($this->app->addProjectUser($project_id, $user_id, 'project-member'));
-
- $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task'));
- $this->assertNotFalse($task_id);
-
- $this->assertTrue($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'owner_id' => $user_id)));
-
- $task = $this->app->getTask($task_id);
- $this->assertEquals($user_id, $task['owner_id']);
- }
-
- public function testChangeAssigneeToNotAssignableUser()
- {
- $project_id = $this->app->createProject('My project');
- $this->assertNotFalse($project_id);
-
- $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task'));
- $this->assertNotFalse($task_id);
-
- $this->assertFalse($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'owner_id' => 1)));
-
- $task = $this->app->getTask($task_id);
- $this->assertEquals(0, $task['owner_id']);
- }
-
- public function testChangeAssigneeToNobody()
- {
- $project_id = $this->app->createProject('My project');
- $this->assertNotFalse($project_id);
-
- $user_id = $this->app->createUser('user1', 'password');
- $this->assertNotFalse($user_id);
-
- $this->assertTrue($this->app->addProjectUser($project_id, $user_id, 'project-member'));
-
- $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task', 'owner_id' => $user_id));
- $this->assertNotFalse($task_id);
-
- $this->assertTrue($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'owner_id' => 0)));
-
- $task = $this->app->getTask($task_id);
- $this->assertEquals(0, $task['owner_id']);
- }
-
- public function testMoveTaskToAnotherProject()
- {
- $project_id1 = $this->app->createProject('My project');
- $this->assertNotFalse($project_id1);
-
- $project_id2 = $this->app->createProject('My project');
- $this->assertNotFalse($project_id2);
-
- $task_id = $this->app->createTask(array('project_id' => $project_id1, 'title' => 'My task'));
- $this->assertNotFalse($task_id);
-
- $this->assertTrue($this->app->moveTaskToProject($task_id, $project_id2));
-
- $task = $this->app->getTask($task_id);
- $this->assertEquals($project_id2, $task['project_id']);
- }
-
- public function testMoveCopyToAnotherProject()
- {
- $project_id1 = $this->app->createProject('My project');
- $this->assertNotFalse($project_id1);
-
- $project_id2 = $this->app->createProject('My project');
- $this->assertNotFalse($project_id2);
-
- $task_id1 = $this->app->createTask(array('project_id' => $project_id1, 'title' => 'My task'));
- $this->assertNotFalse($task_id1);
-
- $task_id2 = $this->app->duplicateTaskToProject($task_id1, $project_id2);
- $this->assertNotFalse($task_id2);
-
- $task = $this->app->getTask($task_id1);
- $this->assertEquals($project_id1, $task['project_id']);
-
- $task = $this->app->getTask($task_id2);
- $this->assertEquals($project_id2, $task['project_id']);
- }
-}
diff --git a/tests/integration/UserProcedureTest.php b/tests/integration/UserProcedureTest.php
new file mode 100644
index 00000000..290f87fb
--- /dev/null
+++ b/tests/integration/UserProcedureTest.php
@@ -0,0 +1,63 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class UserProcedureTest extends BaseProcedureTest
+{
+ public function testAll()
+ {
+ $this->assertCreateUser();
+ $this->assertGetUserById();
+ $this->assertGetUserByName();
+ $this->assertGetAllUsers();
+ $this->assertEnableDisableUser();
+ $this->assertUpdateUser();
+ $this->assertRemoveUser();
+ }
+
+ public function assertGetUserById()
+ {
+ $user = $this->app->getUser($this->userId);
+ $this->assertNotNull($user);
+ $this->assertEquals($this->username, $user['username']);
+ }
+
+ public function assertGetUserByName()
+ {
+ $user = $this->app->getUserByName($this->username);
+ $this->assertNotNull($user);
+ $this->assertEquals($this->username, $user['username']);
+ }
+
+ public function assertGetAllUsers()
+ {
+ $users = $this->app->getAllUsers();
+ $this->assertInternalType('array', $users);
+ $this->assertNotEmpty($users);
+ }
+
+ public function assertEnableDisableUser()
+ {
+ $this->assertTrue($this->app->disableUser($this->userId));
+ $this->assertFalse($this->app->isActiveUser($this->userId));
+ $this->assertTrue($this->app->enableUser($this->userId));
+ $this->assertTrue($this->app->isActiveUser($this->userId));
+ }
+
+ public function assertUpdateUser()
+ {
+ $this->assertTrue($this->app->updateUser(array(
+ 'id' => $this->userId,
+ 'name' => 'My user',
+ )));
+
+ $user = $this->app->getUser($this->userId);
+ $this->assertNotNull($user);
+ $this->assertEquals('My user', $user['name']);
+ }
+
+ public function assertRemoveUser()
+ {
+ $this->assertTrue($this->app->removeUser($this->userId));
+ }
+}
diff --git a/tests/integration/UserTest.php b/tests/integration/UserTest.php
deleted file mode 100644
index 10da051c..00000000
--- a/tests/integration/UserTest.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-class UserTest extends Base
-{
- public function testDisableUser()
- {
- $this->assertEquals(2, $this->app->createUser(array('username' => 'someone', 'password' => 'test123')));
- $this->assertTrue($this->app->isActiveUser(2));
-
- $this->assertTrue($this->app->disableUser(2));
- $this->assertFalse($this->app->isActiveUser(2));
-
- $this->assertTrue($this->app->enableUser(2));
- $this->assertTrue($this->app->isActiveUser(2));
- }
-}
diff --git a/tests/units/Action/BaseActionTest.php b/tests/units/Action/BaseActionTest.php
index 1d50c70e..feeba3f9 100644
--- a/tests/units/Action/BaseActionTest.php
+++ b/tests/units/Action/BaseActionTest.php
@@ -23,7 +23,7 @@ class DummyAction extends Kanboard\Action\Base
public function getEventRequiredParameters()
{
- return array('p1', 'p2');
+ return array('p1', 'p2', 'p3' => array('p4'));
}
public function doAction(array $data)
@@ -60,7 +60,7 @@ class BaseActionTest extends Base
public function testGetEventRequiredParameters()
{
$dummyAction = new DummyAction($this->container);
- $this->assertEquals(array('p1', 'p2'), $dummyAction->getEventRequiredParameters());
+ $this->assertEquals(array('p1', 'p2', 'p3' => array('p4')), $dummyAction->getEventRequiredParameters());
}
public function testGetCompatibleEvents()
@@ -113,7 +113,7 @@ class BaseActionTest extends Base
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
- $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34)));
+ $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34, 'p3' => array('p4' => 'foobar'))));
$this->assertFalse($dummyAction->hasRequiredParameters(array('p1' => 12)));
$this->assertFalse($dummyAction->hasRequiredParameters(array()));
}
@@ -125,7 +125,7 @@ class BaseActionTest extends Base
$dummyAction->addEvent('my.event', 'My Event Overrided');
$events = $dummyAction->getEvents();
- $this->assertcount(2, $events);
+ $this->assertCount(2, $events);
$this->assertEquals(array('my.event', 'foobar'), $events);
}
@@ -136,7 +136,7 @@ class BaseActionTest extends Base
$dummyAction->setParam('p1', 'something');
$dummyAction->addEvent('foobar', 'FooBar');
- $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc'));
+ $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc', 'p3' => array('p4' => 'a')));
$this->assertTrue($dummyAction->execute($event, 'foobar'));
$this->assertFalse($dummyAction->execute($event, 'foobar'));
diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
index 5eaf515e..b3d21287 100644
--- a/tests/units/Action/CommentCreationMoveTaskColumnTest.php
+++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\CommentModel;
@@ -22,7 +22,7 @@ class CommentCreationMoveTaskColumnTest extends Base
$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, 'column_id' => 2));
+ $event = new TaskEvent(array('task' => array('project_id' => 1, 'column_id' => 2), 'task_id' => 1));
$action = new CommentCreationMoveTaskColumn($this->container);
$action->setProjectId(1);
@@ -45,7 +45,7 @@ class CommentCreationMoveTaskColumnTest extends Base
$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, 'column_id' => 3));
+ $event = new TaskEvent(array('task' => array('project_id' => 1, 'column_id' => 3), 'task_id' => 1));
$action = new CommentCreationMoveTaskColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php
index 09c08264..5a0f7d03 100644
--- a/tests/units/Action/TaskAssignCategoryColorTest.php
+++ b/tests/units/Action/TaskAssignCategoryColorTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignCategoryColorTest extends Base
$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, 'color_id' => 'red'));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'color_id' => 'red',
+ )
+ ));
$action = new TaskAssignCategoryColor($this->container);
$action->setProjectId(1);
@@ -47,7 +53,13 @@ class TaskAssignCategoryColorTest extends Base
$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, 'color_id' => 'blue'));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'color_id' => 'blue',
+ )
+ ));
$action = new TaskAssignCategoryColor($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php
index 712c3c02..1576f81b 100644
--- a/tests/units/Action/TaskAssignCategoryLinkTest.php
+++ b/tests/units/Action/TaskAssignCategoryLinkTest.php
@@ -2,94 +2,100 @@
require_once __DIR__.'/../Base.php';
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
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;
class TaskAssignCategoryLinkTest extends Base
{
public function testAssignCategory()
{
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
$action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['category_id']);
}
public function testWhenLinkDontMatch()
{
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
- $action->setParam('link_id', 1);
+ $action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['category_id']);
}
public function testThatExistingCategoryWillNotChange()
{
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
- $action->setParam('category_id', 2);
+ $action->setParam('category_id', 1);
$action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['category_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php
index 6502035f..16ad1290 100644
--- a/tests/units/Action/TaskAssignColorCategoryTest.php
+++ b/tests/units/Action/TaskAssignColorCategoryTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignColorCategoryTest extends Base
$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, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'category_id' => 1,
+ )
+ ));
$action = new TaskAssignColorCategory($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignColorCategoryTest extends Base
$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, 'category_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'category_id' => 2,
+ )
+ ));
$action = new TaskAssignColorCategory($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php
index d4ba8e01..ccfb9e88 100644
--- a/tests/units/Action/TaskAssignColorColumnTest.php
+++ b/tests/units/Action/TaskAssignColorColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskAssignColorColumnTest extends Base
$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, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignColorColumn($this->container);
$action->setProjectId(1);
@@ -42,7 +48,13 @@ class TaskAssignColorColumnTest extends Base
$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, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignColorColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php
index 07d0969b..77a6c90e 100644
--- a/tests/units/Action/TaskAssignColorLinkTest.php
+++ b/tests/units/Action/TaskAssignColorLinkTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -13,42 +13,55 @@ class TaskAssignColorLinkTest extends Base
{
public function testChangeColor()
{
- $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')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 1));
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
$task = $taskFinderModel->getById(1);
- $this->assertNotEmpty($task);
$this->assertEquals('red', $task['color_id']);
}
public function testWithWrongLink()
{
- $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, 'link_id' => 2));
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorPriorityTest.php b/tests/units/Action/TaskAssignColorPriorityTest.php
index 2fce8e66..0ea874cd 100644
--- a/tests/units/Action/TaskAssignColorPriorityTest.php
+++ b/tests/units/Action/TaskAssignColorPriorityTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignColorPriorityTest extends Base
$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));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'priority' => 1,
+ )
+ ));
$action = new TaskAssignColorPriority($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignColorPriorityTest extends Base
$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));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'priority' => 2,
+ )
+ ));
$action = new TaskAssignColorPriority($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php
index 370f9070..45faa3ff 100644
--- a/tests/units/Action/TaskAssignColorUserTest.php
+++ b/tests/units/Action/TaskAssignColorUserTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskAssignColorUserTest extends Base
$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, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskAssignColorUser($this->container);
$action->setProjectId(1);
@@ -42,7 +48,13 @@ class TaskAssignColorUserTest extends Base
$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, 'owner_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'owner_id' => 2,
+ )
+ ));
$action = new TaskAssignColorUser($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
index 6fdbda63..3b64d718 100644
--- a/tests/units/Action/TaskAssignCurrentUserColumnTest.php
+++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -22,7 +22,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$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, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$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, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
@@ -62,7 +74,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$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, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignDueDateOnCreationTest.php b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
new file mode 100644
index 00000000..26c0584e
--- /dev/null
+++ b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Action\TaskAssignDueDateOnCreation;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAssignDueDateOnCreationTest extends Base
+{
+ public function testAction()
+ {
+ $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')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskAssignDueDateOnCreation($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 4);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(date('Y-m-d', strtotime('+4days')), date('Y-m-d', $task['date_due']));
+ }
+}
diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php
index 78ec314f..0e63fc13 100644
--- a/tests/units/Action/TaskAssignSpecificUserTest.php
+++ b/tests/units/Action/TaskAssignSpecificUserTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +21,13 @@ class TaskAssignSpecificUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignSpecificUser($this->container);
$action->setProjectId(1);
@@ -42,7 +49,13 @@ class TaskAssignSpecificUserTest extends Base
$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, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignSpecificUser($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php
index f9a938f0..7afb0478 100644
--- a/tests/units/Action/TaskCloseColumnTest.php
+++ b/tests/units/Action/TaskCloseColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskCloseColumnTest extends Base
$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, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskCloseColumn($this->container);
$action->setProjectId(1);
@@ -41,7 +47,13 @@ class TaskCloseColumnTest extends Base
$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, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskCloseColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskCloseNoActivityColumnTest.php b/tests/units/Action/TaskCloseNoActivityColumnTest.php
new file mode 100644
index 00000000..243d3359
--- /dev/null
+++ b/tests/units/Action/TaskCloseNoActivityColumnTest.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Action\TaskCloseNoActivityColumn;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+
+class TaskCloseNoActivityColumnTest extends Base
+{
+ public function testClose()
+ {
+ $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->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(1, 3))->update(array('date_modification' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskCloseNoActivityColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
+ }
+}
diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php
index 3df10cb8..589ef133 100644
--- a/tests/units/Action/TaskCloseTest.php
+++ b/tests/units/Action/TaskCloseTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -19,7 +19,12 @@ class TaskCloseTest extends Base
$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));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskClose($this->container);
$action->setProjectId(1);
@@ -40,7 +45,11 @@ class TaskCloseTest extends Base
$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));
+ $event = new TaskEvent(array(
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskClose($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
index 98ff187f..5cd0c977 100644
--- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php
+++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +21,13 @@ class TaskDuplicateAnotherProjectTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskDuplicateAnotherProject($this->container);
$action->setProjectId(1);
@@ -43,7 +49,13 @@ class TaskDuplicateAnotherProjectTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskDuplicateAnotherProject($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php
index df71aaf8..421c89ca 100644
--- a/tests/units/Action/TaskEmailTest.php
+++ b/tests/units/Action/TaskEmailTest.php
@@ -2,7 +2,8 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
@@ -16,16 +17,20 @@ class TaskEmailTest extends Base
$userModel = new UserModel($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->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => $taskFinderModel->getDetails(1)
+ ));
$action = new TaskEmail($this->container);
$action->setProjectId(1);
- $action->setParam('column_id', 2);
+ $action->setParam('column_id', 1);
$action->setParam('user_id', 1);
$action->setParam('subject', 'My email subject');
@@ -47,7 +52,13 @@ class TaskEmailTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskEmail($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php
index d36df47b..a41fd03f 100644
--- a/tests/units/Action/TaskMoveAnotherProjectTest.php
+++ b/tests/units/Action/TaskMoveAnotherProjectTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +22,13 @@ class TaskMoveAnotherProjectTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskMoveAnotherProject($this->container);
$action->setProjectId(1);
@@ -44,7 +51,13 @@ class TaskMoveAnotherProjectTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskMoveAnotherProject($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php
index f8982969..aa9d3592 100644
--- a/tests/units/Action/TaskMoveColumnAssignedTest.php
+++ b/tests/units/Action/TaskMoveColumnAssignedTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -19,9 +19,12 @@ class TaskMoveColumnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => $taskFinderModel->getDetails(1),
+ ));
$action = new TaskMoveColumnAssigned($this->container);
$action->setProjectId(1);
@@ -43,7 +46,14 @@ class TaskMoveColumnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnAssigned($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
index c42383f8..7e0856df 100644
--- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
+++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
@@ -24,7 +24,16 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'category_id' => 1,
+ 'position' => 1,
+ 'swimlane_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
@@ -50,7 +59,14 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'category_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
@@ -72,7 +88,14 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'category_id' => 2,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnClosedTest.php b/tests/units/Action/TaskMoveColumnClosedTest.php
new file mode 100644
index 00000000..318b995d
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnClosedTest.php
@@ -0,0 +1,91 @@
+<?php
+
+use Kanboard\Action\TaskMoveColumnClosed;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMoveColumnClosedTest extends Base
+{
+ public function testSuccess()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+
+ public function testWhenTaskIsOpen()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(1, $task['column_id']);
+ }
+
+ public function testWhenTaskIsAlreadyInDestinationColumn()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0, 'column_id' => 2)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php b/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php
new file mode 100644
index 00000000..7fa16cf2
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php
@@ -0,0 +1,50 @@
+<?php
+
+use Kanboard\Action\TaskMoveColumnNotMovedPeriod;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMoveColumnNotMovedPeriodTest extends Base
+{
+ public function testAction()
+ {
+ $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', 'column_id' => 3)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(2, 3))->update(array('date_moved' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskMoveColumnNotMovedPeriod($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('src_column_id', 2);
+ $action->setParam('dest_column_id', 3);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['column_id']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['column_id']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['column_id']);
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
index befae36b..b45dec08 100644
--- a/tests/units/Action/TaskMoveColumnUnAssignedTest.php
+++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +21,16 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 0));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'owner_id' => 0,
+ 'position' => 1,
+ 'swimlane_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
@@ -43,7 +52,14 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'owner_id' => 0));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'owner_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
@@ -60,7 +76,14 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php
index 1018e2ea..825c6ac9 100644
--- a/tests/units/Action/TaskOpenTest.php
+++ b/tests/units/Action/TaskOpenTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -19,7 +19,12 @@ class TaskOpenTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskOpen($this->container);
$action->setProjectId(1);
@@ -40,7 +45,11 @@ class TaskOpenTest extends Base
$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));
+ $event = new TaskEvent(array(
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskOpen($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php
index ddd9eafd..05fac100 100644
--- a/tests/units/Action/TaskUpdateStartDateTest.php
+++ b/tests/units/Action/TaskUpdateStartDateTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -11,7 +11,7 @@ use Kanboard\Action\TaskUpdateStartDate;
class TaskUpdateStartDateTest extends Base
{
- public function testClose()
+ public function testAction()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
@@ -20,7 +20,13 @@ class TaskUpdateStartDateTest extends Base
$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, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskUpdateStartDate($this->container);
$action->setProjectId(1);
@@ -41,7 +47,13 @@ class TaskUpdateStartDateTest extends Base
$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, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskUpdateStartDate($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Auth/ReverseProxyAuthTest.php b/tests/units/Auth/ReverseProxyAuthTest.php
new file mode 100644
index 00000000..cdbc247d
--- /dev/null
+++ b/tests/units/Auth/ReverseProxyAuthTest.php
@@ -0,0 +1,111 @@
+<?php
+
+use Kanboard\Auth\ReverseProxyAuth;
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ReverseProxyAuthTest extends Base
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->container['request'] = $this
+ ->getMockBuilder('\Kanboard\Core\Http\Request')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('getRemoteUser'))
+ ->getMock();
+ }
+
+ public function testGetName()
+ {
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertEquals('ReverseProxy', $provider->getName());
+ }
+
+ public function testAuthenticateSuccess()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('admin'));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertTrue($provider->authenticate());
+ }
+
+ public function testAuthenticateFailure()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue(''));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertFalse($provider->authenticate());
+ }
+
+ public function testValidSession()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('admin'));
+
+ $this->container['sessionStorage']->user = array(
+ 'username' => 'admin'
+ );
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertTrue($provider->isValidSession());
+ }
+
+ public function testInvalidSession()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('foobar'));
+
+ $this->container['sessionStorage']->user = array(
+ 'username' => 'admin'
+ );
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertFalse($provider->isValidSession());
+ }
+
+ public function testRoleForNewUser()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('someone'));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertTrue($provider->authenticate());
+
+ $user = $provider->getUser();
+ $this->assertEquals(Role::APP_USER, $user->getRole());
+ }
+
+ public function testRoleIsPreservedForExistingUser()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('someone'));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'someone', 'role' => Role::APP_MANAGER)));
+
+ $this->assertTrue($provider->authenticate());
+
+ $user = $provider->getUser();
+ $this->assertEquals(Role::APP_MANAGER, $user->getRole());
+ }
+}
diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php
index c8dcfb28..3a82c01c 100644
--- a/tests/units/Auth/TotpAuthTest.php
+++ b/tests/units/Auth/TotpAuthTest.php
@@ -35,16 +35,17 @@ class TotpAuthTest extends Base
public function testGetUrl()
{
$provider = new TotpAuth($this->container);
+
$this->assertEmpty($provider->getQrCodeUrl('me'));
$this->assertEmpty($provider->getKeyUrl('me'));
$provider->setSecret('mySecret');
$this->assertEquals(
- 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret',
+ 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret%26issuer%3DKanboard',
$provider->getQrCodeUrl('me')
);
- $this->assertEquals('otpauth://totp/me?secret=mySecret', $provider->getKeyUrl('me'));
+ $this->assertEquals('otpauth://totp/me?secret=mySecret&issuer=Kanboard', $provider->getKeyUrl('me'));
}
public function testAuthentication()
diff --git a/tests/units/Base.php b/tests/units/Base.php
index f7bee241..e44223ce 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -16,6 +16,11 @@ abstract class Base extends PHPUnit_Framework_TestCase
{
protected $container;
+ /**
+ * @var EventDispatcher
+ */
+ protected $dispatcher;
+
public function setUp()
{
date_default_timezone_set('UTC');
@@ -41,6 +46,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
$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\JobProvider());
$this->container->register(new Kanboard\ServiceProvider\QueueProvider());
$this->container['dispatcher'] = new TraceableEventDispatcher(
@@ -48,8 +54,10 @@ abstract class Base extends PHPUnit_Framework_TestCase
new Stopwatch
);
- $this->container['db']->logQueries = true;
- $this->container['logger'] = new Logger;
+ $this->dispatcher = $this->container['dispatcher'];
+
+ $this->container['db']->getStatementHandler()->withLogging();
+ $this->container['logger'] = new Logger();
$this->container['httpClient'] = $this
->getMockBuilder('\Kanboard\Core\Http\Client')
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php
index e7c2071f..4878c0c9 100644
--- a/tests/units/Core/Action/ActionManagerTest.php
+++ b/tests/units/Core/Action/ActionManagerTest.php
@@ -96,7 +96,7 @@ class ActionManagerTest extends Base
$actions = $actionManager->getAvailableActions();
$actionManager->attachEvents();
- $this->assertEmpty($this->container['dispatcher']->getListeners());
+ $this->assertEmpty($this->dispatcher->getListeners());
$this->assertEquals(1, $projectModel->create(array('name' =>'test')));
$this->assertEquals(1, $actionModel->create(array(
@@ -107,7 +107,7 @@ class ActionManagerTest extends Base
)));
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -148,7 +148,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -158,7 +158,6 @@ class ActionManagerTest extends Base
public function testThatEachListenerAreDifferentInstance()
{
$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);
@@ -183,7 +182,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(2, $listeners);
$this->assertFalse($listeners[0][0] === $listeners[1][0]);
@@ -193,4 +192,35 @@ class ActionManagerTest extends Base
$this->assertEquals(1, $listeners[1][0]->getParam('column_id'));
$this->assertEquals('red', $listeners[1][0]->getParam('color_id'));
}
+
+ public function testRemoveEvents()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
+ $actionManager = new ActionManager($this->container);
+ $actionManager->register($actionTaskAssignColorColumn);
+
+ $actions = $actionManager->getAvailableActions();
+
+ $this->assertEquals(1, $projectModel->create(array('name' =>'test')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $actionManager->attachEvents();
+ $this->dispatcher->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(2, $listeners);
+
+ $actionManager->removeEvents();
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(1, $listeners);
+ $this->assertNotInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0]);
+ }
}
diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php
index 23726f32..31e237dc 100644
--- a/tests/units/Core/Filter/LexerBuilderTest.php
+++ b/tests/units/Core/Filter/LexerBuilderTest.php
@@ -8,6 +8,7 @@ use Kanboard\Filter\TaskTitleFilter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
class LexerBuilderTest extends Base
{
@@ -103,4 +104,49 @@ class LexerBuilderTest extends Base
$this->assertFalse($builder === $clone);
$this->assertFalse($builder->build('test')->getQuery() === $clone->build('test')->getQuery());
}
+
+ public function testBuilderWithMixedCaseSearchAttribute()
+ {
+ $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')));
+ $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test')));
+
+ $builder = new LexerBuilder();
+ $builder->withFilter(new TaskAssigneeFilter());
+ $builder->withFilter(new TaskTitleFilter(), true);
+ $builder->withQuery($query);
+ $tasks = $builder->build('AsSignEe:nobody')->toArray();
+
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Test', $tasks[0]['title']);
+ }
+
+ public function testWithOrCriteria()
+ {
+ $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')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0)));
+
+ $builder = new LexerBuilder();
+ $builder->withFilter(new TaskAssigneeFilter());
+ $builder->withFilter(new TaskTitleFilter(), true);
+ $builder->withQuery($query);
+ $tasks = $builder->build('assignee:admin assignee:foobar')->toArray();
+
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('Test 1', $tasks[0]['title']);
+ $this->assertEquals('Test 2', $tasks[1]['title']);
+ }
}
diff --git a/tests/units/Core/Filter/LexerTest.php b/tests/units/Core/Filter/LexerTest.php
index c72231c4..d57a7953 100644
--- a/tests/units/Core/Filter/LexerTest.php
+++ b/tests/units/Core/Filter/LexerTest.php
@@ -202,4 +202,60 @@ class LexerTest extends Base
$this->assertSame($expected, $lexer->tokenize('६Δↈ五一'));
}
+
+ public function testTokenizeWithMultipleValues()
+ {
+ $lexer = new Lexer();
+ $lexer->addToken("/^(tag:)/", 'T_TAG');
+
+ $expected = array(
+ 'T_TAG' => array('tag 1', 'tag2'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('tag:"tag 1" tag:tag2'));
+ }
+
+ public function testTokenizeWithDash()
+ {
+ $lexer = new Lexer();
+ $lexer->addToken("/^(test:)/", 'T_TEST');
+
+ $expected = array(
+ 'T_TEST' => array('PO-123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('test:PO-123'));
+
+ $lexer = new Lexer();
+ $lexer->setDefaultToken('myDefaultToken');
+
+ $expected = array(
+ 'myDefaultToken' => array('PO-123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('PO-123'));
+ }
+
+ public function testTokenizeWithUnderscore()
+ {
+ $lexer = new Lexer();
+ $lexer->addToken("/^(test:)/", 'T_TEST');
+
+ $expected = array(
+ 'T_TEST' => array('PO_123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('test:PO_123'));
+
+ $lexer = new Lexer();
+ $lexer->addToken("/^(test:)/", 'T_TEST');
+ $lexer->setDefaultToken('myDefaultToken');
+
+ $expected = array(
+ 'T_TEST' => array('ABC-123'),
+ 'myDefaultToken' => array('PO_123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('test:ABC-123 PO_123'));
+ }
}
diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php
index a46726c3..cf520f36 100644
--- a/tests/units/Core/Filter/OrCriteriaTest.php
+++ b/tests/units/Core/Filter/OrCriteriaTest.php
@@ -22,8 +22,9 @@ class OrCriteriaTest extends Base
$this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar')));
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
- $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 2)));
- $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0)));
$criteria = new OrCriteria();
$criteria->withQuery($query);
diff --git a/tests/units/Core/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php
index 6fa796f7..1db0100c 100644
--- a/tests/units/Core/Http/RequestTest.php
+++ b/tests/units/Core/Http/RequestTest.php
@@ -169,6 +169,9 @@ class RequestTest extends Base
$request = new Request($this->container, array(), array(), array(), array(), array());
$this->assertEquals('Unknown', $request->getIpAddress());
+ $request = new Request($this->container, array('HTTP_X_REAL_IP' => '192.168.1.1,127.0.0.1'), array(), array(), array(), array());
+ $this->assertEquals('192.168.1.1', $request->getIpAddress());
+
$request = new Request($this->container, array('HTTP_X_FORWARDED_FOR' => '192.168.0.1,127.0.0.1'), array(), array(), array(), array());
$this->assertEquals('192.168.0.1', $request->getIpAddress());
diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php
index 505b8a03..143a8c0d 100644
--- a/tests/units/Core/Ldap/LdapUserTest.php
+++ b/tests/units/Core/Ldap/LdapUserTest.php
@@ -845,4 +845,64 @@ class LdapUserTest extends Base
$this->assertTrue($this->user->hasGroupUserFilter());
}
+
+ public function testHasGroupsConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue('something'));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue('something'));
+
+ $this->assertTrue($this->user->hasGroupsConfigured());
+ }
+
+ public function testHasGroupAdminDnConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue('something'));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue(''));
+
+ $this->assertTrue($this->user->hasGroupsConfigured());
+ }
+
+ public function testHasGroupManagerDnConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue(''));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue('something'));
+
+ $this->assertTrue($this->user->hasGroupsConfigured());
+ }
+
+ public function testHasGroupsNotConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue(''));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue(''));
+
+ $this->assertFalse($this->user->hasGroupsConfigured());
+ }
}
diff --git a/tests/units/Core/Plugin/HookTest.php b/tests/units/Core/Plugin/HookTest.php
index d1c139b3..acadede0 100644
--- a/tests/units/Core/Plugin/HookTest.php
+++ b/tests/units/Core/Plugin/HookTest.php
@@ -8,89 +8,103 @@ class HookTest extends Base
{
public function testGetListeners()
{
- $h = new Hook;
- $this->assertEmpty($h->getListeners('myhook'));
+ $hook = new Hook;
+ $this->assertEmpty($hook->getListeners('myhook'));
- $h->on('myhook', 'A');
- $h->on('myhook', 'B');
+ $hook->on('myhook', 'A');
+ $hook->on('myhook', 'B');
- $this->assertEquals(array('A', 'B'), $h->getListeners('myhook'));
+ $this->assertEquals(array('A', 'B'), $hook->getListeners('myhook'));
}
public function testExists()
{
- $h = new Hook;
- $this->assertFalse($h->exists('myhook'));
+ $hook = new Hook;
+ $this->assertFalse($hook->exists('myhook'));
- $h->on('myhook', 'A');
+ $hook->on('myhook', 'A');
- $this->assertTrue($h->exists('myhook'));
+ $this->assertTrue($hook->exists('myhook'));
}
public function testMergeWithNoBinding()
{
- $h = new Hook;
+ $hook = new Hook;
$values = array('A', 'B');
- $result = $h->merge('myhook', $values, array('p' => 'c'));
+ $result = $hook->merge('myhook', $values, array('p' => 'c'));
$this->assertEquals($values, $result);
}
public function testMergeWithBindings()
{
- $h = new Hook;
+ $hook = new Hook;
$values = array('A', 'B');
$expected = array('A', 'B', 'c', 'D');
- $h->on('myhook', function ($p) {
+ $hook->on('myhook', function ($p) {
return array($p);
});
- $h->on('myhook', function () {
+ $hook->on('myhook', function () {
return array('D');
});
- $result = $h->merge('myhook', $values, array('p' => 'c'));
+ $result = $hook->merge('myhook', $values, array('p' => 'c'));
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $values);
}
public function testMergeWithBindingButReturningBadData()
{
- $h = new Hook;
+ $hook = new Hook;
$values = array('A', 'B');
$expected = array('A', 'B');
- $h->on('myhook', function () {
+ $hook->on('myhook', function () {
return 'string';
});
- $result = $h->merge('myhook', $values);
+ $result = $hook->merge('myhook', $values);
$this->assertEquals($expected, $result);
$this->assertEquals($expected, $values);
}
public function testFirstWithNoBinding()
{
- $h = new Hook;
+ $hook = new Hook;
- $result = $h->first('myhook', array('p' => 2));
+ $result = $hook->first('myhook', array('p' => 2));
$this->assertEquals(null, $result);
}
public function testFirstWithMultipleBindings()
{
- $h = new Hook;
+ $hook = new Hook;
- $h->on('myhook', function ($p) {
+ $hook->on('myhook', function ($p) {
return $p + 1;
});
- $h->on('myhook', function ($p) {
+ $hook->on('myhook', function ($p) {
return $p;
});
- $result = $h->first('myhook', array('p' => 3));
+ $result = $hook->first('myhook', array('p' => 3));
$this->assertEquals(4, $result);
}
+
+ public function testHookWithReference()
+ {
+ $hook = new Hook();
+
+ $hook->on('myhook', function (&$p) {
+ $p = 2;
+ });
+
+ $param = 123;
+ $result = $hook->reference('myhook', $param);
+ $this->assertSame(2, $result);
+ $this->assertSame(2, $param);
+ }
}
diff --git a/tests/units/EventBuilder/CommentEventBuilderTest.php b/tests/units/EventBuilder/CommentEventBuilderTest.php
new file mode 100644
index 00000000..2f6a90b5
--- /dev/null
+++ b/tests/units/EventBuilder/CommentEventBuilderTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\EventBuilder\CommentEventBuilder;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class CommentEventBuilderTest extends Base
+{
+ public function testWithMissingComment()
+ {
+ $commentEventBuilder = new CommentEventBuilder($this->container);
+ $commentEventBuilder->withCommentId(42);
+ $this->assertNull($commentEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $commentEventBuilder = new CommentEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+
+ $commentEventBuilder->withCommentId(1);
+ $event = $commentEventBuilder->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\CommentEvent', $event);
+ $this->assertNotEmpty($event['comment']);
+ $this->assertNotEmpty($event['task']);
+ }
+}
diff --git a/tests/units/EventBuilder/ProjectFileEventBuilderTest.php b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
new file mode 100644
index 00000000..8f5eb87e
--- /dev/null
+++ b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
@@ -0,0 +1,33 @@
+<?php
+
+use Kanboard\EventBuilder\ProjectFileEventBuilder;
+use Kanboard\Model\ProjectFileModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectFileEventBuilderTest extends Base
+{
+ public function testWithMissingFile()
+ {
+ $projectFileEventBuilder = new ProjectFileEventBuilder($this->container);
+ $projectFileEventBuilder->withFileId(42);
+ $this->assertNull($projectFileEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectFileModel = new ProjectFileModel($this->container);
+ $projectFileEventBuilder = new ProjectFileEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $event = $projectFileEventBuilder->withFileId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\ProjectFileEvent', $event);
+ $this->assertNotEmpty($event['file']);
+ $this->assertNotEmpty($event['project']);
+ }
+}
diff --git a/tests/units/EventBuilder/SubtaskEventBuilderTest.php b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
new file mode 100644
index 00000000..fe425cb8
--- /dev/null
+++ b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
@@ -0,0 +1,62 @@
+<?php
+
+use Kanboard\EventBuilder\SubtaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventBuilderTest extends Base
+{
+ public function testWithMissingSubtask()
+ {
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+ $subtaskEventBuilder->withSubtaskId(42);
+ $this->assertNull($subtaskEventBuilder->buildEvent());
+ }
+
+ public function testBuildWithoutChanges()
+ {
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
+
+ $event = $subtaskEventBuilder->withSubtaskId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
+ $this->assertNotEmpty($event['subtask']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertArrayNotHasKey('changes', $event);
+ }
+
+ public function testBuildWithChanges()
+ {
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
+
+ $event = $subtaskEventBuilder
+ ->withSubtaskId(1)
+ ->withValues(array('title' => 'new title', 'user_id' => 1))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
+ $this->assertNotEmpty($event['subtask']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertCount(2, $event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ $this->assertEquals(1, $event['changes']['user_id']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskEventBuilderTest.php b/tests/units/EventBuilder/TaskEventBuilderTest.php
new file mode 100644
index 00000000..c89dcd85
--- /dev/null
+++ b/tests/units/EventBuilder/TaskEventBuilderTest.php
@@ -0,0 +1,100 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskEventBuilderTest extends Base
+{
+ public function testWithMissingTask()
+ {
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+ $taskEventBuilder->withTaskId(42);
+ $this->assertNull($taskEventBuilder->buildEvent());
+ }
+
+ public function testBuildWithTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'before', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withTask(array('title' => 'before'))
+ ->withChanges(array('title' => 'after'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event['task_id']);
+ $this->assertEquals(array('title' => 'after'), $event['changes']);
+ }
+
+ public function testBuildWithoutChanges()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder->withTaskId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event['task_id']);
+ $this->assertArrayNotHasKey('changes', $event);
+ }
+
+ public function testBuildWithChanges()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withChanges(array('title' => 'new title'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ }
+
+ public function testBuildWithChangesAndValues()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withChanges(array('title' => 'new title', 'project_id' => 1))
+ ->withValues(array('key' => 'value'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertNotEmpty($event['key']);
+ $this->assertEquals('value', $event['key']);
+
+ $this->assertCount(1, $event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskFileEventBuilderTest.php b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
new file mode 100644
index 00000000..c90e18d3
--- /dev/null
+++ b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use Kanboard\EventBuilder\TaskFileEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFileModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskFileEventBuilderTest extends Base
+{
+ public function testWithMissingFile()
+ {
+ $taskFileEventBuilder = new TaskFileEventBuilder($this->container);
+ $taskFileEventBuilder->withFileId(42);
+ $this->assertNull($taskFileEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFileEventBuilder = new TaskFileEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $event = $taskFileEventBuilder->withFileId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskFileEvent', $event);
+ $this->assertNotEmpty($event['file']);
+ $this->assertNotEmpty($event['task']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
new file mode 100644
index 00000000..18508146
--- /dev/null
+++ b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
@@ -0,0 +1,70 @@
+<?php
+
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventBuilderTest extends Base
+{
+ public function testWithMissingLink()
+ {
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+ $taskLinkEventBuilder->withTaskLinkId(42);
+ $this->assertNull($taskLinkEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = $taskLinkEventBuilder->withTaskLinkId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskLinkEvent', $event);
+ $this->assertNotEmpty($event['task_link']);
+ $this->assertNotEmpty($event['task']);
+ }
+
+ public function testBuildTitle()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $eventData = $taskLinkEventBuilder->withTaskLinkId(1)->buildEvent();
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('Foobar set a new internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Foobar removed an internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', 'not found', $eventData->getAll());
+ $this->assertSame('', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('A new internal link for the task #1 have been defined', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Internal link removed for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor('not found', $eventData->getAll());
+ $this->assertSame('', $title);
+ }
+}
diff --git a/tests/units/Filter/TaskMovedDateFilterTest.php b/tests/units/Filter/TaskMovedDateFilterTest.php
new file mode 100644
index 00000000..9b721913
--- /dev/null
+++ b/tests/units/Filter/TaskMovedDateFilterTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Filter\TaskMovedDateFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMovedDateFilterTest extends Base
+{
+ public function test()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $taskModification = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 1, 'date_moved' => time())));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 2, 'date_moved' => strtotime('-1days'))));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test3', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 3, 'date_moved' => strtotime('-3days'))));
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('>='.date('Y-m-d', strtotime('-1days')));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(2, $query->findAll());
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('<yesterday');
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/TaskPriorityFilterTest.php b/tests/units/Filter/TaskPriorityFilterTest.php
new file mode 100644
index 00000000..4c95ddce
--- /dev/null
+++ b/tests/units/Filter/TaskPriorityFilterTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Kanboard\Filter\TaskPriorityFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskPriorityFilterTest extends Base
+{
+ public function testWithDefinedPriority()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'priority' => 2)));
+
+ $filter = new TaskPriorityFilter();
+ $filter->withQuery($query);
+ $filter->withValue(2);
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+
+ public function testWithNoPriority()
+ {
+ $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')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+
+ $filter = new TaskPriorityFilter();
+ $filter->withQuery($query);
+ $filter->withValue(2);
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/TaskTagFilterTest.php b/tests/units/Filter/TaskTagFilterTest.php
new file mode 100644
index 00000000..72ed9904
--- /dev/null
+++ b/tests/units/Filter/TaskTagFilterTest.php
@@ -0,0 +1,122 @@
+<?php
+
+use Kanboard\Filter\TaskTagFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskTagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskTagFilterTest extends Base
+{
+ public function testWithMultipleMatches()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag 3');
+ $filter->apply();
+
+ $tasks = $query->asc(TaskModel::TABLE.'.title')->findAll();
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ $this->assertEquals('test2', $tasks[1]['title']);
+ }
+
+ public function testWithSingleMatch()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag 2');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ }
+
+ public function testWithNoMatch()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag 42');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(0, $tasks);
+ }
+
+ public function testWithSameTagInMultipleProjects()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'test2')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag')));
+ $this->assertTrue($taskTagModel->save(2, 2, array('My tag')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag');
+ $filter->apply();
+
+ $tasks = $query->asc(TaskModel::TABLE.'.title')->findAll();
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ $this->assertEquals('test2', $tasks[1]['title']);
+ }
+}
diff --git a/tests/units/Formatter/BoardFormatterTest.php b/tests/units/Formatter/BoardFormatterTest.php
new file mode 100644
index 00000000..c107eaf5
--- /dev/null
+++ b/tests/units/Formatter/BoardFormatterTest.php
@@ -0,0 +1,392 @@
+<?php
+
+use Kanboard\Formatter\BoardFormatter;
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskTagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class BoardFormatterTest extends Base
+{
+ public function testFormatWithSwimlanes()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'Swimlane 1', 'project_id' => 1)));
+ $this->assertEquals(2, $swimlaneModel->create(array('name' => 'Swimlane 2', 'project_id' => 1)));
+
+ // 2 task within the same column but no score
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1)));
+
+ // 2 tasks in the same column with score
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task 3', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1, 'score' => 4)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task 4', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1, 'score' => 5)));
+
+ // 1 task in 2nd column
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task 5', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 2)));
+
+ // tasks in same column but different swimlanes
+ $this->assertEquals(6, $taskCreationModel->create(array('title' => 'Task 6', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 3, 'score' => 1)));
+ $this->assertEquals(7, $taskCreationModel->create(array('title' => 'Task 7', 'project_id' => 1, 'swimlane_id' => 1, 'column_id' => 3, 'score' => 2)));
+ $this->assertEquals(8, $taskCreationModel->create(array('title' => 'Task 8', 'project_id' => 1, 'swimlane_id' => 2, 'column_id' => 3, 'score' => 3)));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(3, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(3, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(6, $board[0]['nb_tasks']);
+ $this->assertEquals(10, $board[0]['score']);
+
+ $this->assertEquals(4, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(1, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(3, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(9, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(6, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(9, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(1, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(4, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('Task 2', $board[0]['columns'][0]['tasks'][1]['title']);
+ $this->assertEquals('Task 3', $board[0]['columns'][0]['tasks'][2]['title']);
+ $this->assertEquals('Task 4', $board[0]['columns'][0]['tasks'][3]['title']);
+ $this->assertEquals('Task 5', $board[0]['columns'][1]['tasks'][0]['title']);
+ $this->assertEquals('Task 6', $board[0]['columns'][2]['tasks'][0]['title']);
+
+ $this->assertEquals('Swimlane 1', $board[1]['name']);
+ $this->assertCount(4, $board[1]['columns']);
+ $this->assertEquals(3, $board[1]['nb_swimlanes']);
+ $this->assertEquals(4, $board[1]['nb_columns']);
+ $this->assertEquals(1, $board[1]['nb_tasks']);
+ $this->assertEquals(2, $board[1]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['score']);
+ $this->assertSame(0, $board[1]['columns'][1]['score']);
+ $this->assertSame(2, $board[1]['columns'][2]['score']);
+ $this->assertSame(0, $board[1]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[1]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 7', $board[1]['columns'][2]['tasks'][0]['title']);
+
+ $this->assertEquals('Swimlane 2', $board[2]['name']);
+ $this->assertCount(4, $board[2]['columns']);
+ $this->assertEquals(3, $board[2]['nb_swimlanes']);
+ $this->assertEquals(4, $board[2]['nb_columns']);
+ $this->assertEquals(1, $board[2]['nb_tasks']);
+ $this->assertEquals(3, $board[2]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['score']);
+ $this->assertSame(0, $board[2]['columns'][1]['score']);
+ $this->assertSame(3, $board[2]['columns'][2]['score']);
+ $this->assertSame(0, $board[2]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[2]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 8', $board[2]['columns'][2]['tasks'][0]['title']);
+ }
+
+ public function testFormatWithoutDefaultSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'Swimlane 1', 'project_id' => 1)));
+ $this->assertEquals(2, $swimlaneModel->create(array('name' => 'Swimlane 2', 'project_id' => 1)));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1, 'swimlane_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1, 'swimlane_id' => 2, 'column_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task 3', 'project_id' => 1, 'swimlane_id' => 1, 'column_id' => 2, 'score' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task 4', 'project_id' => 1, 'swimlane_id' => 2, 'column_id' => 1)));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(2, $board);
+
+ $this->assertEquals('Swimlane 1', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(2, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(2, $board[0]['nb_tasks']);
+ $this->assertEquals(1, $board[0]['score']);
+
+ $this->assertEquals(2, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(2, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(1, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(1, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(1, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('Task 3', $board[0]['columns'][1]['tasks'][0]['title']);
+
+ $this->assertEquals('Swimlane 2', $board[1]['name']);
+ $this->assertCount(4, $board[1]['columns']);
+ $this->assertEquals(2, $board[1]['nb_swimlanes']);
+ $this->assertEquals(4, $board[1]['nb_columns']);
+ $this->assertEquals(2, $board[1]['nb_tasks']);
+ $this->assertEquals(0, $board[1]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['score']);
+ $this->assertSame(0, $board[1]['columns'][1]['score']);
+ $this->assertSame(0, $board[1]['columns'][2]['score']);
+ $this->assertSame(0, $board[1]['columns'][3]['score']);
+
+ $this->assertSame(1, $board[1]['columns'][0]['nb_tasks']);
+ $this->assertSame(1, $board[1]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 4', $board[1]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('Task 2', $board[1]['columns'][1]['tasks'][0]['title']);
+ }
+
+ public function testFormatWithoutSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(0, $board);
+ }
+
+ public function testFormatWithoutColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $columnModel = new ColumnModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($columnModel->remove(1));
+ $this->assertTrue($columnModel->remove(2));
+ $this->assertTrue($columnModel->remove(3));
+ $this->assertTrue($columnModel->remove(4));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(0, $board);
+ }
+
+ public function testFormatWithoutTask()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'Swimlane 1', 'project_id' => 1)));
+ $this->assertEquals(2, $swimlaneModel->create(array('name' => 'Swimlane 2', 'project_id' => 1)));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(3, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(3, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(0, $board[0]['nb_tasks']);
+ $this->assertEquals(0, $board[0]['score']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Swimlane 1', $board[1]['name']);
+ $this->assertCount(4, $board[1]['columns']);
+ $this->assertEquals(3, $board[1]['nb_swimlanes']);
+ $this->assertEquals(4, $board[1]['nb_columns']);
+ $this->assertEquals(0, $board[1]['nb_tasks']);
+ $this->assertEquals(0, $board[1]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['score']);
+ $this->assertSame(0, $board[1]['columns'][1]['score']);
+ $this->assertSame(0, $board[1]['columns'][2]['score']);
+ $this->assertSame(0, $board[1]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Swimlane 2', $board[2]['name']);
+ $this->assertCount(4, $board[2]['columns']);
+ $this->assertEquals(3, $board[2]['nb_swimlanes']);
+ $this->assertEquals(4, $board[2]['nb_columns']);
+ $this->assertEquals(0, $board[2]['nb_tasks']);
+ $this->assertEquals(0, $board[2]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['score']);
+ $this->assertSame(0, $board[2]['columns'][1]['score']);
+ $this->assertSame(0, $board[2]['columns'][2]['score']);
+ $this->assertSame(0, $board[2]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
+ }
+
+ public function testFormatWithTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'column_id' => 3)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(1, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(1, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(3, $board[0]['nb_tasks']);
+ $this->assertEquals(0, $board[0]['score']);
+
+ $this->assertEquals(2, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(1, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(2, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('test1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('test3', $board[0]['columns'][0]['tasks'][1]['title']);
+ $this->assertEquals('test2', $board[0]['columns'][2]['tasks'][0]['title']);
+
+ $expected = array(
+ array(
+ 'id' => 1,
+ 'name' => 'My tag 1',
+ 'task_id' => 1,
+ ),
+ array(
+ 'id' => 2,
+ 'name' => 'My tag 2',
+ 'task_id' => 1,
+ ),
+ );
+
+ $this->assertEquals($expected, $board[0]['columns'][0]['tasks'][0]['tags']);
+ $this->assertEquals(array(), $board[0]['columns'][0]['tasks'][1]['tags']);
+
+ $expected = array(
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 2,
+ ),
+ );
+
+ $this->assertEquals($expected, $board[0]['columns'][2]['tasks'][0]['tags']);
+ }
+}
diff --git a/tests/units/Formatter/TaskAutoCompleteFormatterTest.php b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php
new file mode 100644
index 00000000..20baf549
--- /dev/null
+++ b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php
@@ -0,0 +1,34 @@
+<?php
+
+use Kanboard\Formatter\TaskAutoCompleteFormatter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAutoCompleteFormatterTest extends Base
+{
+ public function testFormat()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My Project')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1)));
+
+ $tasks = TaskAutoCompleteFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->format();
+
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('My Project > #1 Task 1', $tasks[0]['label']);
+ $this->assertEquals('Task 1', $tasks[0]['value']);
+ $this->assertEquals(1, $tasks[0]['id']);
+ $this->assertEquals('My Project > #2 Task 2', $tasks[1]['label']);
+ $this->assertEquals('Task 2', $tasks[1]['value']);
+ $this->assertEquals(2, $tasks[1]['id']);
+ }
+}
diff --git a/tests/units/FunctionTest.php b/tests/units/FunctionTest.php
new file mode 100644
index 00000000..1c5f971d
--- /dev/null
+++ b/tests/units/FunctionTest.php
@@ -0,0 +1,123 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+class FunctionTest extends Base
+{
+ public function testArrayColumnSum()
+ {
+ $input = array(
+ array(
+ 'my_column' => 123
+ ),
+ array(
+ 'my_column' => 456.7
+ ),
+ array()
+ );
+
+ $this->assertSame(579.7, array_column_sum($input, 'my_column'));
+ }
+
+ public function testArrayColumnIndex()
+ {
+ $input = array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ ),
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ ),
+ array()
+ );
+
+ $expected = array(
+ 11 => array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ )
+ ),
+ 33 => array(
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ )
+ )
+ );
+
+ $this->assertSame($expected, array_column_index($input, 'k1'));
+ }
+
+ public function testArrayMergeRelation()
+ {
+ $relations = array(
+ 88 => array(
+ 'id' => 123,
+ 'value' => 'test1',
+ ),
+ 99 => array(
+ 'id' => 456,
+ 'value' => 'test2',
+ ),
+ 55 => array()
+ );
+
+ $input = array(
+ array(),
+ array(
+ 'task_id' => 88,
+ 'title' => 'task1'
+ ),
+ array(
+ 'task_id' => 99,
+ 'title' => 'task2'
+ ),
+ array(
+ 'task_id' => 11,
+ 'title' => 'task3'
+ )
+ );
+
+ $expected = array(
+ array(
+ 'my_relation' => array(),
+ ),
+ array(
+ 'task_id' => 88,
+ 'title' => 'task1',
+ 'my_relation' => array(
+ 'id' => 123,
+ 'value' => 'test1',
+ ),
+ ),
+ array(
+ 'task_id' => 99,
+ 'title' => 'task2',
+ 'my_relation' => array(
+ 'id' => 456,
+ 'value' => 'test2',
+ ),
+ ),
+ array(
+ 'task_id' => 11,
+ 'title' => 'task3',
+ 'my_relation' => array(),
+ )
+ );
+
+ array_merge_relation($input, $relations, 'my_relation', 'task_id');
+
+ $this->assertSame($expected, $input);
+ }
+}
diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php
index 6e03acd1..a67eaed9 100644
--- a/tests/units/Helper/HookHelperTest.php
+++ b/tests/units/Helper/HookHelperTest.php
@@ -6,6 +6,79 @@ use Kanboard\Helper\HookHelper;
class HookHelperTest extends Base
{
+ public function testAttachCallable()
+ {
+ $this->container['template'] = $this
+ ->getMockBuilder('\Kanboard\Core\Template')
+ ->setConstructorArgs(array($this->container['helper']))
+ ->setMethods(array('render'))
+ ->getMock();
+
+ $this->container['template']
+ ->expects($this->once())
+ ->method('render')
+ ->with(
+ $this->equalTo('tpl1'),
+ $this->equalTo(array('k0' => 'v0', 'k1' => 'v1'))
+ )
+ ->will($this->returnValue('tpl1_content'));
+
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attachCallable('test', 'tpl1', function() {
+ return array(
+ 'k1' => 'v1',
+ );
+ });
+
+ $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0')));
+ }
+
+ public function testAttachCallableWithNoResult()
+ {
+ $this->container['template'] = $this
+ ->getMockBuilder('\Kanboard\Core\Template')
+ ->setConstructorArgs(array($this->container['helper']))
+ ->setMethods(array('render'))
+ ->getMock();
+
+ $this->container['template']
+ ->expects($this->once())
+ ->method('render')
+ ->with(
+ $this->equalTo('tpl1'),
+ $this->equalTo(array('k0' => 'v0'))
+ )
+ ->will($this->returnValue('tpl1_content'));
+
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attachCallable('test', 'tpl1', function() {
+ });
+
+ $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0')));
+ }
+
+ public function testAttachLocalVariables()
+ {
+ $this->container['template'] = $this
+ ->getMockBuilder('\Kanboard\Core\Template')
+ ->setConstructorArgs(array($this->container['helper']))
+ ->setMethods(array('render'))
+ ->getMock();
+
+ $this->container['template']
+ ->expects($this->once())
+ ->method('render')
+ ->with(
+ $this->equalTo('tpl1'),
+ $this->equalTo(array('k0' => 'v0', 'k1' => 'v1'))
+ )
+ ->will($this->returnValue('tpl1_content'));
+
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attach('test', 'tpl1', array('k1' => 'v1'));
+ $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0')));
+ }
+
public function testMultipleHooks()
{
$this->container['template'] = $this
@@ -32,10 +105,10 @@ class HookHelperTest extends Base
)
->will($this->returnValue('tpl2_content'));
- $h = new HookHelper($this->container);
- $h->attach('test', 'tpl1');
- $h->attach('test', 'tpl2');
- $this->assertEquals('tpl1_contenttpl2_content', $h->render('test'));
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attach('test', 'tpl1');
+ $hookHelper->attach('test', 'tpl2');
+ $this->assertEquals('tpl1_contenttpl2_content', $hookHelper->render('test'));
}
public function testAssetHooks()
@@ -64,11 +137,11 @@ class HookHelperTest extends Base
)
->will($this->returnValue('<script src="skin.js"></script>'));
- $h = new HookHelper($this->container);
- $h->attach('test1', 'skin.css');
- $h->attach('test2', 'skin.js');
+ $hookHelper = new HookHelper($this->container);
+ $hookHelper->attach('test1', 'skin.css');
+ $hookHelper->attach('test2', 'skin.js');
- $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $h->asset('css', 'test1'));
- $this->assertContains('<script src="skin.js"></script>', $h->asset('js', 'test2'));
+ $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $hookHelper->asset('css', 'test1'));
+ $this->assertContains('<script src="skin.js"></script>', $hookHelper->asset('js', 'test2'));
}
}
diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php
index 454da553..2e2da6ee 100644
--- a/tests/units/Helper/TaskHelperTest.php
+++ b/tests/units/Helper/TaskHelperTest.php
@@ -9,6 +9,7 @@ class TaskHelperTest extends Base
public function testSelectPriority()
{
$helper = new TaskHelper($this->container);
+ $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array()));
$this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array()));
$this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array()));
}
diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php
index 10bbc58e..4d1947d8 100644
--- a/tests/units/Helper/UserHelperTest.php
+++ b/tests/units/Helper/UserHelperTest.php
@@ -13,6 +13,21 @@ use Kanboard\Model\UserModel;
class UserHelperTest extends Base
{
+ public function testGetFullname()
+ {
+ $userModel = new UserModel($this->container);
+ $userHelper = new UserHelper($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User #2')));
+
+ $user1 = $userModel->getById(2);
+ $user2 = $userModel->getById(3);
+
+ $this->assertEquals('user1', $userHelper->getFullname($user1));
+ $this->assertEquals('User #2', $userHelper->getFullname($user2));
+ }
+
public function testInitials()
{
$helper = new UserHelper($this->container);
@@ -31,6 +46,12 @@ class UserHelperTest extends Base
$this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER));
}
+ public function testHasAccessWithoutSession()
+ {
+ $helper = new UserHelper($this->container);
+ $this->assertFalse($helper->hasAccess('UserCreationController', 'create'));
+ }
+
public function testHasAccessForAdmins()
{
$helper = new UserHelper($this->container);
@@ -73,6 +94,15 @@ class UserHelperTest extends Base
$this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate'));
}
+ public function testHasProjectAccessWithoutSession()
+ {
+ $helper = new UserHelper($this->container);
+ $project = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $project->create(array('name' => 'My project')));
+ $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1));
+ }
+
public function testHasProjectAccessForAdmins()
{
$helper = new UserHelper($this->container);
diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php
new file mode 100644
index 00000000..8571af8e
--- /dev/null
+++ b/tests/units/Job/CommentEventJobTest.php
@@ -0,0 +1,52 @@
+<?php
+
+use Kanboard\Job\CommentEventJob;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class CommentEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $commentEventJob = new CommentEventJob($this->container);
+ $commentEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $commentEventJob->getJobParams());
+ }
+
+ public function testWithMissingComment()
+ {
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
+
+ $commentEventJob = new CommentEventJob($this->container);
+ $commentEventJob->execute(42, CommentModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_DELETE, function() {});
+
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'foobar', 'user_id' => 1)));
+ $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'test')));
+ $this->assertTrue($commentModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/ProjectFileEventJobTest.php b/tests/units/Job/ProjectFileEventJobTest.php
new file mode 100644
index 00000000..f266d293
--- /dev/null
+++ b/tests/units/Job/ProjectFileEventJobTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Job\ProjectFileEventJob;
+use Kanboard\Model\ProjectFileModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectFileEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $projectFileEventJob = new ProjectFileEventJob($this->container);
+ $projectFileEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $projectFileEventJob->getJobParams());
+ }
+
+ public function testWithMissingFile()
+ {
+ $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {});
+
+ $projectFileEventJob = new ProjectFileEventJob($this->container);
+ $projectFileEventJob->execute(42, ProjectFileModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {});
+
+ $projectModel = new ProjectModel($this->container);
+ $projectFileModel = new ProjectFileModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(ProjectFileModel::EVENT_CREATE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/ProjectMetricJobTest.php b/tests/units/Job/ProjectMetricJobTest.php
new file mode 100644
index 00000000..e5b0474d
--- /dev/null
+++ b/tests/units/Job/ProjectMetricJobTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Kanboard\Job\ProjectMetricJob;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectMetricJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $projectMetricJob = new ProjectMetricJob($this->container);
+ $projectMetricJob->withParams(123);
+
+ $this->assertSame(
+ array(123),
+ $projectMetricJob->getJobParams()
+ );
+ }
+
+ public function testJob()
+ {
+ $this->container['projectDailyColumnStatsModel'] = $this
+ ->getMockBuilder('\Kanboard\Model\ProjectDailyColumnStatsModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('updateTotals'))
+ ->getMock();
+
+ $this->container['projectDailyStatsModel'] = $this
+ ->getMockBuilder('\Kanboard\Model\ProjectDailyStatsModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('updateTotals'))
+ ->getMock();
+
+ $this->container['projectDailyColumnStatsModel']
+ ->expects($this->once())
+ ->method('updateTotals')
+ ->with(42, date('Y-m-d'));
+
+ $this->container['projectDailyStatsModel']
+ ->expects($this->once())
+ ->method('updateTotals')
+ ->with(42, date('Y-m-d'));
+
+ $job = new ProjectMetricJob($this->container);
+ $job->execute(42);
+ }
+}
diff --git a/tests/units/Job/SubtaskEventJobTest.php b/tests/units/Job/SubtaskEventJobTest.php
new file mode 100644
index 00000000..bdc30b51
--- /dev/null
+++ b/tests/units/Job/SubtaskEventJobTest.php
@@ -0,0 +1,52 @@
+<?php
+
+use Kanboard\Job\SubtaskEventJob;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->withParams(123, 'foobar', array('k' => 'v'));
+
+ $this->assertSame(array(123, 'foobar', array('k' => 'v')), $subtaskEventJob->getJobParams());
+ }
+
+ public function testWithMissingSubtask()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->execute(42, SubtaskModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, function() {});
+
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'before')));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'title' => 'after')));
+ $this->assertTrue($subtaskModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(SubtaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php
new file mode 100644
index 00000000..c399faad
--- /dev/null
+++ b/tests/units/Job/TaskEventJobTest.php
@@ -0,0 +1,189 @@
+<?php
+
+use Kanboard\Job\TaskEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskPositionModel;
+use Kanboard\Model\TaskProjectMoveModel;
+use Kanboard\Model\TaskStatusModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskEventJob = new TaskEventJob($this->container);
+ $taskEventJob->withParams(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2'));
+
+ $this->assertSame(
+ array(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2')),
+ $taskEventJob->getJobParams()
+ );
+ }
+
+ public function testWithMissingTask()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {});
+
+ $taskEventJob = new TaskEventJob($this->container);
+ $taskEventJob->execute(42, array(TaskModel::EVENT_CREATE));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreateEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerUpdateEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'new title')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerAssigneeChangeEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'owner_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.closure', $called);
+ }
+
+ public function testTriggerCloseEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CLOSE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskStatusModel->close(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CLOSE.'.closure', $called);
+ }
+
+ public function testTriggerOpenEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_OPEN, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskStatusModel->close(1));
+ $this->assertTrue($taskStatusModel->open(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_OPEN.'.closure', $called);
+ }
+
+ public function testTriggerMovePositionEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($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(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.closure', $called);
+ }
+
+ public function testTriggerMoveColumnEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($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->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.closure', $called);
+ }
+
+ public function testTriggerMoveSwimlaneEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($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('name' => 'S1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 1, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.closure', $called);
+ }
+
+ public function testTriggerMoveProjectEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskFileEventJobTest.php b/tests/units/Job/TaskFileEventJobTest.php
new file mode 100644
index 00000000..921fe801
--- /dev/null
+++ b/tests/units/Job/TaskFileEventJobTest.php
@@ -0,0 +1,46 @@
+<?php
+
+use Kanboard\Job\TaskFileEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFileModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskFileEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskFileEventJob = new TaskFileEventJob($this->container);
+ $taskFileEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskFileEventJob->getJobParams());
+ }
+
+ public function testWithMissingFile()
+ {
+ $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {});
+
+ $taskFileEventJob = new TaskFileEventJob($this->container);
+ $taskFileEventJob->execute(42, TaskFileModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {});
+
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskFileModel::EVENT_CREATE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskLinkEventJobTest.php b/tests/units/Job/TaskLinkEventJobTest.php
new file mode 100644
index 00000000..1949316a
--- /dev/null
+++ b/tests/units/Job/TaskLinkEventJobTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use Kanboard\Job\TaskLinkEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskLinkEventJob->getJobParams());
+ }
+
+ public function testWithMissingLink()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->execute(42, TaskLinkModel::EVENT_CREATE_UPDATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreationEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerDeleteEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_DELETE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+ $this->assertTrue($taskLinkModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionModelTest.php
index 5db18983..4e21a999 100644
--- a/tests/units/Model/ActionTest.php
+++ b/tests/units/Model/ActionModelTest.php
@@ -11,7 +11,7 @@ use Kanboard\Model\CategoryModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Core\Security\Role;
-class ActionTest extends Base
+class ActionModelTest extends Base
{
public function testCreate()
{
@@ -69,6 +69,24 @@ class ActionTest extends Base
$this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']);
}
+ public function testGetProjectId()
+ {
+ $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' => TaskModel::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(1, $actionModel->getProjectId(1));
+ $this->assertSame(0, $actionModel->getProjectId(42));
+ }
+
public function testGetAll()
{
$projectModel = new ProjectModel($this->container);
diff --git a/tests/units/Model/BoardTest.php b/tests/units/Model/BoardTest.php
index 80587d89..9f540c63 100644
--- a/tests/units/Model/BoardTest.php
+++ b/tests/units/Model/BoardTest.php
@@ -3,12 +3,8 @@
require_once __DIR__.'/../Base.php';
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
{
@@ -45,121 +41,4 @@ class BoardTest extends Base
$this->assertEquals('column #1', $columns[5]);
$this->assertEquals('column #2', $columns[6]);
}
-
- public function testGetBoard()
- {
- $p = new ProjectModel($this->container);
- $b = new BoardModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
-
- $board = $b->getBoard(1);
- $this->assertNotEmpty($board);
- $this->assertEquals(1, count($board));
- $this->assertEquals(6, count($board[0]));
- $this->assertArrayHasKey('name', $board[0]);
- $this->assertArrayHasKey('nb_tasks', $board[0]);
- $this->assertArrayHasKey('columns', $board[0]);
- $this->assertArrayHasKey('tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('title', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_column_tasks', $board[0]['columns'][0]);
- $this->assertArrayHasKey('total_score', $board[0]['columns'][0]);
- }
-
- public function testGetBoardWithSwimlane()
- {
- $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')));
- $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' => 3)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 3)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 4, 'score' => 2)));
- $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 4, 'score' => 3, 'swimlane_id' => 1)));
-
- $board = $b->getBoard(1);
- $this->assertNotEmpty($board);
- $this->assertEquals(2, count($board));
- $this->assertEquals(6, count($board[0]));
- $this->assertArrayHasKey('name', $board[0]);
- $this->assertArrayHasKey('nb_tasks', $board[0]);
- $this->assertArrayHasKey('columns', $board[0]);
- $this->assertArrayHasKey('tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('title', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_column_tasks', $board[0]['columns'][0]);
- $this->assertArrayNotHasKey('nb_column_tasks', $board[1]['columns'][0]);
- $this->assertArrayNotHasKey('total_score', $board[1]['columns'][0]);
- $this->assertArrayHasKey('score', $board[0]['columns'][3]);
- $this->assertArrayHasKey('total_score', $board[0]['columns'][3]);
- $this->assertEquals(2, $board[0]['columns'][3]['score']);
- $this->assertEquals(5, $board[0]['columns'][3]['total_score']);
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['id']);
- $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['column_id']);
- $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['position']);
- $this->assertEquals(0, $board[0]['columns'][0]['tasks'][0]['swimlane_id']);
-
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(2, $board[0]['columns'][2]['tasks'][0]['id']);
- $this->assertEquals(3, $board[0]['columns'][2]['tasks'][0]['column_id']);
- $this->assertEquals(1, $board[0]['columns'][2]['tasks'][0]['position']);
- $this->assertEquals(0, $board[0]['columns'][2]['tasks'][0]['swimlane_id']);
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(1, $task['swimlane_id']);
- $this->assertEquals(3, $board[1]['columns'][1]['tasks'][0]['id']);
- $this->assertEquals(2, $board[1]['columns'][1]['tasks'][0]['column_id']);
- $this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['position']);
- $this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['swimlane_id']);
-
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(4, $board[0]['columns'][2]['tasks'][1]['id']);
- $this->assertEquals(3, $board[0]['columns'][2]['tasks'][1]['column_id']);
- $this->assertEquals(2, $board[0]['columns'][2]['tasks'][1]['position']);
- $this->assertEquals(0, $board[0]['columns'][2]['tasks'][1]['swimlane_id']);
-
- $task = $tf->getById(5);
- $this->assertEquals(5, $task['id']);
- $this->assertEquals(4, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(5, $board[0]['columns'][3]['tasks'][0]['id']);
- $this->assertEquals(4, $board[0]['columns'][3]['tasks'][0]['column_id']);
- $this->assertEquals(1, $board[0]['columns'][3]['tasks'][0]['position']);
- $this->assertEquals(0, $board[0]['columns'][3]['tasks'][0]['swimlane_id']);
-
- $task = $tf->getById(6);
- $this->assertEquals(6, $task['id']);
- $this->assertEquals(4, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(1, $task['swimlane_id']);
- $this->assertEquals(6, $board[1]['columns'][3]['tasks'][0]['id']);
- $this->assertEquals(4, $board[1]['columns'][3]['tasks'][0]['column_id']);
- $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['position']);
- $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['swimlane_id']);
- }
}
diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryModelTest.php
index 1fdc51f6..80a20af6 100644
--- a/tests/units/Model/CategoryTest.php
+++ b/tests/units/Model/CategoryModelTest.php
@@ -8,7 +8,7 @@ use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\CategoryModel;
-class CategoryTest extends Base
+class CategoryModelTest extends Base
{
public function testCreation()
{
@@ -81,6 +81,18 @@ class CategoryTest extends Base
$this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2'));
}
+ public function testGetProjectId()
+ {
+ $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')));
+
+ $this->assertEquals(1, $categoryModel->getProjectId(1));
+ $this->assertSame(0, $categoryModel->getProjectId(2));
+ }
+
public function testGetList()
{
$projectModel = new ProjectModel($this->container);
diff --git a/tests/units/Model/CommentModelTest.php b/tests/units/Model/CommentModelTest.php
new file mode 100644
index 00000000..4178a839
--- /dev/null
+++ b/tests/units/Model/CommentModelTest.php
@@ -0,0 +1,106 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\CommentModel;
+
+class CommentModelTest extends Base
+{
+ public function testCreate()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+ $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla')));
+
+ $comment = $commentModel->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals('bla bla', $comment['comment']);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(1, $comment['user_id']);
+ $this->assertEquals('admin', $comment['username']);
+ $this->assertEquals(time(), $comment['date_creation'], '', 3);
+
+ $comment = $commentModel->getById(2);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals('bla bla', $comment['comment']);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(0, $comment['user_id']);
+ $this->assertEquals('', $comment['username']);
+ $this->assertEquals(time(), $comment['date_creation'], '', 3);
+ }
+
+ public function testGetAll()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
+ $this->assertEquals(3, $commentModel->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
+
+ $comments = $commentModel->getAll(1);
+
+ $this->assertNotEmpty($comments);
+ $this->assertEquals(3, count($comments));
+ $this->assertEquals(1, $comments[0]['id']);
+ $this->assertEquals(2, $comments[1]['id']);
+ $this->assertEquals(3, $comments[2]['id']);
+
+ $this->assertEquals(3, $commentModel->count(1));
+ }
+
+ public function testUpdate()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'bla')));
+
+ $comment = $commentModel->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals('bla', $comment['comment']);
+ }
+
+ public function testRemove()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+
+ $this->assertTrue($commentModel->remove(1));
+ $this->assertFalse($commentModel->remove(1));
+ $this->assertFalse($commentModel->remove(1111));
+ }
+
+ public function testGetProjectId()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+
+ $this->assertEquals(1, $commentModel->getProjectId(1));
+ $this->assertSame(0, $commentModel->getProjectId(2));
+ }
+}
diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php
deleted file mode 100644
index 7250ae0b..00000000
--- a/tests/units/Model/CommentTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\CommentModel;
-
-class CommentTest extends Base
-{
- public function testCreate()
- {
- $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)));
- $this->assertEquals(1, $c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
- $this->assertEquals(2, $c->create(array('task_id' => 1, 'comment' => 'bla bla')));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals('bla bla', $comment['comment']);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(1, $comment['user_id']);
- $this->assertEquals('admin', $comment['username']);
- $this->assertEquals(time(), $comment['date_creation'], '', 3);
-
- $comment = $c->getById(2);
- $this->assertNotEmpty($comment);
- $this->assertEquals('bla bla', $comment['comment']);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(0, $comment['user_id']);
- $this->assertEquals('', $comment['username']);
- $this->assertEquals(time(), $comment['date_creation'], '', 3);
- }
-
- public function testGetAll()
- {
- $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)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
-
- $comments = $c->getAll(1);
-
- $this->assertNotEmpty($comments);
- $this->assertEquals(3, count($comments));
- $this->assertEquals(1, $comments[0]['id']);
- $this->assertEquals(2, $comments[1]['id']);
- $this->assertEquals(3, $comments[2]['id']);
-
- $this->assertEquals(3, $c->count(1));
- }
-
- public function testUpdate()
- {
- $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)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla')));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals('bla', $comment['comment']);
- }
-
- public function validateRemove()
- {
- $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)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
-
- $this->assertTrue($c->remove(1));
- $this->assertFalse($c->remove(1));
- $this->assertFalse($c->remove(1111));
- }
-}
diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupModelTest.php
index 85c2c5d9..4ad0a167 100644
--- a/tests/units/Model/GroupTest.php
+++ b/tests/units/Model/GroupModelTest.php
@@ -4,7 +4,7 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\GroupModel;
-class GroupTest extends Base
+class GroupModelTest extends Base
{
public function testCreation()
{
@@ -57,4 +57,13 @@ class GroupTest extends Base
$this->assertTrue($groupModel->remove(1));
$this->assertEmpty($groupModel->getById(1));
}
+
+ public function testGetOrCreateExternalGroupId()
+ {
+ $groupModel = new GroupModel($this->container);
+ $this->assertEquals(1, $groupModel->create('Group 1', 'ExternalId1'));
+ $this->assertEquals(1, $groupModel->getOrCreateExternalGroupId('Group 1', 'ExternalId1'));
+ $this->assertEquals(1, $groupModel->getOrCreateExternalGroupId('Group 2', 'ExternalId1'));
+ $this->assertEquals(2, $groupModel->getOrCreateExternalGroupId('Group 2', 'ExternalId2'));
+ }
}
diff --git a/tests/units/Model/NotificationModelTest.php b/tests/units/Model/NotificationModelTest.php
new file mode 100644
index 00000000..0bd9db6e
--- /dev/null
+++ b/tests/units/Model/NotificationModelTest.php
@@ -0,0 +1,104 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\NotificationModel;
+use Kanboard\Subscriber\NotificationSubscriber;
+
+class NotificationModelTest extends Base
+{
+ public function testGetTitle()
+ {
+ $notificationModel = new NotificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ );
+
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor($eventName, $eventData));
+ $this->assertNotEmpty($notificationModel->getTitleWithAuthor('Foobar', $eventName, $eventData));
+ }
+
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor('unknown', array()));
+ }
+
+ public function testGetTaskIdFromEvent()
+ {
+ $notificationModel = new NotificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'test', 'blah', 123));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $task_id = $notificationModel->getTaskIdFromEvent($eventName, array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ ));
+
+ $this->assertEquals($task_id, $task['id']);
+ }
+
+ $this->assertEquals(1, $notificationModel->getTaskIdFromEvent(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
+ }
+}
diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php
deleted file mode 100644
index 96ee5f4e..00000000
--- a/tests/units/Model/NotificationTest.php
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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 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)));
- $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
- $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
-
- $task = $tf->getDetails(1);
- $subtask = $s->getById(1, true);
- $comment = $c->getById(1);
- $file = $c->getById(1);
-
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $title = $wn->getTitleWithoutAuthor($event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
-
- $title = $wn->getTitleWithAuthor('foobar', $event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
- }
-
- $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/ProjectDuplicationModelTest.php b/tests/units/Model/ProjectDuplicationModelTest.php
new file mode 100644
index 00000000..54261728
--- /dev/null
+++ b/tests/units/Model/ProjectDuplicationModelTest.php
@@ -0,0 +1,548 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+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\TagModel;
+use Kanboard\Model\TaskTagModel;
+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 ProjectDuplicationModelTest extends Base
+{
+ public function testGetSelections()
+ {
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $this->assertCount(7, $projectDuplicationModel->getOptionalSelection());
+ $this->assertCount(8, $projectDuplicationModel->getPossibleSelection());
+ }
+
+ public function testGetClonedProjectName()
+ {
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals('test (Clone)', $projectDuplicationModel->getClonedProjectName('test'));
+
+ $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 50))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 50)));
+
+ $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 60))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 60)));
+ }
+
+ public function testClonePublicProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Public')));
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Public (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_active']);
+ $this->assertEquals(0, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEquals(0, $project['owner_id']);
+ $this->assertEmpty($project['token']);
+ }
+
+ public function testClonePrivateProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Private', 'is_private' => 1), 1, true));
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Private (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_active']);
+ $this->assertEquals(1, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEquals(0, $project['owner_id']);
+ $this->assertEmpty($project['token']);
+
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
+ }
+
+ public function testCloneSharedProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Shared')));
+ $this->assertTrue($projectModel->update(array('id' => 1, 'is_public' => 1, 'token' => 'test')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals('test', $project['token']);
+ $this->assertEquals(1, $project['is_public']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Shared (Clone)', $project['name']);
+ $this->assertEquals('', $project['token']);
+ $this->assertEquals(0, $project['is_public']);
+ }
+
+ public function testCloneInactiveProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Inactive')));
+ $this->assertTrue($projectModel->update(array('id' => 1, 'is_active' => 0)));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['is_active']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Inactive (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_active']);
+ }
+
+ public function testCloneProjectWithOwner()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['owner_id']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Owner (Clone)', $project['name']);
+ $this->assertEquals(1, $project['owner_id']);
+
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
+ }
+
+ public function testCloneProjectWithDifferentPriorities()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array(
+ 'name' => 'My project',
+ 'priority_default' => 2,
+ 'priority_start' => -2,
+ 'priority_end' => 8,
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('My project (Clone)', $project['name']);
+ $this->assertEquals(2, $project['priority_default']);
+ $this->assertEquals(-2, $project['priority_start']);
+ $this->assertEquals(8, $project['priority_end']);
+ }
+
+ public function testCloneProjectWithDifferentName()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['owner_id']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar'));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Foobar', $project['name']);
+ $this->assertEquals(1, $project['owner_id']);
+ }
+
+ public function testCloneProjectAndForceItToBePrivate()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['owner_id']);
+ $this->assertEquals(0, $project['is_private']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Foobar', $project['name']);
+ $this->assertEquals(1, $project['owner_id']);
+ $this->assertEquals(1, $project['is_private']);
+ }
+
+ public function testCloneProjectWithCategories()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('P1 (Clone)', $project['name']);
+
+ $categories = $categoryModel->getAll(2);
+ $this->assertCount(3, $categories);
+ $this->assertEquals('C1', $categories[0]['name']);
+ $this->assertEquals('C2', $categories[1]['name']);
+ $this->assertEquals('C3', $categories[2]['name']);
+ }
+
+ public function testCloneProjectWithUsers()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $this->assertCount(3, $projectUserRoleModel->getUsers(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
+ $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
+ }
+
+ public function testCloneProjectWithUsersAndOverrideOwner()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(2, $project['owner_id']);
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1));
+
+ $this->assertCount(2, $projectUserRoleModel->getUsers(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
+
+ $project = $projectModel->getById(2);
+ $this->assertEquals(1, $project['owner_id']);
+ }
+
+ public function testCloneTeamProjectToPrivatProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(2, $project['owner_id']);
+ $this->assertEquals(0, $project['is_private']);
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true));
+
+ $this->assertCount(1, $projectUserRoleModel->getUsers(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 3));
+
+ $project = $projectModel->getById(2);
+ $this->assertEquals(3, $project['owner_id']);
+ $this->assertEquals(1, $project['is_private']);
+ }
+
+ public function testCloneProjectWithGroups()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = 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, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $groupModel->create('G1'));
+ $this->assertEquals(2, $groupModel->create('G2'));
+ $this->assertEquals(3, $groupModel->create('G3'));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+ $this->assertTrue($groupMemberModel->addUser(2, 3));
+ $this->assertTrue($groupMemberModel->addUser(3, 4));
+
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $this->assertCount(3, $projectGroupRoleModel->getGroups(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
+ $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
+ }
+
+ public function testCloneProjectWithActionTaskAssignCurrentUser()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_MOVE_COLUMN,
+ 'action_name' => 'TaskAssignCurrentUser',
+ 'params' => array('column_id' => 2),
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $actions = $actionModel->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals(6, $actions[0]['params']['column_id']);
+ }
+
+ public function testCloneProjectWithActionTaskAssignColorCategory()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
+ 'params' => array('color_id' => 'blue', 'category_id' => 2),
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $actions = $actionModel->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals('blue', $actions[0]['params']['color_id']);
+ $this->assertEquals(5, $actions[0]['params']['category_id']);
+ }
+
+ public function testCloneProjectWithSwimlanes()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1', 'default_swimlane' => 'New Default')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1')));
+ $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S2')));
+ $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S3')));
+
+ // create initial tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'swimlaneModel')));
+
+ $swimlanes = $swimlaneModel->getAll(2);
+ $this->assertCount(3, $swimlanes);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals('S1', $swimlanes[0]['name']);
+ $this->assertEquals(5, $swimlanes[1]['id']);
+ $this->assertEquals('S2', $swimlanes[1]['name']);
+ $this->assertEquals(6, $swimlanes[2]['id']);
+ $this->assertEquals('S3', $swimlanes[2]['name']);
+
+ $swimlane = $swimlaneModel->getDefault(2);
+ $this->assertEquals('New Default', $swimlane['default_swimlane']);
+
+ // Check if tasks are NOT been duplicated
+ $this->assertCount(0, $taskFinderModel->getAll(2));
+ }
+
+ public function testCloneProjectWithTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ // create initial tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'projectTaskDuplicationModel')));
+
+ // Check if Tasks have been duplicated
+ $tasks = $taskFinderModel->getAll(2);
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+ }
+
+ public function testCloneProjectWithSwimlanesAndTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1', 'default_swimlane' => 'New Default')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1')));
+ $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S2')));
+ $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S3')));
+
+ // create initial tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'projectTaskDuplicationModel')));
+
+ // Check if Swimlanes have been duplicated
+ $swimlanes = $swimlaneModel->getAll(2);
+ $this->assertCount(3, $swimlanes);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals('S1', $swimlanes[0]['name']);
+ $this->assertEquals(5, $swimlanes[1]['id']);
+ $this->assertEquals('S2', $swimlanes[1]['name']);
+ $this->assertEquals(6, $swimlanes[2]['id']);
+ $this->assertEquals('S3', $swimlanes[2]['name']);
+
+ $swimlane = $swimlaneModel->getDefault(2);
+ $this->assertEquals('New Default', $swimlane['default_swimlane']);
+
+ // Check if Tasks have been duplicated
+ $tasks = $taskFinderModel->getAll(2);
+
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+ }
+
+ public function testCloneProjectWithTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $tagModel = new TagModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'tags' => array('A'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C'))));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'projectTaskDuplicationModel')));
+
+ $tasks = $taskFinderModel->getAll(2);
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+
+ $tags = $tagModel->getAllByProject(2);
+ $this->assertCount(3, $tags);
+ $this->assertEquals(4, $tags[0]['id']);
+ $this->assertEquals('A', $tags[0]['name']);
+ $this->assertEquals(5, $tags[1]['id']);
+ $this->assertEquals('B', $tags[1]['name']);
+ $this->assertEquals(6, $tags[2]['id']);
+ $this->assertEquals('C', $tags[2]['name']);
+
+ $tags = $taskTagModel->getList(4);
+ $this->assertEquals('A', $tags[4]);
+
+ $tags = $taskTagModel->getList(5);
+ $this->assertEquals('A', $tags[4]);
+ $this->assertEquals('B', $tags[5]);
+
+ $tags = $taskTagModel->getList(6);
+ $this->assertEquals('C', $tags[6]);
+ }
+}
diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php
deleted file mode 100644
index 312c7168..00000000
--- a/tests/units/Model/ProjectDuplicationTest.php
+++ /dev/null
@@ -1,482 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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 ProjectDuplicationModel($this->container);
- $this->assertCount(6, $projectDuplicationModel->getOptionalSelection());
- $this->assertCount(7, $projectDuplicationModel->getPossibleSelection());
- }
-
- public function testGetClonedProjectName()
- {
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals('test (Clone)', $pd->getClonedProjectName('test'));
-
- $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 50))));
- $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 50)));
-
- $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 60))));
- $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60)));
- }
-
- public function testClonePublicProject()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Public')));
- $this->assertEquals(2, $pd->duplicate(1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Public (Clone)', $project['name']);
- $this->assertEquals(1, $project['is_active']);
- $this->assertEquals(0, $project['is_private']);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEquals(0, $project['owner_id']);
- $this->assertEmpty($project['token']);
- }
-
- public function testClonePrivateProject()
- {
- $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));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Private (Clone)', $project['name']);
- $this->assertEquals(1, $project['is_active']);
- $this->assertEquals(1, $project['is_private']);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEquals(0, $project['owner_id']);
- $this->assertEmpty($project['token']);
-
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1));
- }
-
- public function testCloneSharedProject()
- {
- $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')));
-
- $project = $p->getById(1);
- $this->assertEquals('test', $project['token']);
- $this->assertEquals(1, $project['is_public']);
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Shared (Clone)', $project['name']);
- $this->assertEquals('', $project['token']);
- $this->assertEquals(0, $project['is_public']);
- }
-
- public function testCloneInactiveProject()
- {
- $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)));
-
- $project = $p->getById(1);
- $this->assertEquals(0, $project['is_active']);
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Inactive (Clone)', $project['name']);
- $this->assertEquals(1, $project['is_active']);
- }
-
- public function testCloneProjectWithOwner()
- {
- $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('projectPermissionModel'), 1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Owner (Clone)', $project['name']);
- $this->assertEquals(1, $project['owner_id']);
-
- $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
- }
-
- public function testCloneProjectWithDifferentName()
- {
- $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('projectPermissionModel'), 1, 'Foobar'));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Foobar', $project['name']);
- $this->assertEquals(1, $project['owner_id']);
- }
-
- public function testCloneProjectAndForceItToBePrivate()
- {
- $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(0, $project['is_private']);
-
- $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Foobar', $project['name']);
- $this->assertEquals(1, $project['owner_id']);
- $this->assertEquals(1, $project['is_private']);
- }
-
- public function testCloneProjectWithCategories()
- {
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
-
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
- $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('P1 (Clone)', $project['name']);
-
- $categories = $c->getAll(2);
- $this->assertCount(3, $categories);
- $this->assertEquals('C1', $categories[0]['name']);
- $this->assertEquals('C2', $categories[1]['name']);
- $this->assertEquals('C3', $categories[2]['name']);
- }
-
- public function testCloneProjectWithUsers()
- {
- $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')));
- $this->assertEquals(4, $u->create(array('username' => 'user3')));
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
-
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER));
- $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_VIEWER));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $this->assertCount(3, $pp->getUsers(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2));
- $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3));
- $this->assertEquals(Role::PROJECT_VIEWER, $pp->getUserRole(2, 4));
- }
-
- public function testCloneProjectWithUsersAndOverrideOwner()
- {
- $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));
-
- $project = $p->getById(1);
- $this->assertEquals(2, $project['owner_id']);
-
- $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('projectPermissionModel'), 1));
-
- $this->assertCount(2, $pp->getUsers(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1));
-
- $project = $p->getById(2);
- $this->assertEquals(1, $project['owner_id']);
- }
-
- public function testCloneTeamProjectToPrivatProject()
- {
- $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')));
- $this->assertEquals(1, $p->create(array('name' => 'P1'), 2));
-
- $project = $p->getById(1);
- $this->assertEquals(2, $project['owner_id']);
- $this->assertEquals(0, $project['is_private']);
-
- $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('projectPermissionModel'), 3, 'My private project', true));
-
- $this->assertCount(1, $pp->getUsers(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3));
-
- $project = $p->getById(2);
- $this->assertEquals(3, $project['owner_id']);
- $this->assertEquals(1, $project['is_private']);
- }
-
- public function testCloneProjectWithGroups()
- {
- $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')));
-
- $this->assertEquals(1, $groupModel->create('G1'));
- $this->assertEquals(2, $groupModel->create('G2'));
- $this->assertEquals(3, $groupModel->create('G3'));
-
- $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
- $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
- $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
-
- $this->assertTrue($groupMemberModel->addUser(1, 2));
- $this->assertTrue($groupMemberModel->addUser(2, 3));
- $this->assertTrue($groupMemberModel->addUser(3, 4));
-
- $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER));
- $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $this->assertCount(3, $projectGroupRoleModel->getGroups(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
- $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
- $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
- }
-
- public function testCloneProjectWithActionTaskAssignCurrentUser()
- {
- $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' => TaskModel::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskAssignCurrentUser',
- 'params' => array('column_id' => 2),
- )));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $actions = $a->getAllByProject(2);
-
- $this->assertNotEmpty($actions);
- $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
- $this->assertNotEmpty($actions[0]['params']);
- $this->assertEquals(6, $actions[0]['params']['column_id']);
- }
-
- public function testCloneProjectWithActionTaskAssignColorCategory()
- {
- $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')));
-
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
- $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
-
- $this->assertEquals(1, $a->create(array(
- 'project_id' => 1,
- 'event_name' => TaskModel::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignColorCategory',
- 'params' => array('color_id' => 'blue', 'category_id' => 2),
- )));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $actions = $a->getAllByProject(2);
-
- $this->assertNotEmpty($actions);
- $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
- $this->assertNotEmpty($actions[0]['params']);
- $this->assertEquals('blue', $actions[0]['params']['color_id']);
- $this->assertEquals(5, $actions[0]['params']['category_id']);
- }
-
- public function testCloneProjectWithSwimlanes()
- {
- $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')));
-
- // create initial swimlanes
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
- $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
-
- // create initial tasks
- $this->assertEquals(1, $tc->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0)));
- $this->assertEquals(2, $tc->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1)));
- $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('categoryModel', 'swimlaneModel')));
-
- $swimlanes = $s->getAll(2);
- $this->assertCount(3, $swimlanes);
- $this->assertEquals(4, $swimlanes[0]['id']);
- $this->assertEquals('S1', $swimlanes[0]['name']);
- $this->assertEquals(5, $swimlanes[1]['id']);
- $this->assertEquals('S2', $swimlanes[1]['name']);
- $this->assertEquals(6, $swimlanes[2]['id']);
- $this->assertEquals('S3', $swimlanes[2]['name']);
-
- $swimlane = $s->getDefault(2);
- $this->assertEquals('New Default', $swimlane['default_swimlane']);
-
- // Check if tasks are NOT been duplicated
- $this->assertCount(0, $tf->getAll(2));
- }
-
- public function testCloneProjectWithTasks()
- {
- $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')));
-
- // create initial tasks
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1)));
- $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('categoryModel', 'actionModel', 'taskModel')));
-
- // Check if Tasks have been duplicated
- $tasks = $tf->getAll(2);
- $this->assertCount(3, $tasks);
- $this->assertEquals('T1', $tasks[0]['title']);
- $this->assertEquals('T2', $tasks[1]['title']);
- $this->assertEquals('T3', $tasks[2]['title']);
- }
-
- public function testCloneProjectWithSwimlanesAndTasks()
- {
- $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')));
-
- // create initial swimlanes
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
- $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
-
- // create initial tasks
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $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('projectPermissionModel', 'swimlaneModel', 'taskModel')));
-
- // Check if Swimlanes have been duplicated
- $swimlanes = $s->getAll(2);
- $this->assertCount(3, $swimlanes);
- $this->assertEquals(4, $swimlanes[0]['id']);
- $this->assertEquals('S1', $swimlanes[0]['name']);
- $this->assertEquals(5, $swimlanes[1]['id']);
- $this->assertEquals('S2', $swimlanes[1]['name']);
- $this->assertEquals(6, $swimlanes[2]['id']);
- $this->assertEquals('S3', $swimlanes[2]['name']);
-
- $swimlane = $s->getDefault(2);
- $this->assertEquals('New Default', $swimlane['default_swimlane']);
-
- // Check if Tasks have been duplicated
- $tasks = $tf->getAll(2);
-
- $this->assertCount(3, $tasks);
- $this->assertEquals('T1', $tasks[0]['title']);
- $this->assertEquals('T2', $tasks[1]['title']);
- $this->assertEquals('T3', $tasks[2]['title']);
- }
-}
diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectModelTest.php
index 472d7351..81e0dd57 100644
--- a/tests/units/Model/ProjectTest.php
+++ b/tests/units/Model/ProjectModelTest.php
@@ -11,16 +11,16 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ConfigModel;
use Kanboard\Model\CategoryModel;
-class ProjectTest extends Base
+class ProjectModelTest extends Base
{
public function testCreationForAllLanguages()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
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);
+ $this->assertNotFalse($projectModel->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
}
Translator::unload();
@@ -28,11 +28,11 @@ class ProjectTest extends Base
public function testCreation()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_active']);
$this->assertEquals(0, $project['is_public']);
@@ -43,19 +43,19 @@ class ProjectTest extends Base
public function testCreationWithDuplicateName()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest')));
}
public function testCreationWithStartAndDate()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('2015-01-01', $project['start_date']);
$this->assertEquals('2015-12-31', $project['end_date']);
@@ -63,19 +63,19 @@ class ProjectTest extends Base
public function testCreationWithDefaultCategories()
{
- $p = new ProjectModel($this->container);
- $c = new ConfigModel($this->container);
- $cat = new CategoryModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $configModel = new ConfigModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
// Multiple categories correctly formatted
- $this->assertTrue($c->save(array('project_categories' => 'Test1, Test2')));
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertTrue($configModel->save(array('project_categories' => 'Test1, Test2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(1);
+ $categories = $categoryModel->getAll(1);
$this->assertNotEmpty($categories);
$this->assertEquals(2, count($categories));
$this->assertEquals('Test1', $categories[0]['name']);
@@ -83,85 +83,85 @@ class ProjectTest extends Base
// Single category
- $this->assertTrue($c->save(array('project_categories' => 'Test1')));
+ $this->assertTrue($configModel->save(array('project_categories' => 'Test1')));
$this->container['memoryCache']->flush();
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(2);
+ $categories = $categoryModel->getAll(2);
$this->assertNotEmpty($categories);
$this->assertEquals(1, count($categories));
$this->assertEquals('Test1', $categories[0]['name']);
// Multiple categories badly formatted
- $this->assertTrue($c->save(array('project_categories' => 'ABC, , DEF 3, ')));
+ $this->assertTrue($configModel->save(array('project_categories' => 'ABC, , DEF 3, ')));
$this->container['memoryCache']->flush();
- $this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'UnitTest3')));
- $project = $p->getById(3);
+ $project = $projectModel->getById(3);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(3);
+ $categories = $categoryModel->getAll(3);
$this->assertNotEmpty($categories);
$this->assertEquals(2, count($categories));
$this->assertEquals('ABC', $categories[0]['name']);
$this->assertEquals('DEF 3', $categories[1]['name']);
// No default categories
- $this->assertTrue($c->save(array('project_categories' => ' ')));
+ $this->assertTrue($configModel->save(array('project_categories' => ' ')));
$this->container['memoryCache']->flush();
- $this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
+ $this->assertEquals(4, $projectModel->create(array('name' => 'UnitTest4')));
- $project = $p->getById(4);
+ $project = $projectModel->getById(4);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(4);
+ $categories = $categoryModel->getAll(4);
$this->assertEmpty($categories);
}
public function testUpdateLastModifiedDate()
{
- $p = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $projectModel = new ProjectModel($this->container);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
$now = time();
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
sleep(1);
- $this->assertTrue($p->updateModificationDate(1));
+ $this->assertTrue($projectModel->updateModificationDate(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertGreaterThan($now, $project['last_modified']);
}
public function testGetAllIds()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
- $this->assertEmpty($p->getAllByIds(array()));
- $this->assertNotEmpty($p->getAllByIds(array(1, 2)));
- $this->assertCount(1, $p->getAllByIds(array(1)));
+ $this->assertEmpty($projectModel->getAllByIds(array()));
+ $this->assertNotEmpty($projectModel->getAllByIds(array(1, 2)));
+ $this->assertCount(1, $projectModel->getAllByIds(array(1)));
}
public function testIsLastModified()
{
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
$now = time();
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals($now, $project['last_modified']);
@@ -170,113 +170,113 @@ class ProjectTest extends Base
$listener = new ProjectModificationDateSubscriber($this->container);
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute'));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called);
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
- $this->assertTrue($p->isModifiedSince(1, $now));
+ $this->assertTrue($projectModel->isModifiedSince(1, $now));
}
public function testRemove()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->remove(1));
- $this->assertFalse($p->remove(1234));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->remove(1));
+ $this->assertFalse($projectModel->remove(1234));
}
public function testEnable()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->disable(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->disable(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(0, $project['is_active']);
- $this->assertFalse($p->disable(1111));
+ $this->assertFalse($projectModel->disable(1111));
}
public function testDisable()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->disable(1));
- $this->assertTrue($p->enable(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->disable(1));
+ $this->assertTrue($projectModel->enable(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_active']);
- $this->assertFalse($p->enable(1234567));
+ $this->assertFalse($projectModel->enable(1234567));
}
public function testEnablePublicAccess()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->enablePublicAccess(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->enablePublicAccess(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_public']);
$this->assertNotEmpty($project['token']);
- $this->assertFalse($p->enablePublicAccess(123));
+ $this->assertFalse($projectModel->enablePublicAccess(123));
}
public function testDisablePublicAccess()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->enablePublicAccess(1));
- $this->assertTrue($p->disablePublicAccess(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->enablePublicAccess(1));
+ $this->assertTrue($projectModel->disablePublicAccess(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(0, $project['is_public']);
$this->assertEmpty($project['token']);
- $this->assertFalse($p->disablePublicAccess(123));
+ $this->assertFalse($projectModel->disablePublicAccess(123));
}
public function testIdentifier()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
// Creation
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('', $project['identifier']);
// Update
- $this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2')));
+ $this->assertTrue($projectModel->update(array('id' => '2', 'identifier' => 'test2')));
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('TEST2', $project['identifier']);
- $project = $p->getByIdentifier('test1');
+ $project = $projectModel->getByIdentifier('test1');
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getByIdentifier('');
+ $project = $projectModel->getByIdentifier('');
$this->assertFalse($project);
}
@@ -303,34 +303,4 @@ class ProjectTest extends Base
$this->assertEquals('', $project['owner_username']);
$this->assertEquals(0, $project['owner_id']);
}
-
- public function testPriority()
- {
- $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
-
- $project = $projectModel->getById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(0, $project['priority_default']);
- $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);
- $this->assertNotEmpty($project);
- $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/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php
index c9e0a481..a9f8ab04 100644
--- a/tests/units/Model/ProjectPermissionTest.php
+++ b/tests/units/Model/ProjectPermissionTest.php
@@ -267,6 +267,29 @@ class ProjectPermissionTest extends Base
$this->assertEquals(array(1), $projectPermission->getActiveProjectIds(3));
}
+ public function testGetProjectIds()
+ {
+ $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')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_active' => 0)));
+
+ $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 3, Role::PROJECT_MEMBER));
+
+ $this->assertEmpty($projectPermission->getProjectIds(1));
+ $this->assertEquals(array(1, 2), $projectPermission->getProjectIds(2));
+ $this->assertEquals(array(1, 2), $projectPermission->getProjectIds(3));
+ }
+
public function testDuplicate()
{
$userModel = new UserModel($this->container);
diff --git a/tests/units/Model/ProjectTaskPriorityModelTest.php b/tests/units/Model/ProjectTaskPriorityModelTest.php
new file mode 100644
index 00000000..61661e5e
--- /dev/null
+++ b/tests/units/Model/ProjectTaskPriorityModelTest.php
@@ -0,0 +1,84 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectTaskPriorityModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectTaskPriorityModelTest extends Base
+{
+ public function testPriority()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
+ $this->assertEquals(0, $projectTaskPriorityModel->getDefaultPriority(1));
+
+ $project = $projectModel->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals(0, $project['priority_default']);
+ $this->assertEquals(0, $project['priority_start']);
+ $this->assertEquals(3, $project['priority_end']);
+
+ $this->assertEquals(
+ array(0 => 0, 1 => 1, 2 => 2, 3 => 3),
+ $projectTaskPriorityModel->getPriorities($project)
+ );
+
+ $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4)));
+
+ $project = $projectModel->getById(1);
+ $this->assertNotEmpty($project);
+ $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),
+ $projectTaskPriorityModel->getPriorities($project)
+ );
+
+ $this->assertEquals(4, $projectTaskPriorityModel->getDefaultPriority(1));
+ }
+
+ public function testGetPrioritySettings()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
+
+ $expected = array(
+ 'priority_default' => 0,
+ 'priority_start' => 0,
+ 'priority_end' => 3,
+ );
+
+ $this->assertEquals($expected, $projectTaskPriorityModel->getPrioritySettings(1));
+ $this->assertNull($projectTaskPriorityModel->getPrioritySettings(2));
+ }
+
+ public function testGetPriorityForProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array(
+ 'name' => 'My project 1',
+ 'priority_default' => 2,
+ 'priority_start' => -2,
+ 'priority_end' => 8,
+ )));
+
+ $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 42));
+ $this->assertEquals(0, $projectTaskPriorityModel->getPriorityForProject(1, 0));
+ $this->assertEquals(1, $projectTaskPriorityModel->getPriorityForProject(1, 1));
+ $this->assertEquals(-2, $projectTaskPriorityModel->getPriorityForProject(1, -2));
+ $this->assertEquals(-1, $projectTaskPriorityModel->getPriorityForProject(1, -1));
+ $this->assertEquals(8, $projectTaskPriorityModel->getPriorityForProject(1, 8));
+ $this->assertEquals(5, $projectTaskPriorityModel->getPriorityForProject(1, 5));
+ $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 9));
+ $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, -3));
+ }
+}
diff --git a/tests/units/Model/SubtaskModelTest.php b/tests/units/Model/SubtaskModelTest.php
new file mode 100644
index 00000000..eed37cf3
--- /dev/null
+++ b/tests/units/Model/SubtaskModelTest.php
@@ -0,0 +1,175 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskFinderModel;
+
+class SubtaskModelTest extends Base
+{
+ public function testCreation()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ $this->assertEquals('subtask #1', $subtask['title']);
+ $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']);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
+ public function testCreationUpdateTaskTimeTracking()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 5)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(7, $task['time_estimated']);
+ $this->assertEquals(6, $task['time_spent']);
+ }
+
+ public function testModification()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ $this->assertEquals('subtask #1', $subtask['title']);
+ $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']);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
+ public function testModificationUpdateTaskTimeTracking()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 2, 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 5)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(7, $task['time_estimated']);
+ $this->assertEquals(6, $task['time_spent']);
+ }
+
+ public function testRemove()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+
+ $this->assertTrue($subtaskModel->remove(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertEmpty($subtask);
+ }
+
+ public function testDuplicate()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ // We create a project
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ // We create 2 tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
+
+ // We create many subtasks for the first task
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
+
+ // We duplicate our subtasks
+ $this->assertTrue($subtaskModel->duplicate(1, 2));
+ $subtasks = $subtaskModel->getAll(2);
+
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(2, count($subtasks));
+
+ $this->assertEquals('subtask #1', $subtasks[0]['title']);
+ $this->assertEquals('subtask #2', $subtasks[1]['title']);
+
+ $this->assertEquals(2, $subtasks[0]['task_id']);
+ $this->assertEquals(2, $subtasks[1]['task_id']);
+
+ $this->assertEquals(5, $subtasks[0]['time_estimated']);
+ $this->assertEquals(0, $subtasks[1]['time_estimated']);
+
+ $this->assertEquals(0, $subtasks[0]['time_spent']);
+ $this->assertEquals(0, $subtasks[1]['time_spent']);
+
+ $this->assertEquals(0, $subtasks[0]['status']);
+ $this->assertEquals(0, $subtasks[1]['status']);
+
+ $this->assertEquals(0, $subtasks[0]['user_id']);
+ $this->assertEquals(0, $subtasks[1]['user_id']);
+
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ }
+
+ public function testGetProjectId()
+ {
+ $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)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->getProjectId(1));
+ $this->assertEquals(0, $subtaskModel->getProjectId(2));
+ }
+}
diff --git a/tests/units/Model/SubtaskPositionModelTest.php b/tests/units/Model/SubtaskPositionModelTest.php
new file mode 100644
index 00000000..92412392
--- /dev/null
+++ b/tests/units/Model/SubtaskPositionModelTest.php
@@ -0,0 +1,77 @@
+<?php
+
+use Kanboard\Model\SubtaskPositionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskPositionModelTest extends Base
+{
+ public function testChangePosition()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskPositionModel = new SubtaskPositionModel($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)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1)));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(2, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 3, 2));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(3, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(2, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 2, 1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(1, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 2, 2));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(2, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 1, 3));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(3, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(1, $subtasks[2]['id']);
+
+ $this->assertFalse($subtaskPositionModel->changePosition(1, 2, 0));
+ $this->assertFalse($subtaskPositionModel->changePosition(1, 2, 4));
+ }
+}
diff --git a/tests/units/Model/SubtaskStatusModelTest.php b/tests/units/Model/SubtaskStatusModelTest.php
new file mode 100644
index 00000000..af4c3955
--- /dev/null
+++ b/tests/units/Model/SubtaskStatusModelTest.php
@@ -0,0 +1,123 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskStatusModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskStatusModelTest extends Base
+{
+ public function testToggleStatusWithoutSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($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)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testToggleStatusWithSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($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)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $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(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testCloseAll()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($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)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskStatusModel->closeAll(1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+
+ foreach ($subtasks as $subtask) {
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ }
+ }
+}
diff --git a/tests/units/Model/SubtaskTaskConversionModelTest.php b/tests/units/Model/SubtaskTaskConversionModelTest.php
new file mode 100644
index 00000000..51a623b2
--- /dev/null
+++ b/tests/units/Model/SubtaskTaskConversionModelTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTaskConversionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskTaskConversionModelTest extends Base
+{
+ public function testConvertToTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskConversion = new SubtaskTaskConversionModel($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 = $subtaskConversion->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/SubtaskTest.php b/tests/units/Model/SubtaskTest.php
deleted file mode 100644
index b65ee609..00000000
--- a/tests/units/Model/SubtaskTest.php
+++ /dev/null
@@ -1,388 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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
-{
- public function onSubtaskCreated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
- public function onSubtaskUpdated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertArrayHasKey('changes', $data);
- $this->assertArrayHasKey('user_id', $data['changes']);
- $this->assertArrayHasKey('status', $data['changes']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']);
- $this->assertEquals(1, $data['changes']['user_id']);
- }
-
- public function onSubtaskDeleted($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
- public function testCreation()
- {
- $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(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated'));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
- $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(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['time_estimated']);
- $this->assertEquals(0, $subtask['time_spent']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['position']);
- }
-
- public function testModification()
- {
- $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(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' => 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(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(0, $subtask['time_estimated']);
- $this->assertEquals(0, $subtask['time_spent']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['position']);
- }
-
- public function testRemove()
- {
- $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(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted'));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
-
- $this->assertTrue($s->remove(1));
-
- $subtask = $s->getById(1);
- $this->assertEmpty($subtask);
- }
-
- public function testToggleStatusWithoutSession()
- {
- $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)));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
- }
-
- public function testToggleStatusWithSession()
- {
- $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')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $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(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
- }
-
- public function testCloseAll()
- {
- $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)));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
-
- $this->assertTrue($s->closeAll(1));
-
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
-
- foreach ($subtasks as $subtask) {
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- }
- }
-
- public function testDuplicate()
- {
- $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')));
-
- // We create 2 tasks
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
-
- // We create many subtasks for the first task
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
-
- // We duplicate our subtasks
- $this->assertTrue($s->duplicate(1, 2));
- $subtasks = $s->getAll(2);
-
- $this->assertNotFalse($subtasks);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(2, count($subtasks));
-
- $this->assertEquals('subtask #1', $subtasks[0]['title']);
- $this->assertEquals('subtask #2', $subtasks[1]['title']);
-
- $this->assertEquals(2, $subtasks[0]['task_id']);
- $this->assertEquals(2, $subtasks[1]['task_id']);
-
- $this->assertEquals(5, $subtasks[0]['time_estimated']);
- $this->assertEquals(0, $subtasks[1]['time_estimated']);
-
- $this->assertEquals(0, $subtasks[0]['time_spent']);
- $this->assertEquals(0, $subtasks[1]['time_spent']);
-
- $this->assertEquals(0, $subtasks[0]['status']);
- $this->assertEquals(0, $subtasks[1]['status']);
-
- $this->assertEquals(0, $subtasks[0]['user_id']);
- $this->assertEquals(0, $subtasks[1]['user_id']);
-
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[1]['position']);
- }
-
- public function testChangePosition()
- {
- $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)));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
- $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1)));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(2, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 3, 2));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(3, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(2, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 2, 1));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(1, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 2, 2));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(2, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 1, 3));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(3, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(1, $subtasks[2]['id']);
-
- $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/SubtaskTimeTrackingModelTest.php b/tests/units/Model/SubtaskTimeTrackingModelTest.php
new file mode 100644
index 00000000..8b0fe698
--- /dev/null
+++ b/tests/units/Model/SubtaskTimeTrackingModelTest.php
@@ -0,0 +1,277 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ConfigModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTimeTrackingModel;
+use Kanboard\Model\ProjectModel;
+
+class SubtaskTimeTrackingModelTest extends Base
+{
+ public function testToggleTimer()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_TODO));
+ $this->assertTrue($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_INPROGRESS));
+ $this->assertTrue($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_DONE));
+ }
+
+ public function testToggleTimerWhenFeatureDisabled()
+ {
+ $configModel = new ConfigModel($this->container);
+ $configModel->save(array('subtask_time_tracking' => '0'));
+ $this->container['memoryCache']->flush();
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_TODO));
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_INPROGRESS));
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_DONE));
+ }
+
+ public function testHasTimer()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->hasTimer(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->hasTimer(1, 1));
+ $this->assertFalse($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $this->assertFalse($subtaskTimeTrackingModel->hasTimer(1, 1));
+ }
+
+ public function testGetTimerStatus()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1)));
+
+ // Nothing started
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(0, $subtasks[0]['timer_start_date']);
+ $this->assertFalse($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(0, $subtask['timer_start_date']);
+ $this->assertFalse($subtask['is_timer_started']);
+
+ // Start the clock
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
+ $this->assertTrue($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
+ $this->assertTrue($subtask['is_timer_started']);
+
+ // Stop the clock
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(0, $subtasks[0]['timer_start_date']);
+ $this->assertFalse($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(0, $subtask['timer_start_date']);
+ $this->assertFalse($subtask['is_timer_started']);
+ }
+
+ public function testLogStartTime()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(1, $timesheet);
+ $this->assertNotEmpty($timesheet[0]['start']);
+ $this->assertEmpty($timesheet[0]['end']);
+ $this->assertEquals(1, $timesheet[0]['user_id']);
+ $this->assertEquals(1, $timesheet[0]['subtask_id']);
+ }
+
+ public function testLogStartEnd()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ // No start time
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertEmpty($timesheet);
+
+ // Log start and end time
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ sleep(1);
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(1, $timesheet);
+ $this->assertNotEmpty($timesheet[0]['start']);
+ $this->assertNotEmpty($timesheet[0]['end']);
+ $this->assertEquals(1, $timesheet[0]['user_id']);
+ $this->assertEquals(1, $timesheet[0]['subtask_id']);
+ $this->assertNotEquals($timesheet[0]['start'], $timesheet[0]['end']);
+ }
+
+ public function testCalculateSubtaskTime()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4)));
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
+ $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);
+ }
+
+ public function testUpdateSubtaskTimeSpent()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(2, 1));
+
+ // Fake start time
+ $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(2, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(2, $timesheet);
+ $this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
+ $this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
+ $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(2);
+ $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateTaskTimeTracking()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($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(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
+
+ $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
+ $this->assertEquals(4, $subtaskModel->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
+
+ $this->assertEquals(5, $subtaskModel->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
+
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(1);
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(2);
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(3);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(8, $task['time_spent']);
+
+ $this->assertTrue($subtaskModel->remove(3));
+ $this->assertTrue($subtaskModel->remove(4));
+
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(2);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+}
diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php
deleted file mode 100644
index d5ae62ae..00000000
--- a/tests/units/Model/SubtaskTimeTrackingTest.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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 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)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
-
- $this->assertFalse($st->hasTimer(1, 1));
- $this->assertTrue($st->logStartTime(1, 1));
- $this->assertTrue($st->hasTimer(1, 1));
- $this->assertFalse($st->logStartTime(1, 1));
- $this->assertTrue($st->logEndTime(1, 1));
- $this->assertFalse($st->hasTimer(1, 1));
- }
-
- public function testGetTimerStatus()
- {
- $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);
-
- $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)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1)));
-
- // Nothing started
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(0, $subtasks[0]['timer_start_date']);
- $this->assertFalse($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(0, $subtask['timer_start_date']);
- $this->assertFalse($subtask['is_timer_started']);
-
- // Start the clock
- $this->assertTrue($st->logStartTime(1, 1));
-
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
- $this->assertTrue($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
- $this->assertTrue($subtask['is_timer_started']);
-
- // Stop the clock
- $this->assertTrue($st->logEndTime(1, 1));
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(0, $subtasks[0]['timer_start_date']);
- $this->assertFalse($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(0, $subtask['timer_start_date']);
- $this->assertFalse($subtask['is_timer_started']);
- }
-
- public function testLogStartTime()
- {
- $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)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
-
- $this->assertTrue($st->logStartTime(1, 1));
-
- $timesheet = $st->getUserTimesheet(1);
- $this->assertNotEmpty($timesheet);
- $this->assertCount(1, $timesheet);
- $this->assertNotEmpty($timesheet[0]['start']);
- $this->assertEmpty($timesheet[0]['end']);
- $this->assertEquals(1, $timesheet[0]['user_id']);
- $this->assertEquals(1, $timesheet[0]['subtask_id']);
- }
-
- public function testLogStartEnd()
- {
- $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)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
-
- // No start time
- $this->assertTrue($st->logEndTime(1, 1));
- $timesheet = $st->getUserTimesheet(1);
- $this->assertEmpty($timesheet);
-
- // Log start and end time
- $this->assertTrue($st->logStartTime(1, 1));
- sleep(1);
- $this->assertTrue($st->logEndTime(1, 1));
-
- $timesheet = $st->getUserTimesheet(1);
- $this->assertNotEmpty($timesheet);
- $this->assertCount(1, $timesheet);
- $this->assertNotEmpty($timesheet[0]['start']);
- $this->assertNotEmpty($timesheet[0]['end']);
- $this->assertEquals(1, $timesheet[0]['user_id']);
- $this->assertEquals(1, $timesheet[0]['subtask_id']);
- $this->assertNotEquals($timesheet[0]['start'], $timesheet[0]['end']);
- }
-
- public function testCalculateSubtaskTime()
- {
- $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)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
- $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->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);
- }
-
- public function testUpdateSubtaskTimeSpent()
- {
- $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)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
-
- $this->assertTrue($st->logStartTime(1, 1));
- $this->assertTrue($st->logStartTime(2, 1));
-
- // Fake start time
- $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600));
-
- $this->assertTrue($st->logEndTime(1, 1));
- $this->assertTrue($st->logEndTime(2, 1));
-
- $timesheet = $st->getUserTimesheet(1);
- $this->assertNotEmpty($timesheet);
- $this->assertCount(2, $timesheet);
- $this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
- $this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
-
- $time = $st->calculateSubtaskTime(1);
- $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->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
- }
-
- public function testUpdateTaskTimeTracking()
- {
- $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')));
-
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
- $this->assertEquals(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
-
- $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
- $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
-
- $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
-
- $st->updateTaskTimeTracking(1);
- $st->updateTaskTimeTracking(2);
- $st->updateTaskTimeTracking(3);
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
-
- $task = $tf->getById(3);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(8, $task['time_spent']);
-
- $this->assertTrue($s->remove(3));
- $this->assertTrue($s->remove(4));
-
- $st->updateTaskTimeTracking(2);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(0, $task['time_spent']);
- }
-}
diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php
index cf0be169..4541e07f 100644
--- a/tests/units/Model/SwimlaneTest.php
+++ b/tests/units/Model/SwimlaneTest.php
@@ -40,7 +40,17 @@ class SwimlaneTest extends Base
$this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
$swimlane = $swimlaneModel->getFirstActiveSwimlane(1);
+ $this->assertEquals(0, $swimlane['id']);
+ $this->assertEquals('Default swimlane', $swimlane['name']);
+
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+
+ $swimlane = $swimlaneModel->getFirstActiveSwimlane(1);
$this->assertEquals(2, $swimlane['id']);
+ $this->assertEquals('Swimlane #2', $swimlane['name']);
+
+ $this->assertTrue($swimlaneModel->disable(1, 2));
+ $this->assertNull($swimlaneModel->getFirstActiveSwimlane(1));
}
public function testGetList()
diff --git a/tests/units/Model/TagDuplicationModelTest.php b/tests/units/Model/TagDuplicationModelTest.php
new file mode 100644
index 00000000..0c95c0fd
--- /dev/null
+++ b/tests/units/Model/TagDuplicationModelTest.php
@@ -0,0 +1,31 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TagDuplicationModel;
+use Kanboard\Model\TagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TagDuplicationModelTest extends Base
+{
+ public function testProjectDuplication()
+ {
+ $tagModel = new TagModel($this->container);
+ $tagDuplicationModel = new TagDuplicationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 2'));
+ $this->assertEquals(3, $tagModel->create(1, 'Tag 3'));
+
+ $this->assertTrue($tagDuplicationModel->duplicate(1, 2));
+
+ $tags = $tagModel->getAllByProject(2);
+ $this->assertCount(2, $tags);
+ $this->assertEquals('Tag 2', $tags[0]['name']);
+ $this->assertEquals('Tag 3', $tags[1]['name']);
+ }
+}
diff --git a/tests/units/Model/TagModelTest.php b/tests/units/Model/TagModelTest.php
new file mode 100644
index 00000000..f090ab4a
--- /dev/null
+++ b/tests/units/Model/TagModelTest.php
@@ -0,0 +1,120 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TagModelTest extends Base
+{
+ public function testCreation()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 1'));
+ $this->assertEquals(3, $tagModel->create(1, 'Tag 2'));
+ $this->assertFalse($tagModel->create(0, 'Tag 1'));
+ $this->assertFalse($tagModel->create(1, 'Tag 2'));
+ }
+
+ public function testGetById()
+ {
+ $tagModel = new TagModel($this->container);
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+
+ $tag = $tagModel->getById(1);
+ $this->assertEquals(0, $tag['project_id']);
+ $this->assertEquals('Tag 1', $tag['name']);
+
+ $tag = $tagModel->getById(3);
+ $this->assertEmpty($tag);
+ }
+
+ public function testGetAll()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 2'));
+
+ $tags = $tagModel->getAll();
+ $this->assertCount(2, $tags);
+ $this->assertEquals(0, $tags[0]['project_id']);
+ $this->assertEquals('Tag 1', $tags[0]['name']);
+
+ $this->assertEquals(1, $tags[1]['project_id']);
+ $this->assertEquals('Tag 2', $tags[1]['name']);
+ }
+
+ public function testGetAllByProjectId()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'B'));
+ $this->assertEquals(3, $tagModel->create(1, 'A'));
+
+ $tags = $tagModel->getAllByProject(1);
+ $this->assertCount(2, $tags);
+ $this->assertEquals(1, $tags[0]['project_id']);
+ $this->assertEquals('A', $tags[0]['name']);
+
+ $this->assertEquals(1, $tags[1]['project_id']);
+ $this->assertEquals('B', $tags[1]['name']);
+ }
+
+ public function testGetIdByName()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 1'));
+ $this->assertEquals(3, $tagModel->create(1, 'Tag 3'));
+
+ $this->assertEquals(1, $tagModel->getIdByName(1, 'tag 1'));
+ $this->assertEquals(1, $tagModel->getIdByName(0, 'tag 1'));
+ $this->assertEquals(3, $tagModel->getIdByName(1, 'TaG 3'));
+ }
+
+ public function testFindOrCreateTag()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+
+ $this->assertEquals(2, $tagModel->findOrCreateTag(1, 'Tag 2'));
+ $this->assertEquals(2, $tagModel->findOrCreateTag(1, 'Tag 2'));
+ $this->assertEquals(1, $tagModel->findOrCreateTag(1, 'Tag 1'));
+ }
+
+ public function testRemove()
+ {
+ $tagModel = new TagModel($this->container);
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+
+ $this->assertTrue($tagModel->remove(1));
+ $this->assertFalse($tagModel->remove(1));
+ }
+
+ public function testUpdate()
+ {
+ $tagModel = new TagModel($this->container);
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertTrue($tagModel->update(1, 'Tag Updated'));
+
+ $tag = $tagModel->getById(1);
+ $this->assertEquals(0, $tag['project_id']);
+ $this->assertEquals('Tag Updated', $tag['name']);
+ }
+}
diff --git a/tests/units/Model/TaskCreationModelTest.php b/tests/units/Model/TaskCreationModelTest.php
new file mode 100644
index 00000000..ce9996d9
--- /dev/null
+++ b/tests/units/Model/TaskCreationModelTest.php
@@ -0,0 +1,403 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ConfigModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskCreationModelTest extends Base
+{
+ public function onCreate($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('test', $event_data['task']['title']);
+ }
+
+ public function testNoTitle()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('Untitled', $task['title']);
+ $this->assertEquals(1, $task['project_id']);
+ }
+
+ public function testMinimum()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $finderModel = new TaskFinderModel($this->container);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, array($this, 'onCreate'));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.TaskCreationModelTest::onCreate', $called);
+
+ $task = $finderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('yellow', $task['color_id']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['creator_id']);
+
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals('', $task['description']);
+ $this->assertEquals('', $task['reference']);
+
+ $this->assertEquals(time(), $task['date_creation'], 'Wrong timestamp', 1);
+ $this->assertEquals(time(), $task['date_modification'], 'Wrong timestamp', 1);
+ $this->assertEquals(0, $task['date_due']);
+ $this->assertEquals(0, $task['date_completed']);
+ $this->assertEquals(0, $task['date_started']);
+
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['is_active']);
+ $this->assertEquals(0, $task['score']);
+ }
+
+ public function testColorId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testOwnerId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testCategoryId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testCreatorId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testThatCreatorIsDefined()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testColumnId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ }
+
+ public function testPosition()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ }
+
+ public function testDescription()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testReference()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['reference']);
+ }
+
+ public function testDateDue()
+ {
+ $date = '2014-11-23';
+ $timestamp = strtotime('+2days');
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date)));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $timestamp)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => '')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals($date, date('Y-m-d', $task['date_due']));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(date('Y-m-d 00:00', $timestamp), date('Y-m-d 00:00', $task['date_due']));
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(0, $task['date_due']);
+ }
+
+ public function testDateStarted()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ // Set only a date
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 16:25')));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '11/24/2014 18:25')));
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a timestamp
+ $this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertEquals(time(), $task['date_started'], '', 1);
+
+ // Set empty string
+ $this->assertEquals(5, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '')));
+ $task = $taskFinderModel->getById(5);
+ $this->assertEquals(0, $task['date_started']);
+ }
+
+ public function testTime()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3)));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => '', 'time_spent' => '')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1.5, $task['time_estimated']);
+ $this->assertEquals(2.3, $task['time_spent']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+
+ public function testStripColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ }
+
+ public function testScore()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'score' => '3')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+ $this->assertEquals(3, $task['score']);
+ }
+
+ public function testDefaultColor()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $this->assertTrue($configModel->save(array('default_color' => 'orange')));
+ $this->container['memoryCache']->flush();
+
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('orange', $task['color_id']);
+ }
+
+ public function testDueDateYear2038TimestampBug()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => strtotime('2050-01-10 12:30'))));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('2050-01-10 00:00', date('Y-m-d H:i', $task['date_due']));
+ }
+}
diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php
deleted file mode 100644
index b249bc0b..00000000
--- a/tests/units/Model/TaskCreationTest.php
+++ /dev/null
@@ -1,414 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\ConfigModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskCreationTest extends Base
-{
- public function onCreate($event)
- {
- $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
-
- $event_data = $event->getAll();
- $this->assertNotEmpty($event_data);
- $this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('test', $event_data['title']);
- }
-
- public function testNoProjectId()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayNotHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
- }
-
- public function testNoTitle()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals('Untitled', $task['title']);
- $this->assertEquals(1, $task['project_id']);
- }
-
- public function testMinimum()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.TaskCreationTest::onCreate', $called);
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertNotFalse($task);
-
- $this->assertEquals(1, $task['id']);
- $this->assertEquals('yellow', $task['color_id']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(0, $task['creator_id']);
-
- $this->assertEquals('test', $task['title']);
- $this->assertEquals('', $task['description']);
- $this->assertEquals('', $task['reference']);
-
- $this->assertEquals(time(), $task['date_creation'], 'Wrong timestamp', 1);
- $this->assertEquals(time(), $task['date_modification'], 'Wrong timestamp', 1);
- $this->assertEquals(0, $task['date_due']);
- $this->assertEquals(0, $task['date_completed']);
- $this->assertEquals(0, $task['date_started']);
-
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(0, $task['time_spent']);
-
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(1, $task['is_active']);
- $this->assertEquals(0, $task['score']);
- }
-
- public function testColorId()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals('blue', $task['color_id']);
- }
-
- public function testOwnerId()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['owner_id']);
- }
-
- public function testCategoryId()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['category_id']);
- }
-
- public function testCreatorId()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['creator_id']);
- }
-
- public function testThatCreatorIsDefined()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->container['sessionStorage']->user = array('id' => 1);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
-
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['creator_id']);
- }
-
- public function testColumnId()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- }
-
- public function testPosition()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
-
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- }
-
- public function testDescription()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals('test', $task['description']);
- }
-
- public function testReference()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals('test', $task['reference']);
- }
-
- public function testDateDue()
- {
- $date = '2014-11-23';
- $timestamp = strtotime('+2days');
- $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)));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $timestamp)));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => '')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals($date, date('Y-m-d', $task['date_due']));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(date('Y-m-d 00:00', $timestamp), date('Y-m-d 00:00', $task['date_due']));
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(0, $task['date_due']);
- }
-
- public function testDateStarted()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
-
- // Set only a date
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 16:25')));
-
- $task = $tf->getById(2);
- $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '11/24/2014 18:25')));
-
- $task = $tf->getById(3);
- $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a timestamp
- $this->assertEquals(4, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));
-
- $task = $tf->getById(4);
- $this->assertEquals(time(), $task['date_started'], '', 1);
-
- // Set empty string
- $this->assertEquals(5, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '')));
- $task = $tf->getById(5);
- $this->assertEquals(0, $task['date_started']);
- }
-
- public function testTime()
- {
- $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->assertEquals(1, $task['id']);
- $this->assertEquals(1.5, $task['time_estimated']);
- $this->assertEquals(2.3, $task['time_spent']);
- }
-
- public function testStripColumn()
- {
- $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);
- }
-
- public function testScore()
- {
- $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')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertNotFalse($task);
- $this->assertEquals(3, $task['score']);
- }
-
- public function testDefaultColor()
- {
- $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')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('yellow', $task['color_id']);
-
- $this->assertTrue($c->save(array('default_color' => 'orange')));
- $this->container['memoryCache']->flush();
-
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test2')));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals('orange', $task['color_id']);
- }
-
- public function testDueDateYear2038TimestampBug()
- {
- $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'))));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('2050-01-10 00:00', date('Y-m-d H:i', $task['date_due']));
- }
-}
diff --git a/tests/units/Model/TaskDuplicationModelTest.php b/tests/units/Model/TaskDuplicationModelTest.php
new file mode 100644
index 00000000..1c42b6a1
--- /dev/null
+++ b/tests/units/Model/TaskDuplicationModelTest.php
@@ -0,0 +1,142 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskDuplicationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\TaskTagModel;
+
+class TaskDuplicationModelTest extends Base
+{
+ public function testThatDuplicateDefineCreator()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(0, $task['creator_id']);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ // We duplicate our task
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testDuplicateSameProject()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create a task and a project
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ // Some categories
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'column_id' => 3,
+ 'owner_id' => 1,
+ 'category_id' => 2,
+ 'time_spent' => 4.4
+ )));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(4.4, $task['time_spent']);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ // We duplicate our task
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $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']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+
+ public function testDuplicateSameProjectWithTags()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'tags' => array('T1', 'T2')
+ )));
+
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ $tags = $taskTagModel->getList(2);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(1, $tags);
+ $this->assertArrayHasKey(2, $tags);
+ }
+
+ public function testDuplicateSameProjectWithPriority()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'priority' => 2
+ )));
+
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['priority']);
+ }
+}
diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php
deleted file mode 100644
index 79b75e54..00000000
--- a/tests/units/Model/TaskDuplicationTest.php
+++ /dev/null
@@ -1,700 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Core\DateParser;
-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 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)));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(0, $task['creator_id']);
-
- $this->container['sessionStorage']->user = array('id' => 1);
-
- // We duplicate our task
- $this->assertEquals(2, $td->duplicate(1));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['creator_id']);
- }
-
- public function testDuplicateSameProject()
- {
- $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')));
-
- // Some categories
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
- $this->assertTrue($c->exists(1));
- $this->assertTrue($c->exists(2));
-
- $this->assertEquals(
- 1,
- $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2, 'time_spent' => 4.4)
- ));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals(4.4, $task['time_spent']);
-
- $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(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(TaskModel::STATUS_OPEN, $task['is_active']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- $this->assertEquals('test', $task['title']);
- $this->assertEquals(0, $task['time_spent']);
- }
-
- public function testDuplicateAnotherProject()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertTrue($c->exists(1));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
-
- $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(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(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithCategory()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
- $this->assertTrue($c->exists(1));
- $this->assertTrue($c->exists(2));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedCategory()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
- $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 2)));
- $this->assertTrue($c->exists(1));
- $this->assertTrue($c->exists(2));
- $this->assertTrue($c->exists(3));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
-
- // We duplicate our task to the 2nd project with no category
- $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, 0));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['category_id']);
-
- // We duplicate our task to the 2nd project with a different category
- $this->assertEquals(3, $td->duplicateToProject(1, 2, null, null, 3));
-
- // Check the values of the duplicated task
- $task = $tf->getById(3);
- $this->assertNotEmpty($task);
- $this->assertEquals(3, $task['category_id']);
- }
-
- public function testDuplicateAnotherProjectWithSwimlane()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(2, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithoutSwimlane()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedSwimlane()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2, 3));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(3, $task['swimlane_id']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedColumn()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2)));
-
- // We duplicate our task to the 2nd project with a different column
- $this->assertEquals(2, $td->duplicateToProject(1, 2, null, 7));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(7, $task['column_id']);
- }
-
- public function testDuplicateAnotherProjectWithUser()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
-
- // We create a new user for our project
- $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));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(3, $td->duplicateToProject(1, 2));
-
- // Check the values of the duplicated task
- $task = $tf->getById(3);
- $this->assertNotEmpty($task);
- $this->assertEquals(2, $task['position']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(2, $task['owner_id']);
- $this->assertEquals(2, $task['project_id']);
-
- // We duplicate a task with a not allowed user
- $this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
- $this->assertEquals(5, $td->duplicateToProject(4, 2));
-
- $task = $tf->getById(5);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(5, $task['column_id']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedUser()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
- $this->assertTrue($pr->addUser(2, 1, Role::PROJECT_MEMBER));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, null, 1));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
- }
-
- public function onMoveProject($event)
- {
- $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
-
- $event_data = $event->getAll();
- $this->assertNotEmpty($event_data);
- $this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('test', $event_data['title']);
- }
-
- public function testMoveAnotherProject()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // 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(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(TaskModel::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called);
-
- // Check the values of the moved task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(5, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveAnotherProjectWithCategory()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
- $this->assertTrue($c->exists(1));
- $this->assertTrue($c->exists(2));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
-
- // We move our task to the 2nd project
- $this->assertTrue($td->moveToProject(1, 2));
-
- // Check the values of the duplicated task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveAnotherProjectWithUser()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a new user for our project
- $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));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
-
- // We move our task to the 2nd project
- $this->assertTrue($td->moveToProject(1, 2));
-
- // Check the values of the moved task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['owner_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(6, $task['column_id']);
- }
-
- public function testMoveAnotherProjectWithForbiddenUser()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a new user for our project
- $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));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
-
- // We move our task to the 2nd project
- $this->assertTrue($td->moveToProject(1, 2));
-
- // Check the values of the moved task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(6, $task['column_id']);
- }
-
- public function testMoveAnotherProjectWithSwimlane()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
-
- // We move our task to the 2nd project
- $this->assertTrue($td->moveToProject(1, 2));
-
- // Check the values of the moved task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(2, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveAnotherProjectWithoutSwimlane()
- {
- $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')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
-
- // We move our task to the 2nd project
- $this->assertTrue($td->moveToProject(1, 2));
-
- // Check the values of the moved task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(0, $task['swimlane_id']);
- $this->assertEquals(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testCalculateRecurringTaskDueDate()
- {
- $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' => 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' => 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' => 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' => 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' => 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' => 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' => 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 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')));
-
- $this->assertEquals(1, $tc->create(array(
- 'title' => 'test',
- 'project_id' => 1,
- 'date_due' => 1436561776,
- 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
- 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
- 'recurrence_factor' => 2,
- 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS,
- 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE,
- )));
-
- $this->assertEquals(2, $td->duplicateRecurringTask(1));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
- $this->assertEquals(2, $task['recurrence_child']);
- $this->assertEquals(1436486400, $task['date_due'], '', 2);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']);
- $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
- $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
- $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
- $this->assertEquals(1, $task['recurrence_parent']);
- $this->assertEquals(2, $task['recurrence_factor']);
- $this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2);
- }
-}
diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileModelTest.php
index 2faee95c..de12553f 100644
--- a/tests/units/Model/TaskFileTest.php
+++ b/tests/units/Model/TaskFileModelTest.php
@@ -6,7 +6,7 @@ use Kanboard\Model\TaskFileModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
-class TaskFileTest extends Base
+class TaskFileModelTest extends Base
{
public function testCreation()
{
@@ -442,4 +442,17 @@ class TaskFileTest extends Base
$this->assertTrue($fileModel->removeAll(1));
}
+
+ public function testGetProjectId()
+ {
+ $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')));
+ $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foobar', 10));
+ $this->assertEquals(1, $fileModel->getProjectId(1));
+ $this->assertEquals(0, $fileModel->getProjectId(2));
+ }
}
diff --git a/tests/units/Model/TaskFinderModelTest.php b/tests/units/Model/TaskFinderModelTest.php
new file mode 100644
index 00000000..a9f018ff
--- /dev/null
+++ b/tests/units/Model/TaskFinderModelTest.php
@@ -0,0 +1,203 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+
+class TaskFinderModelTest extends Base
+{
+ public function testGetDetails()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new \Kanboard\Model\CategoryModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $categoryModel->create(array('project_id' => 1, 'name' => 'C1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'project_id' => 1,
+ 'title' => 'Task #1',
+ 'reference' => 'test',
+ 'description' => 'desc',
+ 'owner_id' => 1,
+ 'category_id' => 1,
+ )));
+
+ $task = $taskFinderModel->getDetails(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['reference']);
+ $this->assertEquals('Task #1', $task['title']);
+ $this->assertEquals('desc', $task['description']);
+ $this->assertEquals(time(), $task['date_creation'], 'Delta', 1);
+ $this->assertEquals(time(), $task['date_modification'], 'Delta', 1);
+ $this->assertEquals(time(), $task['date_moved'], 'Delta', 1);
+ $this->assertEquals(0, $task['date_completed']);
+ $this->assertEquals(0, $task['date_due']);
+ $this->assertEquals(0, $task['date_started']);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ $this->assertEquals('yellow', $task['color_id']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(0, $task['creator_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']);
+ $this->assertEquals(0, $task['score']);
+ $this->assertEquals(1, $task['category_id']);
+ $this->assertEquals(0, $task['priority']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(TaskModel::RECURRING_STATUS_NONE, $task['recurrence_status']);
+ $this->assertEquals(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $task['recurrence_trigger']);
+ $this->assertEquals(0, $task['recurrence_factor']);
+ $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
+ $this->assertEquals(TaskModel::RECURRING_BASEDATE_DUEDATE, $task['recurrence_basedate']);
+ $this->assertEquals(0, $task['recurrence_parent']);
+ $this->assertEquals(0, $task['recurrence_child']);
+ $this->assertEquals('C1', $task['category_name']);
+ $this->assertNull($task['swimlane_name']);
+ $this->assertEquals('Default swimlane', $task['default_swimlane']);
+ $this->assertEquals('Project #1', $task['project_name']);
+ $this->assertEquals('Backlog', $task['column_title']);
+ $this->assertEquals('admin', $task['assignee_username']);
+ $this->assertEquals('', $task['assignee_name']);
+ $this->assertEquals('', $task['creator_username']);
+ $this->assertEquals('', $task['creator_name']);
+ }
+
+ public function testGetTasksForDashboardWithHiddenColumn()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $columnModel = new ColumnModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(2, $tasks);
+
+ $this->assertTrue($columnModel->update(2, 'Test', 0, '', 1));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+
+ $this->assertTrue($columnModel->update(2, 'Test', 0, '', 0));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(2, $tasks);
+ }
+
+ public function testGetOverdueTasks()
+ {
+ $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(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasks();
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ }
+
+ public function testGetOverdueTasksByProject()
+ {
+ $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->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasksByProject(1);
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ }
+
+ public function testGetOverdueTasksByUser()
+ {
+ $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->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasksByUser(1);
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(2, $tasks);
+
+ $this->assertEquals(1, $tasks[0]['id']);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ $this->assertEquals(1, $tasks[0]['owner_id']);
+ $this->assertEquals(1, $tasks[0]['project_id']);
+ $this->assertEquals('Project #1', $tasks[0]['project_name']);
+ $this->assertEquals('admin', $tasks[0]['assignee_username']);
+ $this->assertEquals('', $tasks[0]['assignee_name']);
+
+ $this->assertEquals('Task #2', $tasks[1]['title']);
+ }
+
+ public function testCountByProject()
+ {
+ $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->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 2)));
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ $this->assertEquals(2, $taskFinderModel->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/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php
deleted file mode 100644
index 46792baf..00000000
--- a/tests/units/Model/TaskFinderTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskFinderTest extends Base
-{
- public function testGetOverdueTasks()
- {
- $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'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #3', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasks();
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(1, $tasks);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
- public function testGetOverdueTasksByProject()
- {
- $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')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasksByProject(1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(1, $tasks);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
- public function testGetOverdueTasksByUser()
- {
- $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')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasksByUser(1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(2, $tasks);
-
- $this->assertEquals(1, $tasks[0]['id']);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- $this->assertEquals(1, $tasks[0]['owner_id']);
- $this->assertEquals(1, $tasks[0]['project_id']);
- $this->assertEquals('Project #1', $tasks[0]['project_name']);
- $this->assertEquals('admin', $tasks[0]['assignee_username']);
- $this->assertEquals('', $tasks[0]['assignee_name']);
-
- $this->assertEquals('Task #2', $tasks[1]['title']);
- }
-
- public function testCountByProject()
- {
- $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')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2)));
-
- $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/TaskLinkModelTest.php b/tests/units/Model/TaskLinkModelTest.php
new file mode 100644
index 00000000..01a7888b
--- /dev/null
+++ b/tests/units/Model/TaskLinkModelTest.php
@@ -0,0 +1,239 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskLinkModelTest extends Base
+{
+ public function testGeyById()
+ {
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 6));
+
+ $taskLink = $taskLinkModel->getById(1);
+ $this->assertEquals(1, $taskLink['id']);
+ $this->assertEquals(1, $taskLink['task_id']);
+ $this->assertEquals(2, $taskLink['opposite_task_id']);
+ $this->assertEquals(6, $taskLink['link_id']);
+ $this->assertEquals(7, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a child of', $taskLink['label']);
+
+ $taskLink = $taskLinkModel->getById(2);
+ $this->assertEquals(2, $taskLink['id']);
+ $this->assertEquals(2, $taskLink['task_id']);
+ $this->assertEquals(1, $taskLink['opposite_task_id']);
+ $this->assertEquals(7, $taskLink['link_id']);
+ $this->assertEquals(6, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a parent of', $taskLink['label']);
+ }
+
+ // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
+ public function testGetTaskWithMultipleMilestoneLink()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($taskLinkModel->create(1, 2, 9));
+ $this->assertNotFalse($taskLinkModel->create(1, 3, 9));
+
+ $task = $taskFinderModel->getExtendedQuery()->findOne();
+ $this->assertNotEmpty($task);
+ }
+
+ public function testCreateTaskLinkWithNoOpposite()
+ {
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $task_link = $taskLinkModel->getById(1);
+ $this->assertNotEmpty($task_link);
+ $this->assertEquals(1, $task_link['id']);
+ $this->assertEquals(1, $task_link['task_id']);
+ $this->assertEquals(2, $task_link['opposite_task_id']);
+ $this->assertEquals(1, $task_link['link_id']);
+
+ $opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link);
+ $this->assertNotEmpty($opposite_task_link);
+ $this->assertEquals(2, $opposite_task_link['id']);
+ $this->assertEquals(2, $opposite_task_link['task_id']);
+ $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
+ $this->assertEquals(1, $opposite_task_link['link_id']);
+ }
+
+ public function testCreateTaskLinkWithOpposite()
+ {
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('blocks', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is blocked by', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $task_link = $taskLinkModel->getById(1);
+ $this->assertNotEmpty($task_link);
+ $this->assertEquals(1, $task_link['id']);
+ $this->assertEquals(1, $task_link['task_id']);
+ $this->assertEquals(2, $task_link['opposite_task_id']);
+ $this->assertEquals(2, $task_link['link_id']);
+
+ $opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link);
+ $this->assertNotEmpty($opposite_task_link);
+ $this->assertEquals(2, $opposite_task_link['id']);
+ $this->assertEquals(2, $opposite_task_link['task_id']);
+ $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
+ $this->assertEquals(3, $opposite_task_link['link_id']);
+ }
+
+ public function testGroupByLabel()
+ {
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($taskLinkModel->create(1, 2, 2));
+ $this->assertNotFalse($taskLinkModel->create(1, 3, 2));
+
+ $links = $taskLinkModel->getAllGroupedByLabel(1);
+ $this->assertCount(1, $links);
+ $this->assertArrayHasKey('blocks', $links);
+ $this->assertCount(2, $links['blocks']);
+ $this->assertEquals('test', $links['blocks'][0]['project_name']);
+ $this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
+ $this->assertEquals('blocks', $links['blocks'][0]['label']);
+ }
+
+ public function testUpdate()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 5));
+ $this->assertTrue($taskLinkModel->update(1, 1, 3, 11));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is fixed by', $links[0]['label']);
+ $this->assertEquals('C', $links[0]['title']);
+ $this->assertEquals(3, $links[0]['task_id']);
+
+ $links = $taskLinkModel->getAll(2);
+ $this->assertEmpty($links);
+
+ $links = $taskLinkModel->getAll(3);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('fixes', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ }
+
+ public function testRemove()
+ {
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+
+ $this->assertTrue($taskLinkModel->remove($links[0]['id']));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertEmpty($links);
+ $links = $taskLinkModel->getAll(2);
+ $this->assertEmpty($links);
+ }
+
+ public function testGetProjectId()
+ {
+ $taskLinkModel = new TaskLinkModel($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' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $this->assertEquals(1, $taskLinkModel->getProjectId(1));
+ $this->assertEquals(0, $taskLinkModel->getProjectId(42));
+ }
+}
diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php
deleted file mode 100644
index bc574731..00000000
--- a/tests/units/Model/TaskLinkTest.php
+++ /dev/null
@@ -1,196 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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 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')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertNotFalse($tl->create(1, 2, 9));
- $this->assertNotFalse($tl->create(1, 3, 9));
-
- $task = $tf->getExtendedQuery()->findOne();
- $this->assertNotEmpty($task);
- }
-
- public function testCreateTaskLinkWithNoOpposite()
- {
- $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')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(1, $tl->create(1, 2, 1));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('relates to', $links[0]['label']);
- $this->assertEquals('B', $links[0]['title']);
- $this->assertEquals(2, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $links = $tl->getAll(2);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('relates to', $links[0]['label']);
- $this->assertEquals('A', $links[0]['title']);
- $this->assertEquals(1, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $task_link = $tl->getById(1);
- $this->assertNotEmpty($task_link);
- $this->assertEquals(1, $task_link['id']);
- $this->assertEquals(1, $task_link['task_id']);
- $this->assertEquals(2, $task_link['opposite_task_id']);
- $this->assertEquals(1, $task_link['link_id']);
-
- $opposite_task_link = $tl->getOppositeTaskLink($task_link);
- $this->assertNotEmpty($opposite_task_link);
- $this->assertEquals(2, $opposite_task_link['id']);
- $this->assertEquals(2, $opposite_task_link['task_id']);
- $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
- $this->assertEquals(1, $opposite_task_link['link_id']);
- }
-
- public function testCreateTaskLinkWithOpposite()
- {
- $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')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(1, $tl->create(1, 2, 2));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('blocks', $links[0]['label']);
- $this->assertEquals('B', $links[0]['title']);
- $this->assertEquals(2, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $links = $tl->getAll(2);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('is blocked by', $links[0]['label']);
- $this->assertEquals('A', $links[0]['title']);
- $this->assertEquals(1, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $task_link = $tl->getById(1);
- $this->assertNotEmpty($task_link);
- $this->assertEquals(1, $task_link['id']);
- $this->assertEquals(1, $task_link['task_id']);
- $this->assertEquals(2, $task_link['opposite_task_id']);
- $this->assertEquals(2, $task_link['link_id']);
-
- $opposite_task_link = $tl->getOppositeTaskLink($task_link);
- $this->assertNotEmpty($opposite_task_link);
- $this->assertEquals(2, $opposite_task_link['id']);
- $this->assertEquals(2, $opposite_task_link['task_id']);
- $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
- $this->assertEquals(3, $opposite_task_link['link_id']);
- }
-
- public function testGroupByLabel()
- {
- $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')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertNotFalse($tl->create(1, 2, 2));
- $this->assertNotFalse($tl->create(1, 3, 2));
-
- $links = $tl->getAllGroupedByLabel(1);
- $this->assertCount(1, $links);
- $this->assertArrayHasKey('blocks', $links);
- $this->assertCount(2, $links['blocks']);
- $this->assertEquals('test', $links['blocks'][0]['project_name']);
- $this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
- $this->assertEquals('blocks', $links['blocks'][0]['label']);
- }
-
- public function testUpdate()
- {
- $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')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 2, 'title' => 'B')));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertEquals(1, $tl->create(1, 2, 5));
- $this->assertTrue($tl->update(1, 1, 3, 11));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('is fixed by', $links[0]['label']);
- $this->assertEquals('C', $links[0]['title']);
- $this->assertEquals(3, $links[0]['task_id']);
-
- $links = $tl->getAll(2);
- $this->assertEmpty($links);
-
- $links = $tl->getAll(3);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('fixes', $links[0]['label']);
- $this->assertEquals('A', $links[0]['title']);
- $this->assertEquals(1, $links[0]['task_id']);
- }
-
- public function testRemove()
- {
- $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')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(1, $tl->create(1, 2, 2));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $links = $tl->getAll(2);
- $this->assertNotEmpty($links);
-
- $this->assertTrue($tl->remove($links[0]['id']));
-
- $links = $tl->getAll(1);
- $this->assertEmpty($links);
- $links = $tl->getAll(2);
- $this->assertEmpty($links);
- }
-}
diff --git a/tests/units/Model/TaskModelTest.php b/tests/units/Model/TaskModelTest.php
new file mode 100644
index 00000000..e42b5ae6
--- /dev/null
+++ b/tests/units/Model/TaskModelTest.php
@@ -0,0 +1,30 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskModelTest extends Base
+{
+ public function testRemove()
+ {
+ $taskModel = new TaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+
+ $this->assertTrue($taskModel->remove(1));
+ $this->assertFalse($taskModel->remove(1234));
+ }
+
+ public function testGetTaskIdFromText()
+ {
+ $taskModel = new TaskModel($this->container);
+ $this->assertEquals(123, $taskModel->getTaskIdFromText('My task #123'));
+ $this->assertEquals(0, $taskModel->getTaskIdFromText('My task 123'));
+ }
+}
diff --git a/tests/units/Model/TaskModificationModelTest.php b/tests/units/Model/TaskModificationModelTest.php
new file mode 100644
index 00000000..f70561b3
--- /dev/null
+++ b/tests/units/Model/TaskModificationModelTest.php
@@ -0,0 +1,323 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskTagModel;
+
+class TaskModificationModelTest extends Base
+{
+ public function onCreateUpdate($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('After', $event_data['task']['title']);
+ $this->assertEquals('After', $event_data['changes']['title']);
+ }
+
+ public function onUpdate($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('After', $event_data['task']['title']);
+ }
+
+ public function onAssigneeChange($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(1, $event_data['changes']['owner_id']);
+ }
+
+ public function testThatNoEventAreFiredWhenNoChanges()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'test')));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testChangeTitle()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Before', 'project_id' => 1)));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'After')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.TaskModificationModelTest::onCreateUpdate', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.TaskModificationModelTest::onUpdate', $called);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('After', $task['title']);
+ }
+
+ public function testChangeAssignee()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['owner_id']);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'owner_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.TaskModificationModelTest::onAssigneeChange', $called);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testChangeDescription()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('', $task['description']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'description' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testChangeCategory()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['category_id']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'category_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testChangeColor()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'color_id' => 'blue')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testChangeScore()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['score']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'score' => 13)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(13, $task['score']);
+ }
+
+ public function testChangeDueDate()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['date_due']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_due' => '2014-11-24')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_due']));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_due' => time())));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_due']));
+ }
+
+ public function testChangeStartedDate()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['date_started']);
+
+ // Set only a date
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => '2014-11-24')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => '2014-11-24 16:25')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => '11/24/2014 18:25')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a timestamp
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => time())));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(time(), $task['date_started'], '', 1);
+ }
+
+ public function testChangeTimeEstimated()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['time_estimated']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'time_estimated' => 13.3)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(13.3, $task['time_estimated']);
+ }
+
+ public function testChangeTimeSpent()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['time_spent']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'time_spent' => 13.3)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(13.3, $task['time_spent']);
+ }
+
+ public function testChangeTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('tag1', 'tag2'))));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'tags' => array('tag2'))));
+
+ $tags = $taskTagModel->getList(1);
+ $this->assertEquals(array(2 => 'tag2'), $tags);
+ }
+
+ public function testRemoveAllTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test1', 'project_id' => 1, 'tags' => array('tag1', 'tag2'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test2', 'project_id' => 1, 'tags' => array('tag1', 'tag2'))));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1)));
+ $tags = $taskTagModel->getList(1);
+ $this->assertEquals(array(1 => 'tag1', 2 => 'tag2'), $tags);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'tags' => array())));
+ $tags = $taskTagModel->getList(1);
+ $this->assertEquals(array(), $tags);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 2, 'tags' => array(''))));
+ $tags = $taskTagModel->getList(2);
+ $this->assertEquals(array(), $tags);
+ }
+}
diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php
deleted file mode 100644
index a8ace25a..00000000
--- a/tests/units/Model/TaskModificationTest.php
+++ /dev/null
@@ -1,283 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskModificationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskModificationTest extends Base
-{
- public function onCreateUpdate($event)
- {
- $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
-
- $event_data = $event->getAll();
- $this->assertNotEmpty($event_data);
- $this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('Task #1', $event_data['title']);
- }
-
- public function onUpdate($event)
- {
- $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
-
- $event_data = $event->getAll();
- $this->assertNotEmpty($event_data);
- $this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals('Task #1', $event_data['title']);
- }
-
- public function onAssigneeChange($event)
- {
- $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
-
- $event_data = $event->getAll();
- $this->assertNotEmpty($event_data);
- $this->assertEquals(1, $event_data['task_id']);
- $this->assertEquals(1, $event_data['owner_id']);
- }
-
- public function testThatNoEventAreFiredWhenNoChanges()
- {
- $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(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')));
-
- $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
- }
-
- public function testChangeTitle()
- {
- $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(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(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']);
- }
-
- public function testChangeAssignee()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['owner_id']);
-
- $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(TaskModel::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called);
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['owner_id']);
- }
-
- public function testChangeDescription()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals('', $task['description']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'description' => 'test')));
-
- $task = $tf->getById(1);
- $this->assertEquals('test', $task['description']);
- }
-
- public function testChangeCategory()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['category_id']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'category_id' => 1)));
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['category_id']);
- }
-
- public function testChangeColor()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals('yellow', $task['color_id']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'color_id' => 'blue')));
-
- $task = $tf->getById(1);
- $this->assertEquals('blue', $task['color_id']);
- }
-
- public function testChangeScore()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['score']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'score' => 13)));
-
- $task = $tf->getById(1);
- $this->assertEquals(13, $task['score']);
- }
-
- public function testChangeDueDate()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['date_due']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'date_due' => '2014-11-24')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_due']));
-
- $this->assertTrue($tm->update(array('id' => 1, 'date_due' => time())));
-
- $task = $tf->getById(1);
- $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_due']));
- }
-
- public function testChangeStartedDate()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['date_started']);
-
- // Set only a date
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24 16:25')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '11/24/2014 18:25')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a timestamp
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => time())));
-
- $task = $tf->getById(1);
- $this->assertEquals(time(), $task['date_started'], '', 1);
- }
-
- public function testChangeTimeEstimated()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['time_estimated']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'time_estimated' => 13.3)));
-
- $task = $tf->getById(1);
- $this->assertEquals(13.3, $task['time_estimated']);
- }
-
- public function testChangeTimeSpent()
- {
- $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)));
-
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['time_spent']);
-
- $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 13.3)));
-
- $task = $tf->getById(1);
- $this->assertEquals(13.3, $task['time_spent']);
- }
-}
diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionModelTest.php
index 7ab6950e..03caf7ed 100644
--- a/tests/units/Model/TaskPositionTest.php
+++ b/tests/units/Model/TaskPositionModelTest.php
@@ -11,57 +11,57 @@ use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\SwimlaneModel;
-class TaskPositionTest extends Base
+class TaskPositionModelTest extends Base
{
public function testGetTaskProgression()
{
- $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);
+ $taskModel = new TaskModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = 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)));
- $this->assertEquals(0, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(0, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 2, 1));
- $this->assertEquals(25, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1));
+ $this->assertEquals(25, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 3, 1));
- $this->assertEquals(50, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1));
+ $this->assertEquals(50, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 4, 1));
- $this->assertEquals(75, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 4, 1));
+ $this->assertEquals(75, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($ts->close(1));
- $this->assertEquals(100, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskStatusModel->close(1));
+ $this->assertEquals(100, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
}
public function testMoveTaskToWrongPosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $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' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 0
- $this->assertFalse($tp->movePosition(1, 1, 3, 0));
+ $this->assertFalse($taskPositionModel->movePosition(1, 1, 3, 0));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
@@ -69,26 +69,26 @@ class TaskPositionTest extends Base
public function testMoveTaskToGreaterPosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $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' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 42
- $this->assertTrue($tp->movePosition(1, 1, 1, 42));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 42));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -96,26 +96,26 @@ class TaskPositionTest extends Base
public function testMoveTaskToEmptyColumn()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $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' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 1 to the column 3
- $this->assertTrue($tp->movePosition(1, 1, 3, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -123,62 +123,62 @@ class TaskPositionTest extends Base
public function testMoveTaskToAnotherColumn()
{
- $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)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(7, $tc->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
- $this->assertEquals(8, $tc->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $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(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(6, $taskCreationModel->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(7, $taskCreationModel->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
+ $this->assertEquals(8, $taskCreationModel->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
// We move the task 3 to the column 3
- $this->assertTrue($tp->movePosition(1, 3, 3, 2));
+ $this->assertTrue($taskPositionModel->movePosition(1, 3, 3, 2));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(6);
+ $task = $taskFinderModel->getById(6);
$this->assertEquals(6, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(7);
+ $task = $taskFinderModel->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(8);
+ $task = $taskFinderModel->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -186,37 +186,37 @@ class TaskPositionTest extends Base
public function testMoveTaskTop()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = 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)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
// Move the last task to the top
- $this->assertTrue($tp->movePosition(1, 4, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 4, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -224,37 +224,37 @@ class TaskPositionTest extends Base
public function testMoveTaskBottom()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = 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)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
// Move the first task to the bottom
- $this->assertTrue($tp->movePosition(1, 1, 1, 4));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 4));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -262,12 +262,12 @@ class TaskPositionTest extends Base
public function testMovePosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$counter = 1;
$task_per_column = 5;
@@ -280,240 +280,240 @@ class TaskPositionTest extends Base
'owner_id' => 0,
);
- $this->assertEquals($counter, $tc->create($task));
+ $this->assertEquals($counter, $taskCreationModel->create($task));
- $task = $tf->getById($counter);
+ $task = $taskFinderModel->getById($counter);
$this->assertNotEmpty($task);
$this->assertEquals($i, $task['position']);
}
}
// We move task id #4, column 1, position 4 to the column 2, position 3
- $this->assertTrue($tp->movePosition(1, 4, 2, 3));
+ $this->assertTrue($taskPositionModel->movePosition(1, 4, 2, 3));
// We check the new position of the task
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// The tasks before have the correct position
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(7);
+ $task = $taskFinderModel->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
// The tasks after have the correct position
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(8);
+ $task = $taskFinderModel->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(4, $task['position']);
// The number of tasks per column
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 4));
// We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
- $this->assertTrue($tp->movePosition(1, 1, 4, $task_per_column + 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 4, $task_per_column + 1));
// We check the new position of the task
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals($task_per_column + 1, $task['position']);
// The tasks before have the correct position
- $task = $tf->getById(20);
+ $task = $taskFinderModel->getById(20);
$this->assertEquals(20, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals($task_per_column, $task['position']);
// The tasks after have the correct position
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
// The number of tasks per column
- $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 2, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// Test wrong position number
- $this->assertFalse($tp->movePosition(1, 2, 3, 0));
- $this->assertFalse($tp->movePosition(1, 2, 3, -2));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 3, 0));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 3, -2));
// Wrong column
- $this->assertFalse($tp->movePosition(1, 2, 22, 2));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 22, 2));
// Test position greater than the last position
- $this->assertTrue($tp->movePosition(1, 11, 1, 22));
+ $this->assertTrue($taskPositionModel->movePosition(1, 11, 1, 22));
- $task = $tf->getById(11);
+ $task = $taskFinderModel->getById(11);
$this->assertEquals(11, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
+ $this->assertEquals($taskFinderModel->countByColumnId(1, 1), $task['position']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
+ $this->assertEquals($taskFinderModel->countByColumnId(1, 1) - 1, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// Test moving task to position 1
- $this->assertTrue($tp->movePosition(1, 14, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 14, 1, 1));
- $task = $tf->getById(14);
+ $task = $taskFinderModel->getById(14);
$this->assertEquals(14, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 2, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
}
public function testMoveTaskSwimlane()
{
- $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')));
- $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' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 1)));
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'test 1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 1)));
// Move the task to the swimlane
- $this->assertTrue($tp->movePosition(1, 1, 2, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
// Move the task to the swimlane
- $this->assertTrue($tp->movePosition(1, 2, 2, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 2, 2, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
// Move the task 5 to the last column
- $this->assertTrue($tp->movePosition(1, 5, 4, 1, 0));
+ $this->assertTrue($taskPositionModel->movePosition(1, 5, 4, 1, 0));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -522,73 +522,73 @@ class TaskPositionTest extends Base
public function testEvents()
{
- $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);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = 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')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'test 1')));
- $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->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
$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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionModelTest::onMoveColumn', $called);
$this->assertEquals(1, count($called));
// We move the task 1 to the position 2
- $this->assertTrue($tp->movePosition(1, 1, 2, 2));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionModelTest::onMovePosition', $called);
$this->assertEquals(2, count($called));
// Move to another swimlane
- $this->assertTrue($tp->movePosition(1, 1, 3, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1, 1));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['swimlane_id']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$this->assertEquals(0, $task['swimlane_id']);
$called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionModelTest::onMoveSwimlane', $called);
$this->assertEquals(3, count($called));
}
diff --git a/tests/units/Model/TaskProjectDuplicationModelTest.php b/tests/units/Model/TaskProjectDuplicationModelTest.php
new file mode 100644
index 00000000..9ff33bc1
--- /dev/null
+++ b/tests/units/Model/TaskProjectDuplicationModelTest.php
@@ -0,0 +1,377 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskProjectDuplicationModel;
+use Kanboard\Model\TaskTagModel;
+use Kanboard\Model\UserModel;
+
+class TaskProjectDuplicationModelTest extends Base
+{
+ public function testDuplicateAnotherProject()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($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' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertTrue($categoryModel->exists(1));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'owner_id' => 1,
+ 'category_id' => 1,
+ 'priority' => 3,
+ )));
+
+ $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, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(3, $task['priority']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithCategory()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedCategory()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 2)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+ $this->assertTrue($categoryModel->exists(3));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project with no category
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 0));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['category_id']);
+
+ // We duplicate our task to the 2nd project with a different category
+ $this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 3));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['category_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithSwimlane()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(2, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithoutSwimlane()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedSwimlane()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, 3));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['swimlane_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedColumn()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2)));
+
+ // We duplicate our task to the 2nd project with a different column
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, 7));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(7, $task['column_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithUser()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+
+ // We create a new user for our project
+ $user = new UserModel($this->container);
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+
+ // We duplicate a task with a not allowed user
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
+ $this->assertEquals(5, $taskProjectDuplicationModel->duplicateToProject(4, 2));
+
+ $task = $taskFinderModel->getById(5);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedUser()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, null, 1));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithDifferentTags()
+ {
+ $taskProjectMoveModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $tagModel = new TagModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create our tags for each projects
+ $this->assertEquals(1, $tagModel->create(1, 'T1'));
+ $this->assertEquals(2, $tagModel->create(1, 'T2'));
+ $this->assertEquals(3, $tagModel->create(2, 'T2'));
+ $this->assertEquals(4, $tagModel->create(2, 'T3'));
+ $this->assertEquals(5, $tagModel->create(0, 'T4'));
+ $this->assertEquals(6, $tagModel->create(0, 'T5'));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T2', 'T5'))));
+
+ // We move our task to the 2nd project
+ $this->assertEquals(2, $taskProjectMoveModel->duplicateToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['project_id']);
+
+ // Check tags
+ $tags = $taskTagModel->getList(2);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(3, $tags);
+ $this->assertArrayHasKey(6, $tags);
+ }
+}
diff --git a/tests/units/Model/TaskProjectMoveModelTest.php b/tests/units/Model/TaskProjectMoveModelTest.php
new file mode 100644
index 00000000..52f61b28
--- /dev/null
+++ b/tests/units/Model/TaskProjectMoveModelTest.php
@@ -0,0 +1,277 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskProjectMoveModel;
+use Kanboard\Model\TaskTagModel;
+use Kanboard\Model\UserModel;
+
+class TaskProjectMoveModelTest extends Base
+{
+ public function onMoveProject($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('test', $event_data['task']['title']);
+ }
+
+ public function testMoveAnotherProject()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'owner_id' => 1,
+ 'category_id' => 10,
+ 'position' => 333,
+ 'priority' => 1,
+ )));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
+
+ // We duplicate our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskProjectMoveModelTest::onMoveProject', $called);
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['priority']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithCategory()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithUser()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(6, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithForbiddenUser()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(6, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithSwimlane()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(2, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithoutSwimlane()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithDifferentTags()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $tagModel = new TagModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create our tags for each projects
+ $this->assertEquals(1, $tagModel->create(1, 'T1'));
+ $this->assertEquals(2, $tagModel->create(1, 'T2'));
+ $this->assertEquals(3, $tagModel->create(2, 'T3'));
+ $this->assertEquals(4, $tagModel->create(2, 'T4'));
+ $this->assertEquals(5, $tagModel->create(0, 'T5'));
+ $this->assertEquals(6, $tagModel->create(0, 'T6'));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T5', 'T6'))));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+
+ // Check tags
+ $tags = $taskTagModel->getList(1);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(5, $tags);
+ $this->assertArrayHasKey(6, $tags);
+ }
+}
diff --git a/tests/units/Model/TaskRecurrenceModelTest.php b/tests/units/Model/TaskRecurrenceModelTest.php
new file mode 100644
index 00000000..85d77bc2
--- /dev/null
+++ b/tests/units/Model/TaskRecurrenceModelTest.php
@@ -0,0 +1,126 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\DateParser;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskRecurrenceModel;
+use Kanboard\Model\TaskTagModel;
+
+class TaskRecurrenceModelTest extends Base
+{
+ public function testRecurrenceSettings()
+ {
+ $taskRecurrenceModel = new TaskRecurrenceModel($this->container);
+
+ $statuses = $taskRecurrenceModel->getRecurrenceStatusList();
+ $this->assertCount(2, $statuses);
+ $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_NONE, $statuses);
+ $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_PENDING, $statuses);
+ $this->assertArrayNotHasKey(TaskModel::RECURRING_STATUS_PROCESSED, $statuses);
+
+ $triggers = $taskRecurrenceModel->getRecurrenceTriggerList();
+ $this->assertCount(3, $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 = $taskRecurrenceModel->getRecurrenceBasedateList();
+ $this->assertCount(2, $dates);
+ $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_DUEDATE, $dates);
+ $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $dates);
+
+ $timeframes = $taskRecurrenceModel->getRecurrenceTimeframeList();
+ $this->assertCount(3, $timeframes);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_DAYS, $timeframes);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_MONTHS, $timeframes);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_YEARS, $timeframes);
+ }
+
+ public function testCalculateRecurringTaskDueDate()
+ {
+ $taskRecurrenceModel = new TaskRecurrenceModel($this->container);
+
+ $values = array('date_due' => 0);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(0, $values['date_due']);
+
+ $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(0, $values['date_due']);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(time() + 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1436561776, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1494449776, $values['date_due'], '', 1);
+ }
+
+ public function testDuplicateRecurringTask()
+ {
+ $taskRecurrenceModel = new TaskRecurrenceModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $dateParser = new DateParser($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'date_due' => 1436561776,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
+ 'recurrence_factor' => 2,
+ 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS,
+ 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE,
+ 'tags' => array('T1', 'T2'),
+ )));
+
+ $this->assertEquals(2, $taskRecurrenceModel->duplicateRecurringTask(1));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
+ $this->assertEquals(2, $task['recurrence_child']);
+ $this->assertEquals(1436486400, $task['date_due'], '', 2);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']);
+ $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
+ $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
+ $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
+ $this->assertEquals(1, $task['recurrence_parent']);
+ $this->assertEquals(2, $task['recurrence_factor']);
+ $this->assertEquals($dateParser->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2);
+
+ $tags = $taskTagModel->getList(2);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(1, $tags);
+ $this->assertArrayHasKey(2, $tags);
+ }
+}
diff --git a/tests/units/Model/TaskTagModelTest.php b/tests/units/Model/TaskTagModelTest.php
new file mode 100644
index 00000000..3485368e
--- /dev/null
+++ b/tests/units/Model/TaskTagModelTest.php
@@ -0,0 +1,148 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskTagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskTagModelTest extends Base
+{
+ public function testAssociationAndDissociation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $tagModel = new TagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $tagModel->create(0, 'My tag 1'));
+ $this->assertEquals(2, $tagModel->create(0, 'My tag 2'));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', '', 'My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTask(1);
+ $this->assertCount(3, $tags);
+
+ $this->assertEquals(1, $tags[0]['id']);
+ $this->assertEquals('My tag 1', $tags[0]['name']);
+
+ $this->assertEquals(2, $tags[1]['id']);
+ $this->assertEquals('My tag 2', $tags[1]['name']);
+
+ $this->assertEquals(3, $tags[2]['id']);
+ $this->assertEquals('My tag 3', $tags[2]['name']);
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 3', 'My tag 1', 'My tag 4')));
+
+ $tags = $taskTagModel->getTagsByTask(1);
+ $this->assertCount(3, $tags);
+
+ $this->assertEquals(1, $tags[0]['id']);
+ $this->assertEquals('My tag 1', $tags[0]['name']);
+
+ $this->assertEquals(3, $tags[1]['id']);
+ $this->assertEquals('My tag 3', $tags[1]['name']);
+
+ $this->assertEquals(4, $tags[2]['id']);
+ $this->assertEquals('My tag 4', $tags[2]['name']);
+
+ $tags = $tagModel->getAll();
+ $this->assertCount(4, $tags);
+ $this->assertEquals('My tag 1', $tags[0]['name']);
+ $this->assertEquals(0, $tags[0]['project_id']);
+
+ $this->assertEquals('My tag 2', $tags[1]['name']);
+ $this->assertEquals(0, $tags[1]['project_id']);
+
+ $this->assertEquals('My tag 3', $tags[2]['name']);
+ $this->assertEquals(1, $tags[2]['project_id']);
+
+ $this->assertEquals('My tag 4', $tags[3]['name']);
+ $this->assertEquals(1, $tags[3]['project_id']);
+ }
+
+ public function testGetTagsForTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTasks(array(1, 2, 3));
+
+ $expected = array(
+ 1 => array(
+ array(
+ 'id' => 1,
+ 'name' => 'My tag 1',
+ 'task_id' => 1
+ ),
+ array(
+ 'id' => 2,
+ 'name' => 'My tag 2',
+ 'task_id' => 1
+ ),
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 1
+ ),
+ ),
+ 2 => array(
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 2,
+ )
+ )
+ );
+
+ $this->assertEquals($expected, $tags);
+ }
+
+ public function testGetTagsForTasksWithEmptyList()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTasks(array());
+ $this->assertEquals(array(), $tags);
+ }
+
+ public function testGetTagIdNotAvailableInDestinationProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $tagModel = new TagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+
+ $this->assertEquals(1, $tagModel->create(0, 'T0'));
+ $this->assertEquals(2, $tagModel->create(2, 'T1'));
+ $this->assertEquals(3, $tagModel->create(2, 'T3'));
+ $this->assertEquals(4, $tagModel->create(1, 'T2'));
+ $this->assertEquals(5, $tagModel->create(1, 'T3'));
+ $this->assertTrue($taskTagModel->save(1, 1, array('T0', 'T2', 'T3')));
+
+ $this->assertEquals(array(4, 5), $taskTagModel->getTagIdsByTaskNotAvailableInProject(1, 2));
+ }
+}
diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php
deleted file mode 100644
index 89fc4dc1..00000000
--- a/tests/units/Model/TaskTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskTest extends Base
-{
- public function testRemove()
- {
- $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)));
-
- $this->assertTrue($t->remove(1));
- $this->assertFalse($t->remove(1234));
- }
-
- public function testGetTaskIdFromText()
- {
- $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 TaskModel($this->container);
-
- $statuses = $t->getRecurrenceStatusList();
- $this->assertCount(2, $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(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(TaskModel::RECURRING_BASEDATE_DUEDATE, $dates);
- $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $dates);
-
- $timeframes = $t->getRecurrenceTimeframeList();
- $this->assertCount(3, $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/UserModelTest.php b/tests/units/Model/UserModelTest.php
new file mode 100644
index 00000000..a0c9c575
--- /dev/null
+++ b/tests/units/Model/UserModelTest.php
@@ -0,0 +1,384 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+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 UserModelTest extends Base
+{
+ public function testGetByEmail()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'password' => '123456', 'email' => '')));
+
+ $this->assertNotEmpty($userModel->getByEmail('user1@localhost'));
+ $this->assertEmpty($userModel->getByEmail(''));
+ }
+
+ public function testGetByExternalId()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('gitlab_id', '1234'));
+ $this->assertEmpty($userModel->getByExternalId('gitlab_id', ''));
+
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user3', 'password' => '123456', 'github_id' => '')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('github_id', 'plop'));
+ $this->assertEmpty($userModel->getByExternalId('github_id', ''));
+
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user5', 'password' => '123456', 'google_id' => '')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('google_id', '1234'));
+ $this->assertEmpty($userModel->getByExternalId('google_id', ''));
+ }
+
+ public function testGetByToken()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'token' => 'random')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'token' => '')));
+
+ $this->assertNotEmpty($userModel->getByToken('random'));
+ $this->assertEmpty($userModel->getByToken(''));
+ }
+
+ public function testGetByUsername()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+
+ $this->assertNotEmpty($userModel->getByUsername('user1'));
+ $this->assertEmpty($userModel->getByUsername('user2'));
+ $this->assertEmpty($userModel->getByUsername(''));
+ }
+
+ public function testExists()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($userModel->exists(1));
+ $this->assertTrue($userModel->exists(2));
+ $this->assertFalse($userModel->exists(3));
+ }
+
+ public function testCount()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+ $this->assertEquals(2, $userModel->count());
+ }
+
+ public function testGetAll()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'you')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'me', 'name' => 'Me')));
+
+ $users = $userModel->getAll();
+ $this->assertCount(3, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('me', $users[1]['username']);
+ $this->assertEquals('you', $users[2]['username']);
+ }
+
+ public function testGetActiveUsersList()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'you')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'me', 'name' => 'Me too')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'foobar', 'is_active' => 0)));
+
+ $users = $userModel->getActiveUsersList();
+
+ $expected = array(
+ 1 => 'admin',
+ 3 => 'Me too',
+ 2 => 'you',
+ );
+
+ $this->assertEquals($expected, $users);
+
+ $users = $userModel->getActiveUsersList(true);
+
+ $expected = array(
+ UserModel::EVERYBODY_ID => 'Everybody',
+ 1 => 'admin',
+ 3 => 'Me too',
+ 2 => 'you',
+ );
+
+ $this->assertEquals($expected, $users);
+ }
+
+ public function testIsAdmin()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($userModel->isAdmin(1));
+ $this->assertFalse($userModel->isAdmin(2));
+ }
+
+ public function testPassword()
+ {
+ $password = 'test123';
+ $hash = password_hash($password, PASSWORD_BCRYPT);
+
+ $this->assertNotEmpty($hash);
+ $this->assertTrue(password_verify($password, $hash));
+ }
+
+ public function testPrepare()
+ {
+ $userModel = new UserModel($this->container);
+
+ $input = array(
+ 'username' => 'user1',
+ 'password' => '1234',
+ 'confirmation' => '1234',
+ 'name' => 'me',
+ 'role' => Role::APP_ADMIN,
+ );
+
+ $userModel->prepare($input);
+ $this->assertArrayNotHasKey('confirmation', $input);
+
+ $this->assertArrayHasKey('password', $input);
+ $this->assertNotEquals('1234', $input['password']);
+ $this->assertNotEmpty($input['password']);
+
+ $input = array(
+ 'username' => 'user1',
+ 'password' => '1234',
+ 'current_password' => 'bla',
+ 'confirmation' => '1234',
+ 'name' => 'me',
+ 'is_ldap_user' => '1',
+ );
+
+ $userModel->prepare($input);
+ $this->assertArrayNotHasKey('confirmation', $input);
+ $this->assertArrayNotHasKey('current_password', $input);
+
+ $this->assertArrayHasKey('password', $input);
+ $this->assertNotEquals('1234', $input['password']);
+ $this->assertNotEmpty($input['password']);
+
+ $this->assertArrayHasKey('is_ldap_user', $input);
+ $this->assertEquals(1, $input['is_ldap_user']);
+
+ $input = array(
+ 'id' => 2,
+ 'name' => 'me',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
+
+ $input = array(
+ 'gitlab_id' => '1234',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => 1234), $input);
+
+ $input = array(
+ 'gitlab_id' => '',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => null), $input);
+
+ $input = array(
+ 'gitlab_id' => 'something',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => 0), $input);
+
+ $input = array(
+ 'username' => 'something',
+ 'password' => ''
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('username' => 'something'), $input);
+ }
+
+ public function testCreate()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user #2', 'is_ldap_user' => 1)));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER)));
+ $this->assertEquals(5, $userModel->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
+ $this->assertEquals(6, $userModel->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
+ $this->assertFalse($userModel->create(array('username' => 'user #1')));
+
+ $user = $userModel->getById(1);
+ $this->assertEquals('admin', $user['username']);
+ $this->assertEquals('', $user['name']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(2);
+ $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 = $userModel->getById(3);
+ $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 = $userModel->getById(4);
+ $this->assertEquals('user #3', $user['username']);
+ $this->assertEquals(Role::APP_MANAGER, $user['role']);
+
+ $user = $userModel->getById(5);
+ $this->assertEquals('user #4', $user['username']);
+ $this->assertEquals('', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
+
+ $user = $userModel->getById(6);
+ $this->assertEquals('user #5', $user['username']);
+ $this->assertEquals('1234', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ }
+
+ public function testUpdate()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'plop', 'gitlab_id' => '123')));
+
+ $this->assertTrue($userModel->update(array('id' => 2, 'username' => 'biloute')));
+ $this->assertTrue($userModel->update(array('id' => 3, 'gitlab_id' => '')));
+
+ $user = $userModel->getById(2);
+ $this->assertEquals('biloute', $user['username']);
+ $this->assertEquals('Toto', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(3);
+ $this->assertNotEmpty($user);
+ $this->assertEquals(null, $user['gitlab_id']);
+ }
+
+ public function testRemove()
+ {
+ $userModel = new UserModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['owner_id']);
+
+ $this->assertTrue($userModel->remove(1));
+ $this->assertTrue($userModel->remove(2));
+ $this->assertFalse($userModel->remove(2));
+ $this->assertFalse($userModel->remove(55));
+
+ // Make sure that assigned tasks are unassigned after removing the user
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(0, $task['owner_id']);
+
+ // Make sure that assigned subtasks are unassigned after removing the user
+ $subtask = $subtaskModel->getById(1);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(0, $subtask['user_id']);
+
+ // Make sure that comments are not related to the user anymore
+ $comment = $commentModel->getById(1);
+ $this->assertEquals(1, $comment['id']);
+ $this->assertEquals(0, $comment['user_id']);
+
+ // Make sure that private projects are also removed
+ $user_id1 = $userModel->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
+ $user_id2 = $userModel->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
+ $this->assertNotFalse($user_id1);
+ $this->assertNotFalse($user_id2);
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
+
+ $this->assertTrue($userModel->remove($user_id1));
+
+ $this->assertNotEmpty($projectModel->getById(1));
+ $this->assertNotEmpty($projectModel->getById(3));
+
+ $this->assertEmpty($projectModel->getById(2));
+ }
+
+ public function testEnableDisablePublicAccess()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456')));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+
+ $this->assertTrue($userModel->enablePublicAccess(2));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertNotEmpty($user['token']);
+
+ $this->assertTrue($userModel->disablePublicAccess(2));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+ }
+
+ public function testEnableDisable()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
+
+ $this->assertTrue($userModel->isActive(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+
+ $this->assertTrue($userModel->disable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(0, $user['is_active']);
+ $this->assertFalse($userModel->isActive(2));
+
+ $this->assertTrue($userModel->enable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+ $this->assertTrue($userModel->isActive(2));
+ }
+}
diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php
deleted file mode 100644
index 0be6172e..00000000
--- a/tests/units/Model/UserTest.php
+++ /dev/null
@@ -1,400 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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 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' => '')));
-
- $this->assertNotEmpty($u->getByEmail('user1@localhost'));
- $this->assertEmpty($u->getByEmail(''));
- }
-
- public function testGetByExternalId()
- {
- $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 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 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' => '')));
-
- $this->assertNotEmpty($u->getByExternalId('google_id', '1234'));
- $this->assertEmpty($u->getByExternalId('google_id', ''));
- }
-
- public function testGetByToken()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'token' => 'random')));
- $this->assertNotFalse($u->create(array('username' => 'user2', 'token' => '')));
-
- $this->assertNotEmpty($u->getByToken('random'));
- $this->assertEmpty($u->getByToken(''));
- }
-
- public function testGetByUsername()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
-
- $this->assertNotEmpty($u->getByUsername('user1'));
- $this->assertEmpty($u->getByUsername('user2'));
- $this->assertEmpty($u->getByUsername(''));
- }
-
- public function testExists()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
-
- $this->assertTrue($u->exists(1));
- $this->assertTrue($u->exists(2));
- $this->assertFalse($u->exists(3));
- }
-
- public function testCount()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
- $this->assertEquals(2, $u->count());
- }
-
- public function testGetAll()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'you')));
- $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me')));
-
- $users = $u->getAll();
- $this->assertCount(3, $users);
- $this->assertEquals('admin', $users[0]['username']);
- $this->assertEquals('me', $users[1]['username']);
- $this->assertEquals('you', $users[2]['username']);
- }
-
- public function testGetActiveUsersList()
- {
- $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)));
-
- $users = $u->getActiveUsersList();
-
- $expected = array(
- 1 => 'admin',
- 3 => 'Me too',
- 2 => 'you',
- );
-
- $this->assertEquals($expected, $users);
-
- $users = $u->getActiveUsersList(true);
-
- $expected = array(
- UserModel::EVERYBODY_ID => 'Everybody',
- 1 => 'admin',
- 3 => 'Me too',
- 2 => 'you',
- );
-
- $this->assertEquals($expected, $users);
- }
-
- public function testGetFullname()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
- $this->assertEquals(3, $u->create(array('username' => 'user2', 'name' => 'User #2')));
-
- $user1 = $u->getById(2);
- $user2 = $u->getById(3);
-
- $this->assertNotEmpty($user1);
- $this->assertNotEmpty($user2);
-
- $this->assertEquals('user1', $u->getFullname($user1));
- $this->assertEquals('User #2', $u->getFullname($user2));
- }
-
- public function testIsAdmin()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
-
- $this->assertTrue($u->isAdmin(1));
- $this->assertFalse($u->isAdmin(2));
- }
-
- public function testPassword()
- {
- $password = 'test123';
- $hash = password_hash($password, PASSWORD_BCRYPT);
-
- $this->assertNotEmpty($hash);
- $this->assertTrue(password_verify($password, $hash));
- }
-
- public function testPrepare()
- {
- $u = new UserModel($this->container);
-
- $input = array(
- 'username' => 'user1',
- 'password' => '1234',
- 'confirmation' => '1234',
- 'name' => 'me',
- 'role' => Role::APP_ADMIN,
- );
-
- $u->prepare($input);
- $this->assertArrayNotHasKey('confirmation', $input);
-
- $this->assertArrayHasKey('password', $input);
- $this->assertNotEquals('1234', $input['password']);
- $this->assertNotEmpty($input['password']);
-
- $input = array(
- 'username' => 'user1',
- 'password' => '1234',
- 'current_password' => 'bla',
- 'confirmation' => '1234',
- 'name' => 'me',
- 'is_ldap_user' => '1',
- );
-
- $u->prepare($input);
- $this->assertArrayNotHasKey('confirmation', $input);
- $this->assertArrayNotHasKey('current_password', $input);
-
- $this->assertArrayHasKey('password', $input);
- $this->assertNotEquals('1234', $input['password']);
- $this->assertNotEmpty($input['password']);
-
- $this->assertArrayHasKey('is_ldap_user', $input);
- $this->assertEquals(1, $input['is_ldap_user']);
-
- $input = array(
- 'id' => 2,
- 'name' => 'me',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
-
- $input = array(
- 'gitlab_id' => '1234',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => 1234), $input);
-
- $input = array(
- 'gitlab_id' => '',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => null), $input);
-
- $input = array(
- 'gitlab_id' => 'something',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => 0), $input);
-
- $input = array(
- 'username' => 'something',
- 'password' => ''
- );
-
- $u->prepare($input);
- $this->assertEquals(array('username' => 'something'), $input);
- }
-
- public function testCreate()
- {
- $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)));
- $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
- $this->assertEquals(6, $u->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
- $this->assertFalse($u->create(array('username' => 'user #1')));
-
- $user = $u->getById(1);
- $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->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->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->assertEquals('user #3', $user['username']);
- $this->assertEquals(Role::APP_MANAGER, $user['role']);
-
- $user = $u->getById(5);
- $this->assertEquals('user #4', $user['username']);
- $this->assertEquals('', $user['gitlab_id']);
- $this->assertEquals(Role::APP_ADMIN, $user['role']);
-
- $user = $u->getById(6);
- $this->assertEquals('user #5', $user['username']);
- $this->assertEquals('1234', $user['gitlab_id']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- }
-
- public function testUpdate()
- {
- $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')));
-
- $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
- $this->assertTrue($u->update(array('id' => 3, 'gitlab_id' => '')));
-
- $user = $u->getById(2);
- $this->assertEquals('biloute', $user['username']);
- $this->assertEquals('Toto', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(3);
- $this->assertNotEmpty($user);
- $this->assertEquals(null, $user['gitlab_id']);
- }
-
- public function testRemove()
- {
- $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')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
- $this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['owner_id']);
-
- $this->assertTrue($u->remove(1));
- $this->assertTrue($u->remove(2));
- $this->assertFalse($u->remove(2));
- $this->assertFalse($u->remove(55));
-
- // Make sure that assigned tasks are unassigned after removing the user
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(0, $task['owner_id']);
-
- // Make sure that assigned subtasks are unassigned after removing the user
- $subtask = $s->getById(1);
- $this->assertEquals(1, $subtask['id']);
- $this->assertEquals(0, $subtask['user_id']);
-
- // Make sure that comments are not related to the user anymore
- $comment = $c->getById(1);
- $this->assertEquals(1, $comment['id']);
- $this->assertEquals(0, $comment['user_id']);
-
- // Make sure that private projects are also removed
- $user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
- $user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
- $this->assertNotFalse($user_id1);
- $this->assertNotFalse($user_id2);
- $this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
- $this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
-
- $this->assertTrue($u->remove($user_id1));
-
- $this->assertNotEmpty($p->getById(1));
- $this->assertNotEmpty($p->getById(3));
-
- $this->assertEmpty($p->getById(2));
- }
-
- public function testEnableDisablePublicAccess()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
-
- $user = $u->getById(2);
- $this->assertNotEmpty($user);
- $this->assertEquals('toto', $user['username']);
- $this->assertEmpty($user['token']);
-
- $this->assertTrue($u->enablePublicAccess(2));
-
- $user = $u->getById(2);
- $this->assertNotEmpty($user);
- $this->assertEquals('toto', $user['username']);
- $this->assertNotEmpty($user['token']);
-
- $this->assertTrue($u->disablePublicAccess(2));
-
- $user = $u->getById(2);
- $this->assertNotEmpty($user);
- $this->assertEquals('toto', $user['username']);
- $this->assertEmpty($user['token']);
- }
-
- public function testEnableDisable()
- {
- $userModel = new UserModel($this->container);
- $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
-
- $this->assertTrue($userModel->isActive(2));
- $user = $userModel->getById(2);
- $this->assertEquals(1, $user['is_active']);
-
- $this->assertTrue($userModel->disable(2));
- $user = $userModel->getById(2);
- $this->assertEquals(0, $user['is_active']);
- $this->assertFalse($userModel->isActive(2));
-
- $this->assertTrue($userModel->enable(2));
- $user = $userModel->getById(2);
- $this->assertEquals(1, $user['is_active']);
- $this->assertTrue($userModel->isActive(2));
- }
-}
diff --git a/tests/units/Notification/MailNotificationTest.php b/tests/units/Notification/MailNotificationTest.php
new file mode 100644
index 00000000..93eeef0c
--- /dev/null
+++ b/tests/units/Notification/MailNotificationTest.php
@@ -0,0 +1,122 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskLinkModel;
+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 MailNotificationTest extends Base
+{
+ public function testGetMailContent()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $fileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $fileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ );
+ $this->assertNotEmpty($mailNotification->getMailContent($eventName, $eventData));
+ $this->assertStringStartsWith('[test] ', $mailNotification->getMailSubject($eventName, $eventData));
+ }
+
+ $this->assertStringStartsWith('[Test1, Test2] ', $mailNotification->getMailSubject(TaskModel::EVENT_OVERDUE, array(
+ 'tasks' => array(array('id' => 123), array('id' => 456)),
+ 'project_name' => 'Test1, Test2',
+ )));
+ }
+
+ public function testSendWithEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'test@localhost')));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->once())
+ ->method('send')
+ ->with(
+ $this->equalTo('test@localhost'),
+ $this->equalTo('admin'),
+ $this->equalTo('[test] New task #1: test'),
+ $this->stringContains('test')
+ );
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+
+ public function testSendWithoutEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->never())
+ ->method('send');
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+}
diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php
deleted file mode 100644
index 9f077ac8..00000000
--- a/tests/units/Notification/MailTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-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 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)));
- $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
- $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
-
- $task = $tf->getDetails(1);
- $subtask = $s->getById(1, true);
- $comment = $c->getById(1);
- $file = $c->getById(1);
-
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event => $values) {
- $this->assertNotEmpty($en->getMailContent($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
-
- $this->assertNotEmpty($en->getMailSubject($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
- }
- }
-
- public function testSendWithEmailAddress()
- {
- $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)));
- $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->once())
- ->method('send')
- ->with(
- $this->equalTo('test@localhost'),
- $this->equalTo('admin'),
- $this->equalTo('[test][New task] test (#1)'),
- $this->stringContains('test')
- );
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-
- public function testSendWithoutEmailAddress()
- {
- $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)));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->never())
- ->method('send');
-
- $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/WebhookNotificationTest.php
index 5a9eb1c7..6fbc349c 100644
--- a/tests/units/Notification/WebhookTest.php
+++ b/tests/units/Notification/WebhookNotificationTest.php
@@ -7,23 +7,23 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Subscriber\NotificationSubscriber;
-class WebhookTest extends Base
+class WebhookNotificationTest extends Base
{
public function testTaskCreation()
{
- $c = new ConfigModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $configModel = new ConfigModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
$this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container));
- $c->save(array('webhook_url' => 'http://localhost/?task-creation'));
+ $configModel->save(array('webhook_url' => 'http://localhost/?task-creation'));
$this->container['httpClient']
->expects($this->once())
->method('postJson')
->with($this->stringContains('http://localhost/?task-creation&token='), $this->anything());
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
}
}
diff --git a/tests/units/Pagination/ProjectPaginationTest.php b/tests/units/Pagination/ProjectPaginationTest.php
new file mode 100644
index 00000000..35532d0d
--- /dev/null
+++ b/tests/units/Pagination/ProjectPaginationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Pagination\ProjectPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectPagination = new ProjectPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2', 'is_private' => 1)));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'Project #3')));
+ $this->assertEquals(4, $projectModel->create(array('name' => 'Project #4', 'is_private' => 1)));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MANAGER));
+
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->getCollection());
+ $this->assertCount(0, $projectPagination->getDashboardPaginator(3, 'projects', 5)->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.id')->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.is_private')->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.name')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/SubtaskPaginationTest.php b/tests/units/Pagination/SubtaskPaginationTest.php
new file mode 100644
index 00000000..26a51a8b
--- /dev/null
+++ b/tests/units/Pagination/SubtaskPaginationTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Pagination\SubtaskPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskPagination = new SubtaskPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(3, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(4, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask #1')));
+ $this->assertEquals(5, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1')));
+
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->getCollection());
+ $this->assertCount(0, $subtaskPagination->getDashboardPaginator(2, 'subtasks', 5)->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder(TaskModel::TABLE.'.id')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder('project_name')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder('task_name')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder(SubtaskModel::TABLE.'.title')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/TaskPaginationTest.php b/tests/units/Pagination/TaskPaginationTest.php
new file mode 100644
index 00000000..027212e2
--- /dev/null
+++ b/tests/units/Pagination/TaskPaginationTest.php
@@ -0,0 +1,30 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Pagination\TaskPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskPagination = new TaskPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->getCollection());
+ $this->assertCount(0, $taskPagination->getDashboardPaginator(2, 'tasks', 5)->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.id')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder('project_name')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.title')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.priority')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.date_due')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/UserPaginationTest.php b/tests/units/Pagination/UserPaginationTest.php
new file mode 100644
index 00000000..c475aacd
--- /dev/null
+++ b/tests/units/Pagination/UserPaginationTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use Kanboard\Model\UserModel;
+use Kanboard\Pagination\UserPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class UserPaginationTest extends Base
+{
+ public function testListingPagination()
+ {
+ $userModel = new UserModel($this->container);
+ $userPagination = new UserPagination($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'test2')));
+
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('id')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('username')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('name')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('email')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('role')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('twofactor_activated')->setDirection('DESC')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('is_ldap_user')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('is_active')->getCollection());
+ }
+}
diff --git a/tests/units/Subscriber/RecurringTaskSubscriberTest.php b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
new file mode 100644
index 00000000..d6aba7cf
--- /dev/null
+++ b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
@@ -0,0 +1,164 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Subscriber\RecurringTaskSubscriber;
+
+require_once __DIR__.'/../Base.php';
+
+class RecurringTaskSubscriberTest extends Base
+{
+ public function testWithNoRecurrence()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 1))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ 'column_id' => 2,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 4))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceOnClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withChanges(array('is_active' => 0))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+}
diff --git a/tests/units/User/Avatar/LetterAvatarProviderTest.php b/tests/units/User/Avatar/LetterAvatarProviderTest.php
index 0eb3ef8e..c145967b 100644
--- a/tests/units/User/Avatar/LetterAvatarProviderTest.php
+++ b/tests/units/User/Avatar/LetterAvatarProviderTest.php
@@ -23,7 +23,7 @@ class LetterAvatarProviderTest extends Base
{
$provider = new LetterAvatarProvider($this->container);
$user = array('id' => 123, 'name' => 'Kanboard Admin', 'username' => 'bob', 'email' => '');
- $expected = '<div class="avatar-letter" style="background-color: rgb(131, 224, 108)" title="Kanboard Admin">KA</div>';
+ $expected = '<div class="avatar-letter" style="background-color: rgb(120, 83, 58)" title="Kanboard Admin">KA</div>';
$this->assertEquals($expected, $provider->render($user, 48));
}
diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php
index 07de6c25..e1e2f077 100644
--- a/tests/units/Validator/ProjectValidatorTest.php
+++ b/tests/units/Validator/ProjectValidatorTest.php
@@ -55,13 +55,19 @@ class ProjectValidatorTest extends Base
$r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
+ $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
+ $r = $validator->validateModification(array('id' => 1, 'identifier' => ''));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
+ $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => ''));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => null));
$this->assertFalse($r[0]);
}
}