Add unit test to remove metadata

This commit is contained in:
Frederic Guillot
2015-12-30 16:59:21 +01:00
parent 9039e27b13
commit 65f26699a6
5 changed files with 18 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ New features:
- Added support of user mentions (@username)
- Added report to compare working hours between open and closed tasks
- Added the possiblity to define custom routes from plugins
- Added new method to remove metadata
Improvements:

View File

@@ -101,21 +101,11 @@ abstract class Metadata extends Base
*
* @access public
* @param integer $entity_id
* @param string $name
* @param string $name
* @return bool
*/
public function remove($entity_id, $name)
{
$this->db->startTransaction();
if (! $this->db->table(static::TABLE)->eq($this->getEntityKey(), $entity_id)->eq('name', $name)->remove()) {
$this->db->cancelTransaction();
return false;
}
$this->db->closeTransaction();
return true;
return $this->db->table(static::TABLE)->eq($this->getEntityKey(), $entity_id)->eq('name', $name)->remove();
}
}

View File

@@ -30,6 +30,11 @@ class ProjectMetadataTest extends Base
$this->assertEquals(array('key1' => 'value2'), $pm->getAll(1));
$this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $pm->getAll(2));
$this->assertTrue($pm->remove(2, 'key1'));
$this->assertFalse($pm->remove(2, 'key1'));
$this->assertEquals(array('key2' => 'value2'), $pm->getAll(2));
}
public function testAutomaticRemove()

View File

@@ -33,5 +33,10 @@ class TaskMetadataTest extends Base
$this->assertEquals(array('key1' => 'value2'), $tm->getAll(1));
$this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $tm->getAll(2));
$this->assertTrue($tm->remove(2, 'key1'));
$this->assertFalse($tm->remove(2, 'key1'));
$this->assertEquals(array('key2' => 'value2'), $tm->getAll(2));
}
}

View File

@@ -29,5 +29,10 @@ class UserMetadataTest extends Base
$this->assertEquals(array('key1' => 'value2'), $m->getAll(1));
$this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $m->getAll(2));
$this->assertTrue($m->remove(2, 'key1'));
$this->assertFalse($m->remove(2, 'key1'));
$this->assertEquals(array('key2' => 'value2'), $m->getAll(2));
}
}