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

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

use Kanboard\Model\UserModel;
use Kanboard\Model\UserMetadataModel;

class UserMetadataTest extends Base
{
    public function testOperations()
    {
        $m = new UserMetadataModel($this->container);
        $u = new UserModel($this->container);

        $this->assertEquals(2, $u->create(array('username' => 'foobar')));

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

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

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

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

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

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