summaryrefslogtreecommitdiff
path: root/tests/units/Model/ProjectMetadataTest.php
blob: 16f4903372fdfbecd770a5f17123eed4a23821e1 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

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

use Kanboard\Model\Project;
use Kanboard\Model\ProjectMetadata;

class ProjectMetadataTest extends Base
{
    public function testOperations()
    {
        $projectModel = new Project($this->container);
        $projectMetadataModel = new ProjectMetadata($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'project #1')));
        $this->assertEquals(2, $projectModel->create(array('name' => 'project #2')));

        $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1')));
        $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value2')));
        $this->assertTrue($projectMetadataModel->save(2, array('key1' => 'value1')));
        $this->assertTrue($projectMetadataModel->save(2, array('key2' => 'value2')));

        $this->assertEquals('value2', $projectMetadataModel->get(1, 'key1'));
        $this->assertEquals('value1', $projectMetadataModel->get(2, 'key1'));
        $this->assertEquals('', $projectMetadataModel->get(2, 'key3'));
        $this->assertEquals('default', $projectMetadataModel->get(2, 'key3', 'default'));

        $this->assertTrue($projectMetadataModel->exists(2, 'key1'));
        $this->assertFalse($projectMetadataModel->exists(2, 'key3'));

        $this->assertEquals(array('key1' => 'value2'), $projectMetadataModel->getAll(1));
        $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $projectMetadataModel->getAll(2));

        $this->assertTrue($projectMetadataModel->remove(2, 'key1'));
        $this->assertFalse($projectMetadataModel->remove(2, 'key1'));

        $this->assertEquals(array('key2' => 'value2'), $projectMetadataModel->getAll(2));
    }

    public function testAutomaticRemove()
    {
        $projectModel = new Project($this->container);
        $projectMetadataModel = new ProjectMetadata($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'project #1')));
        $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1')));

        $this->assertTrue($projectMetadataModel->exists(1, 'key1'));
        $this->assertTrue($projectModel->remove(1));
        $this->assertFalse($projectMetadataModel->exists(1, 'key1'));
    }

    public function testDuplicate()
    {
        $projectModel = new Project($this->container);
        $projectMetadataModel = new ProjectMetadata($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'project #1')));
        $this->assertEquals(2, $projectModel->create(array('name' => 'project #2')));

        $this->assertTrue($projectMetadataModel->save(1, array('key1' => 'value1', 'key2' => 'value2')));
        $this->assertTrue($projectMetadataModel->duplicate(1, 2));

        $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $projectMetadataModel->getAll(2));
    }
}