diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-17 17:43:11 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-17 17:43:11 -0500 |
commit | bcbb3297860a8fe106094fefc04f74af4e30aed2 (patch) | |
tree | 810195e0c465db2b2f354857aa5ca12acb9e9cf6 | |
parent | 446a7ac6455f00efaac7c878def68fe62d0e9f19 (diff) |
Make sure that no events are fired if nothing have been modified in the task
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | app/Model/TaskModification.php | 2 | ||||
-rw-r--r-- | tests/units/Model/TaskModificationTest.php | 18 |
3 files changed, 20 insertions, 1 deletions
@@ -20,6 +20,7 @@ Improvements: * Remove event subscriber to update date_moved field * Make sure that some event subscribers are not executed multiple times * Show rendering time of individual templates when debug mode is enabled +* Make sure that no events are fired if nothing have been modified in the task Bug fixes: diff --git a/app/Model/TaskModification.php b/app/Model/TaskModification.php index 5f0fd074..a0ad292c 100644 --- a/app/Model/TaskModification.php +++ b/app/Model/TaskModification.php @@ -52,7 +52,7 @@ class TaskModification extends Base if ($this->isFieldModified('owner_id', $event_data['changes'])) { $events[] = Task::EVENT_ASSIGNEE_CHANGE; - } else { + } elseif (! empty($event_data['changes'])) { $events[] = Task::EVENT_CREATE_UPDATE; $events[] = Task::EVENT_UPDATE; } diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php index 25a4952e..119201f0 100644 --- a/tests/units/Model/TaskModificationTest.php +++ b/tests/units/Model/TaskModificationTest.php @@ -41,6 +41,24 @@ class TaskModificationTest extends Base $this->assertEquals(1, $event_data['owner_id']); } + public function testThatNoEventAreFiredWhenNoChanges() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tm = new TaskModification($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); + $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate')); + + $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test'))); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + public function testChangeTitle() { $p = new Project($this->container); |