summaryrefslogtreecommitdiff
path: root/tests/units/Job/SubtaskEventJobTest.php
blob: 66c3db05d9a10b679b88f1af0310df2d139e0d71 (plain)
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
<?php

use Kanboard\Job\SubtaskEventJob;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;

require_once __DIR__.'/../Base.php';

class SubtaskEventJobTest extends Base
{
    public function testJobParams()
    {
        $subtaskEventJob = new SubtaskEventJob($this->container);
        $subtaskEventJob->withParams(123, 'foobar', array('k' => 'v'));

        $this->assertSame(array(123, 'foobar', array('k' => 'v')), $subtaskEventJob->getJobParams());
    }

    public function testWithMissingSubtask()
    {
        $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});

        $subtaskEventJob = new SubtaskEventJob($this->container);
        $subtaskEventJob->execute(42, SubtaskModel::EVENT_CREATE);

        $called = $this->container['dispatcher']->getCalledListeners();
        $this->assertEmpty($called);
    }

    public function testTriggerEvents()
    {
        $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
        $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, function() {});
        $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, function() {});

        $subtaskModel = new SubtaskModel($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, $subtaskModel->create(array('task_id' => 1, 'title' => 'before')));
        $this->assertTrue($subtaskModel->update(array('id' => 1, 'title' => 'after')));
        $this->assertTrue($subtaskModel->remove(1));

        $called = $this->container['dispatcher']->getCalledListeners();
        $this->assertArrayHasKey(SubtaskModel::EVENT_CREATE.'.closure', $called);
        $this->assertArrayHasKey(SubtaskModel::EVENT_UPDATE.'.closure', $called);
        $this->assertArrayHasKey(SubtaskModel::EVENT_DELETE.'.closure', $called);
    }
}