summaryrefslogtreecommitdiff
path: root/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
blob: 76f12ad4de51ae48a35d408504be1a39947fcdb7 (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
<?php

use Kanboard\Core\ExternalTask\ExternalTaskManager;

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

class ExternalTaskManagerTest extends Base
{
    public function testProviderNotFound()
    {
        $this->setExpectedException('Kanboard\Core\ExternalTask\ProviderNotFoundException');

        $manager = new ExternalTaskManager();
        $manager->getProvider('foobar');
    }

    public function testRegister()
    {
        $provider = $this->getMockBuilder('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface')->getMock();
        $provider->expects($this->any())->method('getName')->willReturn('MyProvider');

        $manager = new ExternalTaskManager();
        $manager->register($provider);

        $this->assertInstanceOf('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface', $manager->getProvider('MyProvider'));
    }

    public function testGetList()
    {
        $provider1 = $this->getMockBuilder('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface')->getMock();
        $provider1->expects($this->any())->method('getName')->willReturn('MyProvider1');

        $provider2 = $this->getMockBuilder('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface')->getMock();
        $provider2->expects($this->any())->method('getName')->willReturn('MyProvider2');

        $manager = new ExternalTaskManager();
        $manager->register($provider1);
        $manager->register($provider2);
        $providers = $manager->getProvidersList();

        $expected = array('MyProvider1' => 'MyProvider1', 'MyProvider2' => 'MyProvider2');
        $this->assertEquals($expected, $providers);
    }

    public function testGetProviderListWithNoProviders()
    {
        $manager = new ExternalTaskManager();
        $this->assertSame(array(), $manager->getProvidersList());
    }
}