summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/AppHelperTest.php38
-rw-r--r--tests/units/AssetHelperTest.php21
-rw-r--r--tests/units/DatetimeHelperTest.php44
-rw-r--r--tests/units/FileHelperText.php15
-rw-r--r--tests/units/TextHelperTest.php (renamed from tests/units/HelperTest.php)42
-rw-r--r--tests/units/UrlHelperTest.php64
6 files changed, 210 insertions, 14 deletions
diff --git a/tests/units/AppHelperTest.php b/tests/units/AppHelperTest.php
new file mode 100644
index 00000000..ad4bc151
--- /dev/null
+++ b/tests/units/AppHelperTest.php
@@ -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 &amp; test</div>', $h->flashMessage());
+ $this->assertEmpty($h->flashMessage());
+
+ $this->assertEmpty($h->flashMessage());
+ $s->flashError('test & test');
+ $this->assertEquals('<div class="alert alert-error">test &amp; test</div>', $h->flashMessage());
+ $this->assertEmpty($h->flashMessage());
+ }
+}
diff --git a/tests/units/AssetHelperTest.php b/tests/units/AssetHelperTest.php
new file mode 100644
index 00000000..1143ce1f
--- /dev/null
+++ b/tests/units/AssetHelperTest.php
@@ -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());
+ }
+}
diff --git a/tests/units/DatetimeHelperTest.php b/tests/units/DatetimeHelperTest.php
new file mode 100644
index 00000000..2746beed
--- /dev/null
+++ b/tests/units/DatetimeHelperTest.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Helper\Datetime;
+
+class DatetimeHelperTest extends Base
+{
+ public function testGetDayHours()
+ {
+ $h = new Datetime($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 Datetime($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 Datetime($this->container);
+
+ $this->assertEquals('Monday', $h->getWeekDay(1));
+ $this->assertEquals('Sunday', $h->getWeekDay(7));
+ }
+}
diff --git a/tests/units/FileHelperText.php b/tests/units/FileHelperText.php
new file mode 100644
index 00000000..ce04fdbd
--- /dev/null
+++ b/tests/units/FileHelperText.php
@@ -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'));
+ }
+}
diff --git a/tests/units/HelperTest.php b/tests/units/TextHelperTest.php
index 57d1940a..20b89fa8 100644
--- a/tests/units/HelperTest.php
+++ b/tests/units/TextHelperTest.php
@@ -2,14 +2,13 @@
require_once __DIR__.'/Base.php';
-use Core\Helper;
-use Model\Config;
+use Helper\Text;
-class HelperTest extends Base
+class TextHelperTest extends Base
{
public function testMarkdown()
{
- $h = new Helper($this->container);
+ $h = new Text($this->container);
$this->assertEquals('<p>Test</p>', $h->markdown('Test'));
@@ -32,19 +31,34 @@ class HelperTest extends Base
);
}
- public function testGetCurrentBaseUrl()
+ public function testFormatBytes()
{
- $h = new Helper($this->container);
+ $h = new Text($this->container);
- $_SERVER['PHP_SELF'] = '/';
- $_SERVER['SERVER_NAME'] = 'localhost';
- $_SERVER['SERVER_PORT'] = 1234;
+ $this->assertEquals('1k', $h->bytes(1024));
+ $this->assertEquals('33.71k', $h->bytes(34520));
+ }
- $this->assertEquals('http://localhost:1234/', $h->getCurrentBaseUrl());
+ public function testTruncate()
+ {
+ $h = new Text($this->container);
- $c = new Config($this->container);
- $c->save(array('application_url' => 'https://mykanboard/'));
- $this->assertEquals('https://mykanboard/', $c->get('application_url'));
- $this->assertEquals('https://mykanboard/', $h->getCurrentBaseUrl());
+ $this->assertEquals('abc', $h->truncate('abc'));
+ $this->assertEquals(str_repeat('a', 85).' [...]', $h->truncate(str_repeat('a', 200)));
+ }
+
+ 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')));
}
}
diff --git a/tests/units/UrlHelperTest.php b/tests/units/UrlHelperTest.php
new file mode 100644
index 00000000..d70842aa
--- /dev/null
+++ b/tests/units/UrlHelperTest.php
@@ -0,0 +1,64 @@
+<?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&amp;action=b&amp;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&amp;action=b&amp;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 testServer()
+ {
+ $h = new Url($this->container);
+
+ $_SERVER['PHP_SELF'] = '/';
+ $_SERVER['SERVER_NAME'] = 'localhost';
+ $_SERVER['SERVER_PORT'] = 1234;
+
+ $this->assertEquals('http://localhost:1234/', $h->server());
+ }
+
+ public function testBase()
+ {
+ $h = new Url($this->container);
+
+ $_SERVER['PHP_SELF'] = '/';
+ $_SERVER['SERVER_NAME'] = 'localhost';
+ $_SERVER['SERVER_PORT'] = 1234;
+
+ $this->assertEquals('http://localhost:1234/', $h->base());
+
+ $c = new Config($this->container);
+ $c->save(array('application_url' => 'https://mykanboard/'));
+
+ $this->assertEquals('https://mykanboard/', $c->get('application_url'));
+ $this->assertEquals('https://mykanboard/', $h->base());
+ }
+}