summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/configtest/DefaultConfigFileTest.php9
-rw-r--r--tests/units/Action/TaskAssignColorSwimlaneTest.php70
-rw-r--r--tests/units/Action/TaskAssignPrioritySwimlaneTest.php46
-rw-r--r--tests/units/Base.php1
-rw-r--r--tests/units/Core/Cache/FileCacheTest.php186
-rw-r--r--tests/units/Core/ObjectStorage/FileStorageTest.php (renamed from tests/units/Core/FileStorageTest.php)4
-rw-r--r--tests/units/Core/User/UserSessionTest.php21
-rw-r--r--tests/units/Decorator/MetadataCacheDecoratorTest.php127
8 files changed, 441 insertions, 23 deletions
diff --git a/tests/configtest/DefaultConfigFileTest.php b/tests/configtest/DefaultConfigFileTest.php
new file mode 100644
index 00000000..0840925b
--- /dev/null
+++ b/tests/configtest/DefaultConfigFileTest.php
@@ -0,0 +1,9 @@
+<?php
+
+class DefaultConfigFileTest extends PHPUnit_Framework_TestCase
+{
+ public function testThatFileCanBeImported()
+ {
+ $this->assertNotFalse(include __DIR__.'/../../config.default.php');
+ }
+}
diff --git a/tests/units/Action/TaskAssignColorSwimlaneTest.php b/tests/units/Action/TaskAssignColorSwimlaneTest.php
new file mode 100644
index 00000000..811ffac3
--- /dev/null
+++ b/tests/units/Action/TaskAssignColorSwimlaneTest.php
@@ -0,0 +1,70 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\TaskAssignColorSwimlane;
+
+class TaskAssignColorSwimlaneTest extends Base
+{
+ public function testChangeSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'swimlane_id' => 2,
+ )
+ ));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotEquals('red', $task['color_id']);
+
+ $action = new TaskAssignColorSwimlane($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('swimlane_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('red', $task['color_id']);
+ }
+
+ public function testWithWrongSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'swimlane_id' => 3,
+ )
+ ));
+
+ $action = new TaskAssignColorSwimlane($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('swimlane_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE));
+ }
+}
diff --git a/tests/units/Action/TaskAssignPrioritySwimlaneTest.php b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php
new file mode 100644
index 00000000..39c833bf
--- /dev/null
+++ b/tests/units/Action/TaskAssignPrioritySwimlaneTest.php
@@ -0,0 +1,46 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Action\TaskAssignPrioritySwimlane;
+
+class TaskAssignPrioritySwimlaneTest extends Base
+{
+ public function testChangeSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'priority' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['priority']);
+
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'swimlane_id' => 2,
+ )
+ ));
+
+ $action = new TaskAssignPrioritySwimlane($this->container);
+ $action->setProjectId(1);
+ $action->setParam('priority', 2);
+ $action->setParam('swimlane_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_MOVE_SWIMLANE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['priority']);
+ }
+}
diff --git a/tests/units/Base.php b/tests/units/Base.php
index e44223ce..722a1335 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -38,6 +38,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
}
$this->container = new Pimple\Container;
+ $this->container->register(new Kanboard\ServiceProvider\CacheProvider());
$this->container->register(new Kanboard\ServiceProvider\HelperProvider());
$this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider());
$this->container->register(new Kanboard\ServiceProvider\DatabaseProvider());
diff --git a/tests/units/Core/Cache/FileCacheTest.php b/tests/units/Core/Cache/FileCacheTest.php
new file mode 100644
index 00000000..b6336581
--- /dev/null
+++ b/tests/units/Core/Cache/FileCacheTest.php
@@ -0,0 +1,186 @@
+<?php
+
+namespace Kanboard\Core\Cache;
+
+require_once __DIR__.'/../../Base.php';
+
+function file_put_contents($filename, $data)
+{
+ return FileCacheTest::$functions->file_put_contents($filename, $data);
+}
+
+function file_get_contents($filename)
+{
+ return FileCacheTest::$functions->file_get_contents($filename);
+}
+
+function mkdir($filename, $mode = 0777, $recursif = false)
+{
+ return FileCacheTest::$functions->mkdir($filename, $mode, $recursif);
+}
+
+function is_dir($filename)
+{
+ return FileCacheTest::$functions->is_dir($filename);
+}
+
+function file_exists($filename)
+{
+ return FileCacheTest::$functions->file_exists($filename);
+}
+
+function unlink($filename)
+{
+ return FileCacheTest::$functions->unlink($filename);
+}
+
+class FileCacheTest extends \Base
+{
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ public static $functions;
+
+ public function setUp()
+ {
+ parent::setup();
+
+ self::$functions = $this
+ ->getMockBuilder('stdClass')
+ ->setMethods(array(
+ 'file_put_contents',
+ 'file_get_contents',
+ 'file_exists',
+ 'mkdir',
+ 'is_dir',
+ 'unlink',
+ ))
+ ->getMock();
+ }
+
+ public function tearDown()
+ {
+ parent::tearDown();
+ self::$functions = null;
+ }
+
+ public function testSet()
+ {
+ $key = 'mykey';
+ $data = 'data';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('is_dir')
+ ->with(
+ $this->equalTo(CACHE_DIR)
+ )
+ ->will($this->returnValue(false));
+
+ self::$functions
+ ->expects($this->at(1))
+ ->method('mkdir')
+ ->with(
+ $this->equalTo(CACHE_DIR),
+ 0755
+ )
+ ->will($this->returnValue(true));
+
+ self::$functions
+ ->expects($this->at(2))
+ ->method('file_put_contents')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key),
+ $this->equalTo(serialize($data))
+ )
+ ->will($this->returnValue(true));
+
+ $cache->set($key, $data);
+ }
+
+ public function testGet()
+ {
+ $key = 'mykey';
+ $data = 'data';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(true));
+
+ self::$functions
+ ->expects($this->at(1))
+ ->method('file_get_contents')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(serialize($data)));
+
+ $this->assertSame($data, $cache->get($key));
+ }
+
+ public function testGetWithKeyNotFound()
+ {
+ $key = 'mykey';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(false));
+
+ $this->assertNull($cache->get($key));
+ }
+
+ public function testRemoveWithKeyNotFound()
+ {
+ $key = 'mykey';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(false));
+
+ self::$functions
+ ->expects($this->never())
+ ->method('unlink');
+
+ $cache->remove($key);
+ }
+
+ public function testRemove()
+ {
+ $key = 'mykey';
+ $cache = new FileCache();
+
+ self::$functions
+ ->expects($this->at(0))
+ ->method('file_exists')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(true));
+
+ self::$functions
+ ->expects($this->at(1))
+ ->method('unlink')
+ ->with(
+ $this->equalTo(CACHE_DIR.DIRECTORY_SEPARATOR.$key)
+ )
+ ->will($this->returnValue(true));
+
+ $cache->remove($key);
+ }
+}
diff --git a/tests/units/Core/FileStorageTest.php b/tests/units/Core/ObjectStorage/FileStorageTest.php
index a3ad2448..ed77dedd 100644
--- a/tests/units/Core/FileStorageTest.php
+++ b/tests/units/Core/ObjectStorage/FileStorageTest.php
@@ -2,7 +2,7 @@
namespace Kanboard\Core\ObjectStorage;
-require_once __DIR__.'/../Base.php';
+require_once __DIR__.'/../../Base.php';
function file_put_contents($filename, $data)
{
@@ -105,7 +105,7 @@ class FileStorageTest extends \Base
->method('file_put_contents')
->with(
$this->equalTo('somewhere'.DIRECTORY_SEPARATOR.'mykey'),
- $this->equalTo('data')
+ $this->equalTo($data)
)
->will($this->returnValue(true));
diff --git a/tests/units/Core/User/UserSessionTest.php b/tests/units/Core/User/UserSessionTest.php
index 64413f98..2a118079 100644
--- a/tests/units/Core/User/UserSessionTest.php
+++ b/tests/units/Core/User/UserSessionTest.php
@@ -83,27 +83,6 @@ class UserSessionTest extends Base
$this->assertFalse($us->isAdmin());
}
- public function testCommentSorting()
- {
- $us = new UserSession($this->container);
- $this->assertEquals('ASC', $us->getCommentSorting());
-
- $us->setCommentSorting('DESC');
- $this->assertEquals('DESC', $us->getCommentSorting());
- }
-
- public function testBoardCollapseMode()
- {
- $us = new UserSession($this->container);
- $this->assertFalse($us->isBoardCollapsed(2));
-
- $us->setBoardDisplayMode(3, false);
- $this->assertFalse($us->isBoardCollapsed(3));
-
- $us->setBoardDisplayMode(3, true);
- $this->assertTrue($us->isBoardCollapsed(3));
- }
-
public function testFilters()
{
$us = new UserSession($this->container);
diff --git a/tests/units/Decorator/MetadataCacheDecoratorTest.php b/tests/units/Decorator/MetadataCacheDecoratorTest.php
new file mode 100644
index 00000000..3e4dd320
--- /dev/null
+++ b/tests/units/Decorator/MetadataCacheDecoratorTest.php
@@ -0,0 +1,127 @@
+<?php
+
+use Kanboard\Decorator\MetadataCacheDecorator;
+
+require_once __DIR__.'/../Base.php';
+
+class MetadataCacheDecoratorTest extends Base
+{
+ protected $cachePrefix = 'cache_prefix';
+ protected $entityId = 123;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $cacheMock;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $metadataModelMock;
+
+ /**
+ * @var MetadataCacheDecorator
+ */
+ protected $metadataCacheDecorator;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->cacheMock = $this
+ ->getMockBuilder('\Kanboard\Core\Cache\MemoryCache')
+ ->setMethods(array(
+ 'set',
+ 'get',
+ ))
+ ->getMock();
+
+ $this->metadataModelMock = $this
+ ->getMockBuilder('\Kanboard\Model\UserMetadataModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array(
+ 'getAll',
+ 'save',
+ ))
+ ->getMock()
+ ;
+
+ $this->metadataCacheDecorator = new MetadataCacheDecorator(
+ $this->cacheMock,
+ $this->metadataModelMock,
+ $this->cachePrefix,
+ $this->entityId
+ );
+ }
+
+ public function testSet()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('set');
+
+ $this->metadataModelMock
+ ->expects($this->at(0))
+ ->method('save');
+
+ $this->metadataModelMock
+ ->expects($this->at(1))
+ ->method('getAll')
+ ->with($this->entityId)
+ ;
+
+ $this->metadataCacheDecorator->set('key', 'value');
+ }
+
+ public function testGetWithCache()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(array('key' => 'foobar')))
+ ;
+
+ $this->assertEquals('foobar', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+
+ public function testGetWithCacheAndDefaultValue()
+ {
+ $this->cacheMock
+ ->expects($this->once())
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(array('key1' => 'foobar')))
+ ;
+
+ $this->assertEquals('default', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+
+ public function testGetWithoutCache()
+ {
+ $this->cacheMock
+ ->expects($this->at(0))
+ ->method('get')
+ ->with($this->cachePrefix.$this->entityId)
+ ->will($this->returnValue(null))
+ ;
+
+ $this->cacheMock
+ ->expects($this->at(1))
+ ->method('set')
+ ->with(
+ $this->cachePrefix.$this->entityId,
+ array('key' => 'something')
+ )
+ ;
+
+ $this->metadataModelMock
+ ->expects($this->once())
+ ->method('getAll')
+ ->with($this->entityId)
+ ->will($this->returnValue(array('key' => 'something')))
+ ;
+
+ $this->assertEquals('something', $this->metadataCacheDecorator->get('key', 'default'));
+ }
+}