diff options
Diffstat (limited to 'tests/units')
33 files changed, 881 insertions, 200 deletions
diff --git a/tests/units/Auth/ApiAccessTokenAuthTest.php b/tests/units/Auth/ApiAccessTokenAuthTest.php new file mode 100644 index 00000000..22852805 --- /dev/null +++ b/tests/units/Auth/ApiAccessTokenAuthTest.php @@ -0,0 +1,71 @@ +<?php + +use Kanboard\Auth\ApiAccessTokenAuth; +use Kanboard\Model\UserModel; + +require_once __DIR__.'/../Base.php'; + +class ApiAccessTokenAuthTest extends Base +{ + public function testGetName() + { + $provider = new ApiAccessTokenAuth($this->container); + $this->assertEquals('API Access Token', $provider->getName()); + } + + public function testAuthenticateWithoutToken() + { + $provider = new ApiAccessTokenAuth($this->container); + + $provider->setUsername('admin'); + $provider->setPassword('admin'); + $this->assertFalse($provider->authenticate()); + $this->assertNull($provider->getUser()); + } + + public function testAuthenticateWithEmptyPassword() + { + $provider = new ApiAccessTokenAuth($this->container); + + $provider->setUsername('admin'); + $provider->setPassword(''); + $this->assertFalse($provider->authenticate()); + } + + public function testAuthenticateWithTokenAndNoScope() + { + $provider = new ApiAccessTokenAuth($this->container); + $userModel = new UserModel($this->container); + + $userModel->update(array( + 'id' => 1, + 'api_access_token' => 'test', + )); + + $provider->setUsername('admin'); + $provider->setPassword('test'); + $this->assertFalse($provider->authenticate()); + } + + public function testAuthenticateWithToken() + { + $this->container['sessionStorage']->scope = 'API'; + + $provider = new ApiAccessTokenAuth($this->container); + $userModel = new UserModel($this->container); + + $userModel->update(array( + 'id' => 1, + 'api_access_token' => 'test', + )); + + $provider->setUsername('admin'); + $provider->setPassword('test'); + $this->assertTrue($provider->authenticate()); + $this->assertInstanceOf('Kanboard\User\DatabaseUserProvider', $provider->getUser()); + + $provider->setUsername('admin'); + $provider->setPassword('something else'); + $this->assertFalse($provider->authenticate()); + } +} diff --git a/tests/units/Base.php b/tests/units/Base.php index 722a1335..1c93e9b8 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -47,8 +47,10 @@ abstract class Base extends PHPUnit_Framework_TestCase $this->container->register(new Kanboard\ServiceProvider\RouteProvider()); $this->container->register(new Kanboard\ServiceProvider\AvatarProvider()); $this->container->register(new Kanboard\ServiceProvider\FilterProvider()); + $this->container->register(new Kanboard\ServiceProvider\FormatterProvider()); $this->container->register(new Kanboard\ServiceProvider\JobProvider()); $this->container->register(new Kanboard\ServiceProvider\QueueProvider()); + $this->container->register(new Kanboard\ServiceProvider\ExternalTaskProvider()); $this->container['dispatcher'] = new TraceableEventDispatcher( new EventDispatcher, diff --git a/tests/units/Core/DateParserTest.php b/tests/units/Core/DateParserTest.php index 1cf98bd3..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); @@ -204,9 +204,6 @@ class DateParserTest extends Base $this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y')); $this->assertEquals(array('date' => '02/06/2016 7:30 pm'), $dateParser->format($values, array('date'), 'm/d/Y g:i a')); - - $values['date'] = '2016-02-06'; - $this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y')); } public function testConvert() 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/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php index 1db0100c..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() 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/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/EventBuilder/CommentEventBuilderTest.php b/tests/units/EventBuilder/CommentEventBuilderTest.php index 2f6a90b5..ff1c630e 100644 --- a/tests/units/EventBuilder/CommentEventBuilderTest.php +++ b/tests/units/EventBuilder/CommentEventBuilderTest.php @@ -33,5 +33,7 @@ class CommentEventBuilderTest extends Base $this->assertInstanceOf('Kanboard\Event\CommentEvent', $event); $this->assertNotEmpty($event['comment']); $this->assertNotEmpty($event['task']); + $this->assertEquals(1, $event->getTaskId()); + $this->assertEquals(1, $event->getProjectId()); } } diff --git a/tests/units/EventBuilder/ProjectFileEventBuilderTest.php b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php index 8f5eb87e..c3595029 100644 --- a/tests/units/EventBuilder/ProjectFileEventBuilderTest.php +++ b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php @@ -29,5 +29,7 @@ class ProjectFileEventBuilderTest extends Base $this->assertInstanceOf('Kanboard\Event\ProjectFileEvent', $event); $this->assertNotEmpty($event['file']); $this->assertNotEmpty($event['project']); + $this->assertNull($event->getTaskId()); + $this->assertEquals(1, $event->getProjectId()); } } diff --git a/tests/units/EventBuilder/SubtaskEventBuilderTest.php b/tests/units/EventBuilder/SubtaskEventBuilderTest.php index fe425cb8..215b1ed2 100644 --- a/tests/units/EventBuilder/SubtaskEventBuilderTest.php +++ b/tests/units/EventBuilder/SubtaskEventBuilderTest.php @@ -58,5 +58,7 @@ class SubtaskEventBuilderTest extends Base $this->assertCount(2, $event['changes']); $this->assertEquals('new title', $event['changes']['title']); $this->assertEquals(1, $event['changes']['user_id']); + $this->assertEquals(1, $event->getTaskId()); + $this->assertEquals(1, $event->getProjectId()); } } diff --git a/tests/units/EventBuilder/TaskEventBuilderTest.php b/tests/units/EventBuilder/TaskEventBuilderTest.php index c89dcd85..446b862b 100644 --- a/tests/units/EventBuilder/TaskEventBuilderTest.php +++ b/tests/units/EventBuilder/TaskEventBuilderTest.php @@ -33,6 +33,8 @@ class TaskEventBuilderTest extends Base $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event); $this->assertNotEmpty($event['task']); $this->assertEquals(1, $event['task_id']); + $this->assertEquals(1, $event->getTaskId()); + $this->assertEquals(1, $event->getProjectId()); $this->assertEquals(array('title' => 'after'), $event['changes']); } diff --git a/tests/units/EventBuilder/TaskFileEventBuilderTest.php b/tests/units/EventBuilder/TaskFileEventBuilderTest.php index c90e18d3..1e88b6fb 100644 --- a/tests/units/EventBuilder/TaskFileEventBuilderTest.php +++ b/tests/units/EventBuilder/TaskFileEventBuilderTest.php @@ -32,5 +32,7 @@ class TaskFileEventBuilderTest extends Base $this->assertInstanceOf('Kanboard\Event\TaskFileEvent', $event); $this->assertNotEmpty($event['file']); $this->assertNotEmpty($event['task']); + $this->assertEquals(1, $event->getTaskId()); + $this->assertEquals(1, $event->getProjectId()); } } diff --git a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php index 18508146..4e38eeb6 100644 --- a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php +++ b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php @@ -33,6 +33,8 @@ class TaskLinkEventBuilderTest extends Base $this->assertInstanceOf('Kanboard\Event\TaskLinkEvent', $event); $this->assertNotEmpty($event['task_link']); $this->assertNotEmpty($event['task']); + $this->assertEquals(1, $event->getTaskId()); + $this->assertEquals(1, $event->getProjectId()); } public function testBuildTitle() diff --git a/tests/units/Filter/TaskStartsWithIdFilterTest.php b/tests/units/Filter/TaskStartsWithIdFilterTest.php new file mode 100644 index 00000000..e911a6a1 --- /dev/null +++ b/tests/units/Filter/TaskStartsWithIdFilterTest.php @@ -0,0 +1,103 @@ +<?php + +use Kanboard\Filter\TaskStartsWithIdFilter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\TaskFinderModel; + +require_once __DIR__.'/../Base.php'; + +class TaskStartsWithIdFilterTest extends Base +{ + public function testManyResults() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(1); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(11, $tasks); + $this->assertEquals('Task #1', $tasks[0]['title']); + $this->assertEquals('Task #19', $tasks[10]['title']); + } + + public function testOneResult() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(3); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(1, $tasks); + $this->assertEquals('Task #3', $tasks[0]['title']); + } + + public function testEmptyResult() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(30); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(0, $tasks); + } + + public function testWithTwoDigits() + { + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $query = $taskFinderModel->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + for ($i = 1; $i <= 20; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'Task #'.$i))); + } + + $filter = new TaskStartsWithIdFilter(); + $filter->withQuery($query); + $filter->withValue(11); + $filter->apply(); + + $tasks = $query->findAll(); + $this->assertCount(1, $tasks); + $this->assertEquals('Task #11', $tasks[0]['title']); + } +} diff --git a/tests/units/Formatter/TaskSuggestMenuFormatterTest.php b/tests/units/Formatter/TaskSuggestMenuFormatterTest.php new file mode 100644 index 00000000..d247d670 --- /dev/null +++ b/tests/units/Formatter/TaskSuggestMenuFormatterTest.php @@ -0,0 +1,39 @@ +<?php + +use Kanboard\Formatter\TaskSuggestMenuFormatter; +use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskCreationModel; + +require_once __DIR__.'/../Base.php'; + +class TaskSuggestMenuFormatterTest extends Base +{ + public function testFormat() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskSuggestMenuFormatter = new TaskSuggestMenuFormatter($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'My Project'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1))); + + $result = $taskSuggestMenuFormatter + ->withQuery($this->container['taskFinderModel']->getExtendedQuery()) + ->format() + ; + + $expected = array( + array( + 'value' => '1', + 'html' => '#1 Task 1 <small>My Project</small>', + ), + array( + 'value' => '2', + 'html' => '#2 Task 2 <small>My Project</small>', + ), + ); + + $this->assertSame($expected, $result); + } +} diff --git a/tests/units/Formatter/UserMentionFormatterTest.php b/tests/units/Formatter/UserMentionFormatterTest.php new file mode 100644 index 00000000..6338e80f --- /dev/null +++ b/tests/units/Formatter/UserMentionFormatterTest.php @@ -0,0 +1,42 @@ +<?php + +use Kanboard\Formatter\UserMentionFormatter; + +require_once __DIR__.'/../Base.php'; + +class UserMentionFormatterTest extends Base +{ + public function testFormat() + { + $userMentionFormatter = new UserMentionFormatter($this->container); + $users = array( + array( + 'id' => 1, + 'username' => 'someone', + 'name' => 'Someone', + 'email' => 'test@localhost', + 'avatar_path' => 'avatar_image', + ), + array( + 'id' => 2, + 'username' => 'somebody', + 'name' => '', + 'email' => '', + 'avatar_path' => '', + ) + ); + + $expected = array( + array( + 'value' => 'someone', + 'html' => '<div class="avatar avatar-20 avatar-inline"><img src="?controller=AvatarFileController&action=image&user_id=1&size=20" alt="Someone" title="Someone"></div> someone <small>Someone</small>', + ), + array( + 'value' => 'somebody', + 'html' => '<div class="avatar avatar-20 avatar-inline"><div class="avatar-letter" style="background-color: rgb(191, 210, 121)" title="somebody">S</div></div> somebody', + ), + ); + + $this->assertSame($expected, $userMentionFormatter->withUsers($users)->format()); + } +} diff --git a/tests/units/FunctionTest.php b/tests/units/FunctionTest.php index 1c5f971d..0709f1fb 100644 --- a/tests/units/FunctionTest.php +++ b/tests/units/FunctionTest.php @@ -59,6 +59,38 @@ class FunctionTest extends Base $this->assertSame($expected, array_column_index($input, 'k1')); } + public function testArrayColumnIndexUnique() + { + $input = array( + array( + 'k1' => 11, + 'k2' => 22, + ), + array( + 'k1' => 11, + 'k2' => 55, + ), + array( + 'k1' => 33, + 'k2' => 44, + ), + array() + ); + + $expected = array( + 11 => array( + 'k1' => 11, + 'k2' => 22, + ), + 33 => array( + 'k1' => 33, + 'k2' => 44, + ) + ); + + $this->assertSame($expected, array_column_index_unique($input, 'k1')); + } + public function testArrayMergeRelation() { $relations = array( diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperTest.php index 215b024b..7db43460 100644 --- a/tests/units/Helper/FileHelperText.php +++ b/tests/units/Helper/FileHelperTest.php @@ -30,7 +30,14 @@ class FileHelperTest extends Base $helper = new FileHelper($this->container); $this->assertEquals('text', $helper->getPreviewType('test.txt')); $this->assertEquals('markdown', $helper->getPreviewType('test.markdown')); - $this->assertEquals('md', $helper->getPreviewType('test.md')); + $this->assertEquals('markdown', $helper->getPreviewType('test.md')); $this->assertEquals(null, $helper->getPreviewType('test.doc')); } + + public function testGetBrowserViewType() + { + $fileHelper = new FileHelper($this->container); + $this->assertSame('application/pdf', $fileHelper->getBrowserViewType('SomeFile.PDF')); + $this->assertSame(null, $fileHelper->getBrowserViewType('SomeFile.doc')); + } } diff --git a/tests/units/Helper/MailHelperTest.php b/tests/units/Helper/MailHelperTest.php index e871a57d..c6f13042 100644 --- a/tests/units/Helper/MailHelperTest.php +++ b/tests/units/Helper/MailHelperTest.php @@ -20,6 +20,7 @@ class MailHelperTest extends Base $this->assertEquals('Test', $helper->filterSubject('Test')); $this->assertEquals('Test', $helper->filterSubject('RE: Test')); $this->assertEquals('Test', $helper->filterSubject('FW: Test')); + $this->assertEquals('Test', $helper->filterSubject('Fwd: Test')); } public function testGetSenderAddress() diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php index 2e2da6ee..8609983e 100644 --- a/tests/units/Helper/TaskHelperTest.php +++ b/tests/units/Helper/TaskHelperTest.php @@ -9,9 +9,9 @@ class TaskHelperTest extends Base public function testSelectPriority() { $helper = new TaskHelper($this->container); - $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array())); - $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array())); - $this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); + $this->assertNotEmpty($helper->renderPriorityField(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array())); + $this->assertNotEmpty($helper->renderPriorityField(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array())); + $this->assertEmpty($helper->renderPriorityField(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); } public function testFormatPriority() diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index c9447abb..35ed5a1e 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -5,12 +5,13 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\TextHelper; use Kanboard\Model\ProjectModel; use Kanboard\Model\TaskCreationModel; +use Kanboard\Model\UserModel; class TextHelperTest extends Base { public function testMarkdownTaskLink() { - $helper = new TextHelper($this->container); + $textHelper = new TextHelper($this->container); $projectModel = new ProjectModel($this->container); $taskCreationModel = new TaskCreationModel($this->container); @@ -19,26 +20,26 @@ class TextHelperTest extends Base $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1))); $project = $projectModel->getById(1); - $this->assertEquals('<p>Test</p>', $helper->markdown('Test')); + $this->assertEquals('<p>Test</p>', $textHelper->markdown('Test')); $this->assertEquals( '<p>Task <a href="?controller=TaskViewController&action=show&task_id=123">#123</a></p>', - $helper->markdown('Task #123') + $textHelper->markdown('Task #123') ); $this->assertEquals( '<p>Task #123</p>', - $helper->markdown('Task #123', true) + $textHelper->markdown('Task #123', true) ); $this->assertEquals( - '<p>Task <a href="?controller=TaskViewController&action=readonly&token='.$project['token'].'&task_id=1">#1</a></p>', - $helper->markdown('Task #1', true) + '<p>Task <a href="http://localhost/?controller=TaskViewController&action=readonly&token='.$project['token'].'&task_id=1">#1</a></p>', + $textHelper->markdown('Task #1', true) ); $this->assertEquals( '<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>', - $helper->markdown( + $textHelper->markdown( 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454' ) ); @@ -46,39 +47,83 @@ class TextHelperTest extends Base public function testMarkdownUserLink() { - $h = new TextHelper($this->container); - $this->assertEquals('<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound')); - $this->assertEquals('<p>Text @admin @notfound</p>', $h->markdown('Text @admin @notfound', true)); + $textHelper = new TextHelper($this->container); + $userModel = new UserModel($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'firstname.lastname', 'name' => 'Firstname Lastname'))); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a> @notfound</p>', + $textHelper->markdown('Text @admin @notfound') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>,</p>', + $textHelper->markdown('Text @admin,') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>!</p>', + $textHelper->markdown('Text @admin!') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>? </p>', + $textHelper->markdown('Text @admin? ') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>.</p>', + $textHelper->markdown('Text @admin.') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>: test</p>', + $textHelper->markdown('Text @admin: test') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=1" class="user-mention-link" title="admin">@admin</a>: test</p>', + $textHelper->markdown('Text @admin: test') + ); + + $this->assertEquals( + '<p>Text <a href="?controller=UserViewController&action=profile&user_id=2" class="user-mention-link" title="Firstname Lastname">@firstname.lastname</a>. test</p>', + $textHelper->markdown('Text @firstname.lastname. test') + ); + + $this->assertEquals('<p>Text @admin @notfound</p>', $textHelper->markdown('Text @admin @notfound', true)); } public function testMarkdownAttribute() { - $helper = new TextHelper($this->container); - $this->assertEquals('<p>Ça marche</p>', $helper->markdownAttribute('Ça marche')); - $this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $helper->markdownAttribute('Test with "double quotes"')); - $this->assertEquals('<p>Test with 'single quotes'</p>', $helper->markdownAttribute("Test with 'single quotes'")); + $textHelper = new TextHelper($this->container); + $this->assertEquals('<p>Ça marche</p>', $textHelper->markdownAttribute('Ça marche')); + $this->assertEquals('<p>Test with &quot;double quotes&quot;</p>', $textHelper->markdownAttribute('Test with "double quotes"')); + $this->assertEquals('<p>Test with 'single quotes'</p>', $textHelper->markdownAttribute("Test with 'single quotes'")); } public function testFormatBytes() { - $h = new TextHelper($this->container); + $textHelper = new TextHelper($this->container); - $this->assertEquals('1k', $h->bytes(1024)); - $this->assertEquals('33.71k', $h->bytes(34520)); + $this->assertEquals('0', $textHelper->bytes(0)); + $this->assertEquals('1k', $textHelper->bytes(1024)); + $this->assertEquals('33.71k', $textHelper->bytes(34520)); } public function testContains() { - $h = new TextHelper($this->container); + $textHelper = new TextHelper($this->container); - $this->assertTrue($h->contains('abc', 'b')); - $this->assertFalse($h->contains('abc', 'd')); + $this->assertTrue($textHelper->contains('abc', 'b')); + $this->assertFalse($textHelper->contains('abc', 'd')); } public function testInList() { - $h = new TextHelper($this->container); - $this->assertEquals('?', $h->in('a', array('b' => 'c'))); - $this->assertEquals('c', $h->in('b', array('b' => 'c'))); + $textHelper = new TextHelper($this->container); + $this->assertEquals('?', $textHelper->in('a', array('b' => 'c'))); + $this->assertEquals('c', $textHelper->in('b', array('b' => 'c'))); } } diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php index 8571af8e..b830b2b8 100644 --- a/tests/units/Job/CommentEventJobTest.php +++ b/tests/units/Job/CommentEventJobTest.php @@ -49,4 +49,46 @@ class CommentEventJobTest extends Base $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called); $this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called); } + + public function testThatUserMentionJobIsCalled() + { + $comment = 'some comment'; + + $this->container['queueManager'] = $this + ->getMockBuilder('\Kanboard\Core\Queue\QueueManager') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'push', + )) + ->getMock(); + + $this->container['userMentionJob'] = $this + ->getMockBuilder('\Kanboard\Job\UserMentionJob') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'withParams', + )) + ->getMock(); + + $this->container['queueManager'] + ->expects($this->any()) + ->method('push'); + + $this->container['userMentionJob'] + ->expects($this->once()) + ->method('withParams') + ->with($comment, CommentModel::EVENT_USER_MENTION, $this->anything()) + ->will($this->returnValue($this->container['userMentionJob'])); + + $commentModel = new CommentModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $commentEventJob = new CommentEventJob($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => $comment, 'user_id' => 1))); + + $commentEventJob->execute(1, CommentModel::EVENT_CREATE); + } } diff --git a/tests/units/Job/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php index c399faad..bfd7bc55 100644 --- a/tests/units/Job/TaskEventJobTest.php +++ b/tests/units/Job/TaskEventJobTest.php @@ -186,4 +186,44 @@ class TaskEventJobTest extends Base $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.closure', $called); } + + public function testThatUserMentionJobIsCalled() + { + $description = 'something'; + + $this->container['queueManager'] = $this + ->getMockBuilder('\Kanboard\Core\Queue\QueueManager') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'push', + )) + ->getMock(); + + $this->container['userMentionJob'] = $this + ->getMockBuilder('\Kanboard\Job\UserMentionJob') + ->setConstructorArgs(array($this->container)) + ->setMethods(array( + 'withParams', + )) + ->getMock(); + + $this->container['queueManager'] + ->expects($this->any()) + ->method('push'); + + $this->container['userMentionJob'] + ->expects($this->once()) + ->method('withParams') + ->with($description, TaskModel::EVENT_USER_MENTION, $this->anything()) + ->will($this->returnValue($this->container['userMentionJob'])); + + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskEventJob = new TaskEventJob($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'description' => $description, 'project_id' => 1))); + + $taskEventJob->execute(1, array(TaskModel::EVENT_CREATE)); + } } diff --git a/tests/units/Model/UserMentionTest.php b/tests/units/Job/UserMentionJobTest.php index b41c92cd..04ffa0d3 100644 --- a/tests/units/Model/UserMentionTest.php +++ b/tests/units/Job/UserMentionJobTest.php @@ -1,45 +1,44 @@ <?php -require_once __DIR__.'/../Base.php'; - use Kanboard\Core\Security\Role; -use Kanboard\Event\GenericEvent; -use Kanboard\Model\UserModel; -use Kanboard\Model\TaskModel; -use Kanboard\Model\TaskCreationModel; +use Kanboard\Event\TaskEvent; +use Kanboard\Job\UserMentionJob; use Kanboard\Model\ProjectModel; use Kanboard\Model\ProjectUserRoleModel; -use Kanboard\Model\UserMentionModel; +use Kanboard\Model\TaskModel; +use Kanboard\Model\UserModel; + +require_once __DIR__.'/../Base.php'; -class UserMentionTest extends Base +class UserMentionJobTest extends Base { public function testGetMentionedUsersWithNoMentions() { $userModel = new UserModel($this->container); - $userMentionModel = new UserMentionModel($this->container); + $userMentionJob = new UserMentionJob($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); - $this->assertEmpty($userMentionModel->getMentionedUsers('test')); + $this->assertEmpty($userMentionJob->getMentionedUsers('test')); } public function testGetMentionedUsersWithNotficationDisabled() { $userModel = new UserModel($this->container); - $userMentionModel = new UserMentionModel($this->container); + $userMentionJob = new UserMentionJob($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); - $this->assertEmpty($userMentionModel->getMentionedUsers('test @user1')); + $this->assertEmpty($userMentionJob->getMentionedUsers('test @user1')); } public function testGetMentionedUsersWithNotficationEnabled() { $userModel = new UserModel($this->container); - $userMentionModel = new UserMentionModel($this->container); + $userMentionJob = new UserMentionJob($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); - $users = $userMentionModel->getMentionedUsers('test @user2'); + $users = $userMentionJob->getMentionedUsers('test @user2'); $this->assertCount(1, $users); $this->assertEquals('user2', $users[0]['username']); $this->assertEquals('Foobar', $users[0]['name']); @@ -47,48 +46,47 @@ class UserMentionTest extends Base $this->assertEquals('', $users[0]['language']); } - public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn() + public function testGetMentionedUsersWithNotficationEnabledAndPunctuationMarks() { - $this->container['sessionStorage']->user = array('id' => 3); $userModel = new UserModel($this->container); - $userMentionModel = new UserMentionModel($this->container); + $userMentionJob = new UserMentionJob($this->container); $this->assertNotFalse($userModel->create(array('username' => 'user1'))); $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); + $this->assertNotFalse($userModel->create(array('username' => 'user3.with.dot', 'notifications_enabled' => 1))); + + $users = $userMentionJob->getMentionedUsers('test @user2, test, @user3.with.dot.'); + $this->assertCount(2, $users); + $this->assertEquals('user2', $users[0]['username']); + $this->assertEquals('Foobar', $users[0]['name']); + $this->assertEquals('', $users[0]['email']); + $this->assertEquals('', $users[0]['language']); - $this->assertEmpty($userMentionModel->getMentionedUsers('test @user2')); + $this->assertEquals('user3.with.dot', $users[1]['username']); + $this->assertEquals('', $users[1]['name']); + $this->assertEquals('', $users[1]['email']); + $this->assertEquals('', $users[1]['language']); } - public function testFireEventsWithMultipleMentions() + public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn() { - $projectUserRoleModel = new ProjectUserRoleModel($this->container); - $projectModel = new ProjectModel($this->container); + $this->container['sessionStorage']->user = array('id' => 3); $userModel = new UserModel($this->container); - $userMentionModel = new UserMentionModel($this->container); - $event = new GenericEvent(array('project_id' => 1)); - - $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); - $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1))); - - $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); - $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); - - $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention')); + $userMentionJob = new UserMentionJob($this->container); - $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event); + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + $this->assertEmpty($userMentionJob->getMentionedUsers('test @user2')); } - public function testFireEventsWithNoProjectId() + public function testFireEventsWithMultipleMentions() { $projectUserRoleModel = new ProjectUserRoleModel($this->container); $projectModel = new ProjectModel($this->container); - $taskCreationModel = new TaskCreationModel($this->container); $userModel = new UserModel($this->container); - $userMentionModel = new UserMentionModel($this->container); - $event = new GenericEvent(array('task_id' => 1)); + $userMentionJob = new UserMentionJob($this->container); + $event = new TaskEvent(array('task' => array('project_id' => 1))); $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1))); @@ -96,14 +94,12 @@ class UserMentionTest extends Base $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); - $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1'))); - $this->container['dispatcher']->addListener(TaskModel::EVENT_USER_MENTION, array($this, 'onUserMention')); - $userMentionModel->fireEvents('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event); + $userMentionJob->execute('test @user1 @user2', TaskModel::EVENT_USER_MENTION, $event->getAll()); $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + $this->assertArrayHasKey(TaskModel::EVENT_USER_MENTION.'.UserMentionJobTest::onUserMention', $called); } public function onUserMention($event) diff --git a/tests/units/Locale/LocaleTest.php b/tests/units/Locale/LocaleTest.php index 976dfc58..c10b1bc9 100644 --- a/tests/units/Locale/LocaleTest.php +++ b/tests/units/Locale/LocaleTest.php @@ -10,13 +10,7 @@ class LocaleTest extends Base $locale = require($file . '/translations.php'); foreach ($locale as $k => $v) { - if (strpos($k, '%B %e, %Y') !== false) { - continue; - } - - if (strpos($k, '%b %e, %Y') !== false) { - continue; - } + $this->assertNotEmpty($v, 'Empty value for the key "'.$k.'" in translation '.basename($file)); foreach (array('%s', '%d') as $placeholder) { $this->assertEquals( diff --git a/tests/units/Model/CommentModelTest.php b/tests/units/Model/CommentModelTest.php index 4178a839..c75401cc 100644 --- a/tests/units/Model/CommentModelTest.php +++ b/tests/units/Model/CommentModelTest.php @@ -26,6 +26,7 @@ class CommentModelTest extends Base $this->assertEquals(1, $comment['user_id']); $this->assertEquals('admin', $comment['username']); $this->assertEquals(time(), $comment['date_creation'], '', 3); + $this->assertEquals(time(), $comment['date_modification'], '', 3); $comment = $commentModel->getById(2); $this->assertNotEmpty($comment); @@ -34,6 +35,7 @@ class CommentModelTest extends Base $this->assertEquals(0, $comment['user_id']); $this->assertEquals('', $comment['username']); $this->assertEquals(time(), $comment['date_creation'], '', 3); + $this->assertEquals(time(), $comment['date_modification'], '', 3); } public function testGetAll() @@ -73,6 +75,7 @@ class CommentModelTest extends Base $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals('bla', $comment['comment']); + $this->assertEquals(time(), $comment['date_modification'], '', 3); } public function testRemove() diff --git a/tests/units/Model/ConfigModelTest.php b/tests/units/Model/ConfigModelTest.php new file mode 100644 index 00000000..bbc792e3 --- /dev/null +++ b/tests/units/Model/ConfigModelTest.php @@ -0,0 +1,125 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\ConfigModel; + +class ConfigModelTest extends Base +{ + public function testRegenerateToken() + { + $configModel = new ConfigModel($this->container); + $token = $configModel->getOption('api_token'); + $this->assertTrue($configModel->regenerateToken('api_token')); + $this->assertNotEquals($token, $configModel->getOption('api_token')); + } + + public function testCRUDOperations() + { + $configModel = new ConfigModel($this->container); + + $this->assertTrue($configModel->save(array('key1' => 'value1'))); + $this->assertTrue($configModel->save(array('key1' => 'value2'))); + $this->assertTrue($configModel->save(array('key2' => 'value2'))); + + $this->assertEquals('value2', $configModel->getOption('key1')); + $this->assertEquals('value2', $configModel->getOption('key2')); + $this->assertEquals('', $configModel->getOption('key3')); + $this->assertEquals('default', $configModel->getOption('key3', 'default')); + + $this->assertTrue($configModel->exists('key1')); + $this->assertFalse($configModel->exists('key3')); + + $this->assertTrue($configModel->save(array('key1' => 'value1'))); + + $this->assertArrayHasKey('key1', $configModel->getAll()); + $this->assertArrayHasKey('key2', $configModel->getAll()); + + $this->assertContains('value1', $configModel->getAll()); + $this->assertContains('value2', $configModel->getAll()); + } + + public function testSaveApplicationUrl() + { + $configModel = new ConfigModel($this->container); + + $this->assertTrue($configModel->save(array('application_url' => 'http://localhost/'))); + $this->assertEquals('http://localhost/', $configModel->getOption('application_url')); + + $this->assertTrue($configModel->save(array('application_url' => 'http://localhost'))); + $this->assertEquals('http://localhost/', $configModel->getOption('application_url')); + + $this->assertTrue($configModel->save(array('application_url' => ''))); + $this->assertEquals('', $configModel->getOption('application_url')); + } + + public function testDefaultValues() + { + $configModel = new ConfigModel($this->container); + + $this->assertEquals(172800, $configModel->getOption('board_highlight_period')); + $this->assertEquals(60, $configModel->getOption('board_public_refresh_interval')); + $this->assertEquals(10, $configModel->getOption('board_private_refresh_interval')); + $this->assertEmpty($configModel->getOption('board_columns')); + + $this->assertEquals('yellow', $configModel->getOption('default_color')); + $this->assertEquals('en_US', $configModel->getOption('application_language')); + $this->assertEquals('UTC', $configModel->getOption('application_timezone')); + $this->assertEquals('m/d/Y', $configModel->getOption('application_date_format')); + $this->assertEmpty($configModel->getOption('application_url')); + $this->assertEmpty($configModel->getOption('application_stylesheet')); + $this->assertEquals('USD', $configModel->getOption('application_currency')); + + $this->assertEquals(0, $configModel->getOption('calendar_user_subtasks_time_tracking')); + $this->assertEquals('date_started', $configModel->getOption('calendar_user_tasks')); + $this->assertEquals('date_started', $configModel->getOption('calendar_user_tasks')); + + $this->assertEquals(0, $configModel->getOption('integration_gravatar')); + $this->assertEquals(1, $configModel->getOption('cfd_include_closed_tasks')); + $this->assertEquals(1, $configModel->getOption('password_reset')); + + $this->assertEquals(1, $configModel->getOption('subtask_time_tracking')); + $this->assertEquals(0, $configModel->getOption('subtask_restriction')); + $this->assertEmpty($configModel->getOption('project_categories')); + + $this->assertEmpty($configModel->getOption('webhook_url_task_modification')); + $this->assertEmpty($configModel->getOption('webhook_url_task_creation')); + $this->assertNotEmpty($configModel->getOption('webhook_token')); + $this->assertEmpty($configModel->getOption('webhook_url')); + + $this->assertNotEmpty($configModel->getOption('api_token')); + } + + public function testGetOption() + { + $configModel = new ConfigModel($this->container); + + $this->assertEquals('', $configModel->getOption('board_columns')); + $this->assertEquals('test', $configModel->getOption('board_columns', 'test')); + $this->assertEquals(0, $configModel->getOption('board_columns', 0)); + } + + public function testGetWithCaching() + { + $configModel = new ConfigModel($this->container); + + $this->assertEquals('UTC', $configModel->get('application_timezone')); + $this->assertTrue($configModel->save(array('application_timezone' => 'Europe/Paris'))); + + $this->assertEquals('UTC', $configModel->get('application_timezone')); // cached value + $this->assertEquals('Europe/Paris', $configModel->getOption('application_timezone')); + + $this->assertEquals('', $configModel->get('board_columns')); + $this->assertEquals('test', $configModel->get('board_columns', 'test')); + $this->assertEquals('test', $configModel->get('empty_value', 'test')); + } + + public function testValueLength() + { + $configModel = new ConfigModel($this->container); + $string = str_repeat('a', 65535); + + $this->assertTrue($configModel->save(array('application_stylesheet' => $string))); + $this->assertSame($string, $configModel->getOption('application_stylesheet')); + } +} diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php deleted file mode 100644 index 3345ee3e..00000000 --- a/tests/units/Model/ConfigTest.php +++ /dev/null @@ -1,116 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\ConfigModel; - -class ConfigTest extends Base -{ - public function testRegenerateToken() - { - $configModel = new ConfigModel($this->container); - $token = $configModel->getOption('api_token'); - $this->assertTrue($configModel->regenerateToken('api_token')); - $this->assertNotEquals($token, $configModel->getOption('api_token')); - } - - public function testCRUDOperations() - { - $c = new ConfigModel($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 ConfigModel($this->container); - - $this->assertTrue($c->save(array('application_url' => 'http://localhost/'))); - $this->assertEquals('http://localhost/', $c->getOption('application_url')); - - $this->assertTrue($c->save(array('application_url' => 'http://localhost'))); - $this->assertEquals('http://localhost/', $c->getOption('application_url')); - - $this->assertTrue($c->save(array('application_url' => ''))); - $this->assertEquals('', $c->getOption('application_url')); - } - - public function testDefaultValues() - { - $c = new ConfigModel($this->container); - - $this->assertEquals(172800, $c->getOption('board_highlight_period')); - $this->assertEquals(60, $c->getOption('board_public_refresh_interval')); - $this->assertEquals(10, $c->getOption('board_private_refresh_interval')); - $this->assertEmpty($c->getOption('board_columns')); - - $this->assertEquals('yellow', $c->getOption('default_color')); - $this->assertEquals('en_US', $c->getOption('application_language')); - $this->assertEquals('UTC', $c->getOption('application_timezone')); - $this->assertEquals('m/d/Y', $c->getOption('application_date_format')); - $this->assertEmpty($c->getOption('application_url')); - $this->assertEmpty($c->getOption('application_stylesheet')); - $this->assertEquals('USD', $c->getOption('application_currency')); - - $this->assertEquals(0, $c->getOption('calendar_user_subtasks_time_tracking')); - $this->assertEquals('date_started', $c->getOption('calendar_user_tasks')); - $this->assertEquals('date_started', $c->getOption('calendar_user_tasks')); - - $this->assertEquals(0, $c->getOption('integration_gravatar')); - $this->assertEquals(1, $c->getOption('cfd_include_closed_tasks')); - $this->assertEquals(1, $c->getOption('password_reset')); - - $this->assertEquals(1, $c->getOption('subtask_time_tracking')); - $this->assertEquals(0, $c->getOption('subtask_restriction')); - $this->assertEmpty($c->getOption('project_categories')); - - $this->assertEmpty($c->getOption('webhook_url_task_modification')); - $this->assertEmpty($c->getOption('webhook_url_task_creation')); - $this->assertNotEmpty($c->getOption('webhook_token')); - $this->assertEmpty($c->getOption('webhook_url')); - - $this->assertNotEmpty($c->getOption('api_token')); - } - - public function testGetOption() - { - $c = new ConfigModel($this->container); - - $this->assertEquals('', $c->getOption('board_columns')); - $this->assertEquals('test', $c->getOption('board_columns', 'test')); - $this->assertEquals(0, $c->getOption('board_columns', 0)); - } - - public function testGetWithCaching() - { - $c = new ConfigModel($this->container); - - $this->assertEquals('UTC', $c->get('application_timezone')); - $this->assertTrue($c->save(array('application_timezone' => 'Europe/Paris'))); - - $this->assertEquals('UTC', $c->get('application_timezone')); // cached value - $this->assertEquals('Europe/Paris', $c->getOption('application_timezone')); - - $this->assertEquals('', $c->get('board_columns')); - $this->assertEquals('test', $c->get('board_columns', 'test')); - $this->assertEquals('test', $c->get('empty_value', 'test')); - } -} diff --git a/tests/units/Model/InviteModelTest.php b/tests/units/Model/InviteModelTest.php new file mode 100644 index 00000000..3a0519fb --- /dev/null +++ b/tests/units/Model/InviteModelTest.php @@ -0,0 +1,27 @@ +<?php + +use Kanboard\Model\InviteModel; + +require_once __DIR__.'/../Base.php'; + +class InviteModelTest extends Base +{ + public function testCreation() + { + $inviteModel = new InviteModel($this->container); + + $this->container['emailClient'] + ->expects($this->exactly(2)) + ->method('send'); + + $inviteModel->createInvites(array('user@domain1.tld', '', 'user@domain2.tld'), 1); + } + + public function testRemove() + { + $inviteModel = new InviteModel($this->container); + $inviteModel->createInvites(array('user@domain1.tld', 'user@domain2.tld'), 0); + $this->assertTrue($inviteModel->remove('user@domain1.tld')); + $this->assertFalse($inviteModel->remove('foobar')); + } +} diff --git a/tests/units/Model/ProjectModelTest.php b/tests/units/Model/ProjectModelTest.php index cd86b654..1f65cad7 100644 --- a/tests/units/Model/ProjectModelTest.php +++ b/tests/units/Model/ProjectModelTest.php @@ -298,6 +298,39 @@ class ProjectModelTest extends Base $this->assertFalse($project); } + public function testEmail() + { + $projectModel = new ProjectModel($this->container); + + // Creation + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'email' => 'test1@localhost'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2'))); + + $project = $projectModel->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('test1@localhost', $project['email']); + + $project = $projectModel->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('', $project['email']); + + // Update + $this->assertTrue($projectModel->update(array('id' => '1', 'email' => 'test1@here'))); + + $project = $projectModel->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('test1@here', $project['email']); + + $project = $projectModel->getByEmail('test1@here'); + $this->assertEquals(1, $project['id']); + + $project = $projectModel->getByEmail('test1@localhost'); + $this->assertEmpty($project); + + $project = $projectModel->getByEmail(''); + $this->assertFalse($project); + } + public function testThatProjectCreatorAreAlsoOwner() { $projectModel = new ProjectModel($this->container); diff --git a/tests/units/Model/ProjectPermissionModelTest.php b/tests/units/Model/ProjectPermissionModelTest.php index 3313cf2d..7f604374 100644 --- a/tests/units/Model/ProjectPermissionModelTest.php +++ b/tests/units/Model/ProjectPermissionModelTest.php @@ -26,7 +26,7 @@ class ProjectPermissionModelTest extends Base $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); - $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'email' => 'test@here', 'avatar_path' => 'test'))); $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); $this->assertEquals(1, $groupModel->create('Group A')); @@ -35,7 +35,24 @@ class ProjectPermissionModelTest extends Base $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER)); $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER)); - $this->assertEquals(array('user1', 'user2'), $projectPermissionModel->findUsernames(1, 'us')); + $expected = array( + 'user1' => array( + 'username' => 'user1', + 'name' => null, + 'email' => null, + 'avatar_path' => null, + 'id' => '2', + ), + 'user2' => array( + 'username' => 'user2', + 'name' => 'User 2', + 'email' => 'test@here', + 'avatar_path' => 'test', + 'id' => '3', + ) + ); + + $this->assertEquals($expected, $projectPermissionModel->findUsernames(1, 'us')); $this->assertEmpty($projectPermissionModel->findUsernames(1, 'a')); $this->assertEmpty($projectPermissionModel->findUsernames(2, 'user')); } diff --git a/tests/units/ServiceProvider/ClassProviderTest.php b/tests/units/ServiceProvider/ClassProviderTest.php new file mode 100644 index 00000000..f6528918 --- /dev/null +++ b/tests/units/ServiceProvider/ClassProviderTest.php @@ -0,0 +1,21 @@ +<?php + +use Kanboard\ServiceProvider\ClassProvider; +use Pimple\Container; + +require_once __DIR__.'/../Base.php'; + +class ModelProviderTest extends Base +{ + public function testServiceInstance() + { + $container = new Container(); + $serviceProvider = new ClassProvider($container); + $serviceProvider->register($container); + + $instance1 = $container['userModel']; + $instance2 = $container['userModel']; + + $this->assertSame($instance1, $instance2); + } +} diff --git a/tests/units/ServiceProvider/FormatterProviderTest.php b/tests/units/ServiceProvider/FormatterProviderTest.php new file mode 100644 index 00000000..7984a12b --- /dev/null +++ b/tests/units/ServiceProvider/FormatterProviderTest.php @@ -0,0 +1,21 @@ +<?php + +use Kanboard\ServiceProvider\FormatterProvider; +use Pimple\Container; + +require_once __DIR__.'/../Base.php'; + +class FormatterProviderTest extends Base +{ + public function testServiceInstance() + { + $container = new Container(); + $serviceProvider = new FormatterProvider($container); + $serviceProvider->register($container); + + $instance1 = $container['userAutoCompleteFormatter']; + $instance2 = $container['userAutoCompleteFormatter']; + + $this->assertNotSame($instance1, $instance2); + } +} |