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