summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-14 22:44:25 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-14 22:44:25 -0500
commitb081288188bb1744c9d7bd075aa5936e0ccbb9c4 (patch)
tree68008e35eb129f74b9b2a49f6f6076ed02b601c6
parent1487cb27634161ef558c367150213bc7077e4198 (diff)
Use Pimple instead of Core\Registry and add Monolog for logging
-rw-r--r--app/Action/Base.php20
-rw-r--r--app/Auth/Base.php20
-rw-r--r--app/Auth/RememberMe.php5
-rw-r--r--app/Controller/Base.php17
-rw-r--r--app/Core/Registry.php83
-rw-r--r--app/Core/Request.php14
-rw-r--r--app/Core/Response.php2
-rw-r--r--app/Core/Router.php20
-rw-r--r--app/Core/Session.php2
-rw-r--r--app/Core/Tool.php28
-rw-r--r--app/Event/Base.php16
-rw-r--r--app/Event/ProjectActivityListener.php2
-rw-r--r--app/Model/Action.php2
-rw-r--r--app/Model/Authentication.php6
-rw-r--r--app/Model/Base.php20
-rw-r--r--app/Model/Notification.php7
-rw-r--r--app/Model/Project.php2
-rw-r--r--app/Model/ProjectActivity.php2
-rw-r--r--app/Model/Webhook.php4
-rw-r--r--app/ServiceProvider/Database.php100
-rw-r--r--app/ServiceProvider/Event.php15
-rw-r--r--app/ServiceProvider/Logging.php21
-rw-r--r--app/ServiceProvider/Mailer.php36
-rw-r--r--app/common.php11
-rw-r--r--app/functions.php135
-rw-r--r--app/helpers.php4
-rw-r--r--composer.json4
-rw-r--r--index.php2
-rw-r--r--jsonrpc.php28
-rwxr-xr-xkanboard12
-rw-r--r--tests/functionals/ApiTest.php3
-rw-r--r--tests/units/AclTest.php8
-rw-r--r--tests/units/ActionTaskAssignColorCategoryTest.php12
-rw-r--r--tests/units/ActionTaskAssignColorUserTest.php10
-rw-r--r--tests/units/ActionTaskAssignCurrentUserTest.php14
-rw-r--r--tests/units/ActionTaskAssignSpecificUserTest.php12
-rw-r--r--tests/units/ActionTaskCloseTest.php18
-rw-r--r--tests/units/ActionTaskDuplicateAnotherProjectTest.php12
-rw-r--r--tests/units/ActionTaskMoveAnotherProjectTest.php12
-rw-r--r--tests/units/ActionTest.php38
-rw-r--r--tests/units/Base.php13
-rw-r--r--tests/units/BoardTest.php30
-rw-r--r--tests/units/CategoryTest.php16
-rw-r--r--tests/units/CommentTest.php28
-rw-r--r--tests/units/ConfigTest.php4
-rw-r--r--tests/units/DateParserTest.php4
-rw-r--r--tests/units/NotificationTest.php16
-rw-r--r--tests/units/ProjectActivityTest.php28
-rw-r--r--tests/units/ProjectPermissionTest.php30
-rw-r--r--tests/units/ProjectTest.php26
-rw-r--r--tests/units/SubtaskTest.php6
-rw-r--r--tests/units/TaskExportTest.php8
-rw-r--r--tests/units/TaskFinderTest.php6
-rw-r--r--tests/units/TaskPermissionTest.php10
-rw-r--r--tests/units/TaskTest.php114
-rw-r--r--tests/units/TimeTrackingTest.php10
-rw-r--r--tests/units/UserTest.php14
57 files changed, 549 insertions, 593 deletions
diff --git a/app/Action/Base.php b/app/Action/Base.php
index be9c3d48..a438ce04 100644
--- a/app/Action/Base.php
+++ b/app/Action/Base.php
@@ -2,8 +2,8 @@
namespace Action;
+use Pimple\Container;
use Core\Listener;
-use Core\Registry;
use Core\Tool;
/**
@@ -44,12 +44,12 @@ abstract class Base implements Listener
protected $event_name = '';
/**
- * Registry instance
+ * Container instance
*
* @access protected
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- protected $registry;
+ protected $container;
/**
* Execute the action
@@ -101,13 +101,13 @@ abstract class Base implements Listener
* Constructor
*
* @access public
- * @param \Core\Registry $registry Regsitry instance
- * @param integer $project_id Project id
- * @param string $event_name Attached event name
+ * @param Pimple\Container $container Container
+ * @param integer $project_id Project id
+ * @param string $event_name Attached event name
*/
- public function __construct(Registry $registry, $project_id, $event_name)
+ public function __construct(Container $container, $project_id, $event_name)
{
- $this->registry = $registry;
+ $this->container = $container;
$this->project_id = $project_id;
$this->event_name = $event_name;
}
@@ -132,7 +132,7 @@ abstract class Base implements Listener
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
/**
diff --git a/app/Auth/Base.php b/app/Auth/Base.php
index e174ff8f..e3a1c88c 100644
--- a/app/Auth/Base.php
+++ b/app/Auth/Base.php
@@ -3,7 +3,7 @@
namespace Auth;
use Core\Tool;
-use Core\Registry;
+use Pimple\Container;
/**
* Base auth class
@@ -26,34 +26,34 @@ abstract class Base
protected $db;
/**
- * Registry instance
+ * Container instance
*
* @access protected
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- protected $registry;
+ protected $container;
/**
* Constructor
*
* @access public
- * @param \Core\Registry $registry Registry instance
+ * @param Pimple\Container $container
*/
- public function __construct(Registry $registry)
+ public function __construct(Container $container)
{
- $this->registry = $registry;
- $this->db = $this->registry->shared('db');
+ $this->container = $container;
+ $this->db = $this->container['db'];
}
/**
* Load automatically models
*
* @access public
- * @param string $name Model name
+ * @param string $name Model name
* @return mixed
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
}
diff --git a/app/Auth/RememberMe.php b/app/Auth/RememberMe.php
index 380abbed..2585e96c 100644
--- a/app/Auth/RememberMe.php
+++ b/app/Auth/RememberMe.php
@@ -4,7 +4,6 @@ namespace Auth;
use Core\Request;
use Core\Security;
-use Core\Tool;
/**
* RememberMe model
@@ -311,7 +310,7 @@ class RememberMe extends Base
$expiration,
BASE_URL_DIRECTORY,
null,
- Tool::isHTTPS(),
+ Request::isHTTPS(),
true
);
}
@@ -344,7 +343,7 @@ class RememberMe extends Base
time() - 3600,
BASE_URL_DIRECTORY,
null,
- Tool::isHTTPS(),
+ Request::isHTTPS(),
true
);
}
diff --git a/app/Controller/Base.php b/app/Controller/Base.php
index 2c8fb221..da08a130 100644
--- a/app/Controller/Base.php
+++ b/app/Controller/Base.php
@@ -2,6 +2,7 @@
namespace Controller;
+use Pimple\Container;
use Core\Tool;
use Core\Registry;
use Core\Security;
@@ -75,34 +76,34 @@ abstract class Base
public $session;
/**
- * Registry instance
+ * Container instance
*
* @access private
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- private $registry;
+ private $container;
/**
* Constructor
*
* @access public
- * @param \Core\Registry $registry Registry instance
+ * @param Pimple\Container $container
*/
- public function __construct(Registry $registry)
+ public function __construct(Container $container)
{
- $this->registry = $registry;
+ $this->container = $container;
}
/**
* Load automatically models
*
* @access public
- * @param string $name Model name
+ * @param string $name Model name
* @return mixed
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
/**
diff --git a/app/Core/Registry.php b/app/Core/Registry.php
deleted file mode 100644
index d8b9063e..00000000
--- a/app/Core/Registry.php
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-
-namespace Core;
-
-use RuntimeException;
-
-/**
- * The registry class is a dependency injection container
- *
- * @property mixed db
- * @property mixed event
- * @package core
- * @author Frederic Guillot
- */
-class Registry
-{
- /**
- * Contains all dependencies
- *
- * @access private
- * @var array
- */
- private $container = array();
-
- /**
- * Contains all instances
- *
- * @access private
- * @var array
- */
- private $instances = array();
-
- /**
- * Set a dependency
- *
- * @access public
- * @param string $name Unique identifier for the service/parameter
- * @param mixed $value The value of the parameter or a closure to define an object
- */
- public function __set($name, $value)
- {
- $this->container[$name] = $value;
- }
-
- /**
- * Get a dependency
- *
- * @access public
- * @param string $name Unique identifier for the service/parameter
- * @return mixed The value of the parameter or an object
- * @throws RuntimeException If the identifier is not found
- */
- public function __get($name)
- {
- if (isset($this->container[$name])) {
-
- if (is_callable($this->container[$name])) {
- return $this->container[$name]();
- }
- else {
- return $this->container[$name];
- }
- }
-
- throw new \RuntimeException('Identifier not found in the registry: '.$name);
- }
-
- /**
- * Return a shared instance of a dependency
- *
- * @access public
- * @param string $name Unique identifier for the service/parameter
- * @return mixed Same object instance of the dependency
- */
- public function shared($name)
- {
- if (! isset($this->instances[$name])) {
- $this->instances[$name] = $this->$name;
- }
-
- return $this->instances[$name];
- }
-}
diff --git a/app/Core/Request.php b/app/Core/Request.php
index 1b643208..c7ca3184 100644
--- a/app/Core/Request.php
+++ b/app/Core/Request.php
@@ -125,6 +125,20 @@ class Request
}
/**
+ * Check if the page is requested through HTTPS
+ *
+ * Note: IIS return the value 'off' and other web servers an empty value when it's not HTTPS
+ *
+ * @static
+ * @access public
+ * @return boolean
+ */
+ public static function isHTTPS()
+ {
+ return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== '' && $_SERVER['HTTPS'] !== 'off';
+ }
+
+ /**
* Return a HTTP header value
*
* @access public
diff --git a/app/Core/Response.php b/app/Core/Response.php
index 347cdde7..6534d64f 100644
--- a/app/Core/Response.php
+++ b/app/Core/Response.php
@@ -246,7 +246,7 @@ class Response
*/
public function hsts()
{
- if (Tool::isHTTPS()) {
+ if (Request::isHTTPS()) {
header('Strict-Transport-Security: max-age=31536000');
}
}
diff --git a/app/Core/Router.php b/app/Core/Router.php
index c9af6e2c..1750753c 100644
--- a/app/Core/Router.php
+++ b/app/Core/Router.php
@@ -2,6 +2,8 @@
namespace Core;
+use Pimple\Container;
+
/**
* Router class
*
@@ -27,24 +29,24 @@ class Router
private $action = '';
/**
- * Registry instance
+ * Container instance
*
* @access private
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- private $registry;
+ private $container;
/**
* Constructor
*
* @access public
- * @param Registry $registry Registry instance
- * @param string $controller Controller name
- * @param string $action Action name
+ * @param Pimple\Container $container Container instance
+ * @param string $controller Controller name
+ * @param string $action Action name
*/
- public function __construct(Registry $registry, $controller = '', $action = '')
+ public function __construct(Container $container, $controller = '', $action = '')
{
- $this->registry = $registry;
+ $this->container = $container;
$this->controller = empty($_GET['controller']) ? $controller : $_GET['controller'];
$this->action = empty($_GET['action']) ? $action : $_GET['action'];
}
@@ -81,7 +83,7 @@ class Router
return false;
}
- $instance = new $class($this->registry);
+ $instance = new $class($this->container);
$instance->request = new Request;
$instance->response = new Response;
$instance->session = new Session;
diff --git a/app/Core/Session.php b/app/Core/Session.php
index 6028f0b9..e50c36b3 100644
--- a/app/Core/Session.php
+++ b/app/Core/Session.php
@@ -49,7 +49,7 @@ class Session
self::SESSION_LIFETIME,
$base_path ?: '/',
null,
- Tool::isHTTPS(),
+ Request::isHTTPS(),
true
);
diff --git a/app/Core/Tool.php b/app/Core/Tool.php
index e54a0d3b..c010d932 100644
--- a/app/Core/Tool.php
+++ b/app/Core/Tool.php
@@ -2,6 +2,8 @@
namespace Core;
+use Pimple\Container;
+
/**
* Tool class
*
@@ -37,31 +39,17 @@ class Tool
*
* @static
* @access public
- * @param Core\Registry $registry DPI container
- * @param string $name Model name
+ * @param Pimple\Container $container Container instance
+ * @param string $name Model name
* @return mixed
*/
- public static function loadModel(Registry $registry, $name)
+ public static function loadModel(Container $container, $name)
{
- if (! isset($registry->$name)) {
+ if (! isset($container[$name])) {
$class = '\Model\\'.ucfirst($name);
- $registry->$name = new $class($registry);
+ $container[$name] = new $class($container);
}
- return $registry->shared($name);
- }
-
- /**
- * Check if the page is requested through HTTPS
- *
- * Note: IIS return the value 'off' and other web servers an empty value when it's not HTTPS
- *
- * @static
- * @access public
- * @return boolean
- */
- public static function isHTTPS()
- {
- return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== '' && $_SERVER['HTTPS'] !== 'off';
+ return $container[$name];
}
}
diff --git a/app/Event/Base.php b/app/Event/Base.php
index 745871a5..5381471a 100644
--- a/app/Event/Base.php
+++ b/app/Event/Base.php
@@ -2,8 +2,8 @@
namespace Event;
+use Pimple\Container;
use Core\Listener;
-use Core\Registry;
use Core\Tool;
/**
@@ -25,19 +25,19 @@ abstract class Base implements Listener
* Registry instance
*
* @access protected
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- protected $registry;
+ protected $container;
/**
* Constructor
*
* @access public
- * @param \Core\Registry $registry Regsitry instance
+ * @param Pimple\Container $container
*/
- public function __construct(Registry $registry)
+ public function __construct(Container $container)
{
- $this->registry = $registry;
+ $this->container = $container;
}
/**
@@ -60,7 +60,7 @@ abstract class Base implements Listener
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
/**
@@ -73,7 +73,7 @@ abstract class Base implements Listener
*/
public function getEventNamespace()
{
- $event_name = $this->registry->event->getLastTriggeredEvent();
+ $event_name = $this->container['event']->getLastTriggeredEvent();
return substr($event_name, 0, strpos($event_name, '.'));
}
}
diff --git a/app/Event/ProjectActivityListener.php b/app/Event/ProjectActivityListener.php
index 8958bd2b..75efe65d 100644
--- a/app/Event/ProjectActivityListener.php
+++ b/app/Event/ProjectActivityListener.php
@@ -27,7 +27,7 @@ class ProjectActivityListener extends Base
$values['task']['project_id'],
$values['task']['id'],
$this->acl->getUserId(),
- $this->registry->event->getLastTriggeredEvent(),
+ $this->container['event']->getLastTriggeredEvent(),
$values
);
}
diff --git a/app/Model/Action.php b/app/Model/Action.php
index c3acdc5b..f8dbd88e 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -264,7 +264,7 @@ class Action extends Base
public function load($name, $project_id, $event)
{
$className = '\Action\\'.$name;
- return new $className($this->registry, $project_id, $event);
+ return new $className($this->container, $project_id, $event);
}
/**
diff --git a/app/Model/Authentication.php b/app/Model/Authentication.php
index b9ebcfe2..a0e9684f 100644
--- a/app/Model/Authentication.php
+++ b/app/Model/Authentication.php
@@ -24,12 +24,12 @@ class Authentication extends Base
*/
public function backend($name)
{
- if (! isset($this->registry->$name)) {
+ if (! isset($this->container[$name])) {
$class = '\Auth\\'.ucfirst($name);
- $this->registry->$name = new $class($this->registry);
+ $this->container[$name] = new $class($this->container);
}
- return $this->registry->shared($name);
+ return $this->container[$name];
}
/**
diff --git a/app/Model/Base.php b/app/Model/Base.php
index 72d91c3c..5a8d8f1c 100644
--- a/app/Model/Base.php
+++ b/app/Model/Base.php
@@ -4,7 +4,7 @@ namespace Model;
use Core\Event;
use Core\Tool;
-use Core\Registry;
+use Pimple\Container;
use PicoDb\Database;
/**
@@ -58,24 +58,24 @@ abstract class Base
public $event;
/**
- * Registry instance
+ * Container instance
*
* @access protected
- * @var \Core\Registry
+ * @var Pimple\Container
*/
- protected $registry;
+ protected $container;
/**
* Constructor
*
* @access public
- * @param \Core\Registry $registry Registry instance
+ * @param Pimple\Container $container
*/
- public function __construct(Registry $registry)
+ public function __construct(Container $container)
{
- $this->registry = $registry;
- $this->db = $this->registry->shared('db');
- $this->event = $this->registry->shared('event');
+ $this->container = $container;
+ $this->db = $this->container['db'];
+ $this->event = $this->container['event'];
}
/**
@@ -87,7 +87,7 @@ abstract class Base
*/
public function __get($name)
{
- return Tool::loadModel($this->registry, $name);
+ return Tool::loadModel($this->container, $name);
}
/**
diff --git a/app/Model/Notification.php b/app/Model/Notification.php
index d2fcf525..32765041 100644
--- a/app/Model/Notification.php
+++ b/app/Model/Notification.php
@@ -117,7 +117,7 @@ class Notification extends Base
foreach ($events as $event_name => $template_name) {
- $listener = new NotificationListener($this->registry);
+ $listener = new NotificationListener($this->container);
$listener->setTemplate($template_name);
$this->event->attach($event_name, $listener);
@@ -135,8 +135,7 @@ class Notification extends Base
public function sendEmails($template, array $users, array $data)
{
try {
- $transport = $this->registry->shared('mailer');
- $mailer = Swift_Mailer::newInstance($transport);
+ $mailer = Swift_Mailer::newInstance($this->container['mailer']);
$message = Swift_Message::newInstance()
->setSubject($this->getMailSubject($template, $data))
@@ -149,7 +148,7 @@ class Notification extends Base
}
}
catch (Swift_TransportException $e) {
- debug($e->getMessage());
+ $this->container['logger']->addError($e->getMessage());
}
}
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 305e3f1e..2abee2aa 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -546,7 +546,7 @@ class Project extends Base
GithubWebhook::EVENT_COMMIT,
);
- $listener = new ProjectModificationDateListener($this->registry);
+ $listener = new ProjectModificationDateListener($this->container);
foreach ($events as $event_name) {
$this->event->attach($event_name, $listener);
diff --git a/app/Model/ProjectActivity.php b/app/Model/ProjectActivity.php
index 6d6ef454..9d7ecfac 100644
--- a/app/Model/ProjectActivity.php
+++ b/app/Model/ProjectActivity.php
@@ -147,7 +147,7 @@ class ProjectActivity extends Base
SubTask::EVENT_CREATE,
);
- $listener = new ProjectActivityListener($this->registry);
+ $listener = new ProjectActivityListener($this->container);
foreach ($events as $event_name) {
$this->event->attach($event_name, $listener);
diff --git a/app/Model/Webhook.php b/app/Model/Webhook.php
index b84728cf..14d50684 100644
--- a/app/Model/Webhook.php
+++ b/app/Model/Webhook.php
@@ -93,7 +93,7 @@ class Webhook extends Base
Task::EVENT_ASSIGNEE_CHANGE,
);
- $listener = new WebhookListener($this->registry);
+ $listener = new WebhookListener($this->container);
$listener->setUrl($this->url_task_modification);
foreach ($events as $event_name) {
@@ -108,7 +108,7 @@ class Webhook extends Base
*/
public function attachCreateEvents()
{
- $listener = new WebhookListener($this->registry);
+ $listener = new WebhookListener($this->container);
$listener->setUrl($this->url_task_creation);
$this->event->attach(Task::EVENT_CREATE, $listener);
diff --git a/app/ServiceProvider/Database.php b/app/ServiceProvider/Database.php
new file mode 100644
index 00000000..75e1f73e
--- /dev/null
+++ b/app/ServiceProvider/Database.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace ServiceProvider;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+use PicoDb\Database as Dbal;
+
+class Database implements ServiceProviderInterface
+{
+ public function register(Container $container)
+ {
+ $container['db'] = $this->getInstance();
+ }
+
+ /**
+ * Setup the database driver and execute schema migration
+ *
+ * @return PicoDb\Database
+ */
+ public function getInstance()
+ {
+ switch (DB_DRIVER) {
+ case 'sqlite':
+ $db = $this->getSqliteInstance();
+ break;
+
+ case 'mysql':
+ $db = $this->getMysqlInstance();
+ break;
+
+ case 'postgres':
+ $db = $this->getPostgresInstance();
+ break;
+
+ default:
+ die('Database driver not supported');
+ }
+
+ if ($db->schema()->check(\Schema\VERSION)) {
+ return $db;
+ }
+ else {
+ $errors = $db->getLogMessages();
+ die('Unable to migrate database schema: <br/><br/><strong>'.(isset($errors[0]) ? $errors[0] : 'Unknown error').'</strong>');
+ }
+ }
+
+ /**
+ * Setup the Sqlite database driver
+ *
+ * @return PicoDb\Database
+ */
+ function getSqliteInstance()
+ {
+ require_once __DIR__.'/../Schema/Sqlite.php';
+
+ return new Dbal(array(
+ 'driver' => 'sqlite',
+ 'filename' => DB_FILENAME
+ ));
+ }
+
+ /**
+ * Setup the Mysql database driver
+ *
+ * @return PicoDb\Database
+ */
+ function getMysqlInstance()
+ {
+ require_once __DIR__.'/../Schema/Mysql.php';
+
+ return new Dbal(array(
+ 'driver' => 'mysql',
+ 'hostname' => DB_HOSTNAME,
+ 'username' => DB_USERNAME,
+ 'password' => DB_PASSWORD,
+ 'database' => DB_NAME,
+ 'charset' => 'utf8',
+ ));
+ }
+
+ /**
+ * Setup the Postgres database driver
+ *
+ * @return PicoDb\Database
+ */
+ public function getPostgresInstance()
+ {
+ require_once __DIR__.'/../Schema/Postgres.php';
+
+ return new Dbal(array(
+ 'driver' => 'postgres',
+ 'hostname' => DB_HOSTNAME,
+ 'username' => DB_USERNAME,
+ 'password' => DB_PASSWORD,
+ 'database' => DB_NAME,
+ ));
+ }
+}
diff --git a/app/ServiceProvider/Event.php b/app/ServiceProvider/Event.php
new file mode 100644
index 00000000..0436aa7b
--- /dev/null
+++ b/app/ServiceProvider/Event.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace ServiceProvider;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+use Core\Event as EventDispatcher;
+
+class Event implements ServiceProviderInterface
+{
+ public function register(Container $container)
+ {
+ $container['event'] = new EventDispatcher;
+ }
+}
diff --git a/app/ServiceProvider/Logging.php b/app/ServiceProvider/Logging.php
new file mode 100644
index 00000000..9737cadc
--- /dev/null
+++ b/app/ServiceProvider/Logging.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace ServiceProvider;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+use Monolog\Logger;
+use Monolog\Handler\StreamHandler;
+use Monolog\Handler\SyslogHandler;
+
+class Logging implements ServiceProviderInterface
+{
+ public function register(Container $container)
+ {
+ $logger = new Logger('app');
+ $logger->pushHandler(new StreamHandler(__DIR__.'/../../data/debug.log', Logger::DEBUG));
+ $logger->pushHandler(new SyslogHandler('kanboard', LOG_USER, Logger::DEBUG));
+
+ $container['logger'] = $logger;
+ }
+}
diff --git a/app/ServiceProvider/Mailer.php b/app/ServiceProvider/Mailer.php
new file mode 100644
index 00000000..c82c16f6
--- /dev/null
+++ b/app/ServiceProvider/Mailer.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace ServiceProvider;
+
+use Pimple\Container;
+use Pimple\ServiceProviderInterface;
+use Swift_SmtpTransport;
+use Swift_SendmailTransport;
+use Swift_MailTransport;
+
+class Mailer implements ServiceProviderInterface
+{
+ public function register(Container $container)
+ {
+ $container['mailer'] = $this->getInstance();
+ }
+
+ public function getInstance()
+ {
+ switch (MAIL_TRANSPORT) {
+ case 'smtp':
+ $transport = Swift_SmtpTransport::newInstance(MAIL_SMTP_HOSTNAME, MAIL_SMTP_PORT);
+ $transport->setUsername(MAIL_SMTP_USERNAME);
+ $transport->setPassword(MAIL_SMTP_PASSWORD);
+ $transport->setEncryption(MAIL_SMTP_ENCRYPTION);
+ break;
+ case 'sendmail':
+ $transport = Swift_SendmailTransport::newInstance(MAIL_SENDMAIL_COMMAND);
+ break;
+ default:
+ $transport = Swift_MailTransport::newInstance();
+ }
+
+ return $transport;
+ }
+}
diff --git a/app/common.php b/app/common.php
index 613d4501..addfe874 100644
--- a/app/common.php
+++ b/app/common.php
@@ -1,7 +1,5 @@
<?php
-// Common file between cli and web interface
-
require 'vendor/autoload.php';
// Include custom config file
@@ -11,7 +9,8 @@ if (file_exists('config.php')) {
require __DIR__.'/constants.php';
-$registry = new Core\Registry;
-$registry->db = setup_db();
-$registry->event = setup_events();
-$registry->mailer = function() { return setup_mailer(); };
+$container = new Pimple\Container;
+$container->register(new ServiceProvider\Logging);
+$container->register(new ServiceProvider\Database);
+$container->register(new ServiceProvider\Event);
+$container->register(new ServiceProvider\Mailer);
diff --git a/app/functions.php b/app/functions.php
index 5fe218ce..d45e78e7 100644
--- a/app/functions.php
+++ b/app/functions.php
@@ -1,141 +1,6 @@
<?php
-use Core\Event;
use Core\Translator;
-use PicoDb\Database;
-
-/**
- * Send a debug message to the log files
- *
- * @param mixed $message Variable or string
- */
-function debug($message)
-{
- if (! is_string($message)) {
- $message = var_export($message, true);
- }
-
- error_log($message.PHP_EOL, 3, 'data/debug.log');
-}
-
-/**
- * Setup events
- *
- * @return Core\Event
- */
-function setup_events()
-{
- return new Event;
-}
-
-/**
- * Setup the mailer according to the configuration
- *
- * @return Swift_SmtpTransport
- */
-function setup_mailer()
-{
- switch (MAIL_TRANSPORT) {
- case 'smtp':
- $transport = Swift_SmtpTransport::newInstance(MAIL_SMTP_HOSTNAME, MAIL_SMTP_PORT);
- $transport->setUsername(MAIL_SMTP_USERNAME);
- $transport->setPassword(MAIL_SMTP_PASSWORD);
- $transport->setEncryption(MAIL_SMTP_ENCRYPTION);
- break;
- case 'sendmail':
- $transport = Swift_SendmailTransport::newInstance(MAIL_SENDMAIL_COMMAND);
- break;
- default:
- $transport = Swift_MailTransport::newInstance();
- }
-
- return $transport;
-}
-
-/**
- * Setup the database driver and execute schema migration
- *
- * @return PicoDb\Database
- */
-function setup_db()
-{
- switch (DB_DRIVER) {
- case 'sqlite':
- $db = setup_sqlite();
- break;
-
- case 'mysql':
- $db = setup_mysql();
- break;
-
- case 'postgres':
- $db = setup_postgres();
- break;
-
- default:
- die('Database driver not supported');
- }
-
- if ($db->schema()->check(Schema\VERSION)) {
- return $db;
- }
- else {
- $errors = $db->getLogMessages();
- die('Unable to migrate database schema: <br/><br/><strong>'.(isset($errors[0]) ? $errors[0] : 'Unknown error').'</strong>');
- }
-}
-
-/**
- * Setup the Sqlite database driver
- *
- * @return PicoDb\Database
- */
-function setup_sqlite()
-{
- require_once __DIR__.'/Schema/Sqlite.php';
-
- return new Database(array(
- 'driver' => 'sqlite',
- 'filename' => DB_FILENAME
- ));
-}
-
-/**
- * Setup the Mysql database driver
- *
- * @return PicoDb\Database
- */
-function setup_mysql()
-{
- require_once __DIR__.'/Schema/Mysql.php';
-
- return new Database(array(
- 'driver' => 'mysql',
- 'hostname' => DB_HOSTNAME,
- 'username' => DB_USERNAME,
- 'password' => DB_PASSWORD,
- 'database' => DB_NAME,
- 'charset' => 'utf8',
- ));
-}
-
-/**
- * Setup the Postgres database driver
- *
- * @return PicoDb\Database
- */
-function setup_postgres()
-{
- require_once __DIR__.'/Schema/Postgres.php';
-
- return new Database(array(
- 'driver' => 'postgres',
- 'hostname' => DB_HOSTNAME,
- 'username' => DB_USERNAME,
- 'password' => DB_PASSWORD,
- 'database' => DB_NAME,
- ));
-}
/**
* Translate a string
diff --git a/app/helpers.php b/app/helpers.php
index f25db0f0..14d6a5ee 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -8,7 +8,7 @@ namespace Helper;
*/
use Core\Security;
use Core\Template;
-use Core\Tool;
+use Core\Request;
use Parsedown;
/**
@@ -142,7 +142,7 @@ function markdown($text, array $link = array('controller' => 'task', 'action' =>
*/
function get_current_base_url()
{
- $url = Tool::isHTTPS() ? 'https://' : 'http://';
+ $url = Request::isHTTPS() ? 'https://' : 'http://';
$url .= $_SERVER['SERVER_NAME'];
$url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 ? '' : ':'.$_SERVER['SERVER_PORT'];
$url .= dirname($_SERVER['PHP_SELF']) !== '/' ? dirname($_SERVER['PHP_SELF']).'/' : '/';
diff --git a/composer.json b/composer.json
index 1f7009ab..6c6f10fa 100644
--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,9 @@
"fguillot/json-rpc": "dev-master",
"fguillot/picodb": "dev-master",
"erusev/parsedown": "1.1.1",
- "lusitanian/oauth": "0.3.5"
+ "lusitanian/oauth": "0.3.5",
+ "pimple/pimple": "~3.0",
+ "monolog/monolog": "1.11.0"
},
"autoload": {
"psr-0": {"": "app/"},
diff --git a/index.php b/index.php
index cee8017d..f146c6d1 100644
--- a/index.php
+++ b/index.php
@@ -5,5 +5,5 @@ require __DIR__.'/app/common.php';
use Core\Router;
-$router = new Router($registry);
+$router = new Router($container);
$router->execute();
diff --git a/jsonrpc.php b/jsonrpc.php
index b81a96e7..d1ef7e6e 100644
--- a/jsonrpc.php
+++ b/jsonrpc.php
@@ -18,23 +18,23 @@ use Model\Action;
use Model\Webhook;
use Model\Notification;
-$config = new Config($registry);
+$config = new Config($container);
$config->setupTranslations();
$config->setupTimezone();
-$project = new Project($registry);
-$projectPermission = new ProjectPermission($registry);
-$task = new Task($registry);
-$taskFinder = new TaskFinder($registry);
-$taskValidator = new TaskValidator($registry);
-$user = new User($registry);
-$category = new Category($registry);
-$comment = new Comment($registry);
-$subtask = new SubTask($registry);
-$board = new Board($registry);
-$action = new Action($registry);
-$webhook = new Webhook($registry);
-$notification = new Notification($registry);
+$project = new Project($container);
+$projectPermission = new ProjectPermission($container);
+$task = new Task($container);
+$taskFinder = new TaskFinder($container);
+$taskValidator = new TaskValidator($container);
+$user = new User($container);
+$category = new Category($container);
+$comment = new Comment($container);
+$subtask = new SubTask($container);
+$board = new Board($container);
+$action = new Action($container);
+$webhook = new Webhook($container);
+$notification = new Notification($container);
$action->attachEvents();
$project->attachEvents();
diff --git a/kanboard b/kanboard
index b82bff0d..3e0cef3d 100755
--- a/kanboard
+++ b/kanboard
@@ -11,7 +11,7 @@ use Model\TaskFinder;
use Model\TaskExport;
use Model\Notification;
-$config = new Config($registry);
+$config = new Config($container);
$config->setupTranslations();
$config->setupTimezone();
@@ -26,7 +26,7 @@ $cli->register('help', function() {
});
// CSV Export
-$cli->register('export-csv', function() use ($cli, $registry) {
+$cli->register('export-csv', function() use ($cli, $container) {
if ($GLOBALS['argc'] !== 5) {
$cli->call($cli->default_command);
@@ -36,7 +36,7 @@ $cli->register('export-csv', function() use ($cli, $registry) {
$start_date = $GLOBALS['argv'][3];
$end_date = $GLOBALS['argv'][4];
- $taskExport = new TaskExport($registry);
+ $taskExport = new TaskExport($container);
$data = $taskExport->export($project_id, $start_date, $end_date);
if (is_array($data)) {
@@ -45,10 +45,10 @@ $cli->register('export-csv', function() use ($cli, $registry) {
});
// Send notification for tasks due
-$cli->register('send-notifications-due-tasks', function() use ($cli, $registry) {
+$cli->register('send-notifications-due-tasks', function() use ($cli, $container) {
- $notificationModel = new Notification($registry);
- $taskModel = new TaskFinder($registry);
+ $notificationModel = new Notification($container);
+ $taskModel = new TaskFinder($container);
$tasks = $taskModel->getOverdueTasks();
// Group tasks by project
diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php
index 88807007..262d289e 100644
--- a/tests/functionals/ApiTest.php
+++ b/tests/functionals/ApiTest.php
@@ -25,7 +25,8 @@ class Api extends PHPUnit_Framework_TestCase
$pdo = new PDO('pgsql:host='.DB_HOSTNAME.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD);
}
- setup_db();
+ $service = new ServiceProvider\Database;
+ $service->getInstance();
$pdo->exec("UPDATE settings SET value='".API_KEY."' WHERE option='api_token'");
$pdo = null;
diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php
index 83351616..99d1a849 100644
--- a/tests/units/AclTest.php
+++ b/tests/units/AclTest.php
@@ -12,7 +12,7 @@ class AclTest extends Base
'controller1' => array('action1', 'action3'),
);
- $acl = new Acl($this->registry);
+ $acl = new Acl($this->container);
$this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action1'));
$this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action3'));
$this->assertFalse($acl->isAllowedAction($acl_rules, 'controller1', 'action2'));
@@ -22,7 +22,7 @@ class AclTest extends Base
public function testIsAdmin()
{
- $acl = new Acl($this->registry);
+ $acl = new Acl($this->container);
$_SESSION = array();
$this->assertFalse($acl->isAdminUser());
@@ -45,7 +45,7 @@ class AclTest extends Base
public function testIsUser()
{
- $acl = new Acl($this->registry);
+ $acl = new Acl($this->container);
$_SESSION = array();
$this->assertFalse($acl->isRegularUser());
@@ -68,7 +68,7 @@ class AclTest extends Base
public function testIsPageAllowed()
{
- $acl = new Acl($this->registry);
+ $acl = new Acl($this->container);
// Public access
$_SESSION = array();
diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php
index b7d99dae..8513501a 100644
--- a/tests/units/ActionTaskAssignColorCategoryTest.php
+++ b/tests/units/ActionTaskAssignColorCategoryTest.php
@@ -11,7 +11,7 @@ class ActionTaskAssignColorCategory extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignColorCategory($this->registry, 3, Task::EVENT_CREATE_UPDATE);
+ $action = new Action\TaskAssignColorCategory($this->container, 3, Task::EVENT_CREATE_UPDATE);
$event = array(
'project_id' => 2,
@@ -25,15 +25,15 @@ class ActionTaskAssignColorCategory extends Base
public function testExecute()
{
- $action = new Action\TaskAssignColorCategory($this->registry, 1, Task::EVENT_CREATE_UPDATE);
+ $action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE);
$action->setParam('category_id', 1);
$action->setParam('color_id', 'blue');
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $c->create(array('name' => 'c1')));
diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php
index 61600fdc..b79c96e6 100644
--- a/tests/units/ActionTaskAssignColorUserTest.php
+++ b/tests/units/ActionTaskAssignColorUserTest.php
@@ -10,7 +10,7 @@ class ActionTaskAssignColorUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignColorUser($this->registry, 3, Task::EVENT_CREATE);
+ $action = new Action\TaskAssignColorUser($this->container, 3, Task::EVENT_CREATE);
$event = array(
'project_id' => 2,
@@ -24,14 +24,14 @@ class ActionTaskAssignColorUser extends Base
public function testExecute()
{
- $action = new Action\TaskAssignColorUser($this->registry, 1, Task::EVENT_ASSIGNEE_CHANGE);
+ $action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE);
$action->setParam('user_id', 1);
$action->setParam('color_id', 'blue');
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($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')));
diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php
index edc2577c..6a02da67 100644
--- a/tests/units/ActionTaskAssignCurrentUserTest.php
+++ b/tests/units/ActionTaskAssignCurrentUserTest.php
@@ -11,7 +11,7 @@ class ActionTaskAssignCurrentUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
+ $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -26,7 +26,7 @@ class ActionTaskAssignCurrentUser extends Base
public function testBadColumn()
{
- $action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
+ $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -40,17 +40,17 @@ class ActionTaskAssignCurrentUser extends Base
public function testExecute()
{
- $action = new Action\TaskAssignCurrentUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$_SESSION = array(
'user' => array('id' => 5)
);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $a = new Acl($this->registry);
+ $t = new Task($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')));
diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php
index 8795d5fb..cdb29a78 100644
--- a/tests/units/ActionTaskAssignSpecificUserTest.php
+++ b/tests/units/ActionTaskAssignSpecificUserTest.php
@@ -10,7 +10,7 @@ class ActionTaskAssignSpecificUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -25,7 +25,7 @@ class ActionTaskAssignSpecificUser extends Base
public function testBadColumn()
{
- $action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -39,14 +39,14 @@ class ActionTaskAssignSpecificUser extends Base
public function testExecute()
{
- $action = new Action\TaskAssignSpecificUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$action->setParam('user_id', 1);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($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)));
diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php
index 6c8e4cf1..bd57cbb9 100644
--- a/tests/units/ActionTaskCloseTest.php
+++ b/tests/units/ActionTaskCloseTest.php
@@ -11,7 +11,7 @@ class ActionTaskCloseTest extends Base
{
public function testExecutable()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -22,7 +22,7 @@ class ActionTaskCloseTest extends Base
$this->assertTrue($action->isExecutable($event));
- $action = new Action\TaskClose($this->registry, 3, GithubWebhook::EVENT_COMMIT);
+ $action = new Action\TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT);
$event = array(
'project_id' => 3,
@@ -34,7 +34,7 @@ class ActionTaskCloseTest extends Base
public function testBadEvent()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_UPDATE);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_UPDATE);
$action->setParam('column_id', 5);
$event = array(
@@ -49,7 +49,7 @@ class ActionTaskCloseTest extends Base
public function testBadProject()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -64,7 +64,7 @@ class ActionTaskCloseTest extends Base
public function testBadColumn()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -78,13 +78,13 @@ class ActionTaskCloseTest extends Base
public function testExecute()
{
- $action = new Action\TaskClose($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($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)));
diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
index 6fb3c8d8..25925f17 100644
--- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php
+++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
@@ -10,7 +10,7 @@ class ActionTaskDuplicateAnotherProject extends Base
{
public function testBadProject()
{
- $action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -25,7 +25,7 @@ class ActionTaskDuplicateAnotherProject extends Base
public function testBadColumn()
{
- $action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -39,12 +39,12 @@ class ActionTaskDuplicateAnotherProject extends Base
public function testExecute()
{
- $action = new Action\TaskDuplicateAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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(2, $p->create(array('name' => 'project 2')));
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php
index 903cc392..df932daa 100644
--- a/tests/units/ActionTaskMoveAnotherProjectTest.php
+++ b/tests/units/ActionTaskMoveAnotherProjectTest.php
@@ -10,7 +10,7 @@ class ActionTaskMoveAnotherProject extends Base
{
public function testBadProject()
{
- $action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -25,7 +25,7 @@ class ActionTaskMoveAnotherProject extends Base
public function testBadColumn()
{
- $action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -39,12 +39,12 @@ class ActionTaskMoveAnotherProject extends Base
public function testExecute()
{
- $action = new Action\TaskMoveAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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(2, $p->create(array('name' => 'project 2')));
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php
index aa923445..dd8e11fe 100644
--- a/tests/units/ActionTest.php
+++ b/tests/units/ActionTest.php
@@ -13,9 +13,9 @@ class ActionTest extends Base
{
public function testFetchActions()
{
- $action = new Action($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
+ $action = new Action($this->container);
+ $board = new Board($this->container);
+ $project = new Project($this->container);
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
@@ -49,11 +49,11 @@ class ActionTest extends Base
public function testEventMoveColumn()
{
- $task = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
- $action = new Action($this->registry);
+ $task = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $board = new Board($this->container);
+ $project = new Project($this->container);
+ $action = new Action($this->container);
// We create a project
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
@@ -88,8 +88,8 @@ class ActionTest extends Base
// We move our task
$task->movePosition(1, 1, 4, 1);
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
- $this->assertFalse($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
+ $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
// Our task should be closed
$t1 = $tf->getById(1);
@@ -99,11 +99,11 @@ class ActionTest extends Base
public function testExecuteMultipleActions()
{
- $task = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
- $action = new Action($this->registry);
+ $task = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $board = new Board($this->container);
+ $project = new Project($this->container);
+ $action = new Action($this->container);
// We create 2 projects
$this->assertEquals(1, $project->create(array('name' => 'unit_test1')));
@@ -142,8 +142,8 @@ class ActionTest extends Base
$action->attachEvents();
// Events should be attached
- $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
- $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
+ $this->assertTrue($this->container['event']->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
+ $this->assertTrue($this->container['event']->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
// Our task should be open, linked to the first project and in the first column
$t1 = $tf->getById(1);
@@ -154,8 +154,8 @@ class ActionTest extends Base
// We move our task
$task->movePosition(1, 1, 4, 1);
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
// Our task should be closed
$t1 = $tf->getById(1);
diff --git a/tests/units/Base.php b/tests/units/Base.php
index cb56060e..27960610 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -3,19 +3,12 @@
require __DIR__.'/../../vendor/autoload.php';
require __DIR__.'/../../app/constants.php';
-use Core\Loader;
-use Core\Registry;
-
date_default_timezone_set('UTC');
abstract class Base extends PHPUnit_Framework_TestCase
{
public function setUp()
{
- $this->registry = new Registry;
- $this->registry->db = function() { return setup_db(); };
- $this->registry->event = function() { return setup_events(); };
-
if (DB_DRIVER === 'mysql') {
$pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
$pdo->exec('DROP DATABASE '.DB_NAME);
@@ -28,10 +21,14 @@ abstract class Base extends PHPUnit_Framework_TestCase
$pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
$pdo = null;
}
+
+ $this->container = new Pimple\Container;
+ $this->container->register(new ServiceProvider\Database);
+ $this->container->register(new ServiceProvider\Event);
}
public function tearDown()
{
- $this->registry->shared('db')->closeConnection();
+ $this->container['db']->closeConnection();
}
}
diff --git a/tests/units/BoardTest.php b/tests/units/BoardTest.php
index cdf23a82..b83fee85 100644
--- a/tests/units/BoardTest.php
+++ b/tests/units/BoardTest.php
@@ -10,9 +10,9 @@ class BoardTest extends Base
{
public function testCreation()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
- $c = new Config($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
+ $c = new Config($this->container);
// Default columns
@@ -43,8 +43,8 @@ class BoardTest extends Base
public function testGetBoard()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -57,8 +57,8 @@ class BoardTest extends Base
public function testGetColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -72,8 +72,8 @@ class BoardTest extends Base
public function testRemoveColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertTrue($b->removeColumn(3));
@@ -86,8 +86,8 @@ class BoardTest extends Base
public function testUpdateColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -107,8 +107,8 @@ class BoardTest extends Base
public function testAddColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertTrue($b->addColumn(1, 'another column'));
@@ -129,8 +129,8 @@ class BoardTest extends Base
public function testMoveColumns()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php
index ef061419..e7452d26 100644
--- a/tests/units/CategoryTest.php
+++ b/tests/units/CategoryTest.php
@@ -12,10 +12,10 @@ class CategoryTest extends Base
{
public function testCreation()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
@@ -35,10 +35,10 @@ class CategoryTest extends Base
public function testRemove()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
diff --git a/tests/units/CommentTest.php b/tests/units/CommentTest.php
index 31c46996..f784382a 100644
--- a/tests/units/CommentTest.php
+++ b/tests/units/CommentTest.php
@@ -10,9 +10,9 @@ class CommentTest extends Base
{
public function testCreate()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $t = new Task($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)));
@@ -30,9 +30,9 @@ class CommentTest extends Base
public function testGetAll()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $t = new Task($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)));
@@ -53,9 +53,9 @@ class CommentTest extends Base
public function testUpdate()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $t = new Task($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)));
@@ -69,9 +69,9 @@ class CommentTest extends Base
public function validateRemove()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $t = new Task($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)));
@@ -84,7 +84,7 @@ class CommentTest extends Base
public function testValidateCreation()
{
- $c = new Comment($this->registry);
+ $c = new Comment($this->container);
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
@@ -113,7 +113,7 @@ class CommentTest extends Base
public function testValidateModification()
{
- $c = new Comment($this->registry);
+ $c = new Comment($this->container);
$result = $c->validateModification(array('id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
diff --git a/tests/units/ConfigTest.php b/tests/units/ConfigTest.php
index 4992092b..9ea9bc9a 100644
--- a/tests/units/ConfigTest.php
+++ b/tests/units/ConfigTest.php
@@ -8,7 +8,7 @@ class ConfigTest extends Base
{
public function testDefaultValues()
{
- $c = new Config($this->registry);
+ $c = new Config($this->container);
$this->assertEquals('en_US', $c->get('application_language'));
$this->assertEquals('UTC', $c->get('application_timezone'));
@@ -23,7 +23,7 @@ class ConfigTest extends Base
public function testGet()
{
- $c = new Config($this->registry);
+ $c = new Config($this->container);
$this->assertEquals('', $c->get('board_columns'));
$this->assertEquals('test', $c->get('board_columns', 'test'));
diff --git a/tests/units/DateParserTest.php b/tests/units/DateParserTest.php
index 68addf3f..e98fa6a5 100644
--- a/tests/units/DateParserTest.php
+++ b/tests/units/DateParserTest.php
@@ -8,7 +8,7 @@ class DateParserTest extends Base
{
public function testValidDate()
{
- $d = new DateParser($this->registry);
+ $d = new DateParser($this->container);
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014-03-05', 'Y-m-d')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014_03_05', 'Y_m_d')));
@@ -23,7 +23,7 @@ class DateParserTest extends Base
public function testGetTimestamp()
{
- $d = new DateParser($this->registry);
+ $d = new DateParser($this->container);
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014-03-05')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014_03_05')));
diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php
index 6c0539c2..770a9829 100644
--- a/tests/units/NotificationTest.php
+++ b/tests/units/NotificationTest.php
@@ -11,10 +11,10 @@ class NotificationTest extends Base
{
public function testGetUsersWithNotification()
{
- $u = new User($this->registry);
- $p = new Project($this->registry);
- $n = new Notification($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $n = new Notification($this->container);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -51,10 +51,10 @@ class NotificationTest extends Base
public function testGetUserList()
{
- $u = new User($this->registry);
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $n = new Notification($this->registry);
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $n = new Notification($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
diff --git a/tests/units/ProjectActivityTest.php b/tests/units/ProjectActivityTest.php
index 7e7841dd..f2d3206d 100644
--- a/tests/units/ProjectActivityTest.php
+++ b/tests/units/ProjectActivityTest.php
@@ -11,10 +11,10 @@ class ProjectActivityTest extends Base
{
public function testCreation()
{
- $e = new ProjectActivity($this->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $e = new ProjectActivity($this->container);
+ $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)));
@@ -36,10 +36,10 @@ class ProjectActivityTest extends Base
public function testFetchAllContent()
{
- $e = new ProjectActivity($this->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $e = new ProjectActivity($this->container);
+ $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)));
@@ -62,10 +62,10 @@ class ProjectActivityTest extends Base
public function testCleanup()
{
- $e = new ProjectActivity($this->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $e = new ProjectActivity($this->container);
+ $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)));
@@ -77,7 +77,7 @@ class ProjectActivityTest extends Base
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
}
- $this->assertEquals($nb_events, $this->registry->shared('db')->table('project_activities')->count());
+ $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count());
$e->cleanup($max);
$events = $e->getProject(1);
@@ -97,6 +97,6 @@ class ProjectActivityTest extends Base
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
}
- $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->registry->shared('db')->table('project_activities')->count());
+ $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->container['db']->table('project_activities')->count());
}
}
diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/ProjectPermissionTest.php
index fd0c7331..394e0ac5 100644
--- a/tests/units/ProjectPermissionTest.php
+++ b/tests/units/ProjectPermissionTest.php
@@ -10,12 +10,12 @@ class ProjectPermissionTest extends Base
{
public function testAllowEverybody()
{
- $user = new User($this->registry);
+ $user = new User($this->container);
$this->assertTrue($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
$this->assertTrue($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertFalse($pp->isEverybodyAllowed(1));
@@ -37,11 +37,11 @@ class ProjectPermissionTest extends Base
public function testDisallowEverybody()
{
// We create a regular user
- $user = new User($this->registry);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
@@ -52,9 +52,9 @@ class ProjectPermissionTest extends Base
public function testAllowUser()
{
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $user = new User($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
@@ -79,9 +79,9 @@ class ProjectPermissionTest extends Base
public function testRevokeUser()
{
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $user = new User($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
@@ -135,10 +135,10 @@ class ProjectPermissionTest extends Base
public function testUsersList()
{
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
- $user = new User($this->registry);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
// We create project
diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php
index c507739b..04e0418b 100644
--- a/tests/units/ProjectTest.php
+++ b/tests/units/ProjectTest.php
@@ -13,7 +13,7 @@ class ProjectTest extends Base
{
public function testCreation()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
@@ -28,7 +28,7 @@ class ProjectTest extends Base
public function testUpdateLastModifiedDate()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$now = time();
@@ -47,8 +47,8 @@ class ProjectTest extends Base
public function testIsLastModified()
{
- $p = new Project($this->registry);
- $t = new Task($this->registry);
+ $p = new Project($this->container);
+ $t = new Task($this->container);
$now = time();
$p->attachEvents();
@@ -62,8 +62,8 @@ class ProjectTest extends Base
sleep(1);
$this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
- $this->assertEquals('Event\ProjectModificationDateListener', $this->registry->shared('event')->getLastListenerExecuted());
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertEquals('Event\ProjectModificationDateListener', $this->container['event']->getLastListenerExecuted());
$project = $p->getById(1);
$this->assertNotEmpty($project);
@@ -72,7 +72,7 @@ class ProjectTest extends Base
public function testRemove()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->remove(1));
@@ -81,7 +81,7 @@ class ProjectTest extends Base
public function testEnable()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->disable(1));
@@ -95,7 +95,7 @@ class ProjectTest extends Base
public function testDisable()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->disable(1));
@@ -110,7 +110,7 @@ class ProjectTest extends Base
public function testEnablePublicAccess()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->enablePublicAccess(1));
@@ -125,7 +125,7 @@ class ProjectTest extends Base
public function testDisablePublicAccess()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->enablePublicAccess(1));
@@ -141,7 +141,7 @@ class ProjectTest extends Base
public function testDuplicate()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
// Clone public project
$this->assertEquals(1, $p->create(array('name' => 'Public')));
@@ -165,7 +165,7 @@ class ProjectTest extends Base
$this->assertEquals(0, $project['is_public']);
$this->assertEmpty($project['token']);
- $pp = new ProjectPermission($this->registry);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(array(1 => 'admin'), $pp->getMembers(3));
$this->assertEquals(array(1 => 'admin'), $pp->getMembers(4));
diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php
index f272db1f..f15ebf81 100644
--- a/tests/units/SubtaskTest.php
+++ b/tests/units/SubtaskTest.php
@@ -12,9 +12,9 @@ class SubTaskTest extends Base
{
public function testDuplicate()
{
- $t = new Task($this->registry);
- $s = new SubTask($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $s = new SubTask($this->container);
+ $p = new Project($this->container);
// We create a project
$this->assertEquals(1, $p->create(array('name' => 'test1')));
diff --git a/tests/units/TaskExportTest.php b/tests/units/TaskExportTest.php
index ad0bbdc4..a7faa52a 100644
--- a/tests/units/TaskExportTest.php
+++ b/tests/units/TaskExportTest.php
@@ -12,10 +12,10 @@ class TaskExportTest extends Base
{
public function testExport()
{
- $t = new Task($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
- $e = new TaskExport($this->registry);
+ $t = new Task($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+ $e = new TaskExport($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Export Project')));
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
diff --git a/tests/units/TaskFinderTest.php b/tests/units/TaskFinderTest.php
index 5a90f3af..96454f22 100644
--- a/tests/units/TaskFinderTest.php
+++ b/tests/units/TaskFinderTest.php
@@ -13,9 +13,9 @@ class TaskFinderTest extends Base
{
public function testGetOverdueTasks()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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, 'date_due' => strtotime('-1 day'))));
diff --git a/tests/units/TaskPermissionTest.php b/tests/units/TaskPermissionTest.php
index 5a94a274..426941ce 100644
--- a/tests/units/TaskPermissionTest.php
+++ b/tests/units/TaskPermissionTest.php
@@ -13,11 +13,11 @@ class TaskPermissionTest extends Base
{
public function testPrepareCreation()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $tp = new TaskPermission($this->registry);
- $p = new Project($this->registry);
- $u = new User($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $tp = new TaskPermission($this->container);
+ $p = new Project($this->container);
+ $u = new User($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456')));
$this->assertTrue($u->create(array('username' => 'toto2', 'password' => '123456')));
diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php
index e82faf19..06dfd5f1 100644
--- a/tests/units/TaskTest.php
+++ b/tests/units/TaskTest.php
@@ -13,9 +13,9 @@ class TaskTest extends Base
{
public function testPrepareCreation()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -92,9 +92,9 @@ class TaskTest extends Base
public function testPrepareModification()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -112,9 +112,9 @@ class TaskTest extends Base
public function testCreation()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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)));
@@ -150,9 +150,9 @@ class TaskTest extends Base
public function testRemove()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($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)));
@@ -163,9 +163,9 @@ class TaskTest extends Base
public function testMoveTaskWithColumnThatNotChange()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -225,16 +225,16 @@ class TaskTest extends Base
public function testMoveTaskWithBadPreviousPosition()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
+ $this->assertEquals(1, $this->container['db']->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
// Both tasks have the same position
- $this->assertEquals(2, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
- $this->assertEquals(3, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
+ $this->assertEquals(2, $this->container['db']->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
+ $this->assertEquals(3, $this->container['db']->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
// Move the first column to the last position of the 2nd column
$this->assertTrue($t->movePosition(1, 1, 2, 3));
@@ -258,9 +258,9 @@ class TaskTest extends Base
public function testMoveTaskTop()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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)));
@@ -295,9 +295,9 @@ class TaskTest extends Base
public function testMoveTaskBottom()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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)));
@@ -332,9 +332,9 @@ class TaskTest extends Base
public function testMovePosition()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$counter = 1;
@@ -487,10 +487,10 @@ class TaskTest extends Base
public function testDuplicateToTheSameProject()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
// We create a task and a project
$this->assertEquals(1, $p->create(array('name' => 'test1')));
@@ -509,7 +509,7 @@ class TaskTest extends Base
// We duplicate our task
$this->assertEquals(2, $t->duplicateToSameProject($task));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -524,10 +524,10 @@ class TaskTest extends Base
public function testDuplicateToAnotherProject()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'test1')));
@@ -542,7 +542,7 @@ class TaskTest extends Base
// We duplicate our task to the 2nd project
$this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
$task = $tf->getById(2);
@@ -557,11 +557,11 @@ class TaskTest extends Base
public function testMoveToAnotherProject()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $user = new User($this->registry);
+ $t = new Task($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
// We create a regular user
$user->create(array('username' => 'unittest1', 'password' => 'unittest'));
@@ -578,7 +578,7 @@ class TaskTest extends Base
// We duplicate our task to the 2nd project
$task = $tf->getById(1);
$this->assertEquals(1, $t->moveToAnotherProject(2, $task));
- //$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
+ //$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
$task = $tf->getById(1);
@@ -604,44 +604,44 @@ class TaskTest extends Base
public function testEvents()
{
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $p = new Project($this->container);
// We create a project
$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->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
// We update a task
$this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE_UPDATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
// We close our task
$this->assertTrue($t->close(1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
// We open our task
$this->assertTrue($t->open(1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_OPEN));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_OPEN));
// We change the column of our task
$this->assertTrue($t->movePosition(1, 1, 2, 1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
+ $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->assertTrue($t->movePosition(1, 1, 2, 2));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_POSITION));
// We change the column and the position of our task
$this->assertTrue($t->movePosition(1, 1, 1, 1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
// We change the assignee
$this->assertTrue($t->update(array('owner_id' => 1, 'id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
}
}
diff --git a/tests/units/TimeTrackingTest.php b/tests/units/TimeTrackingTest.php
index aa772a36..eb8b6a61 100644
--- a/tests/units/TimeTrackingTest.php
+++ b/tests/units/TimeTrackingTest.php
@@ -12,11 +12,11 @@ class TimeTrackingTest extends Base
{
public function testCalculateTime()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $s = new SubTask($this->registry);
- $ts = new TimeTracking($this->registry);
+ $t = new Task($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)));
diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php
index d4f9dd92..f0ef8543 100644
--- a/tests/units/UserTest.php
+++ b/tests/units/UserTest.php
@@ -20,7 +20,7 @@ class UserTest extends Base
public function testPrepare()
{
- $u = new User($this->registry);
+ $u = new User($this->container);
$input = array(
'username' => 'user1',
@@ -71,7 +71,7 @@ class UserTest extends Base
public function testCreate()
{
- $u = new User($this->registry);
+ $u = new User($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertTrue($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
$this->assertFalse($u->create(array('username' => 'toto')));
@@ -103,7 +103,7 @@ class UserTest extends Base
public function testUpdate()
{
- $u = new User($this->registry);
+ $u = new User($this->container);
$this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
@@ -118,10 +118,10 @@ class UserTest extends Base
public function testRemove()
{
- $u = new User($this->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $u = new User($this->container);
+ $t = new Task($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')));