diff options
36 files changed, 1061 insertions, 296 deletions
@@ -44,7 +44,6 @@ Thumbs.db *.swp .*.swp *~ -*.lock *.out # Vagrant # diff --git a/app/Action/Base.php b/app/Action/Base.php index c9363617..c8c589c1 100644 --- a/app/Action/Base.php +++ b/app/Action/Base.php @@ -15,6 +15,7 @@ use Core\Tool; * @property \Model\Acl $acl * @property \Model\Comment $comment * @property \Model\Task $task + * @property \Model\TaskCreation $taskCreation * @property \Model\TaskFinder $taskFinder * @property \Model\TaskStatus $taskStatus */ diff --git a/app/Action/TaskCreation.php b/app/Action/TaskCreation.php index 41d0200c..5715310f 100644 --- a/app/Action/TaskCreation.php +++ b/app/Action/TaskCreation.php @@ -59,7 +59,7 @@ class TaskCreation extends Base */ public function doAction(array $data) { - return $this->task->create(array( + return $this->taskCreation->create(array( 'project_id' => $data['project_id'], 'title' => $data['title'], 'reference' => $data['reference'], diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 5e208009..8285f458 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -33,6 +33,7 @@ use Model\LastLogin; * @property \Model\ProjectAnalytic $projectAnalytic * @property \Model\SubTask $subTask * @property \Model\Task $task + * @property \Model\TaskCreation $taskCreation * @property \Model\TaskHistory $taskHistory * @property \Model\TaskExport $taskExport * @property \Model\TaskFinder $taskFinder diff --git a/app/Controller/Task.php b/app/Controller/Task.php index cad2f583..e75058d9 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -127,7 +127,7 @@ class Task extends Base if ($valid) { - if ($this->task->create($values)) { + if ($this->taskCreation->create($values)) { $this->session->flash(t('Task created successfully.')); if (isset($values['another_task']) && $values['another_task'] == 1) { diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index a0bf369a..dcd66a1a 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -35,7 +35,7 @@ class Webhook extends Base list($valid,) = $this->taskValidator->validateCreation($values); - if ($valid && $this->task->create($values)) { + if ($valid && $this->taskCreation->create($values)) { $this->response->text('OK'); } diff --git a/app/Model/Color.php b/app/Model/Color.php index f414e837..8668cf0f 100644 --- a/app/Model/Color.php +++ b/app/Model/Color.php @@ -28,4 +28,15 @@ class Color extends Base 'grey' => t('Grey'), ); } + + /** + * Get the default color + * + * @access public + * @return string + */ + public function getDefaultColor() + { + return 'yellow'; // TODO: make this parameter configurable + } } diff --git a/app/Model/Task.php b/app/Model/Task.php index 1b2a66cd..93914fba 100644 --- a/app/Model/Task.php +++ b/app/Model/Task.php @@ -54,30 +54,6 @@ class Task extends Base } /** - * Prepare data before task creation - * - * @access public - * @param array $values Form values - */ - public function prepareCreation(array &$values) - { - $this->prepare($values); - - if (empty($values['column_id'])) { - $values['column_id'] = $this->board->getFirstColumn($values['project_id']); - } - - if (empty($values['color_id'])) { - $colors = $this->color->getList(); - $values['color_id'] = key($colors); - } - - $values['date_creation'] = time(); - $values['date_modification'] = $values['date_creation']; - $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1; - } - - /** * Prepare data before task modification * * @access public @@ -90,35 +66,6 @@ class Task extends Base } /** - * Create a task - * - * @access public - * @param array $values Form values - * @return boolean|integer - */ - public function create(array $values) - { - $this->db->startTransaction(); - - $this->prepareCreation($values); - - if (! $this->db->table(self::TABLE)->save($values)) { - $this->db->cancelTransaction(); - return false; - } - - $task_id = $this->db->getConnection()->getLastId(); - - $this->db->closeTransaction(); - - // Trigger events - $this->event->trigger(self::EVENT_CREATE_UPDATE, array('task_id' => $task_id) + $values); - $this->event->trigger(self::EVENT_CREATE, array('task_id' => $task_id) + $values); - - return $task_id; - } - - /** * Update a task * * @access public diff --git a/app/Model/TaskCreation.php b/app/Model/TaskCreation.php new file mode 100644 index 00000000..58cfa6ed --- /dev/null +++ b/app/Model/TaskCreation.php @@ -0,0 +1,88 @@ +<?php + +namespace Model; + +/** + * Task Creation + * + * @package model + * @author Frederic Guillot + */ +class TaskCreation extends Base +{ + /** + * Create a task + * + * @access public + * @param array $values Form values + * @return integer + */ + public function create(array $values) + { + $this->prepare($values); + $task_id = $this->persist($values); + $this->fireEvents($task_id, $values); + + return (int) $task_id; + } + + /** + * Prepare data + * + * @access public + * @param array $values Form values + */ + public function prepare(array &$values) + { + $this->dateParser->convert($values, array('date_due', 'date_started')); + $this->removeFields($values, array('another_task')); + $this->resetFields($values, array('owner_id', 'owner_id', 'date_due', 'score', 'category_id', 'time_estimated')); + + if (empty($values['column_id'])) { + $values['column_id'] = $this->board->getFirstColumn($values['project_id']); + } + + if (empty($values['color_id'])) { + $values['color_id'] = $this->color->getDefaultColor(); + } + + $values['date_creation'] = time(); + $values['date_modification'] = $values['date_creation']; + $values['position'] = $this->taskFinder->countByColumnId($values['project_id'], $values['column_id']) + 1; + } + + /** + * Save the task to the database + * + * @access private + * @param array $values Form values + * @return boolean|integer + */ + private function persist(array $values) + { + return $this->db->transaction(function($db) use ($values) { + + if (! $db->table(Task::TABLE)->save($values)) { + return false; + } + + return $db->getConnection()->getLastId(); + }); + } + + /** + * Fire events + * + * @access private + * @param integer $task_id Task id + * @param array $values Form values + */ + private function fireEvents($task_id, array $values) + { + if ($task_id) { + $values['task_id'] = $task_id; + $this->event->trigger(Task::EVENT_CREATE_UPDATE, $values); + $this->event->trigger(Task::EVENT_CREATE, $values); + } + } +} diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index e73f6cf4..52dbea50 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -5,7 +5,12 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 35; +const VERSION = 36; + +function version_36($pdo) +{ + $pdo->exec('ALTER TABLE tasks MODIFY title VARCHAR(255) NOT NULL'); +} function version_35($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index 4ec3885c..9493e60e 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -5,7 +5,12 @@ namespace Schema; use PDO; use Core\Security; -const VERSION = 16; +const VERSION = 17; + +function version_17($pdo) +{ + $pdo->exec('ALTER TABLE tasks ALTER COLUMN title SET NOT NULL'); +} function version_16($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index cdc74465..82c2f41c 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -457,7 +457,7 @@ function version_1($pdo) $pdo->exec(" CREATE TABLE tasks ( id INTEGER PRIMARY KEY, - title TEXT, + title TEXT NOT NULL, description TEXT, date_creation INTEGER, color_id TEXT, diff --git a/composer.lock b/composer.lock new file mode 100644 index 00000000..a90cbb00 --- /dev/null +++ b/composer.lock @@ -0,0 +1,481 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "2057eedc0ff404a75ab43f197dd41bb9", + "packages": [ + { + "name": "erusev/parsedown", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/erusev/parsedown.git", + "reference": "da5d75e97e1ed19e57bd54fa6cb595a6a0879a67" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/da5d75e97e1ed19e57bd54fa6cb595a6a0879a67", + "reference": "da5d75e97e1ed19e57bd54fa6cb595a6a0879a67", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Parsedown": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Emanuil Rusev", + "email": "hello@erusev.com", + "homepage": "http://erusev.com" + } + ], + "description": "Parser for Markdown.", + "homepage": "http://parsedown.org", + "keywords": [ + "markdown", + "parser" + ], + "time": "2014-10-29 20:29:46" + }, + { + "name": "fguillot/json-rpc", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/fguillot/JsonRPC.git", + "reference": "66db4093984790c34577c0ba0e17f2e3d2dc14a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fguillot/JsonRPC/zipball/66db4093984790c34577c0ba0e17f2e3d2dc14a0", + "reference": "66db4093984790c34577c0ba0e17f2e3d2dc14a0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "JsonRPC": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Unlicense" + ], + "authors": [ + { + "name": "Frédéric Guillot", + "homepage": "http://fredericguillot.com" + } + ], + "description": "A simple Json-RPC client/server library that just works", + "homepage": "https://github.com/fguillot/JsonRPC", + "time": "2014-11-05 01:56:31" + }, + { + "name": "fguillot/picodb", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/fguillot/picoDb.git", + "reference": "48602866414b5b396a37c40eef9724962042ff21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fguillot/picoDb/zipball/48602866414b5b396a37c40eef9724962042ff21", + "reference": "48602866414b5b396a37c40eef9724962042ff21", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "PicoDb": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "WTFPL" + ], + "authors": [ + { + "name": "Frédéric Guillot", + "homepage": "http://fredericguillot.com" + } + ], + "description": "Minimalist database query builder", + "homepage": "https://github.com/fguillot/picoDb", + "time": "2014-11-15 23:37:30" + }, + { + "name": "fguillot/simple-validator", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/fguillot/simpleValidator.git", + "reference": "14f7c0b111444a5b26ce447ef5f0de655279b5f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/14f7c0b111444a5b26ce447ef5f0de655279b5f1", + "reference": "14f7c0b111444a5b26ce447ef5f0de655279b5f1", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "SimpleValidator": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Frédéric Guillot", + "homepage": "http://fredericguillot.com" + } + ], + "description": "The most easy to use validator library for PHP :)", + "homepage": "https://github.com/fguillot/simpleValidator", + "time": "2014-09-09 05:31:14" + }, + { + "name": "ircmaxell/password-compat", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/ircmaxell/password_compat.git", + "reference": "1fc1521b5e9794ea77e4eca30717be9635f1d4f4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ircmaxell/password_compat/zipball/1fc1521b5e9794ea77e4eca30717be9635f1d4f4", + "reference": "1fc1521b5e9794ea77e4eca30717be9635f1d4f4", + "shasum": "" + }, + "type": "library", + "autoload": { + "files": [ + "lib/password.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Ferrara", + "email": "ircmaxell@ircmaxell.com", + "homepage": "http://blog.ircmaxell.com" + } + ], + "description": "A compatibility library for the proposed simplified password hashing algorithm: https://wiki.php.net/rfc/password_hash", + "homepage": "https://github.com/ircmaxell/password_compat", + "keywords": [ + "hashing", + "password" + ], + "time": "2013-04-30 19:58:08" + }, + { + "name": "lusitanian/oauth", + "version": "v0.3.5", + "source": { + "type": "git", + "url": "https://github.com/Lusitanian/PHPoAuthLib.git", + "reference": "ac5a1cd5a4519143728dce2213936eea302edf8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Lusitanian/PHPoAuthLib/zipball/ac5a1cd5a4519143728dce2213936eea302edf8a", + "reference": "ac5a1cd5a4519143728dce2213936eea302edf8a", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*", + "predis/predis": "0.8.*@dev", + "symfony/http-foundation": "~2.1" + }, + "suggest": { + "ext-openssl": "Allows for usage of secure connections with the stream-based HTTP client.", + "predis/predis": "Allows using the Redis storage backend.", + "symfony/http-foundation": "Allows using the Symfony Session storage backend." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.1-dev" + } + }, + "autoload": { + "psr-0": { + "OAuth": "src", + "OAuth\\Unit": "tests" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "David Desberg", + "email": "david@daviddesberg.com" + }, + { + "name": "Pieter Hordijk", + "email": "info@pieterhordijk.com" + } + ], + "description": "PHP 5.3+ oAuth 1/2 Library", + "keywords": [ + "Authentication", + "authorization", + "oauth", + "security" + ], + "time": "2014-09-05 15:19:58" + }, + { + "name": "monolog/monolog", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "ec3961874c43840e96da3a8a1ed20d8c73d7e5aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/ec3961874c43840e96da3a8a1ed20d8c73d7e5aa", + "reference": "ec3961874c43840e96da3a8a1ed20d8c73d7e5aa", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "provide": { + "psr/log-implementation": "1.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "~2.4, >2.4.8", + "doctrine/couchdb": "~1.0@dev", + "graylog2/gelf-php": "~1.0", + "phpunit/phpunit": "~3.7.0", + "raven/raven": "~0.5", + "ruflin/elastica": "0.90.*", + "videlalvaro/php-amqplib": "~2.4" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-mongo": "Allow sending log messages to a MongoDB server", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "raven/raven": "Allow sending log messages to a Sentry server", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.11.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "http://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "time": "2014-09-30 13:30:58" + }, + { + "name": "pimple/pimple", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/silexphp/Pimple.git", + "reference": "876bf0899d01feacd2a2e83f04641e51350099ef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/876bf0899d01feacd2a2e83f04641e51350099ef", + "reference": "876bf0899d01feacd2a2e83f04641e51350099ef", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Pimple": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Pimple is a simple Dependency Injection Container for PHP 5.3", + "homepage": "http://pimple.sensiolabs.org", + "keywords": [ + "container", + "dependency injection" + ], + "time": "2014-07-24 09:48:15" + }, + { + "name": "psr/log", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Psr\\Log\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2012-12-21 11:40:51" + }, + { + "name": "swiftmailer/swiftmailer", + "version": "v5.3.0", + "source": { + "type": "git", + "url": "https://github.com/swiftmailer/swiftmailer.git", + "reference": "b86b927dfefdb56ab0b22d1350033d9a38e9f205" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/b86b927dfefdb56ab0b22d1350033d9a38e9f205", + "reference": "b86b927dfefdb56ab0b22d1350033d9a38e9f205", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "mockery/mockery": "~0.9.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.3-dev" + } + }, + "autoload": { + "files": [ + "lib/swift_required.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Corbyn" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Swiftmailer, free feature-rich PHP mailer", + "homepage": "http://swiftmailer.org", + "keywords": [ + "mail", + "mailer" + ], + "time": "2014-10-04 05:53:18" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "fguillot/simple-validator": 20, + "swiftmailer/swiftmailer": 0, + "fguillot/json-rpc": 20, + "fguillot/picodb": 20 + }, + "prefer-stable": false, + "platform": [], + "platform-dev": [] +} diff --git a/jsonrpc.php b/jsonrpc.php index 62537ff6..39c2f474 100644 --- a/jsonrpc.php +++ b/jsonrpc.php @@ -6,6 +6,7 @@ use JsonRPC\Server; use Model\Project; use Model\ProjectPermission; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\TaskStatus; use Model\TaskValidator; @@ -26,6 +27,7 @@ $config->setupTimezone(); $project = new Project($container); $projectPermission = new ProjectPermission($container); $task = new Task($container); +$taskCreation = new TaskCreation($container); $taskFinder = new TaskFinder($container); $taskStatus = new TaskStatus($container); $taskValidator = new TaskValidator($container); @@ -163,7 +165,7 @@ $server->register('allowUser', function($project_id, $user_id) use ($project, $p /** * Task procedures */ -$server->register('createTask', function($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0) use ($task, $taskValidator) { +$server->register('createTask', function($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, $date_due = '', $description = '', $category_id = 0, $score = 0) use ($taskCreation, $taskValidator) { $values = array( 'title' => $title, @@ -179,7 +181,7 @@ $server->register('createTask', function($title, $project_id, $color_id = '', $c ); list($valid,) = $taskValidator->validateCreation($values); - return $valid && $task->create($values) !== false; + return $valid && $taskCreation->create($values) !== false; }); $server->register('getTask', function($task_id) use ($taskFinder) { diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php index 8513501a..ff41a4b9 100644 --- a/tests/units/ActionTaskAssignColorCategoryTest.php +++ b/tests/units/ActionTaskAssignColorCategoryTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\Category; @@ -30,7 +31,7 @@ class ActionTaskAssignColorCategory extends Base $action->setParam('color_id', 'blue'); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); @@ -38,7 +39,7 @@ class ActionTaskAssignColorCategory extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $c->create(array('name' => 'c1'))); $this->assertEquals(2, $c->create(array('name' => 'c2'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2))); // We create an event but we don't do anything $event = array( diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php index b79c96e6..d41a5ef4 100644 --- a/tests/units/ActionTaskAssignColorUserTest.php +++ b/tests/units/ActionTaskAssignColorUserTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; @@ -29,11 +30,11 @@ class ActionTaskAssignColorUser extends Base $action->setParam('color_id', 'blue'); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green'))); // We change the assignee $event = array( diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php index 6a02da67..afc659ce 100644 --- a/tests/units/ActionTaskAssignCurrentUserTest.php +++ b/tests/units/ActionTaskAssignCurrentUserTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\Acl; @@ -47,14 +48,14 @@ class ActionTaskAssignCurrentUser extends Base ); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $a = new Acl($this->container); $this->assertEquals(5, $a->getUserId()); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array( diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php index cdb29a78..07fa1e25 100644 --- a/tests/units/ActionTaskAssignSpecificUserTest.php +++ b/tests/units/ActionTaskAssignSpecificUserTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; @@ -44,11 +45,11 @@ class ActionTaskAssignSpecificUser extends Base $action->setParam('user_id', 1); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array( diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php index bd57cbb9..fd4f752d 100644 --- a/tests/units/ActionTaskCloseTest.php +++ b/tests/units/ActionTaskCloseTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\GithubWebhook; @@ -82,11 +83,11 @@ class ActionTaskCloseTest extends Base $action->setParam('column_id', 2); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array( diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php index 25925f17..bbfa928f 100644 --- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php +++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; @@ -42,12 +43,12 @@ class ActionTaskDuplicateAnotherProject extends Base $action = new Action\TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'project 1'))); $this->assertEquals(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array( diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php index df932daa..605c3e55 100644 --- a/tests/units/ActionTaskMoveAnotherProjectTest.php +++ b/tests/units/ActionTaskMoveAnotherProjectTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; @@ -42,12 +43,12 @@ class ActionTaskMoveAnotherProject extends Base $action = new Action\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); // We create a task in the first column - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'project 1'))); $this->assertEquals(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); // We create an event to move the task to the 2nd column $event = array( diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php index dd8e11fe..1115e4fc 100644 --- a/tests/units/ActionTest.php +++ b/tests/units/ActionTest.php @@ -6,6 +6,7 @@ use Model\Action; use Model\Project; use Model\Board; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Category; @@ -49,7 +50,8 @@ class ActionTest extends Base public function testEventMoveColumn() { - $task = new Task($this->container); + $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $board = new Board($this->container); $project = new Project($this->container); @@ -59,7 +61,7 @@ class ActionTest extends Base $this->assertEquals(1, $project->create(array('name' => 'unit_test'))); // We create a task - $this->assertEquals(1, $task->create(array( + $this->assertEquals(1, $tc->create(array( 'title' => 'unit_test', 'project_id' => 1, 'owner_id' => 1, @@ -86,7 +88,7 @@ class ActionTest extends Base $this->assertEquals(1, $t1['column_id']); // We move our task - $task->movePosition(1, 1, 4, 1); + $t->movePosition(1, 1, 4, 1); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN)); $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_UPDATE)); @@ -99,7 +101,8 @@ class ActionTest extends Base public function testExecuteMultipleActions() { - $task = new Task($this->container); + $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $board = new Board($this->container); $project = new Project($this->container); @@ -110,7 +113,7 @@ class ActionTest extends Base $this->assertEquals(2, $project->create(array('name' => 'unit_test2'))); // We create a task - $this->assertEquals(1, $task->create(array( + $this->assertEquals(1, $tc->create(array( 'title' => 'unit_test', 'project_id' => 1, 'owner_id' => 1, @@ -152,7 +155,7 @@ class ActionTest extends Base $this->assertEquals(1, $t1['project_id']); // We move our task - $task->movePosition(1, 1, 4, 1); + $t->movePosition(1, 1, 4, 1); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE)); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN)); diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php index e7452d26..f169e961 100644 --- a/tests/units/CategoryTest.php +++ b/tests/units/CategoryTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\Category; @@ -12,7 +13,7 @@ class CategoryTest extends Base { public function testCreation() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); @@ -20,7 +21,7 @@ class CategoryTest extends Base $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); $task = $tf->getById(1); $this->assertTrue(is_array($task)); @@ -35,7 +36,7 @@ class CategoryTest extends Base public function testRemove() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); @@ -43,7 +44,7 @@ class CategoryTest extends Base $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1))); $this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2))); $task = $tf->getById(1); $this->assertTrue(is_array($task)); diff --git a/tests/units/CommentTest.php b/tests/units/CommentTest.php index f784382a..8846c0b8 100644 --- a/tests/units/CommentTest.php +++ b/tests/units/CommentTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\Project; use Model\Comment; @@ -11,11 +12,11 @@ class CommentTest extends Base public function testCreate() { $c = new Comment($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $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' => 'bla bla', 'user_id' => 1))); $comment = $c->getById(1); @@ -31,11 +32,11 @@ class CommentTest extends Base public function testGetAll() { $c = new Comment($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $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->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1))); $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1))); @@ -54,11 +55,11 @@ class CommentTest extends Base public function testUpdate() { $c = new Comment($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $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->update(array('id' => 1, 'comment' => 'bla'))); @@ -70,11 +71,11 @@ class CommentTest extends Base public function validateRemove() { $c = new Comment($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $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)); diff --git a/tests/units/ProjectActivityTest.php b/tests/units/ProjectActivityTest.php index f2d3206d..67d94ecf 100644 --- a/tests/units/ProjectActivityTest.php +++ b/tests/units/ProjectActivityTest.php @@ -4,6 +4,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; use Model\TaskFinder; +use Model\TaskCreation; use Model\ProjectActivity; use Model\Project; @@ -12,13 +13,13 @@ class ProjectActivityTest extends Base public function testCreation() { $e = new ProjectActivity($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1))); $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); $this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2)))); @@ -37,12 +38,12 @@ class ProjectActivityTest extends Base public function testFetchAllContent() { $e = new ProjectActivity($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $nb_events = 80; @@ -63,12 +64,12 @@ class ProjectActivityTest extends Base public function testCleanup() { $e = new ProjectActivity($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $max = 15; $nb_events = 100; diff --git a/tests/units/ProjectDailySummary.php b/tests/units/ProjectDailySummary.php index 88a0e05c..9ae875fa 100644 --- a/tests/units/ProjectDailySummary.php +++ b/tests/units/ProjectDailySummary.php @@ -5,6 +5,7 @@ require_once __DIR__.'/Base.php'; use Model\Project; use Model\ProjectDailySummary; use Model\Task; +use Model\TaskCreation; class ProjectDailySummaryTest extends Base { @@ -12,27 +13,27 @@ class ProjectDailySummaryTest extends Base { $p = new Project($this->container); $pds = new ProjectDailySummary($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); $this->assertEquals(0, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d'))); for ($i = 0; $i < 10; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 1))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 1))); } for ($i = 0; $i < 5; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4))); } $pds->updateTotals(1, date('Y-m-d', strtotime('-2days'))); for ($i = 0; $i < 15; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3))); } for ($i = 0; $i < 25; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2))); } $pds->updateTotals(1, date('Y-m-d', strtotime('-1 day'))); @@ -41,15 +42,15 @@ class ProjectDailySummaryTest extends Base $this->assertNotFalse($t->close(2)); for ($i = 0; $i < 3; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3))); } for ($i = 0; $i < 5; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2))); } for ($i = 0; $i < 4; $i++) { - $this->assertNotFalse($t->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4))); + $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4))); } $pds->updateTotals(1, date('Y-m-d')); diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php index 04e0418b..93cdcf6a 100644 --- a/tests/units/ProjectTest.php +++ b/tests/units/ProjectTest.php @@ -6,6 +6,7 @@ use Model\Project; use Model\ProjectPermission; use Model\User; use Model\Task; +use Model\TaskCreation; use Model\Acl; use Model\Board; @@ -48,7 +49,7 @@ class ProjectTest extends Base public function testIsLastModified() { $p = new Project($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $now = time(); $p->attachEvents(); @@ -61,7 +62,7 @@ class ProjectTest extends Base sleep(1); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); $this->assertEquals('Event\ProjectModificationDateListener', $this->container['event']->getLastListenerExecuted()); diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php index f15ebf81..1f6ad8ab 100644 --- a/tests/units/SubtaskTest.php +++ b/tests/units/SubtaskTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\SubTask; use Model\Project; use Model\Category; @@ -12,7 +13,7 @@ class SubTaskTest extends Base { public function testDuplicate() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $s = new SubTask($this->container); $p = new Project($this->container); @@ -20,8 +21,8 @@ class SubTaskTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test1'))); // We create 2 tasks - $this->assertEquals(1, $t->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); - $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0))); + $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'))); diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php new file mode 100644 index 00000000..48742a19 --- /dev/null +++ b/tests/units/TaskCreationTest.php @@ -0,0 +1,330 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\TaskStatus; +use Model\Project; +use Model\ProjectPermission; + +class TaskCreationTest extends Base +{ + public function testNoProjectId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0))); + + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); + } + + public function testNoTitle() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(0, $tc->create(array('project_id' => 1))); + + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE)); + $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); + } + + public function testMinimum() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE)); + $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); + + $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']); + $this->assertEquals(time(), $task['date_modification']); + $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 Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('blue', $task['color_id']); + } + + public function testOwnerId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['owner_id']); + } + + public function testCategoryId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['category_id']); + } + + public function testCreatorId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1, $task['creator_id']); + } + + public function testColumnId() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(1, $task['position']); + } + + public function testPosition() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(2, $task['column_id']); + $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->assertNotFalse($task); + + $this->assertEquals(2, $task['id']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(2, $task['position']); + } + + public function testDescription() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('test', $task['description']); + } + + public function testReference() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals('test', $task['reference']); + } + + public function testDateDue() + { + $date = '2014-11-23'; + $timestamp = strtotime('+2days'); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($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))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals($date, date('Y-m-d', $task['date_due'])); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(2, $task['id']); + $this->assertEquals($timestamp, $task['date_due']); + } + + public function testDateStarted() + { + $date = '2014-11-23'; + $timestamp = strtotime('+2days'); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $date))); + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $timestamp))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals($date, date('Y-m-d', $task['date_started'])); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(2, $task['id']); + $this->assertEquals($timestamp, $task['date_started']); + } + + public function testTime() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + + $this->assertEquals(1, $task['id']); + $this->assertEquals(1.5, $task['time_estimated']); + $this->assertEquals(2.3, $task['time_spent']); + } + + public function testStripColumn() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1'))); + + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertNotFalse($task); + } + + public function testScore() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + + $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']); + } +} diff --git a/tests/units/TaskExportTest.php b/tests/units/TaskExportTest.php index a7faa52a..fc080c0a 100644 --- a/tests/units/TaskExportTest.php +++ b/tests/units/TaskExportTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskExport; use Model\Project; use Model\Category; @@ -12,7 +13,7 @@ class TaskExportTest extends Base { public function testExport() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $p = new Project($this->container); $c = new Category($this->container); $e = new TaskExport($this->container); @@ -36,7 +37,7 @@ class TaskExportTest extends Base 'score' => rand(0, 21) ); - $this->assertEquals($i, $t->create($task)); + $this->assertEquals($i, $tc->create($task)); } $rows = $e->export(1, strtotime('-1 day'), strtotime('+1 day')); diff --git a/tests/units/TaskFinderTest.php b/tests/units/TaskFinderTest.php index 96454f22..96a3809b 100644 --- a/tests/units/TaskFinderTest.php +++ b/tests/units/TaskFinderTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\ProjectPermission; @@ -13,15 +14,15 @@ class TaskFinderTest extends Base { public function testGetOverdueTasks() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day')))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day')))); - $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0))); - $this->assertEquals(4, $t->create(array('title' => 'Task #3', 'project_id' => 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); diff --git a/tests/units/TaskPermissionTest.php b/tests/units/TaskPermissionTest.php index 426941ce..963864b2 100644 --- a/tests/units/TaskPermissionTest.php +++ b/tests/units/TaskPermissionTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\TaskPermission; use Model\Project; @@ -13,7 +14,7 @@ class TaskPermissionTest extends Base { public function testPrepareCreation() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $tp = new TaskPermission($this->container); $p = new Project($this->container); @@ -22,10 +23,10 @@ class TaskPermissionTest extends Base $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456'))); $this->assertTrue($u->create(array('username' => 'toto2', 'password' => '123456'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2))); - $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3))); - $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2))); + $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3))); + $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1))); // User #1 can remove everything $user = $u->getbyId(1); diff --git a/tests/units/TaskStatusTest.php b/tests/units/TaskStatusTest.php index 9b17ccd7..f2847bda 100644 --- a/tests/units/TaskStatusTest.php +++ b/tests/units/TaskStatusTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\TaskStatus; use Model\Project; @@ -12,13 +13,13 @@ class TaskStatusTest extends Base { public function testStatus() { - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $ts = new TaskStatus($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); // The task must be open @@ -32,8 +33,7 @@ class TaskStatusTest extends Base // We close the task - $ts->close(1); - + $this->assertTrue($ts->close(1)); $this->assertTrue($ts->isClosed(1)); $task = $tf->getById(1); @@ -46,8 +46,7 @@ class TaskStatusTest extends Base // We open the task again - $ts->open(1); - + $this->assertTrue($ts->open(1)); $this->assertTrue($ts->isOpen(1)); $task = $tf->getById(1); diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php index 2e478b42..d8f89cf2 100644 --- a/tests/units/TaskTest.php +++ b/tests/units/TaskTest.php @@ -3,6 +3,7 @@ require_once __DIR__.'/Base.php'; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\TaskStatus; use Model\Project; @@ -12,151 +13,15 @@ use Model\User; class TaskTest extends Base { - public function testPrepareCreation() - { - $t = new Task($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - - $input = array( - 'title' => 'youpi', - 'description' => '', - 'project_id' => '1', - 'owner_id' => '0', - 'category_id' => '0', - 'column_id' => '2', - 'color_id' => 'yellow', - 'score' => '', - 'date_due' => '', - 'creator_id' => '1', - 'another_task' => '1', - ); - - $t->prepareCreation($input); - - $this->assertInternalType('integer', $input['date_due']); - $this->assertEquals(0, $input['date_due']); - - $this->assertInternalType('integer', $input['score']); - $this->assertEquals(0, $input['score']); - - $this->assertArrayNotHasKey('another_task', $input); - - $this->assertArrayHasKey('date_creation', $input); - $this->assertEquals(time(), $input['date_creation']); - - $this->assertArrayHasKey('date_modification', $input); - $this->assertEquals(time(), $input['date_modification']); - - $this->assertArrayHasKey('position', $input); - $this->assertGreaterThan(0, $input['position']); - - $input = array( - 'title' => 'youpi', - 'project_id' => '1', - ); - - $t->prepareCreation($input); - - $this->assertArrayNotHasKey('date_due', $input); - $this->assertArrayNotHasKey('score', $input); - - $this->assertArrayHasKey('date_creation', $input); - $this->assertEquals(time(), $input['date_creation']); - - $this->assertArrayHasKey('date_modification', $input); - $this->assertEquals(time(), $input['date_modification']); - - $this->assertArrayHasKey('position', $input); - $this->assertGreaterThan(0, $input['position']); - - $this->assertArrayHasKey('color_id', $input); - $this->assertEquals('yellow', $input['color_id']); - - $this->assertArrayHasKey('column_id', $input); - $this->assertEquals(1, $input['column_id']); - - $input = array( - 'title' => 'youpi', - 'project_id' => '1', - 'date_due' => '2014-09-15', - ); - - $t->prepareCreation($input); - - $this->assertArrayHasKey('date_due', $input); - $this->assertInternalType('integer', $input['date_due']); - $this->assertEquals('2014-09-15', date('Y-m-d', $input['date_due'])); - } - - public function testPrepareModification() - { - $t = new Task($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - - $input = array( - 'id' => '1', - 'description' => 'Boo', - ); - - $t->prepareModification($input); - - $this->assertArrayNotHasKey('id', $input); - $this->assertArrayHasKey('date_modification', $input); - $this->assertEquals(time(), $input['date_modification']); - } - - public function testCreation() - { - $t = new Task($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); - - $task = $tf->getById(1); - $this->assertEquals(1, $task['id']); - $this->assertEquals(1, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals('yellow', $task['color_id']); - $this->assertEquals(time(), $task['date_creation']); - $this->assertEquals(time(), $task['date_modification']); - $this->assertEquals(0, $task['date_due']); - - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1))); - - $task = $tf->getById(2); - $this->assertEquals(2, $task['id']); - $this->assertEquals(1, $task['column_id']); - $this->assertEquals(2, $task['position']); - $this->assertEquals(time(), $task['date_creation']); - $this->assertEquals(time(), $task['date_modification']); - $this->assertEquals(0, $task['date_due']); - - $tasks = $tf->getAll(1, 1); - $this->assertNotEmpty($tasks); - $this->assertTrue(is_array($tasks)); - $this->assertEquals(1, $tasks[0]['id']); - $this->assertEquals(2, $tasks[1]['id']); - - $tasks = $tf->getAll(1, 0); - $this->assertEmpty($tasks); - } - public function testRemove() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); $this->assertTrue($t->remove(1)); $this->assertFalse($t->remove(1234)); @@ -165,19 +30,20 @@ class TaskTest extends Base public function testMoveTaskWithColumnThatNotChange() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2))); - $this->assertEquals(5, $t->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2))); - $this->assertEquals(6, $t->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2))); - $this->assertEquals(7, $t->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3))); - $this->assertEquals(8, $t->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 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))); // We move the task 3 to the column 3 $this->assertTrue($t->movePosition(1, 3, 3, 2)); @@ -227,6 +93,7 @@ class TaskTest extends Base public function testMoveTaskWithBadPreviousPosition() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); @@ -260,14 +127,15 @@ class TaskTest extends Base public function testMoveTaskTop() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 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))); // Move the last task to the top $this->assertTrue($t->movePosition(1, 4, 1, 1)); @@ -297,14 +165,15 @@ class TaskTest extends Base public function testMoveTaskBottom() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 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))); // Move the last task to hte top $this->assertTrue($t->movePosition(1, 1, 1, 4)); @@ -334,6 +203,7 @@ class TaskTest extends Base public function testMovePosition() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); @@ -352,7 +222,7 @@ class TaskTest extends Base 'owner_id' => 0, ); - $this->assertEquals($counter, $t->create($task)); + $this->assertEquals($counter, $tc->create($task)); $task = $tf->getById($counter); $this->assertNotFalse($task); @@ -489,6 +359,7 @@ class TaskTest extends Base public function testDuplicateToTheSameProject() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); @@ -502,7 +373,7 @@ class TaskTest extends Base $this->assertTrue($c->exists(1, 1)); $this->assertTrue($c->exists(2, 1)); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2))); $task = $tf->getById(1); $this->assertNotEmpty($task); @@ -526,6 +397,7 @@ class TaskTest extends Base public function testDuplicateToAnotherProject() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); @@ -538,7 +410,7 @@ class TaskTest extends Base $this->assertTrue($c->exists(1, 1)); // We create a task - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); $task = $tf->getById(1); // We duplicate our task to the 2nd project @@ -559,6 +431,7 @@ class TaskTest extends Base public function testMoveToAnotherProject() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); @@ -573,8 +446,8 @@ class TaskTest extends Base $this->assertEquals(2, $p->create(array('name' => 'test2'))); // We create a task - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); - $this->assertEquals(2, $t->create(array('title' => 'test2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3, 'category_id' => 10, 'position' => 333))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); + $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3, 'category_id' => 10, 'position' => 333))); // We duplicate our task to the 2nd project $task = $tf->getById(1); @@ -606,6 +479,7 @@ class TaskTest extends Base public function testEvents() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $ts = new TaskStatus($this->container); $p = new Project($this->container); @@ -613,7 +487,7 @@ class TaskTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); // We create task - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE)); // We update a task @@ -634,7 +508,7 @@ class TaskTest extends Base $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN)); // We change the position of our task - $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 2))); + $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 2))); $this->assertTrue($t->movePosition(1, 1, 2, 2)); $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION)); diff --git a/tests/units/TimeTrackingTest.php b/tests/units/TimeTrackingTest.php index eb8b6a61..b7790b51 100644 --- a/tests/units/TimeTrackingTest.php +++ b/tests/units/TimeTrackingTest.php @@ -4,6 +4,7 @@ require_once __DIR__.'/Base.php'; use Model\SubTask; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; use Model\TimeTracking; @@ -13,13 +14,14 @@ class TimeTrackingTest extends Base public function testCalculateTime() { $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $s = new SubTask($this->container); $ts = new TimeTracking($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5))); $this->assertTrue($t->update(array('id' => 1, 'time_spent' => 3.5))); $task = $tf->getById(1); diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php index f0ef8543..ebb76a92 100644 --- a/tests/units/UserTest.php +++ b/tests/units/UserTest.php @@ -4,6 +4,7 @@ require_once __DIR__.'/Base.php'; use Model\User; use Model\Task; +use Model\TaskCreation; use Model\TaskFinder; use Model\Project; @@ -119,13 +120,13 @@ class UserTest extends Base public function testRemove() { $u = new User($this->container); - $t = new Task($this->container); + $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); |