File size: 3,855 Bytes
e4f4821 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
<?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_DELETE, 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->assertCount(3, $called);
$this->assertEquals(CommentModel::EVENT_CREATE, $called[0]['event']);
$this->assertEquals(CommentModel::EVENT_UPDATE, $called[1]['event']);
$this->assertEquals(CommentModel::EVENT_DELETE, $called[2]['event']);
}
public function testThatUserMentionJobIsCalled()
{
$comment = 'some comment';
$this->container['queueManager'] = $this
->getMockBuilder('\Kanboard\Core\Queue\QueueManager')
->setConstructorArgs(array($this->container))
->setMethods(array(
'push',
))
->getMock();
$this->container['userMentionJob'] = $this
->getMockBuilder('\Kanboard\Job\UserMentionJob')
->setConstructorArgs(array($this->container))
->setMethods(array(
'withParams',
))
->getMock();
$this->container['queueManager']
->expects($this->any())
->method('push');
$this->container['userMentionJob']
->expects($this->once())
->method('withParams')
->with($comment, CommentModel::EVENT_USER_MENTION, $this->anything())
->will($this->returnValue($this->container['userMentionJob']));
$commentModel = new CommentModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$projectModel = new ProjectModel($this->container);
$commentEventJob = new CommentEventJob($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' => $comment, 'user_id' => 1)));
$commentEventJob->execute(1, CommentModel::EVENT_CREATE);
}
}
|