Add event subtask.delete
This commit is contained in:
parent
63426c5374
commit
eaff957839
|
|
@ -19,6 +19,7 @@ Improvements:
|
|||
* Avoid scrollbar in Gantt chart for row title on Windows platform
|
||||
* Remove unnecessary margin for calendar header
|
||||
* Show localized documentation if available
|
||||
* Add event subtask.delete
|
||||
|
||||
Bug fixes:
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class Subtask extends Base
|
|||
*/
|
||||
const EVENT_UPDATE = 'subtask.update';
|
||||
const EVENT_CREATE = 'subtask.create';
|
||||
const EVENT_DELETE = 'subtask.delete';
|
||||
|
||||
/**
|
||||
* Get available status
|
||||
|
|
@ -173,6 +174,23 @@ class Subtask extends Base
|
|||
$this->resetFields($values, array('time_estimated', 'time_spent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data before insert
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
*/
|
||||
public function prepareCreation(array &$values)
|
||||
{
|
||||
$this->prepare($values);
|
||||
|
||||
$values['position'] = $this->getLastPosition($values['task_id']) + 1;
|
||||
$values['status'] = isset($values['status']) ? $values['status'] : self::STATUS_TODO;
|
||||
$values['time_estimated'] = isset($values['time_estimated']) ? $values['time_estimated'] : 0;
|
||||
$values['time_spent'] = isset($values['time_spent']) ? $values['time_spent'] : 0;
|
||||
$values['user_id'] = isset($values['user_id']) ? $values['user_id'] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of the last column for a given project
|
||||
*
|
||||
|
|
@ -198,9 +216,7 @@ class Subtask extends Base
|
|||
*/
|
||||
public function create(array $values)
|
||||
{
|
||||
$this->prepare($values);
|
||||
$values['position'] = $this->getLastPosition($values['task_id']) + 1;
|
||||
|
||||
$this->prepareCreation($values);
|
||||
$subtask_id = $this->persist(self::TABLE, $values);
|
||||
|
||||
if ($subtask_id) {
|
||||
|
|
@ -223,14 +239,13 @@ class Subtask extends Base
|
|||
public function update(array $values)
|
||||
{
|
||||
$this->prepare($values);
|
||||
$subtask = $this->getById($values['id']);
|
||||
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
|
||||
|
||||
if ($result) {
|
||||
|
||||
$this->container['dispatcher']->dispatch(
|
||||
self::EVENT_UPDATE,
|
||||
new SubtaskEvent($values)
|
||||
);
|
||||
$event = $subtask;
|
||||
$event['changes'] = array_diff_assoc($values, $subtask);
|
||||
$this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new SubtaskEvent($event));
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
@ -302,7 +317,6 @@ class Subtask extends Base
|
|||
$positions = array_flip($subtasks);
|
||||
|
||||
if (isset($subtasks[$subtask_id]) && $subtasks[$subtask_id] < count($subtasks)) {
|
||||
|
||||
$position = ++$subtasks[$subtask_id];
|
||||
$subtasks[$positions[$position]]--;
|
||||
|
||||
|
|
@ -402,7 +416,14 @@ class Subtask extends Base
|
|||
*/
|
||||
public function remove($subtask_id)
|
||||
{
|
||||
return $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
|
||||
$subtask = $this->getById($subtask_id);
|
||||
$result = $this->db->table(self::TABLE)->eq('id', $subtask_id)->remove();
|
||||
|
||||
if ($result) {
|
||||
$this->container['dispatcher']->dispatch(self::EVENT_DELETE, new SubtaskEvent($subtask));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -13,6 +13,136 @@ use Model\UserSession;
|
|||
|
||||
class SubTaskTest extends Base
|
||||
{
|
||||
public function onSubtaskCreated($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\SubtaskEvent', $event);
|
||||
$data = $event->getAll();
|
||||
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('title', $data);
|
||||
$this->assertArrayHasKey('status', $data);
|
||||
$this->assertArrayHasKey('time_estimated', $data);
|
||||
$this->assertArrayHasKey('time_spent', $data);
|
||||
$this->assertArrayHasKey('status', $data);
|
||||
$this->assertArrayHasKey('task_id', $data);
|
||||
$this->assertArrayHasKey('user_id', $data);
|
||||
$this->assertArrayHasKey('position', $data);
|
||||
$this->assertNotEmpty($data['task_id']);
|
||||
$this->assertNotEmpty($data['id']);
|
||||
}
|
||||
|
||||
public function onSubtaskUpdated($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\SubtaskEvent', $event);
|
||||
$data = $event->getAll();
|
||||
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('title', $data);
|
||||
$this->assertArrayHasKey('status', $data);
|
||||
$this->assertArrayHasKey('time_estimated', $data);
|
||||
$this->assertArrayHasKey('time_spent', $data);
|
||||
$this->assertArrayHasKey('status', $data);
|
||||
$this->assertArrayHasKey('task_id', $data);
|
||||
$this->assertArrayHasKey('user_id', $data);
|
||||
$this->assertArrayHasKey('position', $data);
|
||||
$this->assertArrayHasKey('changes', $data);
|
||||
$this->assertArrayHasKey('user_id', $data['changes']);
|
||||
$this->assertArrayHasKey('status', $data['changes']);
|
||||
|
||||
$this->assertEquals(Subtask::STATUS_INPROGRESS, $data['changes']['status']);
|
||||
$this->assertEquals(1, $data['changes']['user_id']);
|
||||
}
|
||||
|
||||
public function onSubtaskDeleted($event)
|
||||
{
|
||||
$this->assertInstanceOf('Event\SubtaskEvent', $event);
|
||||
$data = $event->getAll();
|
||||
|
||||
$this->assertArrayHasKey('id', $data);
|
||||
$this->assertArrayHasKey('title', $data);
|
||||
$this->assertArrayHasKey('status', $data);
|
||||
$this->assertArrayHasKey('time_estimated', $data);
|
||||
$this->assertArrayHasKey('time_spent', $data);
|
||||
$this->assertArrayHasKey('status', $data);
|
||||
$this->assertArrayHasKey('task_id', $data);
|
||||
$this->assertArrayHasKey('user_id', $data);
|
||||
$this->assertArrayHasKey('position', $data);
|
||||
$this->assertNotEmpty($data['task_id']);
|
||||
$this->assertNotEmpty($data['id']);
|
||||
}
|
||||
|
||||
public function testCreation()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Subtask::EVENT_CREATE, array($this, 'onSubtaskCreated'));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
$this->assertEquals('subtask #1', $subtask['title']);
|
||||
$this->assertEquals(Subtask::STATUS_TODO, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['time_estimated']);
|
||||
$this->assertEquals(0, $subtask['time_spent']);
|
||||
$this->assertEquals(0, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
}
|
||||
|
||||
public function testModification()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Subtask::EVENT_UPDATE, array($this, 'onSubtaskUpdated'));
|
||||
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
$this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => Subtask::STATUS_INPROGRESS)));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
$this->assertEquals(1, $subtask['id']);
|
||||
$this->assertEquals(1, $subtask['task_id']);
|
||||
$this->assertEquals('subtask #1', $subtask['title']);
|
||||
$this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']);
|
||||
$this->assertEquals(0, $subtask['time_estimated']);
|
||||
$this->assertEquals(0, $subtask['time_spent']);
|
||||
$this->assertEquals(1, $subtask['user_id']);
|
||||
$this->assertEquals(1, $subtask['position']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$s = new Subtask($this->container);
|
||||
$p = new Project($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'test')));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
|
||||
|
||||
$this->container['dispatcher']->addListener(Subtask::EVENT_DELETE, array($this, 'onSubtaskDeleted'));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertNotEmpty($subtask);
|
||||
|
||||
$this->assertTrue($s->remove(1));
|
||||
|
||||
$subtask = $s->getById(1);
|
||||
$this->assertEmpty($subtask);
|
||||
}
|
||||
|
||||
public function testToggleStatusWithoutSession()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
|
|
|
|||
Loading…
Reference in New Issue