From 69c97a71476e4eaa6c629022fcd4ec7f36d4ec0d Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 20 Apr 2011 21:44:54 -0400 Subject: Adding early bootstrap ideas for core test suite --- tests/codeigniter/helpers/Array_helper_test.php | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/codeigniter/helpers/Array_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/Array_helper_test.php b/tests/codeigniter/helpers/Array_helper_test.php new file mode 100644 index 000000000..bbefdb49d --- /dev/null +++ b/tests/codeigniter/helpers/Array_helper_test.php @@ -0,0 +1,49 @@ +my_array = array( + 'foo' => 'bar', + 'sally' => 'jim', + 'maggie' => 'bessie', + 'herb' => 'cook' + ); + } + + // ------------------------------------------------------------------------ + + public function testElementWithExistingItem() + { + $this->assertEquals(FALSE, element('testing', $this->my_array)); + + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); + + $this->assertEquals('bar', element('foo', $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testRandomElement() + { + // Send a string, not an array to random_element + $this->assertEquals('my string', random_element('my string')); + + // Test sending an array + $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testElements() + { + $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); + $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b567947d38a20960aade96f9179ad6bc21f22646 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:34:31 -0500 Subject: Moving tests/codeigniter/helpers/Array_helper_test.php to be lower cased. Adding html_helper_test.php as well. --- tests/codeigniter/helpers/Array_helper_test.php | 49 ------------------ tests/codeigniter/helpers/array_helper_test.php | 49 ++++++++++++++++++ tests/codeigniter/helpers/html_helper_test.php | 67 +++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 49 deletions(-) delete mode 100644 tests/codeigniter/helpers/Array_helper_test.php create mode 100644 tests/codeigniter/helpers/array_helper_test.php create mode 100644 tests/codeigniter/helpers/html_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/Array_helper_test.php b/tests/codeigniter/helpers/Array_helper_test.php deleted file mode 100644 index bbefdb49d..000000000 --- a/tests/codeigniter/helpers/Array_helper_test.php +++ /dev/null @@ -1,49 +0,0 @@ -my_array = array( - 'foo' => 'bar', - 'sally' => 'jim', - 'maggie' => 'bessie', - 'herb' => 'cook' - ); - } - - // ------------------------------------------------------------------------ - - public function testElementWithExistingItem() - { - $this->assertEquals(FALSE, element('testing', $this->my_array)); - - $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); - - $this->assertEquals('bar', element('foo', $this->my_array)); - } - - // ------------------------------------------------------------------------ - - public function testRandomElement() - { - // Send a string, not an array to random_element - $this->assertEquals('my string', random_element('my string')); - - // Test sending an array - $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); - } - - // ------------------------------------------------------------------------ - - public function testElements() - { - $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); - $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); - } - -} \ No newline at end of file diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php new file mode 100644 index 000000000..bbefdb49d --- /dev/null +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -0,0 +1,49 @@ +my_array = array( + 'foo' => 'bar', + 'sally' => 'jim', + 'maggie' => 'bessie', + 'herb' => 'cook' + ); + } + + // ------------------------------------------------------------------------ + + public function testElementWithExistingItem() + { + $this->assertEquals(FALSE, element('testing', $this->my_array)); + + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); + + $this->assertEquals('bar', element('foo', $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testRandomElement() + { + // Send a string, not an array to random_element + $this->assertEquals('my string', random_element('my string')); + + // Test sending an array + $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); + } + + // ------------------------------------------------------------------------ + + public function testElements() + { + $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); + $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php new file mode 100644 index 000000000..3b7f2b342 --- /dev/null +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -0,0 +1,67 @@ +assertEquals('

foobar

', heading('foobar')); + } + + // ------------------------------------------------------------------------ + + public function testUl() + { + $expect = << +
  • foo
  • +
  • bar
  • + + +EOH; + + $expect = ltrim($expect); + + $list = array('foo', 'bar'); + + $this->assertEquals($expect, ul($list)); + + + $expect = << +
  • foo
  • +
  • bar
  • + + +EOH; + + $expect = ltrim($expect); + + $list = array('foo', 'bar'); + + $this->assertEquals($expect, ul($list, ' class="test"')); + + $this->assertEquals($expect, ul($list, array('class' => 'test'))); + } + + // ------------------------------------------------------------------------ + + public function testNBS() + { + $this->assertEquals('   ', nbs(3)); + } + + // ------------------------------------------------------------------------ + + public function testMeta() + { + $this->assertEquals("\n", meta('test', 'foo')); + + $expect = "\n"; + + $this->assertEquals($expect, meta(array('name' => 'foo'))); + + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9071573bc510f127fa22ddd367b2ff46a60242cc Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:36:26 -0500 Subject: Adding text_helper_test --- tests/codeigniter/helpers/text_helper_test.php | 151 +++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/codeigniter/helpers/text_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php new file mode 100644 index 000000000..aa6660ea0 --- /dev/null +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -0,0 +1,151 @@ +_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; + } + + // ------------------------------------------------------------------------ + + public function testWordLimiter() + { + $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); + $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); + $this->assertEquals('', word_limiter('', 4)); + } + + // ------------------------------------------------------------------------ + + public function testCharacterLimiter() + { + $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); + $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); + $this->assertEquals('Short', character_limiter('Short', 20)); + $this->assertEquals('Short', character_limiter('Short', 5)); + } + + // ------------------------------------------------------------------------ + + public function testAsciiToEntities() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, ascii_to_entities($str)); + } + } + + // ------------------------------------------------------------------------ + + public function testEntitiesToAscii() + { + $strs = array( + '“‘ “test”' => '“‘ “test”', + '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, entities_to_ascii($str)); + } + } + + // ------------------------------------------------------------------------ + + public function testCensoredWords() + { + $censored = array('boob', 'nerd', 'ass', 'fart'); + + $strs = array( + 'Ted bobbled the ball' => 'Ted bobbled the ball', + 'Jake is a nerdo' => 'Jake is a nerdo', + 'The borg will assimilate you' => 'The borg will assimilate you', + 'Did Mary Fart?' => 'Did Mary $*#?', + 'Jake is really a boob' => 'Jake is really a $*#' + ); + + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, word_censor($str, $censored, '$*#')); + } + + // test censored words being sent as a string + $this->assertEquals('test', word_censor('test', 'test')); + } + + // ------------------------------------------------------------------------ + + public function testHighlightCode() + { + $code = ''; + $expect = "\n<?php var_dump(\$this); ?> \n\n"; + + $this->assertEquals($expect, highlight_code($code)); + } + + // ------------------------------------------------------------------------ + + public function testHighlightPhrase() + { + $strs = array( + 'this is a phrase' => 'this is a phrase', + 'this is another' => 'this is another', + 'Gimme a test, Sally' => 'Gimme a test, Sally', + 'Or tell me what this is' => 'Or tell me what this is', + '' => '' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, highlight_phrase($str, 'this is')); + } + } + + // ------------------------------------------------------------------------ + + public function testEllipsizing() + { + $strs = array( + '0' => array( + 'this is my string' => '… my string', + "here's another one" => '…nother one', + 'this one is just a bit longer' => '…bit longer', + 'short' => 'short' + ), + '.5' => array( + 'this is my string' => 'this …tring', + "here's another one" => "here'…r one", + 'this one is just a bit longer' => 'this …onger', + 'short' => 'short' + ), + '1' => array( + 'this is my string' => 'this is my…', + "here's another one" => "here's ano…", + 'this one is just a bit longer' => 'this one i…', + 'short' => 'short' + ), + ); + + foreach ($strs as $pos => $s) + { + foreach ($s as $str => $expect) + { + $this->assertEquals($expect, ellipsize($str, 10, $pos)); + } + } + } + + // ------------------------------------------------------------------------ + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 052b01d9398de56e23300242f25d5317afcacf82 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:38:03 -0500 Subject: Adding string helper and inflector helper tests --- .../codeigniter/helpers/inflector_helper_test.php | 91 ++++++++++++++++ tests/codeigniter/helpers/string_helper_test.php | 117 +++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 tests/codeigniter/helpers/inflector_helper_test.php create mode 100644 tests/codeigniter/helpers/string_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php new file mode 100644 index 000000000..5e2fae9fd --- /dev/null +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -0,0 +1,91 @@ + 'telly', + 'smellies' => 'smelly', + 'abjectnesses' => 'abjectness', + 'smells' => 'smell' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, singular($str)); + } + } + + // -------------------------------------------------------------------- + + public function testPlural() + { + $strs = array( + 'telly' => 'tellies', + 'smelly' => 'smellies', + 'abjectness' => 'abjectness', + 'smell' => 'smells', + 'witch' => 'witches' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, plural($str)); + } + } + + // -------------------------------------------------------------------- + + public function testCamelize() + { + $strs = array( + 'this is the string' => 'thisIsTheString', + 'this is another one' => 'thisIsAnotherOne', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, camelize($str)); + } + } + + // -------------------------------------------------------------------- + + public function testUnderscore() + { + $strs = array( + 'this is the string' => 'this_is_the_string', + 'this is another one' => 'this_is_another_one', + 'i-am-playing-a-trick' => 'i-am-playing-a-trick', + 'what_do_you_think-yo?' => 'what_do_you_think-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, underscore($str)); + } + } + + // -------------------------------------------------------------------- + + public function testHumanize() + { + $strs = array( + 'this_is_the_string' => 'This Is The String', + 'this_is_another_one' => 'This Is Another One', + 'i-am-playing-a-trick' => 'I-am-playing-a-trick', + 'what_do_you_think-yo?' => 'What Do You Think-yo?', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, humanize($str)); + } + } +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php new file mode 100644 index 000000000..71449f64a --- /dev/null +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -0,0 +1,117 @@ + 'Slashes//\\', + '/var/www/html/' => 'var/www/html' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, trim_slashes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testStripSlashes() + { + $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd")); + } + + // -------------------------------------------------------------------- + + public function testStripQuotes() + { + $strs = array( + '"me oh my!"' => 'me oh my!', + "it's a winner!" => 'its a winner!', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, strip_quotes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testQuotesToEntities() + { + $strs = array( + '"me oh my!"' => '"me oh my!"', + "it's a winner!" => 'it's a winner!', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, quotes_to_entities($str)); + } + } + + // -------------------------------------------------------------------- + + public function testReduceDoubleSlashes() + { + $strs = array( + 'http://codeigniter.com' => 'http://codeigniter.com', + '//var/www/html/example.com/' => '/var/www/html/example.com/', + '/var/www/html//index.php' => '/var/www/html/index.php' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, reduce_double_slashes($str)); + } + } + + // -------------------------------------------------------------------- + + public function testReduceMultiples() + { + $strs = array( + 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', + 'Ringo, John, Paul,,' => 'Ringo, John, Paul,' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, reduce_multiples($str)); + } + + $strs = array( + 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', + 'Ringo, John, Paul,,' => 'Ringo, John, Paul' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, reduce_multiples($str, ',', TRUE)); + } + } + + // -------------------------------------------------------------------- + + public function testRepeater() + { + $strs = array( + 'a' => 'aaaaaaaaaa', + ' ' => '          ', + '
    ' => '









    ' + + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, repeater($str, 10)); + } + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b4d93dbab7253f98613ab10e75e0ed20f06eaf19 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 14:42:33 -0500 Subject: Updating helper test classes to extend CI_TestCase --- tests/codeigniter/helpers/array_helper_test.php | 2 +- tests/codeigniter/helpers/html_helper_test.php | 2 +- tests/codeigniter/helpers/inflector_helper_test.php | 2 +- tests/codeigniter/helpers/string_helper_test.php | 2 +- tests/codeigniter/helpers/text_helper_test.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index bbefdb49d..fd306cee8 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -4,7 +4,7 @@ require_once(BASEPATH.'helpers/array_helper.php'); -class Array_helper_test extends PHPUnit_Framework_TestCase +class Array_helper_test extends CI_TestCase { public function setUp() { diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 3b7f2b342..8c0e53301 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/html_helper.php'); -class Html_helper_test extends PHPUnit_Framework_TestCase +class Html_helper_test extends CI_TestCase { public function testHeading() { diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 5e2fae9fd..e59875e4a 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/inflector_helper.php'); -class Inflector_helper_test extends PHPUnit_Framework_TestCase { +class Inflector_helper_test extends CI_TestCase { public function testSingular() diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 71449f64a..00ba5dec7 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/string_helper.php'); -class String_helper_test extends PHPUnit_Framework_TestCase +class String_helper_test extends CI_TestCase { public function testTrimSlashes() { diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index aa6660ea0..22c834bcf 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -2,7 +2,7 @@ require_once(BASEPATH.'helpers/text_helper.php'); -class Text_helper_test extends PHPUnit_Framework_TestCase +class Text_helper_test extends CI_TestCase { private $_long_string; -- cgit v1.2.3-24-g4f1b From 68286a4dcc1ed4d904ad992173c1b3621bf6fced Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Thu, 21 Apr 2011 22:00:33 -0400 Subject: Reworked unit tests to match rest of framework and added a few more. --- tests/codeigniter/helpers/array_helper_test.php | 8 +++---- tests/codeigniter/helpers/email_helper_test.php | 16 +++++++++++++ tests/codeigniter/helpers/html_helper_test.php | 19 +++++++++++---- .../codeigniter/helpers/inflector_helper_test.php | 10 ++++---- tests/codeigniter/helpers/number_helper_test.php | 13 +++++++++++ tests/codeigniter/helpers/string_helper_test.php | 27 +++++++++++----------- tests/codeigniter/helpers/text_helper_test.php | 26 +++++++++++++-------- tests/codeigniter/helpers/xml_helper_test.php | 13 +++++++++++ 8 files changed, 97 insertions(+), 35 deletions(-) create mode 100644 tests/codeigniter/helpers/email_helper_test.php create mode 100644 tests/codeigniter/helpers/number_helper_test.php create mode 100644 tests/codeigniter/helpers/xml_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index fd306cee8..62559de83 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -6,7 +6,7 @@ require_once(BASEPATH.'helpers/array_helper.php'); class Array_helper_test extends CI_TestCase { - public function setUp() + public function set_up() { $this->my_array = array( 'foo' => 'bar', @@ -18,7 +18,7 @@ class Array_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testElementWithExistingItem() + public function test_element_with_existing_item() { $this->assertEquals(FALSE, element('testing', $this->my_array)); @@ -29,7 +29,7 @@ class Array_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testRandomElement() + public function test_random_element() { // Send a string, not an array to random_element $this->assertEquals('my string', random_element('my string')); @@ -40,7 +40,7 @@ class Array_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testElements() + public function test_elements() { $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php new file mode 100644 index 000000000..7324e8109 --- /dev/null +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -0,0 +1,16 @@ +assertEquals(FALSE, valid_email('test')); + $this->assertEquals(FALSE, valid_email('test@test@test.com')); + $this->assertEquals(TRUE, valid_email('test@test.com')); + $this->assertEquals(TRUE, valid_email('my.test@test.com')); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 8c0e53301..706874f9e 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -4,14 +4,25 @@ require_once(BASEPATH.'helpers/html_helper.php'); class Html_helper_test extends CI_TestCase { - public function testHeading() + + // ------------------------------------------------------------------------ + + public function test_br() + { + $this->assertEquals('

    ', br(2)); + } + + // ------------------------------------------------------------------------ + + public function test_heading() { $this->assertEquals('

    foobar

    ', heading('foobar')); + $this->assertEquals('

    foobar

    ', heading('foobar', 2, 'class="bar"')); } // ------------------------------------------------------------------------ - public function testUl() + public function test_Ul() { $expect = << @@ -47,14 +58,14 @@ EOH; // ------------------------------------------------------------------------ - public function testNBS() + public function test_NBS() { $this->assertEquals('   ', nbs(3)); } // ------------------------------------------------------------------------ - public function testMeta() + public function test_meta() { $this->assertEquals("\n", meta('test', 'foo')); diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index e59875e4a..34bc34ebb 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -5,7 +5,7 @@ require_once(BASEPATH.'helpers/inflector_helper.php'); class Inflector_helper_test extends CI_TestCase { - public function testSingular() + public function test_singular() { $strs = array( 'tellies' => 'telly', @@ -22,7 +22,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testPlural() + public function test_plural() { $strs = array( 'telly' => 'tellies', @@ -40,7 +40,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testCamelize() + public function test_camelize() { $strs = array( 'this is the string' => 'thisIsTheString', @@ -57,7 +57,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testUnderscore() + public function test_underscore() { $strs = array( 'this is the string' => 'this_is_the_string', @@ -74,7 +74,7 @@ class Inflector_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function testHumanize() + public function test_humanize() { $strs = array( 'this_is_the_string' => 'This Is The String', diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php new file mode 100644 index 000000000..02fc49c3d --- /dev/null +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -0,0 +1,13 @@ +assertEquals('456 Bytes', byte_format(456)); + } + +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 00ba5dec7..5e0ee45de 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -4,7 +4,7 @@ require_once(BASEPATH.'helpers/string_helper.php'); class String_helper_test extends CI_TestCase { - public function testTrimSlashes() + public function test_trim_slashes() { $strs = array( '//Slashes//\/' => 'Slashes//\\', @@ -17,16 +17,9 @@ class String_helper_test extends CI_TestCase } } - // -------------------------------------------------------------------- - - public function testStripSlashes() - { - $this->assertEquals("This is totally foo bar'd", trim_slashes("This is totally foo bar'd")); - } - // -------------------------------------------------------------------- - public function testStripQuotes() + public function test_strip_quotes() { $strs = array( '"me oh my!"' => 'me oh my!', @@ -41,7 +34,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testQuotesToEntities() + public function test_quotes_to_entities() { $strs = array( '"me oh my!"' => '"me oh my!"', @@ -56,7 +49,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testReduceDoubleSlashes() + public function test_reduce_double_slashes() { $strs = array( 'http://codeigniter.com' => 'http://codeigniter.com', @@ -72,7 +65,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testReduceMultiples() + public function test_reduce_multiples() { $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', @@ -97,7 +90,7 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- - public function testRepeater() + public function test_repeater() { $strs = array( 'a' => 'aaaaaaaaaa', @@ -114,4 +107,12 @@ class String_helper_test extends CI_TestCase // -------------------------------------------------------------------- + + public function test_random_string() + { + $this->assertEquals(16, strlen(random_string('alnum', 16))); + $this->assertEquals(32, strlen(random_string('unique', 16))); + $this->assertInternalType('string', random_string('numeric', 16)); + } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 22c834bcf..a0866e638 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -6,14 +6,14 @@ class Text_helper_test extends CI_TestCase { private $_long_string; - public function setUp() + public function set_up() { $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } // ------------------------------------------------------------------------ - public function testWordLimiter() + public function test_word_limiter() { $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); @@ -22,7 +22,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testCharacterLimiter() + public function test_character_limiter() { $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); @@ -32,7 +32,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testAsciiToEntities() + public function test_ascii_to_entities() { $strs = array( '“‘ “test”' => '“‘ “test”', @@ -47,7 +47,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testEntitiesToAscii() + public function test_entities_to_ascii() { $strs = array( '“‘ “test”' => '“‘ “test”', @@ -59,10 +59,18 @@ class Text_helper_test extends CI_TestCase $this->assertEquals($expect, entities_to_ascii($str)); } } + + // ------------------------------------------------------------------------ + + function test_convert_accented_characters() + { + $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); + $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); + } // ------------------------------------------------------------------------ - public function testCensoredWords() + public function test_censored_words() { $censored = array('boob', 'nerd', 'ass', 'fart'); @@ -86,7 +94,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testHighlightCode() + public function test_highlight_code() { $code = ''; $expect = "\n<?php var_dump(\$this); ?> \n\n"; @@ -96,7 +104,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testHighlightPhrase() + public function test_highlight_phrase() { $strs = array( 'this is a phrase' => 'this is a phrase', @@ -114,7 +122,7 @@ class Text_helper_test extends CI_TestCase // ------------------------------------------------------------------------ - public function testEllipsizing() + public function test_ellipsizing() { $strs = array( '0' => array( diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php new file mode 100644 index 000000000..49f49e166 --- /dev/null +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -0,0 +1,13 @@ +assertEquals('<tag>my & test - </tag>', xml_convert('my & test - ')); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d92277d650139af381a856cfa8f23a42b8ce04cb Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Fri, 22 Apr 2011 12:56:22 -0500 Subject: Initial commit of file helper tests. --- tests/codeigniter/helpers/file_helper_test.php | 157 +++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 tests/codeigniter/helpers/file_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php new file mode 100644 index 000000000..a596a0375 --- /dev/null +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -0,0 +1,157 @@ +_test_dir = vfsStreamWrapper::getRoot(); + } + + // -------------------------------------------------------------------- + + public function test_read_file() + { + $this->assertFalse(read_file('does_not_exist')); + + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt')->withContent($content) + ->at($this->_test_dir); + + $this->assertEquals($content, read_file(vfsStream::url('my_file.txt'))); + } + + // -------------------------------------------------------------------- + + public function test_octal_permissions() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('777', octal_permissions($file->getPermissions())); + } + + // -------------------------------------------------------------------- + + /** + * More tests should happen here, since I'm not hitting the whole function. + */ + public function test_symbolic_permissions() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); + } + + // -------------------------------------------------------------------- + + public function test_get_mime_by_extension() + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('text/plain', + get_mime_by_extension(vfsStream::url('my_file.txt'))); + + // Test a mime with an array, such as png + $file = vfsStream::newFile('foo.png')->at($this->_test_dir); + + $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); + + // Test a file not in the mimes array + $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir); + + $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar'))); + } + + // -------------------------------------------------------------------- + + public function test_get_file_info() + { + // Test Bad File + $this->assertFalse(get_file_info('i_am_bad_boo')); + + // Test the rest + + // First pass in an array + $vals = array( + 'name', 'server_path', 'size', 'date', + 'readable', 'writable', 'executable', 'fileperms' + ); + + $this->_test_get_file_info($vals); + + // Test passing in vals as a string. + $vals = 'name, server_path, size, date, readable, writable, executable, fileperms'; + $this->_test_get_file_info($vals); + } + + private function _test_get_file_info($vals) + { + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + $last_modified = time() - 86400; + + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) + ->lastModified($last_modified) + ->at($this->_test_dir); + + $ret_values = array( + 'name' => 'my_file.txt', + 'server_path' => 'vfs://my_file.txt', + 'size' => 57, + 'date' => $last_modified, + 'readable' => TRUE, + 'writable' => TRUE, + 'executable' => TRUE, + 'fileperms' => 33279 + ); + + $info = get_file_info(vfsStream::url('my_file.txt'), $vals); + + foreach ($info as $k => $v) + { + $this->assertEquals($ret_values[$k], $v); + } + } + + // -------------------------------------------------------------------- + + // Skipping for now, as it's not implemented in vfsStreamWrapper + // flock(): vfsStreamWrapper::stream_lock is not implemented! + + // public function test_write_file() + // { + // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) + // { + // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); + // } + // + // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + // + // $file = vfsStream::newFile('write.txt', 0777)->withContent('') + // ->lastModified(time() - 86400) + // ->at($this->_test_dir); + // + // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); + // + // } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 19379ef47a6bc0a788c65038bb59eca0b6624848 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 3 May 2011 22:16:11 -0400 Subject: Added unit tests for number helper. --- tests/codeigniter/helpers/number_helper_test.php | 71 +++++++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 02fc49c3d..3322b2475 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,13 +1,78 @@ ci_core_class('lang'); + + // Mock away load, too much going on in there, + // we'll just check for the expected parameter + + $lang = $this->getMock($lang_cls, array('load')); + $lang->expects($this->once()) + ->method('load') + ->with($this->equalTo('number')); + + // Assign the proper language array + + $lang->language = $this->_get_lang('number'); + + // We don't have a controller, so just create + // a cheap class to act as our super object. + // Make sure it has a lang attribute. + + $obj = new StdClass; + $obj->lang = $lang; + $this->ci_instance($obj); + } + + // Quick helper to actually grab the language + // file. Consider moving this to ci_testcase? + public function _get_lang($name) + { + require BASEPATH.'language/english/'.$name.'_lang.php'; + return $lang; + } + public function test_byte_format() { - // $this->assertEquals('456 Bytes', byte_format(456)); + $this->assertEquals('456 Bytes', byte_format(456)); + } + + public function test_kb_format() + { + $this->assertEquals('4.5 KB', byte_format(4567)); + } + + public function test_kb_format_medium() + { + $this->assertEquals('44.6 KB', byte_format(45678)); } -} \ No newline at end of file + public function test_kb_format_large() + { + $this->assertEquals('446.1 KB', byte_format(456789)); + } + + public function test_mb_format() + { + $this->assertEquals('3.3 MB', byte_format(3456789)); + } + + public function test_gb_format() + { + $this->assertEquals('1.8 GB', byte_format(1932735283.2)); + } + + public function test_tb_format() + { + $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); + } +} + +// EOF \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5d1e32b2fbae74e6f9e1ab2bdb6a3635579ef13e Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 3 May 2011 22:28:59 -0400 Subject: Added unit tests for date helper. --- tests/codeigniter/helpers/date_helper_test.php | 240 +++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 tests/codeigniter/helpers/date_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php new file mode 100644 index 000000000..f6048c324 --- /dev/null +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -0,0 +1,240 @@ +markTestIncomplete('not implemented yet'); + } + + // ------------------------------------------------------------------------ + + public function test_mdate() + { + $time = time(); + $expected = date("Y-m-d - h:i a", $time); + $test = mdate("%Y-%m-%d - %h:%i %a", $time); + $this->assertEquals($expected, $test); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc822() + { + $time = time(); + $format = 'DATE_RFC822'; + $expected = date("D, d F y G:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_atom() + { + $time = time(); + $format = 'DATE_ATOM'; + $expected = date("Y-m-d\TH:i:sO", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_cookie() + { + $time = time(); + $format = 'DATE_COOKIE'; + $expected = date("l, d-M-y H:i:s \U\T\C", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_iso8601() + { + $time = time(); + $format = 'DATE_ISO8601'; + $expected = date("Y-m-d\TH:i:sO", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc850() + { + $time = time(); + $format = 'DATE_RFC850'; + $expected = date("l, d-M-y H:i:s \U\T\C", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc1036() + { + $time = time(); + $format = 'DATE_RFC1036'; + $expected = date("D, d M y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc1123() + { + $time = time(); + $format = 'DATE_RFC1123'; + $expected = date("D, d M Y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rfc2822() + { + $time = time(); + $format = 'DATE_RFC2822'; + $expected = date("D, d M Y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_rss() + { + $time = time(); + $format = 'DATE_RSS'; + $expected = date("D, d M Y H:i:s O", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_standard_date_w3c() + { + $time = time(); + $format = 'DATE_W3C'; + $expected = date("Y-m-d\TH:i:sO", $time); + $this->assertEquals($expected, standard_date($format, $time)); + } + + // ------------------------------------------------------------------------ + + public function test_timespan() + { + $this->markTestIncomplete('not implemented yet'); + } + + // ------------------------------------------------------------------------ + + public function test_days_in_month() + { + $this->assertEquals(30, days_in_month(06, 2005)); + $this->assertEquals(28, days_in_month(02, 2011)); + $this->assertEquals(29, days_in_month(02, 2012)); + } + + // ------------------------------------------------------------------------ + + public function test_local_to_gmt() + { + $this->markTestIncomplete('not implemented yet'); + } + + // ------------------------------------------------------------------------ + + public function test_gmt_to_local() + { + $timestamp = '1140153693'; + $timezone = 'UM8'; + $daylight_saving = TRUE; + + $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving)); + } + + // ------------------------------------------------------------------------ + + public function test_mysql_to_unix() + { + $this->assertEquals(1164378225, mysql_to_unix(20061124092345)); + } + + // ------------------------------------------------------------------------ + + public function test_unix_to_human() + { + $time = time(); + $this->assertEquals(date("Y-m-d h:i A"), unix_to_human($time)); + $this->assertEquals(date("Y-m-d h:i:s A"), unix_to_human($time, TRUE, 'us')); + $this->assertEquals(date("Y-m-d H:i:s"), unix_to_human($time, TRUE, 'eu')); + } + + // ------------------------------------------------------------------------ + + public function test_human_to_unix() + { + $time = time(); + $this->markTestIncomplete('Failed Test'); + // $this->assertEquals($time, human_to_unix(unix_to_human($time))); + } + + // ------------------------------------------------------------------------ + + public function test_timezones() + { + $zones = array( + 'UM12' => -12, + 'UM11' => -11, + 'UM10' => -10, + 'UM95' => -9.5, + 'UM9' => -9, + 'UM8' => -8, + 'UM7' => -7, + 'UM6' => -6, + 'UM5' => -5, + 'UM45' => -4.5, + 'UM4' => -4, + 'UM35' => -3.5, + 'UM3' => -3, + 'UM2' => -2, + 'UM1' => -1, + 'UTC' => 0, + 'UP1' => +1, + 'UP2' => +2, + 'UP3' => +3, + 'UP35' => +3.5, + 'UP4' => +4, + 'UP45' => +4.5, + 'UP5' => +5, + 'UP55' => +5.5, + 'UP575' => +5.75, + 'UP6' => +6, + 'UP65' => +6.5, + 'UP7' => +7, + 'UP8' => +8, + 'UP875' => +8.75, + 'UP9' => +9, + 'UP95' => +9.5, + 'UP10' => +10, + 'UP105' => +10.5, + 'UP11' => +11, + 'UP115' => +11.5, + 'UP12' => +12, + 'UP1275' => +12.75, + 'UP13' => +13, + 'UP14' => +14 + ); + + foreach ($zones AS $test => $expected) + { + $this->assertEquals($expected, timezones($test)); + } + + $this->assertArrayHasKey('UP3', timezones()); + $this->assertEquals(0, timezones('non_existant')); + } +} + +/* End of file date_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 71644d683d0a15a6f7e04fabd0f51a4200d620b4 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Tue, 12 Jul 2011 21:45:40 -0400 Subject: Fixed some small issues in the date tests. --- tests/codeigniter/helpers/date_helper_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index f6048c324..63cf30bbe 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -26,7 +26,7 @@ class Date_helper_test extends CI_TestCase { $time = time(); $format = 'DATE_RFC822'; - $expected = date("D, d F y G:i:s O", $time); + $expected = date("D, d M y H:i:s O", $time); $this->assertEquals($expected, standard_date($format, $time)); } @@ -158,7 +158,7 @@ class Date_helper_test extends CI_TestCase public function test_mysql_to_unix() { - $this->assertEquals(1164378225, mysql_to_unix(20061124092345)); + $this->assertEquals(1344708680, mysql_to_unix(date("YYYY-MM-DD HH:MM:SS"))); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 92ff07ee199d17a4dccd84114da8b66a95a4f56d Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sat, 20 Aug 2011 16:57:48 -0500 Subject: Updating error in html_helper test_Ul --- tests/codeigniter/helpers/html_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 706874f9e..553fc2bb1 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -51,7 +51,7 @@ EOH; $list = array('foo', 'bar'); - $this->assertEquals($expect, ul($list, ' class="test"')); + $this->assertEquals($expect, ul($list, 'class="test"')); $this->assertEquals($expect, ul($list, array('class' => 'test'))); } -- cgit v1.2.3-24-g4f1b From 2e0f825c942e7e77a9aba451f3252762db0c86f5 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 21 Aug 2011 16:19:16 -0500 Subject: Fixing errors in date helper tests. --- tests/codeigniter/helpers/date_helper_test.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 63cf30bbe..c7a2c9b6e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -158,7 +158,9 @@ class Date_helper_test extends CI_TestCase public function test_mysql_to_unix() { - $this->assertEquals(1344708680, mysql_to_unix(date("YYYY-MM-DD HH:MM:SS"))); + $time = time(); + $this->assertEquals($time, + mysql_to_unix(date("Y-m-d H:i:s", $time))); } // ------------------------------------------------------------------------ @@ -166,9 +168,9 @@ class Date_helper_test extends CI_TestCase public function test_unix_to_human() { $time = time(); - $this->assertEquals(date("Y-m-d h:i A"), unix_to_human($time)); - $this->assertEquals(date("Y-m-d h:i:s A"), unix_to_human($time, TRUE, 'us')); - $this->assertEquals(date("Y-m-d H:i:s"), unix_to_human($time, TRUE, 'eu')); + $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time)); + $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us')); + $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu')); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From d031ef79248bef6e188b6726682aac12b2fb8ff6 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 21 Aug 2011 16:19:56 -0500 Subject: ignoring a test in the inflector test. --- tests/codeigniter/helpers/inflector_helper_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 34bc34ebb..ef1f54afc 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -24,6 +24,10 @@ class Inflector_helper_test extends CI_TestCase { public function test_plural() { + $this->markTestSkipped( + 'abjectness is breaking. SKipping for the time being.' + ); + $strs = array( 'telly' => 'tellies', 'smelly' => 'smellies', -- cgit v1.2.3-24-g4f1b From 2c4b36620828173f3caf83fc7f6146bccb3688f4 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 21 Aug 2011 16:28:06 -0500 Subject: Adding url_helper unit test file. GO! --- tests/codeigniter/helpers/url_helper_test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/codeigniter/helpers/url_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php new file mode 100644 index 000000000..ea3fb0e4f --- /dev/null +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -0,0 +1,22 @@ + 'foo-bar', + '\ testing 12' => 'testing-12' + ); + + foreach ($words as $in => $out) + { + $this->assertEquals($out, url_title($in, 'dash', TRUE)); + } + } + + // -------------------------------------------------------------------- + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 78ec0603601001b6f0b4d0c4ef6087d32a133a63 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:48:56 -0500 Subject: Added tests for new increment_string --- tests/codeigniter/helpers/string_helper_test.php | 65 ++++++++++++++---------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 5e0ee45de..2d7f96aa5 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -10,14 +10,14 @@ class String_helper_test extends CI_TestCase '//Slashes//\/' => 'Slashes//\\', '/var/www/html/' => 'var/www/html' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, trim_slashes($str)); } } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- public function test_strip_quotes() { @@ -25,30 +25,30 @@ class String_helper_test extends CI_TestCase '"me oh my!"' => 'me oh my!', "it's a winner!" => 'its a winner!', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, strip_quotes($str)); } } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_quotes_to_entities() { $strs = array( '"me oh my!"' => '"me oh my!"', "it's a winner!" => 'it's a winner!', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, quotes_to_entities($str)); - } + } } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_reduce_double_slashes() { $strs = array( @@ -56,57 +56,56 @@ class String_helper_test extends CI_TestCase '//var/www/html/example.com/' => '/var/www/html/example.com/', '/var/www/html//index.php' => '/var/www/html/index.php' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, reduce_double_slashes($str)); - } + } } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_reduce_multiples() { $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', 'Ringo, John, Paul,,' => 'Ringo, John, Paul,' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, reduce_multiples($str)); } - + $strs = array( 'Fred, Bill,, Joe, Jimmy' => 'Fred, Bill, Joe, Jimmy', 'Ringo, John, Paul,,' => 'Ringo, John, Paul' - ); + ); foreach ($strs as $str => $expect) { $this->assertEquals($expect, reduce_multiples($str, ',', TRUE)); - } + } } - - // -------------------------------------------------------------------- - + + // -------------------------------------------------------------------- + public function test_repeater() { $strs = array( 'a' => 'aaaaaaaaaa', ' ' => '          ', '
    ' => '









    ' - + ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, repeater($str, 10)); } - } - - // -------------------------------------------------------------------- + } + // -------------------------------------------------------------------- public function test_random_string() { @@ -114,5 +113,17 @@ class String_helper_test extends CI_TestCase $this->assertEquals(32, strlen(random_string('unique', 16))); $this->assertInternalType('string', random_string('numeric', 16)); } - + + // -------------------------------------------------------------------- + + public function test_increment_string() + { + $this->assertEquals('my-test_1', increment_string('my-test')); + $this->assertEquals('my-test-1', increment_string('my-test', '-')); + $this->assertEquals('file_5', increment_string('file_4')); + $this->assertEquals('file-5', increment_string('file-4', '-')); + $this->assertEquals('file-5', increment_string('file-4', '-')); + $this->assertEquals('file-1', increment_string('file', '-', '1')); + $this->assertEquals(124, increment_string('123', '')); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 940761464e6f7788bdce0bad55f41850ad73eb89 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 00:59:07 -0500 Subject: Added tests for removing extra dashes in url title. --- tests/codeigniter/helpers/url_helper_test.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index ea3fb0e4f..b5384eaef 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -10,13 +10,25 @@ class Url_helper_test extends CI_TestCase 'foo bar /' => 'foo-bar', '\ testing 12' => 'testing-12' ); - + foreach ($words as $in => $out) { $this->assertEquals($out, url_title($in, 'dash', TRUE)); - } + } } // -------------------------------------------------------------------- + public function test_url_title_extra_dashes() + { + $words = array( + '_foo bar_' => 'foo_bar', + '_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS' + ); + + foreach ($words as $in => $out) + { + $this->assertEquals($out, url_title($in, 'underscore')); + } + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 32b6780d6e75a39e62784cec998ee2b5f69ee77e Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 01:10:09 -0500 Subject: Added prep_url and auto_link tests --- tests/codeigniter/helpers/url_helper_test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index b5384eaef..30ba4a417 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -31,4 +31,27 @@ class Url_helper_test extends CI_TestCase $this->assertEquals($out, url_title($in, 'underscore')); } } + + // -------------------------------------------------------------------- + + public function test_prep_url() + { + $this->assertEquals('http://codeigniter.com', prep_url('codeigniter.com')); + $this->assertEquals('http://www.codeigniter.com', prep_url('www.codeigniter.com')); + } + + // -------------------------------------------------------------------- + + public function test_auto_link_url() + { + $strings = array( + 'www.codeigniter.com test' => 'http://www.codeigniter.com test', + 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', + ); + + foreach ($strings as $in => $out) + { + $this->assertEquals($out, auto_link($in, 'url')); + } + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d90e1a0fb541ee94459a20cf8b0726aebaec9692 Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 27 Nov 2011 14:12:46 -0500 Subject: Added unit test to confirm pull request #675 --- tests/codeigniter/helpers/url_helper_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 30ba4a417..51a8cc7c0 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -47,6 +47,21 @@ class Url_helper_test extends CI_TestCase $strings = array( 'www.codeigniter.com test' => 'http://www.codeigniter.com test', 'This is my noreply@codeigniter.com test' => 'This is my noreply@codeigniter.com test', + '
    www.google.com' => '
    http://www.google.com', + ); + + foreach ($strings as $in => $out) + { + $this->assertEquals($out, auto_link($in, 'url')); + } + } + + // -------------------------------------------------------------------- + + public function test_pull_675() + { + $strings = array( + '
    www.google.com' => '
    http://www.google.com', ); foreach ($strings as $in => $out) -- cgit v1.2.3-24-g4f1b From 8749bc7e836c196dfef37d3b7b5a67736a15092c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 11 Mar 2012 05:43:45 +0700 Subject: Fix incomplete and skipped test --- tests/codeigniter/helpers/date_helper_test.php | 56 +++++++++++++++++++--- .../codeigniter/helpers/inflector_helper_test.php | 6 +-- 2 files changed, 50 insertions(+), 12 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index c7a2c9b6e..662d16485 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -5,9 +5,39 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_now() + public function test_now_local() { - $this->markTestIncomplete('not implemented yet'); + // This stub job, is simply to cater $config['time_reference'] + $config = $this->getMock('CI_Config'); + $config->expects($this->any()) + ->method('item') + ->will($this->returnValue('local')); + + // Add the stub to our test instance + $this->ci_instance_var('config', $config); + + $expected = time(); + $test = now(); + $this->assertEquals($expected, $test); + } + + // ------------------------------------------------------------------------ + + public function test_now_gmt() + { + // This stub job, is simply to cater $config['time_reference'] + $config = $this->getMock('CI_Config'); + $config->expects($this->any()) + ->method('item') + ->will($this->returnValue('gmt')); + + // Add the stub to our stdClass + $this->ci_instance_var('config', $config); + + $t = time(); + $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); + $test = now(); + $this->assertEquals($expected, $test); } // ------------------------------------------------------------------------ @@ -124,7 +154,16 @@ class Date_helper_test extends CI_TestCase public function test_timespan() { - $this->markTestIncomplete('not implemented yet'); + $loader_cls = $this->ci_core_class('load'); + $this->ci_instance_var('load', new $loader_cls); + + $lang_cls = $this->ci_core_class('lang'); + $this->ci_instance_var('lang', new $lang_cls); + + $this->assertEquals('1 Second', timespan(time(), time()+1)); + $this->assertEquals('1 Minute', timespan(time(), time()+60)); + $this->assertEquals('1 Hour', timespan(time(), time()+3600)); + $this->assertEquals('2 Hours', timespan(time(), time()+7200)); } // ------------------------------------------------------------------------ @@ -140,7 +179,9 @@ class Date_helper_test extends CI_TestCase public function test_local_to_gmt() { - $this->markTestIncomplete('not implemented yet'); + $t = time(); + $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); + $this->assertEquals($expected, local_to_gmt($t)); } // ------------------------------------------------------------------------ @@ -177,9 +218,10 @@ class Date_helper_test extends CI_TestCase public function test_human_to_unix() { - $time = time(); - $this->markTestIncomplete('Failed Test'); - // $this->assertEquals($time, human_to_unix(unix_to_human($time))); + $date = '2000-12-31 10:00:00 PM'; + $expected = strtotime($date); + $this->assertEquals($expected, human_to_unix($date)); + $this->assertFalse(human_to_unix()); } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index ef1f54afc..e476f6dc8 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -24,14 +24,10 @@ class Inflector_helper_test extends CI_TestCase { public function test_plural() { - $this->markTestSkipped( - 'abjectness is breaking. SKipping for the time being.' - ); - $strs = array( 'telly' => 'tellies', 'smelly' => 'smellies', - 'abjectness' => 'abjectness', + 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses 'smell' => 'smells', 'witch' => 'witches' ); -- cgit v1.2.3-24-g4f1b From 575895f66884904617fcdd60e9db894ca1786ca9 Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Sun, 11 Mar 2012 11:58:31 +0400 Subject: Add unit tests for directory helper --- .../codeigniter/helpers/directory_helper_test.php | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/codeigniter/helpers/directory_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php new file mode 100644 index 000000000..3fae81b82 --- /dev/null +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -0,0 +1,42 @@ +_test_dir = vfsStreamWrapper::getRoot(); + } + + public function test_directory_map() + { + $structure = array('libraries' => array('benchmark.html' => '', 'database' => + array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '.hiddenfile.txt' => '')); + + vfsStream::create($structure, $this->_test_dir); + + // test default recursive behavior + $expected = array('libraries' => array('benchmark.html', 'database' => + array('active_record.html', 'binds.html'), 'email.html')); + + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); + + // test recursion depth behavior + $expected = array('libraries'); + + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1)); + + // test detection of hidden files + $expected = array('libraries' => array('benchmark.html', 'database' => + array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt')); + + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE)); + } +} + +/* End of file directory_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 756516dac202e376cd16c4dbc11a1292f8cca4e6 Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Mon, 12 Mar 2012 09:47:34 +0400 Subject: Add unit tests for path helper --- tests/codeigniter/helpers/path_helper_test.php | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/codeigniter/helpers/path_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php new file mode 100644 index 000000000..591214bde --- /dev/null +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -0,0 +1,29 @@ +assertEquals($expected, set_realpath(getcwd())); + } + + public function test_set_realpath_nonexistent_directory() + { + $expected = '/path/to/nowhere'; + $this->assertEquals($expected, set_realpath('/path/to/nowhere', FALSE)); + } + + public function test_set_realpath_error_trigger() + { + $this->setExpectedException( + 'RuntimeException', 'CI Error: Not a valid path: /path/to/nowhere' + ); + + set_realpath('/path/to/nowhere', TRUE); + } +} + +/* End of file path_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3ec336fc6020e3126b8be7d2b3516b4e40abd87d Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Wed, 14 Mar 2012 13:50:23 +0400 Subject: Add fix for Windows OS --- tests/codeigniter/helpers/path_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 591214bde..2e6cc6391 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -6,7 +6,7 @@ class Path_helper_test extends CI_TestCase { public function test_set_realpath() { - $expected = getcwd() . '/'; + $expected = getcwd() . DIRECTORY_SEPARATOR; $this->assertEquals($expected, set_realpath(getcwd())); } -- cgit v1.2.3-24-g4f1b From 2a6a6162ff6de8c2114c50254a5046ee6822c5dc Mon Sep 17 00:00:00 2001 From: Hamza Bhatti Date: Thu, 15 Mar 2012 09:45:29 +0400 Subject: Change unit tests to provide one hundred percent code coverage - Add value to test is_countable() conditional in test_singular() - Add value to test is_countable() conditional in test_plural() --- tests/codeigniter/helpers/inflector_helper_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index e476f6dc8..472e28adb 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -11,7 +11,8 @@ class Inflector_helper_test extends CI_TestCase { 'tellies' => 'telly', 'smellies' => 'smelly', 'abjectnesses' => 'abjectness', - 'smells' => 'smell' + 'smells' => 'smell', + 'equipment' => 'equipment' ); foreach ($strs as $str => $expect) @@ -29,7 +30,8 @@ class Inflector_helper_test extends CI_TestCase { 'smelly' => 'smellies', 'abjectness' => 'abjectnesses', // ref : http://en.wiktionary.org/wiki/abjectnesses 'smell' => 'smells', - 'witch' => 'witches' + 'witch' => 'witches', + 'equipment' => 'equipment' ); foreach ($strs as $str => $expect) -- cgit v1.2.3-24-g4f1b From 3fb5aa5886de15ef68e40b556a6ea3f1badf962e Mon Sep 17 00:00:00 2001 From: tiyowan Date: Fri, 16 Mar 2012 19:08:34 +0400 Subject: Add unit test for strip_slashes() in string_helper.php --- tests/codeigniter/helpers/string_helper_test.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 2d7f96aa5..a884d6284 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -4,6 +4,21 @@ require_once(BASEPATH.'helpers/string_helper.php'); class String_helper_test extends CI_TestCase { + public function test_strip_slashes() + { + $expected = array( + "Is your name O'reilly?", + "No, my name is O'connor." + ); + + $str = array( + "Is your name O\'reilly?", + "No, my name is O\'connor." + ); + + $this->assertEquals($expected, strip_slashes($str)); + } + public function test_trim_slashes() { $strs = array( -- cgit v1.2.3-24-g4f1b From a83f063c2cebd50515b99e6ccab5afab4c958c06 Mon Sep 17 00:00:00 2001 From: tiyowan Date: Fri, 16 Mar 2012 23:52:43 +0400 Subject: Add unit tests for form_helper.php * Does not test form_open() and form_open_multipart() * Does not test set_value(), set_select(), set_checkbox() and set_radio() * Above are in progress and will be added once certain issues are resolved --- tests/codeigniter/helpers/form_helper_test.php | 252 +++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/codeigniter/helpers/form_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php new file mode 100644 index 000000000..80bace9d1 --- /dev/null +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -0,0 +1,252 @@ + + +EOH; + + $this->assertEquals($expected, form_hidden('username', 'johndoe')); + } + + public function test_form_input() + { + $expected = << + +EOH; + + $data = array( + 'name' => 'username', + 'id' => 'username', + 'value' => 'johndoe', + 'maxlength' => '100', + 'size' => '50', + 'style' => 'width:50%', + ); + + $this->assertEquals($expected, form_input($data)); + } + + public function test_form_password() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_password('password')); + } + + public function test_form_upload() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_upload('attachment')); + } + + public function test_form_textarea() + { + $expected = <<Notes + +EOH; + + $this->assertEquals($expected, form_textarea('notes', 'Notes')); + } + + public function test_form_dropdown() + { + $expected = << + + + + + + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); + + $expected = << + + + + + + +EOH; + + $shirts_on_sale = array('small', 'large'); + + $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); + + $options = array( + 'Swedish Cars' => array( + 'volvo' => 'Volvo', + 'saab' => 'Saab' + ), + 'German Cars' => array( + 'mercedes' => 'Mercedes', + 'audi' => 'Audi' + ) + ); + + $expected = << + + + + + + + + + + +EOH; + + $cars_on_sale = array('volvo', 'audi'); + + $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale)); + + } + + public function test_form_multiselect() + { + $expected = << + + + + + + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); + } + + public function test_form_fieldset() + { + $expected = << +Address Information + +EOH; + + $this->assertEquals($expected, form_fieldset('Address Information')); + } + + public function test_form_fieldset_close() + { + $expected = << +EOH; + + $this->assertEquals($expected, form_fieldset_close('')); + } + + public function test_form_checkbox() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); + } + + public function test_form_radio() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); + } + + public function test_form_submit() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); + } + + public function test_form_label() + { + $expected = <<What is your Name +EOH; + + $this->assertEquals($expected, form_label('What is your Name', 'username')); + } + + public function test_form_reset() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_reset('myreset', 'Reset')); + } + + public function test_form_button() + { + $expected = <<content + +EOH; + + $this->assertEquals($expected, form_button('name','content')); + } + + public function test_form_close() + { + $expected = << +EOH; + + $this->assertEquals($expected, form_close('')); + } + + public function test_form_prep() + { + $expected = "Here is a string containing "quoted" text."; + + $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); + } +} + +/* End of file form_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e1dc9ea4fcfd4983fa076b70fe631166a95d0b68 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:49:49 +0700 Subject: Remove include or require declaration from all helpers test --- tests/codeigniter/helpers/array_helper_test.php | 10 ++++------ tests/codeigniter/helpers/date_helper_test.php | 10 +++++++--- tests/codeigniter/helpers/directory_helper_test.php | 9 ++++----- tests/codeigniter/helpers/email_helper_test.php | 10 ++++++---- tests/codeigniter/helpers/file_helper_test.php | 7 +++---- tests/codeigniter/helpers/html_helper_test.php | 8 +++++--- tests/codeigniter/helpers/inflector_helper_test.php | 6 ++++-- tests/codeigniter/helpers/number_helper_test.php | 7 +++---- tests/codeigniter/helpers/path_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/string_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/text_helper_test.php | 6 +++--- tests/codeigniter/helpers/url_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/xml_helper_test.php | 8 +++++--- 13 files changed, 62 insertions(+), 46 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 62559de83..9cd15960f 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -1,13 +1,11 @@ helper('array'); + $this->my_array = array( 'foo' => 'bar', 'sally' => 'jim', diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 662d16485..17d1ef21e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -1,8 +1,12 @@ helper('date'); + } + // ------------------------------------------------------------------------ public function test_now_local() diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 3fae81b82..3937d2913 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -1,12 +1,11 @@ helper('directory'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index 7324e8109..a01f3d5af 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -1,10 +1,12 @@ helper('email'); + } -class Email_helper_test extends CI_TestCase -{ - public function test_valid_email() { $this->assertEquals(FALSE, valid_email('test')); diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index a596a0375..4b9c29485 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -1,12 +1,11 @@ helper('file'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 553fc2bb1..28974b0f8 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -1,9 +1,11 @@ helper('html'); + } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 472e28adb..9e9478711 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -1,9 +1,11 @@ helper('inflector'); + } public function test_singular() { diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 3322b2475..4bb9a918a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,12 +1,11 @@ helper('number'); + // Grab the core lang class $lang_cls = $this->ci_core_class('lang'); diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 2e6cc6391..632f57501 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -1,9 +1,12 @@ helper('path'); + } -class Path_helper_test extends CI_TestCase -{ public function test_set_realpath() { $expected = getcwd() . DIRECTORY_SEPARATOR; diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index a884d6284..29c3d6594 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -1,9 +1,12 @@ helper('string'); + } -class String_helper_test extends CI_TestCase -{ public function test_strip_slashes() { $expected = array( diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a0866e638..584066b0c 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -1,13 +1,13 @@ helper('text'); + $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 51a8cc7c0..c561809ce 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -1,9 +1,12 @@ helper('url'); + } -class Url_helper_test extends CI_TestCase -{ public function test_url_title() { $words = array( diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php index 49f49e166..a83fef91e 100644 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -1,9 +1,11 @@ helper('xml'); + } public function test_xml_convert() { -- cgit v1.2.3-24-g4f1b From 5ace440aa4dbd948191c37b67b01871b3a7593e9 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:52:15 +0200 Subject: change ellipsizing to ellipsize --- tests/codeigniter/helpers/text_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 584066b0c..a83c7e74d 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -122,7 +122,7 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_ellipsizing() + public function test_ellipsize() { $strs = array( '0' => array( -- cgit v1.2.3-24-g4f1b From 0ef92f6fa4a40d4a689eee3ebd7eb7d632fe29c0 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:12:37 +0200 Subject: test for word_wrap() --- tests/codeigniter/helpers/text_helper_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a83c7e74d..974247c4f 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -156,4 +156,12 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ + public function test_word_wrap() + { + $string = "Here is a simple string of text that will help us demonstrate this function."; + $word_wraped = word_wrap($string, 25); + preg_match_all("/\r\n|\n/", $word_wraped, $matches); + $this->assertEquals(count($matches[0]), 4); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4221b980b66bbaebc23a0f9cc5dee7d649948e15 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:38:35 +0200 Subject: add test for word_wrap default charlim --- tests/codeigniter/helpers/text_helper_test.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 974247c4f..d59b2743d 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -160,8 +160,17 @@ class Text_helper_test extends CI_TestCase { { $string = "Here is a simple string of text that will help us demonstrate this function."; $word_wraped = word_wrap($string, 25); - preg_match_all("/\r\n|\n/", $word_wraped, $matches); - $this->assertEquals(count($matches[0]), 4); + $this->assertEquals(substr_count($word_wraped, "\n"), 4); + } + + // ------------------------------------------------------------------------ + + public function test_default_word_wrap_charlim() + { + $string = "Here is a simple string of text that will help us demonstrate this function."; + $word_wraped = word_wrap($string); + $matches = preg_split("/\n/", $word_wraped, 1); + $this->assertEquals(strlen($matches[0]) - 1, 76); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From bfaf50258b6f33961210ecc3df4ade2e0a4512b4 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:39:45 +0200 Subject: typo word_wraped -> word_wrapped --- tests/codeigniter/helpers/text_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index d59b2743d..3bc83f050 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -159,8 +159,8 @@ class Text_helper_test extends CI_TestCase { public function test_word_wrap() { $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wraped = word_wrap($string, 25); - $this->assertEquals(substr_count($word_wraped, "\n"), 4); + $word_wrapped = word_wrap($string, 25); + $this->assertEquals(substr_count($word_wrapped, "\n"), 4); } // ------------------------------------------------------------------------ @@ -168,8 +168,8 @@ class Text_helper_test extends CI_TestCase { public function test_default_word_wrap_charlim() { $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wraped = word_wrap($string); - $matches = preg_split("/\n/", $word_wraped, 1); + $word_wrapped = word_wrap($string); + $matches = preg_split("/\n/", $word_wrapped, 1); $this->assertEquals(strlen($matches[0]) - 1, 76); } -- cgit v1.2.3-24-g4f1b From 385452c2ca1f9ce00668ca6d77c6fd0ad1ea4771 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:43:18 +0200 Subject: correction of the test and longer test string --- tests/codeigniter/helpers/text_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 3bc83f050..3c590538a 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -167,10 +167,10 @@ class Text_helper_test extends CI_TestCase { public function test_default_word_wrap_charlim() { - $string = "Here is a simple string of text that will help us demonstrate this function."; + $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; $word_wrapped = word_wrap($string); - $matches = preg_split("/\n/", $word_wrapped, 1); - $this->assertEquals(strlen($matches[0]) - 1, 76); + $matches = preg_split("/\n/", $word_wrapped, 0); + $this->assertEquals(strlen($matches[0]), 73); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4215ddccd369ae8894c1031b97a344ae76eef5f6 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:58:28 +0200 Subject: remove regex in favor of strpos --- tests/codeigniter/helpers/text_helper_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 3c590538a..73e2b9429 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -169,8 +169,7 @@ class Text_helper_test extends CI_TestCase { { $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; $word_wrapped = word_wrap($string); - $matches = preg_split("/\n/", $word_wrapped, 0); - $this->assertEquals(strlen($matches[0]), 73); + $this->assertEquals(strpos($word_wrapped, "\n"), 73); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1b60fda70ff1e1801c133575c530ef0a5a450029 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 21:07:40 +0300 Subject: Modified date helper tests for better accuracy --- tests/codeigniter/helpers/date_helper_test.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 17d1ef21e..df03fe32c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -16,13 +16,11 @@ class Date_helper_test extends CI_TestCase { $config->expects($this->any()) ->method('item') ->will($this->returnValue('local')); - + // Add the stub to our test instance $this->ci_instance_var('config', $config); - $expected = time(); - $test = now(); - $this->assertEquals($expected, $test); + $this->assertEquals(time(), now()); } // ------------------------------------------------------------------------ @@ -34,7 +32,7 @@ class Date_helper_test extends CI_TestCase { $config->expects($this->any()) ->method('item') ->will($this->returnValue('gmt')); - + // Add the stub to our stdClass $this->ci_instance_var('config', $config); @@ -204,8 +202,7 @@ class Date_helper_test extends CI_TestCase { public function test_mysql_to_unix() { $time = time(); - $this->assertEquals($time, - mysql_to_unix(date("Y-m-d H:i:s", $time))); + $this->assertEquals($time, mysql_to_unix(date("Y-m-d H:i:s", $time))); } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 99b782d8a3d92c4703a059cbd62e2f1e6fea689c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 22:24:46 +0300 Subject: Cleanup and optimize helper tests for speed --- tests/codeigniter/helpers/array_helper_test.php | 22 ++-- tests/codeigniter/helpers/date_helper_test.php | 127 +++++++++--------- .../codeigniter/helpers/directory_helper_test.php | 47 ++++--- tests/codeigniter/helpers/email_helper_test.php | 2 +- tests/codeigniter/helpers/file_helper_test.php | 143 ++++++++++----------- tests/codeigniter/helpers/form_helper_test.php | 112 ++++++++-------- tests/codeigniter/helpers/html_helper_test.php | 28 ++-- .../codeigniter/helpers/inflector_helper_test.php | 31 ++--- tests/codeigniter/helpers/number_helper_test.php | 35 +++-- tests/codeigniter/helpers/path_helper_test.php | 5 +- tests/codeigniter/helpers/string_helper_test.php | 9 +- tests/codeigniter/helpers/text_helper_test.php | 70 +++++----- tests/codeigniter/helpers/url_helper_test.php | 1 + tests/codeigniter/helpers/xml_helper_test.php | 4 +- 14 files changed, 317 insertions(+), 319 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 9cd15960f..ba46e86f9 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -1,7 +1,7 @@ helper('array'); @@ -13,31 +13,31 @@ class Array_helper_test extends CI_TestCase { 'herb' => 'cook' ); } - + // ------------------------------------------------------------------------ - + public function test_element_with_existing_item() - { + { $this->assertEquals(FALSE, element('testing', $this->my_array)); - + $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); - + $this->assertEquals('bar', element('foo', $this->my_array)); } - - // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ public function test_random_element() { // Send a string, not an array to random_element $this->assertEquals('my string', random_element('my string')); - + // Test sending an array $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_elements() { $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index df03fe32c..4b747b864 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -5,6 +5,8 @@ class Date_helper_test extends CI_TestCase { public function set_up() { $this->helper('date'); + + $this->time = time(); } // ------------------------------------------------------------------------ @@ -37,119 +39,120 @@ class Date_helper_test extends CI_TestCase { $this->ci_instance_var('config', $config); $t = time(); - $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); - $test = now(); - $this->assertEquals($expected, $test); + $this->assertEquals( + mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), + now() + ); } // ------------------------------------------------------------------------ public function test_mdate() { - $time = time(); - $expected = date("Y-m-d - h:i a", $time); - $test = mdate("%Y-%m-%d - %h:%i %a", $time); - $this->assertEquals($expected, $test); + $this->assertEquals( + date('Y-m-d - h:i a', $this->time), + mdate('%Y-%m-%d - %h:%i %a', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc822() { - $time = time(); - $format = 'DATE_RFC822'; - $expected = date("D, d M y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M y H:i:s O', $this->time), + standard_date('DATE_RFC822', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_atom() { - $time = time(); - $format = 'DATE_ATOM'; - $expected = date("Y-m-d\TH:i:sO", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("Y-m-d\TH:i:sO", $this->time), + standard_date('DATE_ATOM', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_cookie() { - $time = time(); - $format = 'DATE_COOKIE'; - $expected = date("l, d-M-y H:i:s \U\T\C", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("l, d-M-y H:i:s \U\T\C", $this->time), + standard_date('DATE_COOKIE', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_iso8601() { - $time = time(); - $format = 'DATE_ISO8601'; - $expected = date("Y-m-d\TH:i:sO", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("Y-m-d\TH:i:sO", $this->time), + standard_date('DATE_ISO8601', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc850() { - $time = time(); - $format = 'DATE_RFC850'; - $expected = date("l, d-M-y H:i:s \U\T\C", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("l, d-M-y H:i:s \U\T\C", $this->time), + standard_date('DATE_RFC850', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc1036() { - $time = time(); - $format = 'DATE_RFC1036'; - $expected = date("D, d M y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M y H:i:s O', $this->time), + standard_date('DATE_RFC1036', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc1123() { - $time = time(); - $format = 'DATE_RFC1123'; - $expected = date("D, d M Y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M Y H:i:s O', $this->time), + standard_date('DATE_RFC1123', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rfc2822() { - $time = time(); - $format = 'DATE_RFC2822'; - $expected = date("D, d M Y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M Y H:i:s O', $this->time), + standard_date('DATE_RFC2822', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_rss() { - $time = time(); - $format = 'DATE_RSS'; - $expected = date("D, d M Y H:i:s O", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date('D, d M Y H:i:s O', $this->time), + standard_date('DATE_RSS', $this->time) + ); } // ------------------------------------------------------------------------ public function test_standard_date_w3c() { - $time = time(); - $format = 'DATE_W3C'; - $expected = date("Y-m-d\TH:i:sO", $time); - $this->assertEquals($expected, standard_date($format, $time)); + $this->assertEquals( + date("Y-m-d\TH:i:sO", $this->time), + standard_date('DATE_W3C', $this->time) + ); } // ------------------------------------------------------------------------ @@ -181,38 +184,36 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { - $t = time(); - $expected = mktime(gmdate("H", $t), gmdate("i", $t), gmdate("s", $t), gmdate("m", $t), gmdate("d", $t), gmdate("Y", $t)); - $this->assertEquals($expected, local_to_gmt($t)); + $this->assertEquals( + mktime( + gmdate('H', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), + gmdate('m', $this->time), gmdate('d', $this->time), gmdate('Y', $this->time) + ), + local_to_gmt($this->time) + ); } // ------------------------------------------------------------------------ public function test_gmt_to_local() { - $timestamp = '1140153693'; - $timezone = 'UM8'; - $daylight_saving = TRUE; - - $this->assertEquals(1140128493, gmt_to_local($timestamp, $timezone, $daylight_saving)); + $this->assertEquals(1140128493, gmt_to_local('1140153693', 'UM8', TRUE)); } // ------------------------------------------------------------------------ public function test_mysql_to_unix() { - $time = time(); - $this->assertEquals($time, mysql_to_unix(date("Y-m-d H:i:s", $time))); + $this->assertEquals($this->time, mysql_to_unix(date('Y-m-d H:i:s', $this->time))); } // ------------------------------------------------------------------------ public function test_unix_to_human() { - $time = time(); - $this->assertEquals(date("Y-m-d h:i A", $time), unix_to_human($time)); - $this->assertEquals(date("Y-m-d h:i:s A", $time), unix_to_human($time, TRUE, 'us')); - $this->assertEquals(date("Y-m-d H:i:s", $time), unix_to_human($time, TRUE, 'eu')); + $this->assertEquals(date('Y-m-d h:i A', $this->time), unix_to_human($this->time)); + $this->assertEquals(date('Y-m-d h:i:s A', $this->time), unix_to_human($this->time, TRUE, 'us')); + $this->assertEquals(date('Y-m-d H:i:s', $this->time), unix_to_human($this->time, TRUE, 'eu')); } // ------------------------------------------------------------------------ @@ -220,8 +221,7 @@ class Date_helper_test extends CI_TestCase { public function test_human_to_unix() { $date = '2000-12-31 10:00:00 PM'; - $expected = strtotime($date); - $this->assertEquals($expected, human_to_unix($date)); + $this->assertEquals(strtotime($date), human_to_unix($date)); $this->assertFalse(human_to_unix()); } @@ -280,6 +280,7 @@ class Date_helper_test extends CI_TestCase { $this->assertArrayHasKey('UP3', timezones()); $this->assertEquals(0, timezones('non_existant')); } + } /* End of file date_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 3937d2913..176ff1d78 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -1,41 +1,50 @@ helper('directory'); vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - + $this->_test_dir = vfsStreamWrapper::getRoot(); - } - + } + public function test_directory_map() { - $structure = array('libraries' => array('benchmark.html' => '', 'database' => - array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '.hiddenfile.txt' => '')); - + $structure = array( + 'libraries' => array( + 'benchmark.html' => '', + 'database' => array('active_record.html' => '', 'binds.html' => ''), + 'email.html' => '', + '.hiddenfile.txt' => '' + ) + ); + vfsStream::create($structure, $this->_test_dir); // test default recursive behavior - $expected = array('libraries' => array('benchmark.html', 'database' => - array('active_record.html', 'binds.html'), 'email.html')); - - $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); + $expected = array( + 'libraries' => array( + 'benchmark.html', + 'database' => array('active_record.html', 'binds.html'), + 'email.html' + ) + ); - // test recursion depth behavior - $expected = array('libraries'); - - $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 1)); + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'))); // test detection of hidden files - $expected = array('libraries' => array('benchmark.html', 'database' => - array('active_record.html', 'binds.html'), 'email.html', '.hiddenfile.txt')); - + $expected['libraries'][] = '.hiddenfile.txt'; + $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE)); - } + + // test recursion depth behavior + $this->assertEquals(array('libraries'), directory_map(vfsStream::url('testDir'), 1)); + } + } /* End of file directory_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index a01f3d5af..fea452f5f 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -14,5 +14,5 @@ class Email_helper_test extends CI_TestCase { $this->assertEquals(TRUE, valid_email('test@test.com')); $this->assertEquals(TRUE, valid_email('my.test@test.com')); } - + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index 4b9c29485..9b03da9d7 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -5,24 +5,23 @@ class File_helper_Test extends CI_TestCase { public function set_up() { $this->helper('file'); - + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - + $this->_test_dir = vfsStreamWrapper::getRoot(); } - + // -------------------------------------------------------------------- - + public function test_read_file() { $this->assertFalse(read_file('does_not_exist')); - + $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt')->withContent($content) - ->at($this->_test_dir); - + + $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir); + $this->assertEquals($content, read_file(vfsStream::url('my_file.txt'))); } @@ -31,126 +30,124 @@ class File_helper_Test extends CI_TestCase { public function test_octal_permissions() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('777', octal_permissions($file->getPermissions())); + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('777', octal_permissions($file->getPermissions())); } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + /** * More tests should happen here, since I'm not hitting the whole function. */ public function test_symbolic_permissions() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('urwxrwxrwx', symbolic_permissions($file->getPermissions())); } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + public function test_get_mime_by_extension() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified(time() - 86400) - ->at($this->_test_dir); - - $this->assertEquals('text/plain', - get_mime_by_extension(vfsStream::url('my_file.txt'))); - - // Test a mime with an array, such as png + ->lastModified(time() - 86400) + ->at($this->_test_dir); + + $this->assertEquals('text/plain', get_mime_by_extension(vfsStream::url('my_file.txt'))); + + // Test a mime with an array, such as png $file = vfsStream::newFile('foo.png')->at($this->_test_dir); - - $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); - + + $this->assertEquals('image/png', get_mime_by_extension(vfsStream::url('foo.png'))); + // Test a file not in the mimes array $file = vfsStream::newFile('foo.blarfengar')->at($this->_test_dir); - + $this->assertFalse(get_mime_by_extension(vfsStream::url('foo.blarfengar'))); } - // -------------------------------------------------------------------- + // -------------------------------------------------------------------- public function test_get_file_info() { // Test Bad File $this->assertFalse(get_file_info('i_am_bad_boo')); - + // Test the rest - + // First pass in an array $vals = array( 'name', 'server_path', 'size', 'date', - 'readable', 'writable', 'executable', 'fileperms' + 'readable', 'writable', 'executable', 'fileperms' ); - + $this->_test_get_file_info($vals); // Test passing in vals as a string. - $vals = 'name, server_path, size, date, readable, writable, executable, fileperms'; - $this->_test_get_file_info($vals); + $this->_test_get_file_info(implode(', ', $vals)); } - + private function _test_get_file_info($vals) { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; $last_modified = time() - 86400; - + $file = vfsStream::newFile('my_file.txt', 0777)->withContent($content) - ->lastModified($last_modified) - ->at($this->_test_dir); - + ->lastModified($last_modified) + ->at($this->_test_dir); + $ret_values = array( - 'name' => 'my_file.txt', - 'server_path' => 'vfs://my_file.txt', - 'size' => 57, - 'date' => $last_modified, + 'name' => 'my_file.txt', + 'server_path' => 'vfs://my_file.txt', + 'size' => 57, + 'date' => $last_modified, 'readable' => TRUE, - 'writable' => TRUE, - 'executable' => TRUE, + 'writable' => TRUE, + 'executable' => TRUE, 'fileperms' => 33279 ); - + $info = get_file_info(vfsStream::url('my_file.txt'), $vals); - + foreach ($info as $k => $v) { $this->assertEquals($ret_values[$k], $v); } } - - // -------------------------------------------------------------------- + + // -------------------------------------------------------------------- // Skipping for now, as it's not implemented in vfsStreamWrapper // flock(): vfsStreamWrapper::stream_lock is not implemented! - + // public function test_write_file() // { - // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) - // { - // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); - // } - // - // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - // - // $file = vfsStream::newFile('write.txt', 0777)->withContent('') - // ->lastModified(time() - 86400) - // ->at($this->_test_dir); - // - // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); - // + // if ( ! defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')) + // { + // define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); + // } + // + // $content = 'Jack and Jill went up the mountain to fight a billy goat.'; + // + // $file = vfsStream::newFile('write.txt', 0777)->withContent('') + // ->lastModified(time() - 86400) + // ->at($this->_test_dir); + // + // $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); + // // } - // -------------------------------------------------------------------- - + // -------------------------------------------------------------------- + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index 80bace9d1..1a30ed993 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -3,26 +3,26 @@ require BASEPATH . 'core/Common.php'; require BASEPATH . 'helpers/form_helper.php'; -class Form_helper_test extends CI_TestCase +class Form_helper_test extends CI_TestCase { public function test_form_hidden() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_hidden('username', 'johndoe')); } - + public function test_form_input() { $expected = << EOH; - + $data = array( 'name' => 'username', 'id' => 'username', @@ -34,37 +34,37 @@ EOH; $this->assertEquals($expected, form_input($data)); } - + public function test_form_password() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_password('password')); } - + public function test_form_upload() - { + { $expected = << EOH; - + $this->assertEquals($expected, form_upload('attachment')); } - + public function test_form_textarea() - { + { $expected = <<Notes EOH; - + $this->assertEquals($expected, form_textarea('notes', 'Notes')); } - + public function test_form_dropdown() { $expected = << EOH; - + $options = array( - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', ); - + $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); - + $expected = << @@ -95,22 +95,22 @@ EOH; EOH; - + $shirts_on_sale = array('small', 'large'); - + $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); - + $options = array( 'Swedish Cars' => array( - 'volvo' => 'Volvo', - 'saab' => 'Saab' + 'volvo' => 'Volvo', + 'saab' => 'Saab' ), 'German Cars' => array( - 'mercedes' => 'Mercedes', - 'audi' => 'Audi' + 'mercedes' => 'Mercedes', + 'audi' => 'Audi' ) ); - + $expected = << @@ -124,13 +124,10 @@ EOH; EOH; - - $cars_on_sale = array('volvo', 'audi'); - - $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale)); - + + $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi'))); } - + public function test_form_multiselect() { $expected = << EOH; - + $options = array( - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', - ); - + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); } - + public function test_form_fieldset() { $expected = <<Address Information EOH; - + $this->assertEquals($expected, form_fieldset('Address Information')); } @@ -169,10 +166,10 @@ EOH; $expected = << EOH; - + $this->assertEquals($expected, form_fieldset_close('')); } - + public function test_form_checkbox() { $expected = <<assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); } - + public function test_form_radio() { $expected = <<assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); } - + public function test_form_submit() { $expected = <<assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); } - + public function test_form_label() { $expected = <<assertEquals($expected, form_label('What is your Name', 'username')); } - + public function test_form_reset() { $expected = <<assertEquals($expected, form_reset('myreset', 'Reset')); } - + public function test_form_button() { $expected = <<assertEquals($expected, form_button('name','content')); + $this->assertEquals($expected, form_button('name', 'content')); } - + public function test_form_close() { $expected = <<assertEquals($expected, form_close('')); } - + public function test_form_prep() { - $expected = "Here is a string containing "quoted" text."; - + $expected = 'Here is a string containing "quoted" text.'; + $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); } + } /* End of file form_helper_test.php */ \ No newline at end of file diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 28974b0f8..9a7bb48bf 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -6,16 +6,16 @@ class Html_helper_test extends CI_TestCase { { $this->helper('html'); } - + // ------------------------------------------------------------------------ - + public function test_br() { $this->assertEquals('

    ', br(2)); } - + // ------------------------------------------------------------------------ - + public function test_heading() { $this->assertEquals('

    foobar

    ', heading('foobar')); @@ -23,7 +23,7 @@ class Html_helper_test extends CI_TestCase { } // ------------------------------------------------------------------------ - + public function test_Ul() { $expect = <<assertEquals($expect, ul($list)); + $this->assertEquals(ltrim($expect), ul($list)); $expect = << @@ -51,13 +49,11 @@ EOH; $expect = ltrim($expect); - $list = array('foo', 'bar'); - $this->assertEquals($expect, ul($list, 'class="test"')); $this->assertEquals($expect, ul($list, array('class' => 'test'))); } - + // ------------------------------------------------------------------------ public function test_NBS() @@ -66,15 +62,15 @@ EOH; } // ------------------------------------------------------------------------ - + public function test_meta() { $this->assertEquals("\n", meta('test', 'foo')); - + $expect = "\n"; - + $this->assertEquals($expect, meta(array('name' => 'foo'))); - + } - + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 9e9478711..f3b0ebbe8 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -1,12 +1,12 @@ helper('inflector'); } - + public function test_singular() { $strs = array( @@ -16,15 +16,15 @@ class Inflector_helper_test extends CI_TestCase { 'smells' => 'smell', 'equipment' => 'equipment' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, singular($str)); } } - + // -------------------------------------------------------------------- - + public function test_plural() { $strs = array( @@ -35,15 +35,15 @@ class Inflector_helper_test extends CI_TestCase { 'witch' => 'witches', 'equipment' => 'equipment' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, plural($str)); - } - } + } + } // -------------------------------------------------------------------- - + public function test_camelize() { $strs = array( @@ -52,15 +52,15 @@ class Inflector_helper_test extends CI_TestCase { 'i-am-playing-a-trick' => 'i-am-playing-a-trick', 'what_do_you_think-yo?' => 'whatDoYouThink-yo?', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, camelize($str)); } - } + } // -------------------------------------------------------------------- - + public function test_underscore() { $strs = array( @@ -69,7 +69,7 @@ class Inflector_helper_test extends CI_TestCase { 'i-am-playing-a-trick' => 'i-am-playing-a-trick', 'what_do_you_think-yo?' => 'what_do_you_think-yo?', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, underscore($str)); @@ -77,7 +77,7 @@ class Inflector_helper_test extends CI_TestCase { } // -------------------------------------------------------------------- - + public function test_humanize() { $strs = array( @@ -86,10 +86,11 @@ class Inflector_helper_test extends CI_TestCase { 'i-am-playing-a-trick' => 'I-am-playing-a-trick', 'what_do_you_think-yo?' => 'What Do You Think-yo?', ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, humanize($str)); } } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 4bb9a918a..23d5c5c1a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,35 +1,35 @@ helper('number'); - + // Grab the core lang class $lang_cls = $this->ci_core_class('lang'); - + // Mock away load, too much going on in there, // we'll just check for the expected parameter - + $lang = $this->getMock($lang_cls, array('load')); $lang->expects($this->once()) ->method('load') ->with($this->equalTo('number')); - + // Assign the proper language array - + $lang->language = $this->_get_lang('number'); - + // We don't have a controller, so just create // a cheap class to act as our super object. // Make sure it has a lang attribute. - + $obj = new StdClass; $obj->lang = $lang; $this->ci_instance($obj); } - + // Quick helper to actually grab the language // file. Consider moving this to ci_testcase? public function _get_lang($name) @@ -37,41 +37,40 @@ class Number_helper_test extends CI_TestCase { require BASEPATH.'language/english/'.$name.'_lang.php'; return $lang; } - + public function test_byte_format() { $this->assertEquals('456 Bytes', byte_format(456)); } - + public function test_kb_format() { $this->assertEquals('4.5 KB', byte_format(4567)); } - + public function test_kb_format_medium() { $this->assertEquals('44.6 KB', byte_format(45678)); } - + public function test_kb_format_large() { $this->assertEquals('446.1 KB', byte_format(456789)); } - + public function test_mb_format() { $this->assertEquals('3.3 MB', byte_format(3456789)); } - + public function test_gb_format() { $this->assertEquals('1.8 GB', byte_format(1932735283.2)); } - + public function test_tb_format() { $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); } -} -// EOF \ No newline at end of file +} \ No newline at end of file diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 632f57501..0faf6f383 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -8,9 +8,8 @@ class Path_helper_test extends CI_TestCase { } public function test_set_realpath() - { - $expected = getcwd() . DIRECTORY_SEPARATOR; - $this->assertEquals($expected, set_realpath(getcwd())); + { + $this->assertEquals(getcwd().DIRECTORY_SEPARATOR, set_realpath(getcwd())); } public function test_set_realpath_nonexistent_directory() diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 29c3d6594..75701ec13 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -10,18 +10,18 @@ class String_helper_test extends CI_TestCase { public function test_strip_slashes() { $expected = array( - "Is your name O'reilly?", + "Is your name O'reilly?", "No, my name is O'connor." ); - + $str = array( "Is your name O\'reilly?", "No, my name is O\'connor." ); - + $this->assertEquals($expected, strip_slashes($str)); } - + public function test_trim_slashes() { $strs = array( @@ -144,4 +144,5 @@ class String_helper_test extends CI_TestCase { $this->assertEquals('file-1', increment_string('file', '-', '1')); $this->assertEquals(124, increment_string('123', '')); } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 73e2b9429..f131469cb 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -3,16 +3,16 @@ class Text_helper_test extends CI_TestCase { private $_long_string; - + public function set_up() { $this->helper('text'); - + $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } - + // ------------------------------------------------------------------------ - + public function test_word_limiter() { $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); @@ -20,8 +20,8 @@ class Text_helper_test extends CI_TestCase { $this->assertEquals('', word_limiter('', 4)); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_character_limiter() { $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); @@ -30,22 +30,22 @@ class Text_helper_test extends CI_TestCase { $this->assertEquals('Short', character_limiter('Short', 5)); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_ascii_to_entities() { $strs = array( '“‘ “test”' => '“‘ “test”', '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, ascii_to_entities($str)); } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_entities_to_ascii() { @@ -53,27 +53,27 @@ class Text_helper_test extends CI_TestCase { '“‘ “test”' => '“‘ “test”', '†¥¨ˆøåß∂ƒ©˙∆˚¬' => '†¥¨ˆøåß∂ƒ©˙∆˚¬' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, entities_to_ascii($str)); - } + } } - - // ------------------------------------------------------------------------ - - function test_convert_accented_characters() + + // ------------------------------------------------------------------------ + + public function test_convert_accented_characters() { $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); } - // ------------------------------------------------------------------------ - + // ------------------------------------------------------------------------ + public function test_censored_words() { $censored = array('boob', 'nerd', 'ass', 'fart'); - + $strs = array( 'Ted bobbled the ball' => 'Ted bobbled the ball', 'Jake is a nerdo' => 'Jake is a nerdo', @@ -81,28 +81,26 @@ class Text_helper_test extends CI_TestCase { 'Did Mary Fart?' => 'Did Mary $*#?', 'Jake is really a boob' => 'Jake is really a $*#' ); - - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, word_censor($str, $censored, '$*#')); } - + // test censored words being sent as a string $this->assertEquals('test', word_censor('test', 'test')); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_highlight_code() { - $code = ''; $expect = "\n<?php var_dump(\$this); ?> \n\n"; - $this->assertEquals($expect, highlight_code($code)); + $this->assertEquals($expect, highlight_code('')); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_highlight_phrase() { @@ -113,14 +111,14 @@ class Text_helper_test extends CI_TestCase { 'Or tell me what this is' => 'Or tell me what this is', '' => '' ); - + foreach ($strs as $str => $expect) { $this->assertEquals($expect, highlight_phrase($str, 'this is')); } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_ellipsize() { @@ -144,32 +142,30 @@ class Text_helper_test extends CI_TestCase { 'short' => 'short' ), ); - + foreach ($strs as $pos => $s) { foreach ($s as $str => $expect) { - $this->assertEquals($expect, ellipsize($str, 10, $pos)); + $this->assertEquals($expect, ellipsize($str, 10, $pos)); } } } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_word_wrap() { - $string = "Here is a simple string of text that will help us demonstrate this function."; - $word_wrapped = word_wrap($string, 25); - $this->assertEquals(substr_count($word_wrapped, "\n"), 4); + $string = 'Here is a simple string of text that will help us demonstrate this function.'; + $this->assertEquals(substr_count(word_wrap($string, 25), "\n"), 4); } - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ public function test_default_word_wrap_charlim() { $string = "Here is a longer string of text that will help us demonstrate the default charlim of this function."; - $word_wrapped = word_wrap($string); - $this->assertEquals(strpos($word_wrapped, "\n"), 73); + $this->assertEquals(strpos(word_wrap($string), "\n"), 73); } } \ No newline at end of file diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index c561809ce..c81c5f1b8 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -72,4 +72,5 @@ class Url_helper_test extends CI_TestCase { $this->assertEquals($out, auto_link($in, 'url')); } } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php index a83fef91e..e8cf411da 100644 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -6,10 +6,10 @@ class Xml_helper_test extends CI_TestCase { { $this->helper('xml'); } - + public function test_xml_convert() { $this->assertEquals('<tag>my & test - </tag>', xml_convert('my & test - ')); } - + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c186288755aba46a2b6f0c3f104d9a6ce6b11a7f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 9 Jun 2012 23:16:58 +0300 Subject: Cleanup/optimize tests/codeigniter/ --- tests/codeigniter/helpers/number_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 23d5c5c1a..ef6aae138 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -25,7 +25,7 @@ class Number_helper_test extends CI_TestCase { // a cheap class to act as our super object. // Make sure it has a lang attribute. - $obj = new StdClass; + $obj = new stdClass; $obj->lang = $lang; $this->ci_instance($obj); } -- cgit v1.2.3-24-g4f1b From e1c8ee76f4756442094106320d9577c2c7595959 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 11:35:11 +0300 Subject: Alter now() tests --- tests/codeigniter/helpers/date_helper_test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4b747b864..bcb1477bc 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -13,6 +13,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_local() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -22,6 +24,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our test instance $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'local'); + $this->assertEquals(time(), now()); } @@ -29,6 +35,8 @@ class Date_helper_test extends CI_TestCase { public function test_now_gmt() { + /* + // This stub job, is simply to cater $config['time_reference'] $config = $this->getMock('CI_Config'); $config->expects($this->any()) @@ -38,6 +46,10 @@ class Date_helper_test extends CI_TestCase { // Add the stub to our stdClass $this->ci_instance_var('config', $config); + */ + + $this->ci_set_config('time_reference', 'gmt'); + $t = time(); $this->assertEquals( mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), -- cgit v1.2.3-24-g4f1b From 0ddff314d619e5d24bdf07f3da33c779f5b6e2c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:18:07 +0300 Subject: test_now_gmt() -> test_now_utc() --- tests/codeigniter/helpers/date_helper_test.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index bcb1477bc..242935116 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -33,7 +33,7 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_now_gmt() + public function test_now_utc() { /* @@ -41,18 +41,17 @@ class Date_helper_test extends CI_TestCase { $config = $this->getMock('CI_Config'); $config->expects($this->any()) ->method('item') - ->will($this->returnValue('gmt')); + ->will($this->returnValue('UTC')); // Add the stub to our stdClass $this->ci_instance_var('config', $config); */ - $this->ci_set_config('time_reference', 'gmt'); + $this->ci_set_config('time_reference', 'UTC'); - $t = time(); $this->assertEquals( - mktime(gmdate('H', $t), gmdate('i', $t), gmdate('s', $t), gmdate('m', $t), gmdate('d', $t), gmdate('Y', $t)), + gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), now() ); } -- cgit v1.2.3-24-g4f1b From 3ed533109309326a858c778dfea5cb9186f965b4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 14 Jun 2012 13:21:07 +0300 Subject: Some optimizations to the date helper tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 242935116..1d397ac81 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -51,7 +51,7 @@ class Date_helper_test extends CI_TestCase { $this->ci_set_config('time_reference', 'UTC'); $this->assertEquals( - gmmktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')), + gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), now() ); } @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $this->assertEquals( - mktime( - gmdate('H', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), - gmdate('m', $this->time), gmdate('d', $this->time), gmdate('Y', $this->time) + gmmktime( + date('G', $this->time), date('i', $this->time), date('s', $this->time), + date('n', $this->time), date('j', $this->time), date('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From b089e15b1510de6b6a034631c80d3d5e830ff9f3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 16 Jun 2012 19:11:40 +0300 Subject: Fix local_to_gmt() --- tests/codeigniter/helpers/date_helper_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1d397ac81..8258c9248 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -196,9 +196,9 @@ class Date_helper_test extends CI_TestCase { public function test_local_to_gmt() { $this->assertEquals( - gmmktime( - date('G', $this->time), date('i', $this->time), date('s', $this->time), - date('n', $this->time), date('j', $this->time), date('Y', $this->time) + mktime( + gmdate('G', $this->time), gmdate('i', $this->time), gmdate('s', $this->time), + gmdate('n', $this->time), gmdate('j', $this->time), gmdate('Y', $this->time) ), local_to_gmt($this->time) ); -- cgit v1.2.3-24-g4f1b From a84055b49539da1faa2893618b2475d1888a9fea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 20 Jun 2012 14:37:59 +0300 Subject: Fix issue #1510 --- tests/codeigniter/helpers/date_helper_test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 8258c9248..4e01b1aa3 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -48,11 +48,9 @@ class Date_helper_test extends CI_TestCase { */ - $this->ci_set_config('time_reference', 'UTC'); - $this->assertEquals( - gmmktime(date('G'), date('i'), date('s'), date('n'), date('j'), date('Y')), - now() + mktime(gmdate('G'), gmdate('i'), gmdate('s'), gmdate('n'), gmdate('j'), gmdate('Y')), + now('UTC') ); } -- cgit v1.2.3-24-g4f1b From 5211c094c930d69d52539591b306c293c99689ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 2 Jul 2012 16:47:12 +0300 Subject: Fix standard_date() tests --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 4e01b1aa3..eaf4cf8a5 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -79,7 +79,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_atom() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_ATOM', $this->time) ); } @@ -99,7 +99,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_iso8601() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_ISO8601', $this->time) ); } @@ -139,7 +139,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc2822() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date('r', $this->time), standard_date('DATE_RFC2822', $this->time) ); } @@ -159,7 +159,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_w3c() { $this->assertEquals( - date("Y-m-d\TH:i:sO", $this->time), + date('Y-m-d\TH:i:sP', $this->time), standard_date('DATE_W3C', $this->time) ); } -- cgit v1.2.3-24-g4f1b From dd6f32b3b506d29da38f41d307e5ea217c21cb51 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jul 2012 10:08:54 +0300 Subject: Optimize standard_date() --- tests/codeigniter/helpers/date_helper_test.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index eaf4cf8a5..1b79b9480 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -69,7 +69,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc822() { $this->assertEquals( - date('D, d M y H:i:s O', $this->time), + date(DATE_RFC822, $this->time), standard_date('DATE_RFC822', $this->time) ); } @@ -79,7 +79,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_atom() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_ATOM, $this->time), standard_date('DATE_ATOM', $this->time) ); } @@ -89,7 +89,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_cookie() { $this->assertEquals( - date("l, d-M-y H:i:s \U\T\C", $this->time), + date(DATE_COOKIE, $this->time), standard_date('DATE_COOKIE', $this->time) ); } @@ -99,7 +99,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_iso8601() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_ISO8601, $this->time), standard_date('DATE_ISO8601', $this->time) ); } @@ -109,7 +109,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc850() { $this->assertEquals( - date("l, d-M-y H:i:s \U\T\C", $this->time), + date(DATE_RFC850, $this->time), standard_date('DATE_RFC850', $this->time) ); } @@ -119,7 +119,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc1036() { $this->assertEquals( - date('D, d M y H:i:s O', $this->time), + date(DATE_RFC1036, $this->time), standard_date('DATE_RFC1036', $this->time) ); } @@ -129,7 +129,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc1123() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date(DATE_RFC1123, $this->time), standard_date('DATE_RFC1123', $this->time) ); } @@ -139,7 +139,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rfc2822() { $this->assertEquals( - date('r', $this->time), + date(DATE_RFC2822, $this->time), standard_date('DATE_RFC2822', $this->time) ); } @@ -149,7 +149,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_rss() { $this->assertEquals( - date('D, d M Y H:i:s O', $this->time), + date(DATE_RSS, $this->time), standard_date('DATE_RSS', $this->time) ); } @@ -159,7 +159,7 @@ class Date_helper_test extends CI_TestCase { public function test_standard_date_w3c() { $this->assertEquals( - date('Y-m-d\TH:i:sP', $this->time), + date(DATE_W3C, $this->time), standard_date('DATE_W3C', $this->time) ); } -- cgit v1.2.3-24-g4f1b