From 2cadade8e3598fc4d19a3029db0b861a8d3bfc80 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Thu, 21 Apr 2011 15:00:49 -0500 Subject: Adding typography library test. --- tests/codeigniter/libraries/Typography_test.php | 191 ++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tests/codeigniter/libraries/Typography_test.php (limited to 'tests/codeigniter/libraries/Typography_test.php') diff --git a/tests/codeigniter/libraries/Typography_test.php b/tests/codeigniter/libraries/Typography_test.php new file mode 100644 index 000000000..242a6e944 --- /dev/null +++ b/tests/codeigniter/libraries/Typography_test.php @@ -0,0 +1,191 @@ +type = new CI_Typography(); + + $this->ci_instance($obj); + + $this->type = $obj->type; + } + + // -------------------------------------------------------------------- + + /** + * Tests the format_characters() function. + * + * this can and should grow. + */ + public function testFormatCharacters() + { + $strs = array( + '"double quotes"' => '“double quotes”', + '"testing" in "theory" that is' => '“testing” in “theory” that is', + "Here's what I'm" => 'Here’s what I’m', + '&' => '&', + '&' => '&', + ' ' => ' ', + '--' => '—', + 'foo...' => 'foo…', + 'foo..' => 'foo..', + 'foo...bar.' => 'foo…bar.', + 'test. new' => 'test.  new', + ); + + foreach ($strs as $str => $expected) + { + $this->assertEquals($expected, $this->type->format_characters($str)); + } + } + + // -------------------------------------------------------------------- + + public function testNl2brExceptPre() + { + $str = << +I am inside a pre tag. Please don't mess with me. + +k? + + +That's my story and I'm sticking to it. + +The End. +EOH; + + $expected = << +
+I like to skip.
+
+Jump
+
+and sing.
+
+
+I am inside a pre tag.  Please don't mess with me.
+
+k?
+

+
+That's my story and I'm sticking to it.
+
+The End. +EOH; + + $this->assertEquals($expected, + $this->type->nl2br_except_pre($str)); + } + + // -------------------------------------------------------------------- + + public function testAutoTypography() + { + $this->_blank_string(); + $this->_standardize_new_lines(); + $this->_reduce_linebreaks(); + $this->_remove_comments(); + $this->_protect_pre(); + $this->_no_opening_block(); + $this->_protect_braced_quotes(); + } + + // -------------------------------------------------------------------- + + private function _blank_string() + { + // Test blank string + $this->assertEquals('', $this->type->auto_typography('')); + } + + // -------------------------------------------------------------------- + + private function _standardize_new_lines() + { + $strs = array( + "My string\rhas return characters" => "

My string
\nhas return characters

", + 'This one does not!' => '

This one does not!

' + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + } + + // -------------------------------------------------------------------- + + private function _reduce_linebreaks() + { + $str = "This has way too many linebreaks.\n\n\n\nSee?"; + $expect = "

This has way too many linebreaks.

\n\n

See?

"; + + $this->assertEquals($expect, $this->type->auto_typography($str, TRUE)); + } + + // -------------------------------------------------------------------- + + private function _remove_comments() + { + $str = ' But no!'; + $expect = '

  But no!

'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + private function _protect_pre() + { + $str = '

My Sentence

var_dump($this);
'; + $expect = '

My Sentence

var_dump($this);
'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + private function _no_opening_block() + { + $str = 'My Sentence
var_dump($this);
'; + $expect = '

My Sentence

var_dump($this);
'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + } + + // -------------------------------------------------------------------- + + public function _protect_braced_quotes() + { + $this->type->protect_braced_quotes = TRUE; + + $str = 'Test {parse="foobar"}'; + $expect = '

Test {parse="foobar"}

'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + + $this->type->protect_braced_quotes = FALSE; + + $str = 'Test {parse="foobar"}'; + $expect = '

Test {parse=“foobar”}

'; + + $this->assertEquals($expect, $this->type->auto_typography($str)); + + + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b