Add unit test for transition model
This commit is contained in:
@@ -21,7 +21,7 @@ class TransitionExport extends Base
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$data = $this->transition->export(
|
||||
$data = $this->transitionExport->export(
|
||||
$input->getArgument('project_id'),
|
||||
$input->getArgument('start_date'),
|
||||
$input->getArgument('end_date')
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Kanboard\Core\DateParser;
|
||||
|
||||
/**
|
||||
* Task controller
|
||||
*
|
||||
@@ -62,7 +64,7 @@ class Task extends Base
|
||||
'time_spent' => $task['time_spent'] ?: '',
|
||||
);
|
||||
|
||||
$values = $this->dateParser->format($values, array('date_started'), $this->config->get('application_datetime_format', 'm/d/Y H:i'));
|
||||
$values = $this->dateParser->format($values, array('date_started'), $this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT));
|
||||
|
||||
$this->response->html($this->helper->layout->task('task/show', array(
|
||||
'project' => $this->project->getById($task['project_id']),
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Kanboard\Core\DateParser;
|
||||
|
||||
/**
|
||||
* Task Modification controller
|
||||
*
|
||||
@@ -83,8 +85,8 @@ class Taskmodification extends Base
|
||||
$values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values));
|
||||
}
|
||||
|
||||
$values = $this->dateParser->format($values, array('date_due'), $this->config->get('application_date_format', 'm/d/Y'));
|
||||
$values = $this->dateParser->format($values, array('date_started'), $this->config->get('application_datetime_format', 'm/d/Y H:i'));
|
||||
$values = $this->dateParser->format($values, array('date_due'), $this->config->get('application_date_format', DateParser::DATE_FORMAT));
|
||||
$values = $this->dateParser->format($values, array('date_started'), $this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT));
|
||||
|
||||
$this->response->html($this->helper->layout->task('task_modification/edit_task', array(
|
||||
'project' => $project,
|
||||
|
||||
@@ -111,6 +111,7 @@ use Pimple\Container;
|
||||
* @property \Kanboard\Model\TaskStatus $taskStatus
|
||||
* @property \Kanboard\Model\TaskMetadata $taskMetadata
|
||||
* @property \Kanboard\Model\Transition $transition
|
||||
* @property \Kanboard\Model\TransitionExport $transitionExport
|
||||
* @property \Kanboard\Model\User $user
|
||||
* @property \Kanboard\Model\UserImport $userImport
|
||||
* @property \Kanboard\Model\UserLocking $userLocking
|
||||
|
||||
@@ -12,6 +12,9 @@ use DateTime;
|
||||
*/
|
||||
class DateParser extends Base
|
||||
{
|
||||
const DATE_FORMAT = 'm/d/Y';
|
||||
const DATE_TIME_FORMAT = 'm/d/Y H:i';
|
||||
|
||||
/**
|
||||
* List of time formats
|
||||
*
|
||||
@@ -201,7 +204,7 @@ class DateParser extends Base
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a timetstamp from an ISO date format
|
||||
* Get a timestamp from an ISO date format
|
||||
*
|
||||
* @access public
|
||||
* @param string $value
|
||||
|
||||
@@ -29,7 +29,12 @@ class Request extends Base
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param \Pimple\Container $container
|
||||
* @param \Pimple\Container $container
|
||||
* @param array $server
|
||||
* @param array $get
|
||||
* @param array $post
|
||||
* @param array $files
|
||||
* @param array $cookies
|
||||
*/
|
||||
public function __construct(Container $container, array $server = array(), array $get = array(), array $post = array(), array $files = array(), array $cookies = array())
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use Kanboard\Core\DateParser;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
@@ -106,7 +107,7 @@ class TaskExport extends Base
|
||||
$task['score'] = $task['score'] ?: 0;
|
||||
$task['swimlane_id'] = isset($swimlanes[$task['swimlane_id']]) ? $swimlanes[$task['swimlane_id']] : '?';
|
||||
|
||||
$task = $this->dateParser->format($task, array('date_due', 'date_modification', 'date_creation', 'date_started', 'date_completed'), 'Y-m-d');
|
||||
$task = $this->dateParser->format($task, array('date_due', 'date_modification', 'date_creation', 'date_started', 'date_completed'), DateParser::DATE_FORMAT);
|
||||
|
||||
return $task;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Kanboard\Model;
|
||||
|
||||
/**
|
||||
* Transition model
|
||||
* Transition
|
||||
*
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
@@ -21,20 +21,22 @@ class Transition extends Base
|
||||
* Save transition event
|
||||
*
|
||||
* @access public
|
||||
* @param integer $user_id
|
||||
* @param array $task
|
||||
* @return boolean
|
||||
* @param integer $user_id
|
||||
* @param array $task_event
|
||||
* @return bool
|
||||
*/
|
||||
public function save($user_id, array $task)
|
||||
public function save($user_id, array $task_event)
|
||||
{
|
||||
$time = time();
|
||||
|
||||
return $this->db->table(self::TABLE)->insert(array(
|
||||
'user_id' => $user_id,
|
||||
'project_id' => $task['project_id'],
|
||||
'task_id' => $task['task_id'],
|
||||
'src_column_id' => $task['src_column_id'],
|
||||
'dst_column_id' => $task['dst_column_id'],
|
||||
'date' => time(),
|
||||
'time_spent' => time() - $task['date_moved']
|
||||
'project_id' => $task_event['project_id'],
|
||||
'task_id' => $task_event['task_id'],
|
||||
'src_column_id' => $task_event['src_column_id'],
|
||||
'dst_column_id' => $task_event['dst_column_id'],
|
||||
'date' => $time,
|
||||
'time_spent' => $time - $task_event['date_moved']
|
||||
));
|
||||
}
|
||||
|
||||
@@ -116,71 +118,11 @@ class Transition extends Base
|
||||
->lte('date', $to)
|
||||
->eq(self::TABLE.'.project_id', $project_id)
|
||||
->desc('date')
|
||||
->desc(self::TABLE.'.id')
|
||||
->join(Task::TABLE, 'id', 'task_id')
|
||||
->join(User::TABLE, 'id', 'user_id')
|
||||
->join(Column::TABLE.' as src', 'id', 'src_column_id', self::TABLE, 'src')
|
||||
->join(Column::TABLE.' as dst', 'id', 'dst_column_id', self::TABLE, 'dst')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get project export
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param mixed $from Start date (timestamp or user formatted date)
|
||||
* @param mixed $to End date (timestamp or user formatted date)
|
||||
* @return array
|
||||
*/
|
||||
public function export($project_id, $from, $to)
|
||||
{
|
||||
$results = array($this->getColumns());
|
||||
$transitions = $this->getAllByProjectAndDate($project_id, $from, $to);
|
||||
|
||||
foreach ($transitions as $transition) {
|
||||
$results[] = $this->format($transition);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column titles
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
e('Id'),
|
||||
e('Task Title'),
|
||||
e('Source column'),
|
||||
e('Destination column'),
|
||||
e('Executer'),
|
||||
e('Date'),
|
||||
e('Time spent'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the output of a transition array
|
||||
*
|
||||
* @access public
|
||||
* @param array $transition
|
||||
* @return array
|
||||
*/
|
||||
public function format(array $transition)
|
||||
{
|
||||
$values = array();
|
||||
$values[] = $transition['id'];
|
||||
$values[] = $transition['title'];
|
||||
$values[] = $transition['src_column'];
|
||||
$values[] = $transition['dst_column'];
|
||||
$values[] = $transition['name'] ?: $transition['username'];
|
||||
$values[] = date('Y-m-d H:i', $transition['date']);
|
||||
$values[] = round($transition['time_spent'] / 3600, 2);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
|
||||
76
app/Model/TransitionExport.php
Normal file
76
app/Model/TransitionExport.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use Kanboard\Core\DateParser;
|
||||
|
||||
/**
|
||||
* Transition Export
|
||||
*
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TransitionExport extends Base
|
||||
{
|
||||
/**
|
||||
* Get project export
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
* @param mixed $from Start date (timestamp or user formatted date)
|
||||
* @param mixed $to End date (timestamp or user formatted date)
|
||||
* @return array
|
||||
*/
|
||||
public function export($project_id, $from, $to)
|
||||
{
|
||||
$results = array($this->getColumns());
|
||||
$transitions = $this->transition->getAllByProjectAndDate($project_id, $from, $to);
|
||||
|
||||
foreach ($transitions as $transition) {
|
||||
$results[] = $this->format($transition);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column titles
|
||||
*
|
||||
* @access protected
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getColumns()
|
||||
{
|
||||
return array(
|
||||
e('Id'),
|
||||
e('Task Title'),
|
||||
e('Source column'),
|
||||
e('Destination column'),
|
||||
e('Executer'),
|
||||
e('Date'),
|
||||
e('Time spent'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the output of a transition array
|
||||
*
|
||||
* @access protected
|
||||
* @param array $transition
|
||||
* @return array
|
||||
*/
|
||||
protected function format(array $transition)
|
||||
{
|
||||
$values = array(
|
||||
(int) $transition['id'],
|
||||
$transition['title'],
|
||||
$transition['src_column'],
|
||||
$transition['dst_column'],
|
||||
$transition['name'] ?: $transition['username'],
|
||||
date($this->config->get('application_datetime_format', DateParser::DATE_TIME_FORMAT), $transition['date']),
|
||||
round($transition['time_spent'] / 3600, 2)
|
||||
);
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ class ClassProvider implements ServiceProviderInterface
|
||||
'TaskImport',
|
||||
'TaskMetadata',
|
||||
'Transition',
|
||||
'TransitionExport',
|
||||
'User',
|
||||
'UserImport',
|
||||
'UserLocking',
|
||||
|
||||
Reference in New Issue
Block a user