summaryrefslogtreecommitdiff
path: root/tests/units/Model/ProjectNotificationTypeTest.php
blob: 7f7358288dbca48f63e19bd7807a3f7f0b0fa373 (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
<?php

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

use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectNotificationTypeModel;

class ProjectNotificationTypeTest extends Base
{
    public function testGetTypes()
    {
        $nt = new ProjectNotificationTypeModel($this->container);
        $this->assertEmpty($nt->getTypes());

        $nt->setType('foo', 'Foo', 'Something1');
        $nt->setType('bar', 'Bar', 'Something2');
        $nt->setType('baz', 'Baz', 'Something3', true);

        $this->assertEquals(array('bar' => 'Bar', 'foo' => 'Foo'), $nt->getTypes());
        $this->assertEquals(array('baz'), $nt->getHiddenTypes());
    }

    public function testGetSelectedTypes()
    {
        $nt = new ProjectNotificationTypeModel($this->container);
        $p = new ProjectModel($this->container);

        $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));

        // No type defined
        $this->assertEmpty($nt->getSelectedTypes(1));

        // Hidden type
        $nt->setType('baz', 'Baz', 'Something3', true);
        $this->assertEmpty($nt->getSelectedTypes(1));

        // User defined types but not registered
        $this->assertTrue($nt->saveSelectedTypes(1, array('foo', 'bar')));
        $this->assertEmpty($nt->getSelectedTypes(1));

        // User defined types and registered
        $nt->setType('bar', 'Bar', 'Something4');
        $nt->setType('foo', 'Foo', 'Something3');
        $this->assertEquals(array('bar', 'foo'), $nt->getSelectedTypes(1));
    }
}