diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Base.php | 1 | ||||
-rw-r--r-- | tests/units/Core/HelperTest.php | 17 | ||||
-rw-r--r-- | tests/units/Core/Http/RouterTest.php | 22 | ||||
-rw-r--r-- | tests/units/Core/TemplateTest.php | 6 | ||||
-rw-r--r-- | tests/units/Helper/AppHelperTest.php | 8 | ||||
-rw-r--r-- | tests/units/Helper/AssetHelperTest.php | 4 | ||||
-rw-r--r-- | tests/units/Helper/DatetimeHelperTest.php | 16 | ||||
-rw-r--r-- | tests/units/Helper/FileHelperText.php | 8 | ||||
-rw-r--r-- | tests/units/Helper/HookHelperTest.php | 10 | ||||
-rw-r--r-- | tests/units/Helper/TaskHelperTest.php | 6 | ||||
-rw-r--r-- | tests/units/Helper/TextHelperTest.php | 12 | ||||
-rw-r--r-- | tests/units/Helper/UrlHelperTest.php | 24 | ||||
-rw-r--r-- | tests/units/Helper/UserHelperTest.php | 26 |
13 files changed, 91 insertions, 69 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index eb9fc68b..6af14ba5 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -33,6 +33,7 @@ abstract class Base extends PHPUnit_Framework_TestCase } $this->container = new Pimple\Container; + $this->container->register(new Kanboard\ServiceProvider\HelperProvider); $this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider); $this->container->register(new Kanboard\ServiceProvider\DatabaseProvider); $this->container->register(new Kanboard\ServiceProvider\ClassProvider); diff --git a/tests/units/Core/HelperTest.php b/tests/units/Core/HelperTest.php new file mode 100644 index 00000000..b766dd96 --- /dev/null +++ b/tests/units/Core/HelperTest.php @@ -0,0 +1,17 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Core\Helper; + +class HelperTest extends Base +{ + public function testRegister() + { + $helper = new Helper($this->container); + $helper->register('foobar', '\Stdclass'); + + $this->assertInstanceOf('Stdclass', $helper->foobar); + $this->assertInstanceOf('Stdclass', $helper->getHelper('foobar')); + } +} diff --git a/tests/units/Core/Http/RouterTest.php b/tests/units/Core/Http/RouterTest.php index 0b200ab5..75a3ba4f 100644 --- a/tests/units/Core/Http/RouterTest.php +++ b/tests/units/Core/Http/RouterTest.php @@ -40,21 +40,25 @@ namespace { $this->assertEquals('userImport', $dispatcher->sanitize('userImport', 'default')); } - public function testGetPath() + public function testGetPathWithFolder() { - $dispatcher = new Router($this->container); - - $this->container['helper'] = new Helper($this->container); + $router = new Router($this->container); $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/c', 'REQUEST_METHOD' => 'GET')); - $this->assertEquals('a/b/c', $dispatcher->getPath()); + $this->assertEquals('a/b/c', $router->getPath()); + } - $this->container['helper'] = new Helper($this->container); + public function testGetPathWithQueryString() + { + $router = new Router($this->container); $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); - $this->assertEquals('a/b/something', $dispatcher->getPath()); + $this->assertEquals('a/b/something', $router->getPath()); + } - $this->container['helper'] = new Helper($this->container); + public function testGetPathWithSubFolderAndQueryString() + { + $router = new Router($this->container); $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/a/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); - $this->assertEquals('b/something', $dispatcher->getPath()); + $this->assertEquals('b/something', $router->getPath()); } public function testDispatcherWithControllerNotFound() diff --git a/tests/units/Core/TemplateTest.php b/tests/units/Core/TemplateTest.php index 6e5ae00d..bd476c51 100644 --- a/tests/units/Core/TemplateTest.php +++ b/tests/units/Core/TemplateTest.php @@ -8,7 +8,7 @@ class TemplateTest extends Base { public function testGetTemplateFile() { - $t = new Template($this->container); + $t = new Template($this->container['helper']); $this->assertStringEndsWith( 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php', $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') @@ -17,7 +17,7 @@ class TemplateTest extends Base public function testGetPluginTemplateFile() { - $t = new Template($this->container); + $t = new Template($this->container['helper']); $this->assertStringEndsWith( 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php', $t->getTemplateFile('myplugin:a'.DIRECTORY_SEPARATOR.'b') @@ -26,7 +26,7 @@ class TemplateTest extends Base public function testGetOverridedTemplateFile() { - $t = new Template($this->container); + $t = new Template($this->container['helper']); $t->setTemplateOverride('a'.DIRECTORY_SEPARATOR.'b', 'myplugin:c'); $this->assertStringEndsWith( diff --git a/tests/units/Helper/AppHelperTest.php b/tests/units/Helper/AppHelperTest.php index 4fd486f0..dee0750e 100644 --- a/tests/units/Helper/AppHelperTest.php +++ b/tests/units/Helper/AppHelperTest.php @@ -3,25 +3,25 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\Session\FlashMessage; -use Kanboard\Helper\App; +use Kanboard\Helper\AppHelper; class AppHelperTest extends Base { public function testJsLang() { - $h = new App($this->container); + $h = new AppHelper($this->container); $this->assertEquals('en', $h->jsLang()); } public function testTimezone() { - $h = new App($this->container); + $h = new AppHelper($this->container); $this->assertEquals('UTC', $h->getTimezone()); } public function testFlashMessage() { - $h = new App($this->container); + $h = new AppHelper($this->container); $f = new FlashMessage($this->container); $this->assertEmpty($h->flashMessage()); diff --git a/tests/units/Helper/AssetHelperTest.php b/tests/units/Helper/AssetHelperTest.php index 64fcd569..6ef5accd 100644 --- a/tests/units/Helper/AssetHelperTest.php +++ b/tests/units/Helper/AssetHelperTest.php @@ -2,14 +2,14 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\Asset; +use Kanboard\Helper\AssetHelper; use Kanboard\Model\Config; class AssetHelperTest extends Base { public function testCustomCss() { - $h = new Asset($this->container); + $h = new AssetHelper($this->container); $c = new Config($this->container); $this->assertEmpty($h->customCss()); diff --git a/tests/units/Helper/DatetimeHelperTest.php b/tests/units/Helper/DatetimeHelperTest.php index f27a2eb9..19b1b704 100644 --- a/tests/units/Helper/DatetimeHelperTest.php +++ b/tests/units/Helper/DatetimeHelperTest.php @@ -2,19 +2,19 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\Dt; +use Kanboard\Helper\DateHelper; class DatetimeHelperTest extends Base { public function testGetTime() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $this->assertEquals('17:25', $helper->time(1422206700)); } public function testGetDate() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $this->assertEquals('01/25/2015', $helper->date(1422206700)); $this->assertEquals('01/25/2015', $helper->date('2015-01-25')); $this->assertEquals('', $helper->date('0')); @@ -24,13 +24,13 @@ class DatetimeHelperTest extends Base public function testGetDatetime() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $this->assertEquals('01/25/2015 17:25', $helper->datetime(1422206700)); } public function testAge() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $this->assertEquals('<15m', $helper->age(0, 30)); $this->assertEquals('<30m', $helper->age(0, 1000)); @@ -42,7 +42,7 @@ class DatetimeHelperTest extends Base public function testGetDayHours() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $slots = $helper->getDayHours(); @@ -58,7 +58,7 @@ class DatetimeHelperTest extends Base public function testGetWeekDays() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $slots = $helper->getWeekDays(); @@ -70,7 +70,7 @@ class DatetimeHelperTest extends Base public function testGetWeekDay() { - $helper = new Dt($this->container); + $helper = new DateHelper($this->container); $this->assertEquals('Monday', $helper->getWeekDay(1)); $this->assertEquals('Sunday', $helper->getWeekDay(7)); diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperText.php index 6a1b78a4..215b024b 100644 --- a/tests/units/Helper/FileHelperText.php +++ b/tests/units/Helper/FileHelperText.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\File; +use Kanboard\Helper\FileHelper; class FileHelperTest extends Base { public function testIcon() { - $helper = new File($this->container); + $helper = new FileHelper($this->container); $this->assertEquals('fa-file-image-o', $helper->icon('test.png')); $this->assertEquals('fa-file-o', $helper->icon('test')); } public function testGetMimeType() { - $helper = new File($this->container); + $helper = new FileHelper($this->container); $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.JPG')); $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.jpeg')); @@ -27,7 +27,7 @@ class FileHelperTest extends Base public function testGetPreviewType() { - $helper = new File($this->container); + $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')); diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php index aec4a771..6e03acd1 100644 --- a/tests/units/Helper/HookHelperTest.php +++ b/tests/units/Helper/HookHelperTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\Hook; +use Kanboard\Helper\HookHelper; class HookHelperTest extends Base { @@ -10,7 +10,7 @@ class HookHelperTest extends Base { $this->container['template'] = $this ->getMockBuilder('\Kanboard\Core\Template') - ->setConstructorArgs(array($this->container)) + ->setConstructorArgs(array($this->container['helper'])) ->setMethods(array('render')) ->getMock(); @@ -32,7 +32,7 @@ class HookHelperTest extends Base ) ->will($this->returnValue('tpl2_content')); - $h = new Hook($this->container); + $h = new HookHelper($this->container); $h->attach('test', 'tpl1'); $h->attach('test', 'tpl2'); $this->assertEquals('tpl1_contenttpl2_content', $h->render('test')); @@ -41,7 +41,7 @@ class HookHelperTest extends Base public function testAssetHooks() { $this->container['helper']->asset = $this - ->getMockBuilder('\Kanboard\Helper\Asset') + ->getMockBuilder('\Kanboard\Helper\AssetHelper') ->setConstructorArgs(array($this->container)) ->setMethods(array('css', 'js')) ->getMock(); @@ -64,7 +64,7 @@ class HookHelperTest extends Base ) ->will($this->returnValue('<script src="skin.js"></script>')); - $h = new Hook($this->container); + $h = new HookHelper($this->container); $h->attach('test1', 'skin.css'); $h->attach('test2', 'skin.js'); diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php index 726188e4..454da553 100644 --- a/tests/units/Helper/TaskHelperTest.php +++ b/tests/units/Helper/TaskHelperTest.php @@ -2,20 +2,20 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\Task; +use Kanboard\Helper\TaskHelper; class TaskHelperTest extends Base { public function testSelectPriority() { - $helper = new Task($this->container); + $helper = new TaskHelper($this->container); $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())); } public function testFormatPriority() { - $helper = new Task($this->container); + $helper = new TaskHelper($this->container); $this->assertEquals( '<span class="task-board-priority" title="Task priority">P2</span>', diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index a4bdfa91..d7324dfd 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -2,13 +2,13 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\Text; +use Kanboard\Helper\TextHelper; class TextHelperTest extends Base { public function testMarkdownTaskLink() { - $h = new Text($this->container); + $h = new TextHelper($this->container); $this->assertEquals('<p>Test</p>', $h->markdown('Test')); @@ -33,13 +33,13 @@ class TextHelperTest extends Base public function testMarkdownUserLink() { - $h = new Text($this->container); + $h = new TextHelper($this->container); $this->assertEquals('<p>Text <a href="?controller=user&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound')); } public function testFormatBytes() { - $h = new Text($this->container); + $h = new TextHelper($this->container); $this->assertEquals('1k', $h->bytes(1024)); $this->assertEquals('33.71k', $h->bytes(34520)); @@ -47,7 +47,7 @@ class TextHelperTest extends Base public function testContains() { - $h = new Text($this->container); + $h = new TextHelper($this->container); $this->assertTrue($h->contains('abc', 'b')); $this->assertFalse($h->contains('abc', 'd')); @@ -55,7 +55,7 @@ class TextHelperTest extends Base public function testInList() { - $h = new Text($this->container); + $h = new TextHelper($this->container); $this->assertEquals('?', $h->in('a', array('b' => 'c'))); $this->assertEquals('c', $h->in('b', array('b' => 'c'))); } diff --git a/tests/units/Helper/UrlHelperTest.php b/tests/units/Helper/UrlHelperTest.php index 15e01237..34ab7604 100644 --- a/tests/units/Helper/UrlHelperTest.php +++ b/tests/units/Helper/UrlHelperTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\Url; +use Kanboard\Helper\UrlHelper; use Kanboard\Model\Config; use Kanboard\Core\Http\Request; @@ -10,7 +10,7 @@ class UrlHelperTest extends Base { public function testPluginLink() { - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals( '<a href="?controller=a&action=b&d=e&plugin=something" class="f" title=\'g\' target="_blank">label</a>', $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true) @@ -22,7 +22,7 @@ class UrlHelperTest extends Base $this->container['route']->enable(); $this->container['route']->addRoute('/myplugin/something/:d', 'a', 'b', 'something'); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals( '<a href="myplugin/something/e" class="f" title=\'g\' target="_blank">label</a>', $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true) @@ -31,7 +31,7 @@ class UrlHelperTest extends Base public function testAppLink() { - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals( '<a href="?controller=a&action=b&d=e" class="f" title=\'g\' target="_blank">label</a>', $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true) @@ -40,7 +40,7 @@ class UrlHelperTest extends Base public function testHref() { - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals( '?controller=a&action=b&d=e', $h->href('a', 'b', array('d' => 'e')) @@ -49,7 +49,7 @@ class UrlHelperTest extends Base public function testTo() { - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals( '?controller=a&action=b&d=e', $h->to('a', 'b', array('d' => 'e')) @@ -64,7 +64,7 @@ class UrlHelperTest extends Base ) ); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals('/kanboard/', $h->dir()); $this->container['request'] = new Request($this->container, array( @@ -73,7 +73,7 @@ class UrlHelperTest extends Base ) ); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals('/', $h->dir()); } @@ -87,7 +87,7 @@ class UrlHelperTest extends Base ) ); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals('http://localhost/', $h->server()); $this->container['request'] = new Request($this->container, array( @@ -98,7 +98,7 @@ class UrlHelperTest extends Base ) ); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals('http://kb:1234/', $h->server()); } @@ -112,14 +112,14 @@ class UrlHelperTest extends Base ) ); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals('http://kb:1234/', $h->base()); $c = new Config($this->container); $c->save(array('application_url' => 'https://mykanboard/')); $this->container['memoryCache']->flush(); - $h = new Url($this->container); + $h = new UrlHelper($this->container); $this->assertEquals('https://mykanboard/', $c->get('application_url')); $this->assertEquals('https://mykanboard/', $h->base()); } diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index f1099faa..7ee6e8bb 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Helper\User; +use Kanboard\Helper\UserHelper; use Kanboard\Model\Project; use Kanboard\Model\ProjectUserRole; use Kanboard\Model\User as UserModel; @@ -12,7 +12,7 @@ class UserHelperTest extends Base { public function testInitials() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $this->assertEquals('CN', $helper->getInitials('chuck norris')); $this->assertEquals('A', $helper->getInitials('admin')); @@ -20,7 +20,7 @@ class UserHelperTest extends Base public function testGetRoleName() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $this->assertEquals('Administrator', $helper->getRoleName(Role::APP_ADMIN)); $this->assertEquals('Manager', $helper->getRoleName(Role::APP_MANAGER)); $this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER)); @@ -28,7 +28,7 @@ class UserHelperTest extends Base public function testHasAccessForAdmins() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -42,7 +42,7 @@ class UserHelperTest extends Base public function testHasAccessForManagers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -56,7 +56,7 @@ class UserHelperTest extends Base public function testHasAccessForUsers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $this->container['sessionStorage']->user = array( 'id' => 2, @@ -70,7 +70,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForAdmins() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $project = new Project($this->container); $this->container['sessionStorage']->user = array( @@ -86,7 +86,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForManagers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $project = new Project($this->container); $this->container['sessionStorage']->user = array( @@ -102,7 +102,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForUsers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $project = new Project($this->container); $this->container['sessionStorage']->user = array( @@ -118,7 +118,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForAppManagerAndProjectManagers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $user = new UserModel($this->container); $project = new Project($this->container); $projectUserRole = new ProjectUserRole($this->container); @@ -146,7 +146,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForProjectManagers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $user = new UserModel($this->container); $project = new Project($this->container); $projectUserRole = new ProjectUserRole($this->container); @@ -174,7 +174,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForProjectMembers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $user = new UserModel($this->container); $project = new Project($this->container); $projectUserRole = new ProjectUserRole($this->container); @@ -202,7 +202,7 @@ class UserHelperTest extends Base public function testHasProjectAccessForProjectViewers() { - $helper = new User($this->container); + $helper = new UserHelper($this->container); $user = new UserModel($this->container); $project = new Project($this->container); $projectUserRole = new ProjectUserRole($this->container); |