Improve unit tests
This commit is contained in:
38
tests/units/Helper/AppHelperTest.php
Normal file
38
tests/units/Helper/AppHelperTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Core\Session;
|
||||
use Helper\App;
|
||||
use Model\Config;
|
||||
|
||||
class AppHelperTest extends Base
|
||||
{
|
||||
public function testJsLang()
|
||||
{
|
||||
$h = new App($this->container);
|
||||
$this->assertEquals('en', $h->jsLang());
|
||||
}
|
||||
|
||||
public function testTimezone()
|
||||
{
|
||||
$h = new App($this->container);
|
||||
$this->assertEquals('UTC', $h->getTimezone());
|
||||
}
|
||||
|
||||
public function testFlashMessage()
|
||||
{
|
||||
$h = new App($this->container);
|
||||
$s = new Session;
|
||||
|
||||
$this->assertEmpty($h->flashMessage());
|
||||
$s->flash('test & test');
|
||||
$this->assertEquals('<div class="alert alert-success alert-fade-out">test & test</div>', $h->flashMessage());
|
||||
$this->assertEmpty($h->flashMessage());
|
||||
|
||||
$this->assertEmpty($h->flashMessage());
|
||||
$s->flashError('test & test');
|
||||
$this->assertEquals('<div class="alert alert-error">test & test</div>', $h->flashMessage());
|
||||
$this->assertEmpty($h->flashMessage());
|
||||
}
|
||||
}
|
||||
21
tests/units/Helper/AssetHelperTest.php
Normal file
21
tests/units/Helper/AssetHelperTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Helper\Asset;
|
||||
use Model\Config;
|
||||
|
||||
class AssetHelperTest extends Base
|
||||
{
|
||||
public function testCustomCss()
|
||||
{
|
||||
$h = new Asset($this->container);
|
||||
$c = new Config($this->container);
|
||||
|
||||
$this->assertEmpty($h->customCss());
|
||||
|
||||
$this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }')));
|
||||
|
||||
$this->assertEquals('<style>p { color: red }</style>', $h->customCss());
|
||||
}
|
||||
}
|
||||
56
tests/units/Helper/DatetimeHelperTest.php
Normal file
56
tests/units/Helper/DatetimeHelperTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Helper\Dt;
|
||||
|
||||
class DatetimeHelperTest extends Base
|
||||
{
|
||||
public function testAge()
|
||||
{
|
||||
$h = new Dt($this->container);
|
||||
|
||||
$this->assertEquals('<15m', $h->age(0, 30));
|
||||
$this->assertEquals('<30m', $h->age(0, 1000));
|
||||
$this->assertEquals('<1h', $h->age(0, 3000));
|
||||
$this->assertEquals('~2h', $h->age(0, 2*3600));
|
||||
$this->assertEquals('1d', $h->age(0, 30*3600));
|
||||
$this->assertEquals('2d', $h->age(0, 65*3600));
|
||||
}
|
||||
|
||||
public function testGetDayHours()
|
||||
{
|
||||
$h = new Dt($this->container);
|
||||
|
||||
$slots = $h->getDayHours();
|
||||
|
||||
$this->assertNotEmpty($slots);
|
||||
$this->assertCount(48, $slots);
|
||||
$this->assertArrayHasKey('00:00', $slots);
|
||||
$this->assertArrayHasKey('00:30', $slots);
|
||||
$this->assertArrayHasKey('01:00', $slots);
|
||||
$this->assertArrayHasKey('01:30', $slots);
|
||||
$this->assertArrayHasKey('23:30', $slots);
|
||||
$this->assertArrayNotHasKey('24:00', $slots);
|
||||
}
|
||||
|
||||
public function testGetWeekDays()
|
||||
{
|
||||
$h = new Dt($this->container);
|
||||
|
||||
$slots = $h->getWeekDays();
|
||||
|
||||
$this->assertNotEmpty($slots);
|
||||
$this->assertCount(7, $slots);
|
||||
$this->assertContains('Monday', $slots);
|
||||
$this->assertContains('Sunday', $slots);
|
||||
}
|
||||
|
||||
public function testGetWeekDay()
|
||||
{
|
||||
$h = new Dt($this->container);
|
||||
|
||||
$this->assertEquals('Monday', $h->getWeekDay(1));
|
||||
$this->assertEquals('Sunday', $h->getWeekDay(7));
|
||||
}
|
||||
}
|
||||
15
tests/units/Helper/FileHelperText.php
Normal file
15
tests/units/Helper/FileHelperText.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Helper\File;
|
||||
|
||||
class FileHelperTest extends Base
|
||||
{
|
||||
public function testIcon()
|
||||
{
|
||||
$h = new File($this->container);
|
||||
$this->assertEquals('fa-file-image-o', $h->icon('test.png'));
|
||||
$this->assertEquals('fa-file-o', $h->icon('test'));
|
||||
}
|
||||
}
|
||||
56
tests/units/Helper/TextHelperTest.php
Normal file
56
tests/units/Helper/TextHelperTest.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Helper\Text;
|
||||
|
||||
class TextHelperTest extends Base
|
||||
{
|
||||
public function testMarkdown()
|
||||
{
|
||||
$h = new Text($this->container);
|
||||
|
||||
$this->assertEquals('<p>Test</p>', $h->markdown('Test'));
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task #123</p>',
|
||||
$h->markdown('Task #123')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'<p>Task <a href="?controller=a&action=b&c=d&task_id=123">#123</a></p>',
|
||||
$h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')))
|
||||
);
|
||||
|
||||
$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>',
|
||||
$h->markdown(
|
||||
'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454',
|
||||
array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testFormatBytes()
|
||||
{
|
||||
$h = new Text($this->container);
|
||||
|
||||
$this->assertEquals('1k', $h->bytes(1024));
|
||||
$this->assertEquals('33.71k', $h->bytes(34520));
|
||||
}
|
||||
|
||||
public function testContains()
|
||||
{
|
||||
$h = new Text($this->container);
|
||||
|
||||
$this->assertTrue($h->contains('abc', 'b'));
|
||||
$this->assertFalse($h->contains('abc', 'd'));
|
||||
}
|
||||
|
||||
public function testInList()
|
||||
{
|
||||
$h = new Text($this->container);
|
||||
$this->assertEquals('?', $h->in('a', array('b' => 'c')));
|
||||
$this->assertEquals('c', $h->in('b', array('b' => 'c')));
|
||||
}
|
||||
}
|
||||
86
tests/units/Helper/UrlHelperTest.php
Normal file
86
tests/units/Helper/UrlHelperTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Helper\Url;
|
||||
use Model\Config;
|
||||
|
||||
class UrlHelperTest extends Base
|
||||
{
|
||||
public function testLink()
|
||||
{
|
||||
$h = new Url($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)
|
||||
);
|
||||
}
|
||||
|
||||
public function testHref()
|
||||
{
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals(
|
||||
'?controller=a&action=b&d=e',
|
||||
$h->href('a', 'b', array('d' => 'e'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testTo()
|
||||
{
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals(
|
||||
'?controller=a&action=b&d=e',
|
||||
$h->to('a', 'b', array('d' => 'e'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testDir()
|
||||
{
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals('', $h->dir());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['PHP_SELF'] = '/plop/index.php';
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals('/plop/', $h->dir());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['PHP_SELF'] = '';
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals('/', $h->dir());
|
||||
}
|
||||
|
||||
public function testServer()
|
||||
{
|
||||
$h = new Url($this->container);
|
||||
|
||||
$this->assertEquals('http://localhost/', $h->server());
|
||||
|
||||
$_SERVER['PHP_SELF'] = '/';
|
||||
$_SERVER['SERVER_NAME'] = 'kb';
|
||||
$_SERVER['SERVER_PORT'] = 1234;
|
||||
|
||||
$this->assertEquals('http://kb:1234/', $h->server());
|
||||
}
|
||||
|
||||
public function testBase()
|
||||
{
|
||||
$h = new Url($this->container);
|
||||
|
||||
$this->assertEquals('http://localhost/', $h->base());
|
||||
|
||||
$_SERVER['PHP_SELF'] = '/';
|
||||
$_SERVER['SERVER_NAME'] = 'kb';
|
||||
$_SERVER['SERVER_PORT'] = 1234;
|
||||
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals('http://kb:1234/', $h->base());
|
||||
|
||||
$c = new Config($this->container);
|
||||
$c->save(array('application_url' => 'https://mykanboard/'));
|
||||
|
||||
$h = new Url($this->container);
|
||||
$this->assertEquals('https://mykanboard/', $c->get('application_url'));
|
||||
$this->assertEquals('https://mykanboard/', $h->base());
|
||||
}
|
||||
}
|
||||
16
tests/units/Helper/UserHelperTest.php
Normal file
16
tests/units/Helper/UserHelperTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Helper\User;
|
||||
|
||||
class UserHelperTest extends Base
|
||||
{
|
||||
public function testInitials()
|
||||
{
|
||||
$h = new User($this->container);
|
||||
|
||||
$this->assertEquals('CN', $h->getInitials('chuck norris'));
|
||||
$this->assertEquals('A', $h->getInitials('admin'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user