diff options
author | Max Kamashev <kamashev@gollard.ru> | 2015-09-24 12:07:40 +0300 |
---|---|---|
committer | Max Kamashev <kamashev@gollard.ru> | 2015-09-24 12:07:40 +0300 |
commit | 3f5b636c998171837fc2265f760359b421d67b61 (patch) | |
tree | a505f4f1767efff50224b649e647a02ae3638e12 /tests/units | |
parent | 5b2e49d2945ce2c1daaf4dd78746a910eab9c9c8 (diff) | |
parent | 1b0b69a43f7528fd5188d4b48216c6fa7e32eac3 (diff) |
Merge branch 'master' of https://github.com/ukko/kanboard into 1245_bug_with_subtask_timer
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Helper/HookHelperTest.php | 36 | ||||
-rw-r--r-- | tests/units/Integration/SlackWebhookTest.php | 377 | ||||
-rw-r--r-- | tests/units/Model/ActionTest.php | 11 | ||||
-rw-r--r-- | tests/units/Model/FileTest.php | 10 |
4 files changed, 432 insertions, 2 deletions
diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php index 6661c90b..7745c674 100644 --- a/tests/units/Helper/HookHelperTest.php +++ b/tests/units/Helper/HookHelperTest.php @@ -37,4 +37,38 @@ class HookHelperTest extends Base $h->attach('test', 'tpl2'); $this->assertEquals('tpl1_contenttpl2_content', $h->render('test')); } -}
\ No newline at end of file + + public function testAssetHooks() + { + $this->container['helper']->asset = $this + ->getMockBuilder('\Helper\Asset') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('css', 'js')) + ->getMock(); + + $this->container['helper'] + ->asset + ->expects($this->at(0)) + ->method('css') + ->with( + $this->equalTo('skin.css') + ) + ->will($this->returnValue('<link rel="stylesheet" href="skin.css"></link>')); + + $this->container['helper'] + ->asset + ->expects($this->at(1)) + ->method('js') + ->with( + $this->equalTo('skin.js') + ) + ->will($this->returnValue('<script src="skin.js"></script>')); + + $h = new Hook($this->container); + $h->attach('test1', 'skin.css'); + $h->attach('test2', 'skin.js'); + + $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $h->asset('css', 'test1')); + $this->assertContains('<script src="skin.js"></script>', $h->asset('js', 'test2')); + } +} diff --git a/tests/units/Integration/SlackWebhookTest.php b/tests/units/Integration/SlackWebhookTest.php new file mode 100644 index 00000000..3b9a3c1b --- /dev/null +++ b/tests/units/Integration/SlackWebhookTest.php @@ -0,0 +1,377 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Integration\SlackWebhook; +use Model\Project; +use Model\Task; + +class SlackWebhookTest extends Base +{ + public function testIsActivatedFromGlobalConfig() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('integration_slack_webhook')) + ->will($this->returnValue(1)); + + $this->assertTrue($slack->isActivated(1)); + } + + public function testIsActivatedFromProjectConfig() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['projectIntegration'] = $this + ->getMockBuilder('\Model\ProjectIntegration') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'hasValue', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('integration_slack_webhook')) + ->will($this->returnValue(0)); + + $this->container['projectIntegration'] + ->expects($this->once()) + ->method('hasValue') + ->with( + $this->equalTo(1), + $this->equalTo('slack'), + $this->equalTo(1) + ) + ->will($this->returnValue(true)); + + $this->assertTrue($slack->isActivated(1)); + } + + public function testIsNotActivated() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['projectIntegration'] = $this + ->getMockBuilder('\Model\ProjectIntegration') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'hasValue', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('integration_slack_webhook')) + ->will($this->returnValue(0)); + + $this->container['projectIntegration'] + ->expects($this->once()) + ->method('hasValue') + ->with( + $this->equalTo(1), + $this->equalTo('slack'), + $this->equalTo(1) + ) + ->will($this->returnValue(false)); + + $this->assertFalse($slack->isActivated(1)); + } + + public function testGetChannelFromGlobalConfig() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('integration_slack_webhook_channel')) + ->will($this->returnValue('mychannel')); + + $this->assertEquals('mychannel', $slack->getChannel(1)); + } + + public function testGetChannelFromProjectConfig() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['projectIntegration'] = $this + ->getMockBuilder('\Model\ProjectIntegration') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'getParameters', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('integration_slack_webhook_channel')) + ->will($this->returnValue('')); + + $this->container['projectIntegration'] + ->expects($this->once()) + ->method('getParameters') + ->with($this->equalTo(1)) + ->will($this->returnValue(array('slack_webhook_channel' => 'my_project_channel'))); + + $this->assertEquals('my_project_channel', $slack->getChannel(1)); + } + + public function testGetWebhoookUrlFromGlobalConfig() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->at(0)) + ->method('get') + ->with($this->equalTo('integration_slack_webhook')) + ->will($this->returnValue(1)); + + $this->container['config'] + ->expects($this->at(1)) + ->method('get') + ->with($this->equalTo('integration_slack_webhook_url')) + ->will($this->returnValue('url')); + + $this->assertEquals('url', $slack->getWebhookUrl(1)); + } + + public function testGetWebhookUrlFromProjectConfig() + { + $slack = new SlackWebhook($this->container); + + $this->container['config'] = $this + ->getMockBuilder('\Model\Config') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'get', + )) + ->getMock(); + + $this->container['projectIntegration'] = $this + ->getMockBuilder('\Model\ProjectIntegration') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'getParameters', + )) + ->getMock(); + + $this->container['config'] + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('integration_slack_webhook')) + ->will($this->returnValue(0)); + + $this->container['projectIntegration'] + ->expects($this->once()) + ->method('getParameters') + ->with($this->equalTo(1)) + ->will($this->returnValue(array('slack_webhook_url' => 'my_project_url'))); + + $this->assertEquals('my_project_url', $slack->getWebhookUrl(1)); + } + + public function testSendPayloadWithChannel() + { + $this->container['httpClient'] = $this + ->getMockBuilder('\Core\HttpClient') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'postJson', + )) + ->getMock(); + + $slack = $this + ->getMockBuilder('\Integration\SlackWebhook') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'getChannel', + 'getWebhookUrl', + )) + ->getMock(); + + $slack + ->expects($this->at(0)) + ->method('getChannel') + ->with( + $this->equalTo(1) + ) + ->will($this->returnValue('mychannel')); + + $slack + ->expects($this->at(1)) + ->method('getWebhookUrl') + ->with( + $this->equalTo(1) + ) + ->will($this->returnValue('url')); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('postJson') + ->with( + $this->equalTo('url'), + $this->equalTo(array('text' => 'test', 'channel' => 'mychannel')) + ); + + $slack->sendPayload(1, array('text' => 'test')); + } + + public function testSendPayloadWithoutChannel() + { + $this->container['httpClient'] = $this + ->getMockBuilder('\Core\HttpClient') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'postJson', + )) + ->getMock(); + + $slack = $this + ->getMockBuilder('\Integration\SlackWebhook') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'getChannel', + 'getWebhookUrl', + )) + ->getMock(); + + $slack + ->expects($this->at(0)) + ->method('getChannel') + ->with( + $this->equalTo(1) + ) + ->will($this->returnValue('')); + + $slack + ->expects($this->at(1)) + ->method('getWebhookUrl') + ->with( + $this->equalTo(1) + ) + ->will($this->returnValue('url')); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('postJson') + ->with( + $this->equalTo('url'), + $this->equalTo(array('text' => 'test')) + ); + + $slack->sendPayload(1, array('text' => 'test')); + } + + public function testSendMessage() + { + $message = 'test'; + + $payload = array( + 'text' => $message, + 'username' => 'Kanboard', + 'icon_url' => 'http://kanboard.net/assets/img/favicon.png', + ); + + $slack = $this + ->getMockBuilder('\Integration\SlackWebhook') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'sendPayload', + )) + ->getMock(); + + $slack + ->expects($this->once()) + ->method('sendPayload') + ->with( + $this->equalTo(1), + $this->equalTo($payload) + ); + + $slack->sendMessage(1, $message); + } + + public function testNotify() + { + $message = '*[foobar]* FooBar created the task #1 (task #1)'; + + $this->container['session']['user'] = array('username' => 'foobar', 'name' => 'FooBar'); + + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'foobar'))); + $this->assertTrue($this->container['config']->save(array('integration_slack_webhook' => 1))); + + $slack = $this + ->getMockBuilder('\Integration\SlackWebhook') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'sendMessage', + )) + ->getMock(); + + $slack + ->expects($this->once()) + ->method('sendMessage') + ->with( + $this->equalTo(1), + $this->equalTo($message) + ); + + $slack->notify(1, 1, Task::EVENT_CREATE, array('task' => array('id' => 1, 'title' => 'task #1'))); + } +} diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php index 9034679b..66b2cfe3 100644 --- a/tests/units/Model/ActionTest.php +++ b/tests/units/Model/ActionTest.php @@ -27,6 +27,17 @@ class ActionTest extends Base $this->assertEquals('TaskLogMoveAnotherColumn', key($actions)); } + public function testExtendActions() + { + $a = new Action($this->container); + $a->extendActions('MyClass', 'Description'); + + $actions = $a->getAvailableActions(); + $this->assertNotEmpty($actions); + $this->assertContains('Description', $actions); + $this->assertArrayHasKey('MyClass', $actions); + } + public function testGetEvents() { $a = new Action($this->container); diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php index e7520c89..d1ad7248 100644 --- a/tests/units/Model/FileTest.php +++ b/tests/units/Model/FileTest.php @@ -227,7 +227,7 @@ class FileTest extends Base ->expects($this->at(1)) ->method('remove') ->with( - $this->equalTo('/tmp/foo1') + $this->equalTo('thumbnails//tmp/foo2') ) ->will($this->returnValue(true)); @@ -235,6 +235,14 @@ class FileTest extends Base ->expects($this->at(2)) ->method('remove') ->with( + $this->equalTo('/tmp/foo1') + ) + ->will($this->returnValue(true)); + + $this->container['objectStorage'] + ->expects($this->at(3)) + ->method('remove') + ->with( $this->equalTo('/tmp/foo3') ) ->will($this->returnValue(true)); |