Run unit tests across different database backends + fix bugs

This commit is contained in:
Frédéric Guillot
2014-09-15 22:35:56 +02:00
parent 5f962bf4cd
commit e1ddf7f012
28 changed files with 536 additions and 441 deletions

View File

@@ -553,7 +553,8 @@ class Project extends Base
*/
public function update(array $values)
{
return $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
return $this->exists($values['id']) &&
$this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
}
/**
@@ -568,6 +569,18 @@ class Project extends Base
return $this->db->table(self::TABLE)->eq('id', $project_id)->remove();
}
/**
* Return true if the project exists
*
* @access public
* @param integer $project_id Project id
* @return boolean
*/
public function exists($project_id)
{
return $this->db->table(self::TABLE)->eq('id', $project_id)->count() === 1;
}
/**
* Enable a project
*
@@ -577,10 +590,11 @@ class Project extends Base
*/
public function enable($project_id)
{
return $this->db
return $this->exists($project_id) &&
$this->db
->table(self::TABLE)
->eq('id', $project_id)
->save(array('is_active' => 1));
->update(array('is_active' => 1));
}
/**
@@ -592,10 +606,11 @@ class Project extends Base
*/
public function disable($project_id)
{
return $this->db
return $this->exists($project_id) &&
$this->db
->table(self::TABLE)
->eq('id', $project_id)
->save(array('is_active' => 0));
->update(array('is_active' => 0));
}
/**
@@ -607,7 +622,8 @@ class Project extends Base
*/
public function enablePublicAccess($project_id)
{
return $this->db
return $this->exists($project_id) &&
$this->db
->table(self::TABLE)
->eq('id', $project_id)
->save(array('is_public' => 1, 'token' => Security::generateToken()));
@@ -622,7 +638,8 @@ class Project extends Base
*/
public function disablePublicAccess($project_id)
{
return $this->db
return $this->exists($project_id) &&
$this->db
->table(self::TABLE)
->eq('id', $project_id)
->save(array('is_public' => 0, 'token' => ''));

View File

@@ -150,16 +150,16 @@ class Task extends Base
* Count all tasks for a given project and status
*
* @access public
* @param integer $project_id Project id
* @param array $status List of status id
* @param integer $project_id Project id
* @param integer $status_id Status id
* @return array
*/
public function getAll($project_id, array $status = array(self::STATUS_OPEN, self::STATUS_CLOSED))
public function getAll($project_id, $status_id = self::STATUS_OPEN)
{
return $this->db
->table(self::TABLE)
->eq('project_id', $project_id)
->in('is_active', $status)
->eq('is_active', $status_id)
->findAll();
}
@@ -382,6 +382,10 @@ class Task extends Base
if (isset($values['score']) && empty($values['score'])) {
$values['score'] = 0;
}
if (isset($values['is_active'])) {
$values['is_active'] = (int) $values['is_active'];
}
}
/**
@@ -487,6 +491,18 @@ class Task extends Base
}
}
/**
* Return true if the project exists
*
* @access public
* @param integer $task_id Task id
* @return boolean
*/
public function exists($task_id)
{
return $this->db->table(self::TABLE)->eq('id', $task_id)->count() === 1;
}
/**
* Mark a task closed
*
@@ -496,6 +512,10 @@ class Task extends Base
*/
public function close($task_id)
{
if (! $this->exists($task_id)) {
return false;
}
$result = $this->db
->table(self::TABLE)
->eq('id', $task_id)
@@ -520,12 +540,16 @@ class Task extends Base
*/
public function open($task_id)
{
if (! $this->exists($task_id)) {
return false;
}
$result = $this->db
->table(self::TABLE)
->eq('id', $task_id)
->update(array(
'is_active' => 1,
'date_completed' => ''
'date_completed' => 0
));
if ($result) {
@@ -544,6 +568,10 @@ class Task extends Base
*/
public function remove($task_id)
{
if (! $this->exists($task_id)) {
return false;
}
$this->file->removeAll($task_id);
return $this->db->table(self::TABLE)->eq('id', $task_id)->remove();