Use Pimple instead of Core\Registry and add Monolog for logging

This commit is contained in:
Frédéric Guillot 2014-11-14 22:44:25 -05:00
parent 1487cb2763
commit b081288188
57 changed files with 549 additions and 593 deletions

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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
);
}

View File

@ -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);
}
/**

View File

@ -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];
}
}

View File

@ -124,6 +124,20 @@ class Request
return $this->getHeader('X-Requested-With') === 'XMLHttpRequest';
}
/**
* 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
*

View File

@ -246,7 +246,7 @@ class Response
*/
public function hsts()
{
if (Tool::isHTTPS()) {
if (Request::isHTTPS()) {
header('Strict-Transport-Security: max-age=31536000');
}
}

View File

@ -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;

View File

@ -49,7 +49,7 @@ class Session
self::SESSION_LIFETIME,
$base_path ?: '/',
null,
Tool::isHTTPS(),
Request::isHTTPS(),
true
);

View File

@ -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];
}
}

View File

@ -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, '.'));
}
}

View File

@ -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
);
}

View File

@ -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);
}
/**

View File

@ -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];
}
/**

View File

@ -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);
}
/**

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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,
));
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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

View File

@ -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']).'/' : '/';

View File

@ -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/"},

View File

@ -5,5 +5,5 @@ require __DIR__.'/app/common.php';
use Core\Router;
$router = new Router($registry);
$router = new Router($container);
$router->execute();

View File

@ -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();

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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')));

View File

@ -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')));

View File

@ -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')));

View File

@ -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)));

View File

@ -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)));

View File

@ -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)));

View File

@ -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)));

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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')));

View File

@ -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)));

View File

@ -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]);

View File

@ -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'));

View File

@ -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')));

View File

@ -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')));

View File

@ -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());
}
}

View File

@ -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

View File

@ -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));

View File

@ -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')));

View File

@ -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)));

View File

@ -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'))));

View File

@ -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')));

View File

@ -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));
}
}

View File

@ -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)));

View File

@ -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')));