diff options
Diffstat (limited to 'tests/units/Core')
-rw-r--r-- | tests/units/Core/Action/ActionManagerTest.php | 40 | ||||
-rw-r--r-- | tests/units/Core/Cache/FileCacheTest.php | 186 | ||||
-rw-r--r-- | tests/units/Core/DateParserTest.php | 20 | ||||
-rw-r--r-- | tests/units/Core/ExternalTask/ExternalTaskManagerTest.php | 50 | ||||
-rw-r--r-- | tests/units/Core/Filter/LexerBuilderTest.php | 46 | ||||
-rw-r--r-- | tests/units/Core/Filter/OrCriteriaTest.php | 5 | ||||
-rw-r--r-- | tests/units/Core/Http/RequestTest.php | 6 | ||||
-rw-r--r-- | tests/units/Core/ObjectStorage/FileStorageTest.php (renamed from tests/units/Core/FileStorageTest.php) | 4 | ||||
-rw-r--r-- | tests/units/Core/Plugin/DirectoryTest.php | 5 | ||||
-rw-r--r-- | tests/units/Core/Plugin/HookTest.php | 62 | ||||
-rw-r--r-- | tests/units/Core/Plugin/VersionTest.php | 29 | ||||
-rw-r--r-- | tests/units/Core/Security/RoleTest.php | 37 | ||||
-rw-r--r-- | tests/units/Core/TranslatorTest.php | 45 | ||||
-rw-r--r-- | tests/units/Core/User/UserSessionTest.php | 21 |
14 files changed, 488 insertions, 68 deletions
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php index e7c2071f..4878c0c9 100644 --- a/tests/units/Core/Action/ActionManagerTest.php +++ b/tests/units/Core/Action/ActionManagerTest.php @@ -96,7 +96,7 @@ class ActionManagerTest extends Base $actions = $actionManager->getAvailableActions(); $actionManager->attachEvents(); - $this->assertEmpty($this->container['dispatcher']->getListeners()); + $this->assertEmpty($this->dispatcher->getListeners()); $this->assertEquals(1, $projectModel->create(array('name' =>'test'))); $this->assertEquals(1, $actionModel->create(array( @@ -107,7 +107,7 @@ class ActionManagerTest extends Base ))); $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE); + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE); $this->assertCount(1, $listeners); $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); @@ -148,7 +148,7 @@ class ActionManagerTest extends Base $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN); + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN); $this->assertCount(1, $listeners); $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); @@ -158,7 +158,6 @@ class ActionManagerTest extends Base public function testThatEachListenerAreDifferentInstance() { $projectModel = new ProjectModel($this->container); - $projectUserRoleModel = new ProjectUserRoleModel($this->container); $actionModel = new ActionModel($this->container); $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); $actionManager = new ActionManager($this->container); @@ -183,7 +182,7 @@ class ActionManagerTest extends Base $actionManager->attachEvents(); - $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN); + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN); $this->assertCount(2, $listeners); $this->assertFalse($listeners[0][0] === $listeners[1][0]); @@ -193,4 +192,35 @@ class ActionManagerTest extends Base $this->assertEquals(1, $listeners[1][0]->getParam('column_id')); $this->assertEquals('red', $listeners[1][0]->getParam('color_id')); } + + public function testRemoveEvents() + { + $projectModel = new ProjectModel($this->container); + $actionModel = new ActionModel($this->container); + $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); + $actionManager = new ActionManager($this->container); + $actionManager->register($actionTaskAssignColorColumn); + + $actions = $actionManager->getAvailableActions(); + + $this->assertEquals(1, $projectModel->create(array('name' =>'test'))); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => TaskModel::EVENT_CREATE, + 'action_name' => key($actions), + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $actionManager->attachEvents(); + $this->dispatcher->addListener(TaskModel::EVENT_CREATE, function () {}); + + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE); + $this->assertCount(2, $listeners); + + $actionManager->removeEvents(); + + $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE); + $this->assertCount(1, $listeners); + $this->assertNotInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0]); + } } 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/DateParserTest.php b/tests/units/Core/DateParserTest.php index fbde8bd5..e0dfb4c1 100644 --- a/tests/units/Core/DateParserTest.php +++ b/tests/units/Core/DateParserTest.php @@ -64,7 +64,7 @@ class DateParserTest extends Base $dates = $dateParser->getDateTimeFormats(true); $this->assertEquals('m/d/Y H:i', $dates[0]); - $this->container['configModel']->save(array('application_datetime_format' => 'd/m/Y g:i a')); + $this->container['configModel']->save(array('application_date_format' => 'd/m/Y', 'application_time_format' => 'g:i a')); $this->container['memoryCache']->flush(); $dates = $dateParser->getDateTimeFormats(); @@ -121,7 +121,7 @@ class DateParserTest extends Base { $this->container['configModel']->save(array( 'application_date_format' => 'd/m/Y', - 'application_datetime_format' => 'd/m/Y g:i a', + 'application_time_format' => 'g:i a', )); $dateParser = new DateParser($this->container); @@ -138,7 +138,7 @@ class DateParserTest extends Base { $this->container['configModel']->save(array( 'application_date_format' => 'd.m.Y', - 'application_datetime_format' => 'd.m.Y H:i', + 'application_time_format' => 'H:i', )); $dateParser = new DateParser($this->container); @@ -166,17 +166,9 @@ class DateParserTest extends Base $this->assertEquals(1, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00'))); $this->assertEquals(2.5, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:30:00'))); $this->assertEquals(2.75, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:45:00'))); - $this->assertEquals(3, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00'))); - $this->assertEquals(3, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00'))); - } - - public function testRoundSeconds() - { - $dateParser = new DateParser($this->container); - $this->assertEquals('16:30', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:28')))); - $this->assertEquals('16:00', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:02')))); - $this->assertEquals('16:15', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:14')))); - $this->assertEquals('17:00', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:58')))); + $this->assertEquals(3.02, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00'))); + $this->assertEquals(2.98, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00'))); + $this->assertEquals(0, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 14:57:10'))); } public function testGetIsoDate() diff --git a/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php new file mode 100644 index 00000000..8eec64de --- /dev/null +++ b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php @@ -0,0 +1,50 @@ +<?php + +use Kanboard\Core\ExternalTask\ExternalTaskManager; + +require_once __DIR__.'/../../Base.php'; + +class ExternalTaskManagerTest extends Base +{ + public function testProviderNotFound() + { + $this->setExpectedException('Kanboard\Core\ExternalTask\ProviderNotFoundException'); + + $manager = new ExternalTaskManager(); + $manager->getProvider('foobar'); + } + + public function testRegister() + { + $provider = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface'); + $provider->expects($this->any())->method('getName')->willReturn('MyProvider'); + + $manager = new ExternalTaskManager(); + $manager->register($provider); + + $this->assertInstanceOf('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface', $manager->getProvider('MyProvider')); + } + + public function testGetList() + { + $provider1 = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface'); + $provider1->expects($this->any())->method('getName')->willReturn('MyProvider1'); + + $provider2 = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface'); + $provider2->expects($this->any())->method('getName')->willReturn('MyProvider2'); + + $manager = new ExternalTaskManager(); + $manager->register($provider1); + $manager->register($provider2); + $providers = $manager->getProvidersList(); + + $expected = array('MyProvider1' => 'MyProvider1', 'MyProvider2' => 'MyProvider2'); + $this->assertEquals($expected, $providers); + } + + public function testGetProviderListWithNoProviders() + { + $manager = new ExternalTaskManager(); + $this->assertSame(array(), $manager->getProvidersList()); + } +} diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php index 23726f32..31e237dc 100644 --- a/tests/units/Core/Filter/LexerBuilderTest.php +++ b/tests/units/Core/Filter/LexerBuilderTest.php @@ -8,6 +8,7 @@ use Kanboard\Filter\TaskTitleFilter; use Kanboard\Model\ProjectModel; use Kanboard\Model\TaskCreationModel; use Kanboard\Model\TaskFinderModel; +use Kanboard\Model\UserModel; class LexerBuilderTest extends Base { @@ -103,4 +104,49 @@ class LexerBuilderTest extends Base $this->assertFalse($builder === $clone); $this->assertFalse($builder->build('test')->getQuery() === $clone->build('test')->getQuery()); } + + public function testBuilderWithMixedCaseSearchAttribute() + { + $project = new ProjectModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $taskFinder = new TaskFinderModel($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $project->create(array('name' => 'Project'))); + $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test'))); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter(), true); + $builder->withQuery($query); + $tasks = $builder->build('AsSignEe:nobody')->toArray(); + + $this->assertCount(1, $tasks); + $this->assertEquals('Test', $tasks[0]['title']); + } + + public function testWithOrCriteria() + { + $taskFinder = new TaskFinderModel($this->container); + $taskCreation = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1))); + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0))); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter(), true); + $builder->withQuery($query); + $tasks = $builder->build('assignee:admin assignee:foobar')->toArray(); + + $this->assertCount(2, $tasks); + $this->assertEquals('Test 1', $tasks[0]['title']); + $this->assertEquals('Test 2', $tasks[1]['title']); + } } diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php index a46726c3..cf520f36 100644 --- a/tests/units/Core/Filter/OrCriteriaTest.php +++ b/tests/units/Core/Filter/OrCriteriaTest.php @@ -22,8 +22,9 @@ class OrCriteriaTest extends Base $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); - $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 2))); - $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1))); + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0))); $criteria = new OrCriteria(); $criteria->withQuery($query); diff --git a/tests/units/Core/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php index 6fa796f7..697c3c0f 100644 --- a/tests/units/Core/Http/RequestTest.php +++ b/tests/units/Core/Http/RequestTest.php @@ -43,6 +43,9 @@ class RequestTest extends Base $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array()); $this->assertEquals(array('myvar' => 'myvalue'), $request->getValues()); + + $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', '-----------------------------7e1c32510025c--' => '', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array()); + $this->assertEquals(array('myvar' => 'myvalue'), $request->getValues()); } public function testGetFileContent() @@ -169,6 +172,9 @@ class RequestTest extends Base $request = new Request($this->container, array(), array(), array(), array(), array()); $this->assertEquals('Unknown', $request->getIpAddress()); + $request = new Request($this->container, array('HTTP_X_REAL_IP' => '192.168.1.1,127.0.0.1'), array(), array(), array(), array()); + $this->assertEquals('192.168.1.1', $request->getIpAddress()); + $request = new Request($this->container, array('HTTP_X_FORWARDED_FOR' => '192.168.0.1,127.0.0.1'), array(), array(), array(), array()); $this->assertEquals('192.168.0.1', $request->getIpAddress()); 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/Plugin/DirectoryTest.php b/tests/units/Core/Plugin/DirectoryTest.php index 13aef4b9..302bd6f6 100644 --- a/tests/units/Core/Plugin/DirectoryTest.php +++ b/tests/units/Core/Plugin/DirectoryTest.php @@ -12,6 +12,11 @@ class DirectoryTest extends Base $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28')); $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28')); $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), 'master')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.32')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.33')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.33')); + $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.32')); } public function testGetAvailablePlugins() diff --git a/tests/units/Core/Plugin/HookTest.php b/tests/units/Core/Plugin/HookTest.php index d1c139b3..acadede0 100644 --- a/tests/units/Core/Plugin/HookTest.php +++ b/tests/units/Core/Plugin/HookTest.php @@ -8,89 +8,103 @@ class HookTest extends Base { public function testGetListeners() { - $h = new Hook; - $this->assertEmpty($h->getListeners('myhook')); + $hook = new Hook; + $this->assertEmpty($hook->getListeners('myhook')); - $h->on('myhook', 'A'); - $h->on('myhook', 'B'); + $hook->on('myhook', 'A'); + $hook->on('myhook', 'B'); - $this->assertEquals(array('A', 'B'), $h->getListeners('myhook')); + $this->assertEquals(array('A', 'B'), $hook->getListeners('myhook')); } public function testExists() { - $h = new Hook; - $this->assertFalse($h->exists('myhook')); + $hook = new Hook; + $this->assertFalse($hook->exists('myhook')); - $h->on('myhook', 'A'); + $hook->on('myhook', 'A'); - $this->assertTrue($h->exists('myhook')); + $this->assertTrue($hook->exists('myhook')); } public function testMergeWithNoBinding() { - $h = new Hook; + $hook = new Hook; $values = array('A', 'B'); - $result = $h->merge('myhook', $values, array('p' => 'c')); + $result = $hook->merge('myhook', $values, array('p' => 'c')); $this->assertEquals($values, $result); } public function testMergeWithBindings() { - $h = new Hook; + $hook = new Hook; $values = array('A', 'B'); $expected = array('A', 'B', 'c', 'D'); - $h->on('myhook', function ($p) { + $hook->on('myhook', function ($p) { return array($p); }); - $h->on('myhook', function () { + $hook->on('myhook', function () { return array('D'); }); - $result = $h->merge('myhook', $values, array('p' => 'c')); + $result = $hook->merge('myhook', $values, array('p' => 'c')); $this->assertEquals($expected, $result); $this->assertEquals($expected, $values); } public function testMergeWithBindingButReturningBadData() { - $h = new Hook; + $hook = new Hook; $values = array('A', 'B'); $expected = array('A', 'B'); - $h->on('myhook', function () { + $hook->on('myhook', function () { return 'string'; }); - $result = $h->merge('myhook', $values); + $result = $hook->merge('myhook', $values); $this->assertEquals($expected, $result); $this->assertEquals($expected, $values); } public function testFirstWithNoBinding() { - $h = new Hook; + $hook = new Hook; - $result = $h->first('myhook', array('p' => 2)); + $result = $hook->first('myhook', array('p' => 2)); $this->assertEquals(null, $result); } public function testFirstWithMultipleBindings() { - $h = new Hook; + $hook = new Hook; - $h->on('myhook', function ($p) { + $hook->on('myhook', function ($p) { return $p + 1; }); - $h->on('myhook', function ($p) { + $hook->on('myhook', function ($p) { return $p; }); - $result = $h->first('myhook', array('p' => 3)); + $result = $hook->first('myhook', array('p' => 3)); $this->assertEquals(4, $result); } + + public function testHookWithReference() + { + $hook = new Hook(); + + $hook->on('myhook', function (&$p) { + $p = 2; + }); + + $param = 123; + $result = $hook->reference('myhook', $param); + $this->assertSame(2, $result); + $this->assertSame(2, $param); + } } diff --git a/tests/units/Core/Plugin/VersionTest.php b/tests/units/Core/Plugin/VersionTest.php new file mode 100644 index 00000000..78f10d95 --- /dev/null +++ b/tests/units/Core/Plugin/VersionTest.php @@ -0,0 +1,29 @@ +<?php + +use Kanboard\Core\Plugin\Version; + +require_once __DIR__.'/../../Base.php'; + +class VersionTest extends Base +{ + public function testIsCompatible() + { + $this->assertFalse(Version::isCompatible('1.0.29', '1.0.28')); + $this->assertTrue(Version::isCompatible('1.0.28', '1.0.28')); + $this->assertTrue(Version::isCompatible('1.0.28', 'master.1234')); + $this->assertTrue(Version::isCompatible('>=1.0.32', 'master')); + $this->assertTrue(Version::isCompatible('>=1.0.32', '1.0.32')); + $this->assertTrue(Version::isCompatible('>=1.0.32', '1.0.33')); + $this->assertTrue(Version::isCompatible('>1.0.32', '1.0.33')); + $this->assertFalse(Version::isCompatible('>1.0.32', '1.0.32')); + $this->assertTrue(Version::isCompatible('1.0.32', 'v1.0.32')); + $this->assertTrue(Version::isCompatible('>=v1.0.32', 'v1.0.32')); + $this->assertTrue(Version::isCompatible('<=v1.0.36', 'v1.0.36')); + $this->assertFalse(Version::isCompatible('<1.0.36', 'v1.0.36')); + $this->assertTrue(Version::isCompatible('<1.0.40', '1.0.36')); + $this->assertTrue(Version::isCompatible('<=1.0.40', '1.0.36')); + $this->assertFalse(Version::isCompatible('<1.0.40', '1.0.40')); + $this->assertFalse(Version::isCompatible('1.0.40', 'v1.0.36')); + $this->assertTrue(Version::isCompatible('<1.1.0', 'v1.0.36')); + } +} diff --git a/tests/units/Core/Security/RoleTest.php b/tests/units/Core/Security/RoleTest.php new file mode 100644 index 00000000..10b9c409 --- /dev/null +++ b/tests/units/Core/Security/RoleTest.php @@ -0,0 +1,37 @@ +<?php + +use Kanboard\Core\Security\Role; + +require_once __DIR__.'/../../Base.php'; + +class RoleTest extends Base +{ + public function testIsCustomRole() + { + $role = new Role(); + $this->assertFalse($role->isCustomProjectRole(Role::PROJECT_MANAGER)); + $this->assertFalse($role->isCustomProjectRole(Role::PROJECT_MEMBER)); + $this->assertFalse($role->isCustomProjectRole(Role::PROJECT_VIEWER)); + $this->assertFalse($role->isCustomProjectRole('')); + $this->assertTrue($role->isCustomProjectRole('Custom Role')); + } + + public function testGetRoleName() + { + $role = new Role(); + $this->assertEquals('Project Manager', $role->getRoleName(Role::PROJECT_MANAGER)); + $this->assertEquals('Project Member', $role->getRoleName(Role::PROJECT_MEMBER)); + $this->assertEquals('Project Viewer', $role->getRoleName(Role::PROJECT_VIEWER)); + $this->assertEquals('Administrator', $role->getRoleName(Role::APP_ADMIN)); + $this->assertEquals('Manager', $role->getRoleName(Role::APP_MANAGER)); + $this->assertEquals('User', $role->getRoleName(Role::APP_USER)); + $this->assertEquals('Unknown', $role->getRoleName('Foobar')); + } + + public function testGetters() + { + $role = new Role(); + $this->assertCount(3, $role->getApplicationRoles()); + $this->assertCount(3, $role->getProjectRoles()); + } +} diff --git a/tests/units/Core/TranslatorTest.php b/tests/units/Core/TranslatorTest.php new file mode 100644 index 00000000..6aa480e1 --- /dev/null +++ b/tests/units/Core/TranslatorTest.php @@ -0,0 +1,45 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Core\Translator; + +class TranslatorTest extends Base +{ + public function setUp() + { + parent::setUp(); + Translator::unload(); + } + + public function testLoading() + { + $translator = new Translator(); + $this->assertSame('Yes', $translator->translate('Yes')); + + Translator::load('fr_FR'); + $this->assertSame('Oui', $translator->translate('Yes')); + + Translator::unload(); + $this->assertSame('Yes', $translator->translate('Yes')); + + Translator::load('de_DE', Translator::getDefaultFolder()); + $this->assertSame('Ja', $translator->translate('Yes')); + } + + public function testNumberFormatting() + { + $translator = new Translator(); + $this->assertSame('1,024.42', $translator->number(1024.42)); + + Translator::load('fr_FR'); + $this->assertSame('1 024,42', $translator->number(1024.42)); + } + + public function testTranslateEscaping() + { + $translator = new Translator(); + $this->assertSame('<b>', $translator->translate('<b>')); + $this->assertSame('<b>', $translator->translateNoEscaping('<b>')); + } +} 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); |