summaryrefslogtreecommitdiff
path: root/tests/units/Model
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Model')
-rw-r--r--tests/units/Model/ConfigTest.php25
-rw-r--r--tests/units/Model/ProjectMetadataTest.php47
-rw-r--r--tests/units/Model/TaskMetadataTest.php37
-rw-r--r--tests/units/Model/UserMetadataTest.php33
4 files changed, 142 insertions, 0 deletions
diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php
index 7670daac..17617ceb 100644
--- a/tests/units/Model/ConfigTest.php
+++ b/tests/units/Model/ConfigTest.php
@@ -7,6 +7,31 @@ use Kanboard\Core\Session;
class ConfigTest extends Base
{
+ public function testCRUDOperations()
+ {
+ $c = new Config($this->container);
+
+ $this->assertTrue($c->save(array('key1' => 'value1')));
+ $this->assertTrue($c->save(array('key1' => 'value2')));
+ $this->assertTrue($c->save(array('key2' => 'value2')));
+
+ $this->assertEquals('value2', $c->getOption('key1'));
+ $this->assertEquals('value2', $c->getOption('key2'));
+ $this->assertEquals('', $c->getOption('key3'));
+ $this->assertEquals('default', $c->getOption('key3', 'default'));
+
+ $this->assertTrue($c->exists('key1'));
+ $this->assertFalse($c->exists('key3'));
+
+ $this->assertTrue($c->save(array('key1' => 'value1')));
+
+ $this->assertArrayHasKey('key1', $c->getAll());
+ $this->assertArrayHasKey('key2', $c->getAll());
+
+ $this->assertContains('value1', $c->getAll());
+ $this->assertContains('value2', $c->getAll());
+ }
+
public function testSaveApplicationUrl()
{
$c = new Config($this->container);
diff --git a/tests/units/Model/ProjectMetadataTest.php b/tests/units/Model/ProjectMetadataTest.php
new file mode 100644
index 00000000..43d66b7b
--- /dev/null
+++ b/tests/units/Model/ProjectMetadataTest.php
@@ -0,0 +1,47 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectMetadata;
+
+class ProjectMetadataTest extends Base
+{
+ public function testOperations()
+ {
+ $p = new Project($this->container);
+ $pm = new ProjectMetadata($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'project #1')));
+ $this->assertEquals(2, $p->create(array('name' => 'project #2')));
+
+ $this->assertTrue($pm->save(1, array('key1' => 'value1')));
+ $this->assertTrue($pm->save(1, array('key1' => 'value2')));
+ $this->assertTrue($pm->save(2, array('key1' => 'value1')));
+ $this->assertTrue($pm->save(2, array('key2' => 'value2')));
+
+ $this->assertEquals('value2', $pm->get(1, 'key1'));
+ $this->assertEquals('value1', $pm->get(2, 'key1'));
+ $this->assertEquals('', $pm->get(2, 'key3'));
+ $this->assertEquals('default', $pm->get(2, 'key3', 'default'));
+
+ $this->assertTrue($pm->exists(2, 'key1'));
+ $this->assertFalse($pm->exists(2, 'key3'));
+
+ $this->assertEquals(array('key1' => 'value2'), $pm->getAll(1));
+ $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $pm->getAll(2));
+ }
+
+ public function testAutomaticRemove()
+ {
+ $p = new Project($this->container);
+ $pm = new ProjectMetadata($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'project #1')));
+ $this->assertTrue($pm->save(1, array('key1' => 'value1')));
+
+ $this->assertTrue($pm->exists(1, 'key1'));
+ $this->assertTrue($p->remove(1));
+ $this->assertFalse($pm->exists(1, 'key1'));
+ }
+}
diff --git a/tests/units/Model/TaskMetadataTest.php b/tests/units/Model/TaskMetadataTest.php
new file mode 100644
index 00000000..9ce7d6be
--- /dev/null
+++ b/tests/units/Model/TaskMetadataTest.php
@@ -0,0 +1,37 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Project;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskMetadata;
+
+class TaskMetadataTest extends Base
+{
+ public function testOperations()
+ {
+ $p = new Project($this->container);
+ $tm = new TaskMetadata($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'project #1')));
+ $this->assertEquals(1, $tc->create(array('title' => 'task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'task #2', 'project_id' => 1)));
+
+ $this->assertTrue($tm->save(1, array('key1' => 'value1')));
+ $this->assertTrue($tm->save(1, array('key1' => 'value2')));
+ $this->assertTrue($tm->save(2, array('key1' => 'value1')));
+ $this->assertTrue($tm->save(2, array('key2' => 'value2')));
+
+ $this->assertEquals('value2', $tm->get(1, 'key1'));
+ $this->assertEquals('value1', $tm->get(2, 'key1'));
+ $this->assertEquals('', $tm->get(2, 'key3'));
+ $this->assertEquals('default', $tm->get(2, 'key3', 'default'));
+
+ $this->assertTrue($tm->exists(2, 'key1'));
+ $this->assertFalse($tm->exists(2, 'key3'));
+
+ $this->assertEquals(array('key1' => 'value2'), $tm->getAll(1));
+ $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $tm->getAll(2));
+ }
+}
diff --git a/tests/units/Model/UserMetadataTest.php b/tests/units/Model/UserMetadataTest.php
new file mode 100644
index 00000000..cc1fff12
--- /dev/null
+++ b/tests/units/Model/UserMetadataTest.php
@@ -0,0 +1,33 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\User;
+use Kanboard\Model\UserMetadata;
+
+class UserMetadataTest extends Base
+{
+ public function testOperations()
+ {
+ $m = new UserMetadata($this->container);
+ $u = new User($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));
+ }
+}