Add unit tests for last automatic actions

This commit is contained in:
Frederic Guillot
2016-01-31 19:51:59 -05:00
parent 505f62e6ca
commit 0bc51620c7
9 changed files with 247 additions and 93 deletions

View File

@@ -96,10 +96,11 @@ class Swimlane extends Base
*/
public function getDefault($project_id)
{
$result = $this->db->table(Project::TABLE)
->eq('id', $project_id)
->columns('id', 'default_swimlane', 'show_default_swimlane')
->findOne();
$result = $this->db
->table(Project::TABLE)
->eq('id', $project_id)
->columns('id', 'default_swimlane', 'show_default_swimlane')
->findOne();
if ($result['default_swimlane'] === 'Default swimlane') {
$result['default_swimlane'] = t($result['default_swimlane']);
@@ -117,10 +118,11 @@ class Swimlane extends Base
*/
public function getAll($project_id)
{
return $this->db->table(self::TABLE)
->eq('project_id', $project_id)
->orderBy('position', 'asc')
->findAll();
return $this->db
->table(self::TABLE)
->eq('project_id', $project_id)
->orderBy('position', 'asc')
->findAll();
}
/**
@@ -133,9 +135,10 @@ class Swimlane extends Base
*/
public function getAllByStatus($project_id, $status = self::ACTIVE)
{
$query = $this->db->table(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', $status);
$query = $this->db
->table(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', $status);
if ($status == self::ACTIVE) {
$query->asc('position');
@@ -155,17 +158,19 @@ class Swimlane extends Base
*/
public function getSwimlanes($project_id)
{
$swimlanes = $this->db->table(self::TABLE)
->columns('id', 'name', 'description')
->eq('project_id', $project_id)
->eq('is_active', self::ACTIVE)
->orderBy('position', 'asc')
->findAll();
$swimlanes = $this->db
->table(self::TABLE)
->columns('id', 'name', 'description')
->eq('project_id', $project_id)
->eq('is_active', self::ACTIVE)
->orderBy('position', 'asc')
->findAll();
$default_swimlane = $this->db->table(Project::TABLE)
->eq('id', $project_id)
->eq('show_default_swimlane', 1)
->findOneColumn('default_swimlane');
$default_swimlane = $this->db
->table(Project::TABLE)
->eq('id', $project_id)
->eq('show_default_swimlane', 1)
->findOneColumn('default_swimlane');
if ($default_swimlane) {
if ($default_swimlane === 'Default swimlane') {
@@ -200,11 +205,12 @@ class Swimlane extends Base
$swimlanes[0] = $default === 'Default swimlane' ? t($default) : $default;
}
return $swimlanes + $this->db->hashtable(self::TABLE)
->eq('project_id', $project_id)
->in('is_active', $only_active ? array(self::ACTIVE) : array(self::ACTIVE, self::INACTIVE))
->orderBy('position', 'asc')
->getAll('id', 'name');
return $swimlanes + $this->db
->hashtable(self::TABLE)
->eq('project_id', $project_id)
->in('is_active', $only_active ? array(self::ACTIVE) : array(self::ACTIVE, self::INACTIVE))
->orderBy('position', 'asc')
->getAll('id', 'name');
}
/**
@@ -232,9 +238,10 @@ class Swimlane extends Base
*/
public function update(array $values)
{
return $this->db->table(self::TABLE)
->eq('id', $values['id'])
->update($values);
return $this->db
->table(self::TABLE)
->eq('id', $values['id'])
->update($values);
}
/**
@@ -247,12 +254,12 @@ class Swimlane extends Base
public function updateDefault(array $values)
{
return $this->db
->table(Project::TABLE)
->eq('id', $values['id'])
->update(array(
'default_swimlane' => $values['default_swimlane'],
'show_default_swimlane' => $values['show_default_swimlane'],
));
->table(Project::TABLE)
->eq('id', $values['id'])
->update(array(
'default_swimlane' => $values['default_swimlane'],
'show_default_swimlane' => $values['show_default_swimlane'],
));
}
/**
@@ -264,10 +271,11 @@ class Swimlane extends Base
*/
public function getLastPosition($project_id)
{
return $this->db->table(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', 1)
->count() + 1;
return $this->db
->table(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', 1)
->count() + 1;
}
/**
@@ -281,12 +289,12 @@ class Swimlane extends Base
public function disable($project_id, $swimlane_id)
{
$result = $this->db
->table(self::TABLE)
->eq('id', $swimlane_id)
->update(array(
'is_active' => self::INACTIVE,
'position' => 0,
));
->table(self::TABLE)
->eq('id', $swimlane_id)
->update(array(
'is_active' => self::INACTIVE,
'position' => 0,
));
if ($result) {
// Re-order positions
@@ -307,12 +315,12 @@ class Swimlane extends Base
public function enable($project_id, $swimlane_id)
{
return $this->db
->table(self::TABLE)
->eq('id', $swimlane_id)
->update(array(
'is_active' => self::ACTIVE,
'position' => $this->getLastPosition($project_id),
));
->table(self::TABLE)
->eq('id', $swimlane_id)
->update(array(
'is_active' => self::ACTIVE,
'position' => $this->getLastPosition($project_id),
));
}
/**
@@ -353,11 +361,12 @@ class Swimlane extends Base
public function updatePositions($project_id)
{
$position = 0;
$swimlanes = $this->db->table(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', 1)
->asc('position')
->findAllByColumn('id');
$swimlanes = $this->db
->table(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', 1)
->asc('position')
->findAllByColumn('id');
if (! $swimlanes) {
return false;
@@ -365,8 +374,8 @@ class Swimlane extends Base
foreach ($swimlanes as $swimlane_id) {
$this->db->table(self::TABLE)
->eq('id', $swimlane_id)
->update(array('position' => ++$position));
->eq('id', $swimlane_id)
->update(array('position' => ++$position));
}
return true;
@@ -383,10 +392,10 @@ class Swimlane extends Base
public function moveDown($project_id, $swimlane_id)
{
$swimlanes = $this->db->hashtable(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', self::ACTIVE)
->asc('position')
->getAll('id', 'position');
->eq('project_id', $project_id)
->eq('is_active', self::ACTIVE)
->asc('position')
->getAll('id', 'position');
$positions = array_flip($swimlanes);
@@ -416,10 +425,10 @@ class Swimlane extends Base
public function moveUp($project_id, $swimlane_id)
{
$swimlanes = $this->db->hashtable(self::TABLE)
->eq('project_id', $project_id)
->eq('is_active', self::ACTIVE)
->asc('position')
->getAll('id', 'position');
->eq('project_id', $project_id)
->eq('is_active', self::ACTIVE)
->asc('position')
->getAll('id', 'position');
$positions = array_flip($swimlanes);