diff options
author | JLGC @monolinux <monolinux@junglacode.org> | 2016-08-15 23:13:16 -0500 |
---|---|---|
committer | JLGC @monolinux <monolinux@junglacode.org> | 2016-08-15 23:13:16 -0500 |
commit | 683c0464093f6a7976236c68653c2a2cc5dae280 (patch) | |
tree | bf176ecd82415cc4952eea071b7d264dd5fd68b4 /tests/units/Core | |
parent | b1e795fc5b45369f7b9b565b1e106d2673361977 (diff) | |
parent | 5f82a942c0011bf91947b2c1d627c0907bda0c92 (diff) |
Merge https://github.com/kanboard/kanboard
Diffstat (limited to 'tests/units/Core')
-rw-r--r-- | tests/units/Core/Action/ActionManagerTest.php | 40 | ||||
-rw-r--r-- | tests/units/Core/Filter/LexerBuilderTest.php | 46 | ||||
-rw-r--r-- | tests/units/Core/Filter/LexerTest.php | 56 | ||||
-rw-r--r-- | tests/units/Core/Filter/OrCriteriaTest.php | 5 | ||||
-rw-r--r-- | tests/units/Core/Http/RequestTest.php | 3 | ||||
-rw-r--r-- | tests/units/Core/Ldap/LdapUserTest.php | 60 | ||||
-rw-r--r-- | tests/units/Core/Plugin/HookTest.php | 62 |
7 files changed, 241 insertions, 31 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/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/LexerTest.php b/tests/units/Core/Filter/LexerTest.php index c72231c4..d57a7953 100644 --- a/tests/units/Core/Filter/LexerTest.php +++ b/tests/units/Core/Filter/LexerTest.php @@ -202,4 +202,60 @@ class LexerTest extends Base $this->assertSame($expected, $lexer->tokenize('६Δↈ五一')); } + + public function testTokenizeWithMultipleValues() + { + $lexer = new Lexer(); + $lexer->addToken("/^(tag:)/", 'T_TAG'); + + $expected = array( + 'T_TAG' => array('tag 1', 'tag2'), + ); + + $this->assertSame($expected, $lexer->tokenize('tag:"tag 1" tag:tag2')); + } + + public function testTokenizeWithDash() + { + $lexer = new Lexer(); + $lexer->addToken("/^(test:)/", 'T_TEST'); + + $expected = array( + 'T_TEST' => array('PO-123'), + ); + + $this->assertSame($expected, $lexer->tokenize('test:PO-123')); + + $lexer = new Lexer(); + $lexer->setDefaultToken('myDefaultToken'); + + $expected = array( + 'myDefaultToken' => array('PO-123'), + ); + + $this->assertSame($expected, $lexer->tokenize('PO-123')); + } + + public function testTokenizeWithUnderscore() + { + $lexer = new Lexer(); + $lexer->addToken("/^(test:)/", 'T_TEST'); + + $expected = array( + 'T_TEST' => array('PO_123'), + ); + + $this->assertSame($expected, $lexer->tokenize('test:PO_123')); + + $lexer = new Lexer(); + $lexer->addToken("/^(test:)/", 'T_TEST'); + $lexer->setDefaultToken('myDefaultToken'); + + $expected = array( + 'T_TEST' => array('ABC-123'), + 'myDefaultToken' => array('PO_123'), + ); + + $this->assertSame($expected, $lexer->tokenize('test:ABC-123 PO_123')); + } } 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..1db0100c 100644 --- a/tests/units/Core/Http/RequestTest.php +++ b/tests/units/Core/Http/RequestTest.php @@ -169,6 +169,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/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php index 505b8a03..143a8c0d 100644 --- a/tests/units/Core/Ldap/LdapUserTest.php +++ b/tests/units/Core/Ldap/LdapUserTest.php @@ -845,4 +845,64 @@ class LdapUserTest extends Base $this->assertTrue($this->user->hasGroupUserFilter()); } + + public function testHasGroupsConfigured() + { + $this->user + ->expects($this->any()) + ->method('getGroupAdminDn') + ->will($this->returnValue('something')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('something')); + + $this->assertTrue($this->user->hasGroupsConfigured()); + } + + public function testHasGroupAdminDnConfigured() + { + $this->user + ->expects($this->any()) + ->method('getGroupAdminDn') + ->will($this->returnValue('something')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('')); + + $this->assertTrue($this->user->hasGroupsConfigured()); + } + + public function testHasGroupManagerDnConfigured() + { + $this->user + ->expects($this->any()) + ->method('getGroupAdminDn') + ->will($this->returnValue('')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('something')); + + $this->assertTrue($this->user->hasGroupsConfigured()); + } + + public function testHasGroupsNotConfigured() + { + $this->user + ->expects($this->any()) + ->method('getGroupAdminDn') + ->will($this->returnValue('')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('')); + + $this->assertFalse($this->user->hasGroupsConfigured()); + } } 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); + } } |