Added event for removed comments with some refactoring
This commit is contained in:
37
tests/units/EventBuilder/CommentEventBuilderTest.php
Normal file
37
tests/units/EventBuilder/CommentEventBuilderTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Kanboard\EventBuilder\CommentEventBuilder;
|
||||
use Kanboard\Model\CommentModel;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
class CommentEventBuilderTest extends Base
|
||||
{
|
||||
public function testWithMissingComment()
|
||||
{
|
||||
$commentEventBuilder = new CommentEventBuilder($this->container);
|
||||
$commentEventBuilder->withCommentId(42);
|
||||
$this->assertNull($commentEventBuilder->build());
|
||||
}
|
||||
|
||||
public function testBuild()
|
||||
{
|
||||
$commentModel = new CommentModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$commentEventBuilder = new CommentEventBuilder($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
|
||||
|
||||
$commentEventBuilder->withCommentId(1);
|
||||
$event = $commentEventBuilder->build();
|
||||
|
||||
$this->assertInstanceOf('Kanboard\Event\CommentEvent', $event);
|
||||
$this->assertNotEmpty($event['comment']);
|
||||
$this->assertNotEmpty($event['task']);
|
||||
}
|
||||
}
|
||||
52
tests/units/Job/CommentEventJobTest.php
Normal file
52
tests/units/Job/CommentEventJobTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use Kanboard\Job\CommentEventJob;
|
||||
use Kanboard\Model\CommentModel;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
class CommentEventJobTest extends Base
|
||||
{
|
||||
public function testJobParams()
|
||||
{
|
||||
$commentEventJob = new CommentEventJob($this->container);
|
||||
$commentEventJob->withParams(123, 'foobar');
|
||||
|
||||
$this->assertSame(array(123, 'foobar'), $commentEventJob->getJobParams());
|
||||
}
|
||||
|
||||
public function testWithMissingComment()
|
||||
{
|
||||
$this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
|
||||
|
||||
$commentEventJob = new CommentEventJob($this->container);
|
||||
$commentEventJob->execute(42, CommentModel::EVENT_CREATE);
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertEmpty($called);
|
||||
}
|
||||
|
||||
public function testTriggerEvents()
|
||||
{
|
||||
$this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
|
||||
$this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {});
|
||||
$this->container['dispatcher']->addListener(CommentModel::EVENT_REMOVE, function() {});
|
||||
|
||||
$commentModel = new CommentModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'foobar', 'user_id' => 1)));
|
||||
$this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'test')));
|
||||
$this->assertTrue($commentModel->remove(1));
|
||||
|
||||
$called = $this->container['dispatcher']->getCalledListeners();
|
||||
$this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called);
|
||||
$this->assertArrayHasKey(CommentModel::EVENT_REMOVE.'.closure', $called);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ use Kanboard\Model\TaskCreationModel;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\CommentModel;
|
||||
|
||||
class CommentTest extends Base
|
||||
class CommentModelTest extends Base
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
@@ -75,7 +75,7 @@ class CommentTest extends Base
|
||||
$this->assertEquals('bla', $comment['comment']);
|
||||
}
|
||||
|
||||
public function validateRemove()
|
||||
public function testRemove()
|
||||
{
|
||||
$commentModel = new CommentModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
Reference in New Issue
Block a user