From eeac2329baab1fdae7cbf6c707ed2ffd8beb4c1b Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 24 May 2015 16:02:25 -0400 Subject: Helpers refactoring --- tests/units/AppHelperTest.php | 38 ++++++++++++++++++++++ tests/units/AssetHelperTest.php | 21 +++++++++++++ tests/units/DatetimeHelperTest.php | 44 ++++++++++++++++++++++++++ tests/units/FileHelperText.php | 15 +++++++++ tests/units/HelperTest.php | 50 ----------------------------- tests/units/TextHelperTest.php | 64 ++++++++++++++++++++++++++++++++++++++ tests/units/UrlHelperTest.php | 64 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 246 insertions(+), 50 deletions(-) create mode 100644 tests/units/AppHelperTest.php create mode 100644 tests/units/AssetHelperTest.php create mode 100644 tests/units/DatetimeHelperTest.php create mode 100644 tests/units/FileHelperText.php delete mode 100644 tests/units/HelperTest.php create mode 100644 tests/units/TextHelperTest.php create mode 100644 tests/units/UrlHelperTest.php (limited to 'tests/units') 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 @@ +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('
test & test
', $h->flashMessage()); + $this->assertEmpty($h->flashMessage()); + + $this->assertEmpty($h->flashMessage()); + $s->flashError('test & test'); + $this->assertEquals('
test & test
', $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 @@ +container); + $c = new Config($this->container); + + $this->assertEmpty($h->customCss()); + + $this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }'))); + + $this->assertEquals('', $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 @@ +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 @@ +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/HelperTest.php deleted file mode 100644 index 57d1940a..00000000 --- a/tests/units/HelperTest.php +++ /dev/null @@ -1,50 +0,0 @@ -container); - - $this->assertEquals('

Test

', $h->markdown('Test')); - - $this->assertEquals( - '

Task #123

', - $h->markdown('Task #123') - ); - - $this->assertEquals( - '

Task #123

', - $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))) - ); - - $this->assertEquals( - '

Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

', - $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 testGetCurrentBaseUrl() - { - $h = new Helper($this->container); - - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'localhost'; - $_SERVER['SERVER_PORT'] = 1234; - - $this->assertEquals('http://localhost:1234/', $h->getCurrentBaseUrl()); - - $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()); - } -} diff --git a/tests/units/TextHelperTest.php b/tests/units/TextHelperTest.php new file mode 100644 index 00000000..20b89fa8 --- /dev/null +++ b/tests/units/TextHelperTest.php @@ -0,0 +1,64 @@ +container); + + $this->assertEquals('

Test

', $h->markdown('Test')); + + $this->assertEquals( + '

Task #123

', + $h->markdown('Task #123') + ); + + $this->assertEquals( + '

Task #123

', + $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))) + ); + + $this->assertEquals( + '

Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

', + $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 testTruncate() + { + $h = new Text($this->container); + + $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 @@ +container); + $this->assertEquals( + 'label', + $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 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()); + } +} -- cgit v1.2.3