From 81b57b7d5d0d45ee2460dd230e8e0ded22ba8d70 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 12 May 2008 07:05:33 +0000 Subject: [PATCH] Pushing TextHelper code coverage to 100% git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6816 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helpers/text.php | 3 + .../cases/libs/view/helpers/text.test.php | 87 ++++++++++++++----- 2 files changed, 66 insertions(+), 24 deletions(-) diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index cfdbb303a..49aa9e4be 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -313,5 +313,8 @@ class TextHelper extends AppHelper { } return Flay::toHtml($text, false, $allowHtml); } +/** + * @codeCoverageIgnoreEnd + */ } ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/view/helpers/text.test.php b/cake/tests/cases/libs/view/helpers/text.test.php index 5f26fbac5..a0d5865ad 100644 --- a/cake/tests/cases/libs/view/helpers/text.test.php +++ b/cake/tests/cases/libs/view/helpers/text.test.php @@ -43,31 +43,41 @@ class TextTest extends UnitTestCase { } function testTruncate() { + if (!isset($this->method)) { + $this->method = 'truncate'; + } + $m = $this->method; $text1 = 'The quick brown fox jumps over the lazy dog'; $text2 = 'Heizölrückstoßabdämpfung'; $text3 = '© 2005-2007, Cake Software Foundation, Inc.
written by Alexander Wegener'; $text4 = ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Great, or?'; $text5 = '01234567890'; - $this->assertIdentical($this->Text->truncate($text1, 15), 'The quick br...'); - $this->assertIdentical($this->Text->truncate($text1, 15, '...', false), 'The quick...'); - $this->assertIdentical($this->Text->truncate($text1, 100), 'The quick brown fox jumps over the lazy dog'); - $this->assertIdentical($this->Text->truncate($text2, 10, '...'), 'Heiz&ou...'); - $this->assertIdentical($this->Text->truncate($text2, 10, '...', false), '...'); - $this->assertIdentical($this->Text->truncate($text3, 20), '© 2005-20...'); - $this->assertIdentical($this->Text->truncate($text4, 15), 'assertIdentical($this->Text->{$m}($text5, 6, ''), '01<'); - $this->assertIdentical($this->Text->truncate($text1, 15, array('ending' => '...', 'exact' => true, 'considerHtml' => true)), 'The quick br...'); - $this->assertIdentical($this->Text->truncate($text1, 15, '...', true, true), 'The quick br...'); - $this->assertIdentical($this->Text->truncate($text1, 15, '...', false, true), 'The quick...'); - $this->assertIdentical($this->Text->truncate($text2, 10, '...', true, true), 'Heizölr...'); - $this->assertIdentical($this->Text->truncate($text2, 10, '...', false, true), '...'); - $this->assertIdentical($this->Text->truncate($text3, 20, '...', true, true), '© 2005-2007, Cake...'); - $this->assertIdentical($this->Text->truncate($text4, 15, '...', true, true), ' This image ...'); - $this->assertIdentical($this->Text->truncate($text4, 45, '...', true, true), ' This image tag is not XHTML conform!

But t...'); - $this->assertIdentical($this->Text->truncate($text4, 90, '...', true, true), ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Grea...'); - $this->assertIdentical($this->Text->truncate($text5, 6, '', true, true), '012345'); + $this->assertIdentical($this->Text->{$m}($text1, 15, array('ending' => '...', 'exact' => true, 'considerHtml' => true)), 'The quick br...'); + $this->assertIdentical($this->Text->{$m}($text1, 15, '...', true, true), 'The quick br...'); + $this->assertIdentical($this->Text->{$m}($text1, 15, '...', false, true), 'The quick...'); + $this->assertIdentical($this->Text->{$m}($text2, 10, '...', true, true), 'Heizölr...'); + $this->assertIdentical($this->Text->{$m}($text2, 10, '...', false, true), '...'); + $this->assertIdentical($this->Text->{$m}($text3, 20, '...', true, true), '© 2005-2007, Cake...'); + $this->assertIdentical($this->Text->{$m}($text4, 15, '...', true, true), ' This image ...'); + $this->assertIdentical($this->Text->{$m}($text4, 45, '...', true, true), ' This image tag is not XHTML conform!

But t...'); + $this->assertIdentical($this->Text->{$m}($text4, 90, '...', true, true), ' This image tag is not XHTML conform!

But the following image tag should be conform Me, myself and I
Grea...'); + $this->assertIdentical($this->Text->{$m}($text5, 6, '', true, true), '012345'); + $this->assertIdentical($this->Text->{$m}($text5, 20, '', true, true), $text5); + + if ($this->method == 'truncate') { + $this->method = 'trim'; + $this->testTruncate(); + } } function testHighlight() { @@ -76,6 +86,11 @@ class TextTest extends UnitTestCase { $result = $this->Text->highlight($text, $phrases, '\1'); $expected = 'This is a test text'; $this->assertEqual($expected, $result); + + $text = 'This is a test text'; + $phrases = null; + $result = $this->Text->highlight($text, $phrases, '\1'); + $this->assertEqual($result, $text); } function testStripLinks() { @@ -100,6 +115,18 @@ class TextTest extends UnitTestCase { $this->assertEqual($expected, $result); } + function testAutoLink() { + $text = 'This is a test text'; + $expected = 'This is a test text'; + $result = $this->Text->autoLink($text); + $this->assertEqual($expected, $result); + + $text = 'Text with a partial www.cakephp.org URL and test@cakephp.org email address'; + $result = $this->Text->autoLink($text); + $expected = 'Text with a partial www.cakephp.org URL and test@cakephp\.org email address'; + $this->assertPattern('#^' . $expected . '$#', $result); + } + function testAutoLinkUrls() { $text = 'This is a test text'; $expected = 'This is a test text'; @@ -166,6 +193,18 @@ class TextTest extends UnitTestCase { $expected = 'This is a...'; $result = $this->Text->excerpt($text, 'not_found', 9, '...'); $this->assertEqual($expected, $result); + + $expected = 'This is a phras...'; + $result = $this->Text->excerpt($text, null, 9, '...'); + $this->assertEqual($expected, $result); + + $expected = $text; + $result = $this->Text->excerpt($text, null, 200, '...'); + $this->assertEqual($expected, $result); + + $expected = '...phrase...'; + $result = $this->Text->excerpt($text, 'phrase', 2, '...'); + $this->assertEqual($expected, $result); } function testExcerptCaseInsensitivity() { @@ -180,13 +219,13 @@ class TextTest extends UnitTestCase { $this->assertEqual($expected, $result); } - function testListGeneration() { - $result = $this->Text->toList(array('Larry', 'Curly', 'Moe')); - $this->assertEqual($result, 'Larry, Curly and Moe'); + function testListGeneration() { + $result = $this->Text->toList(array('Larry', 'Curly', 'Moe')); + $this->assertEqual($result, 'Larry, Curly and Moe'); - $result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y'); - $this->assertEqual($result, 'Dusty, Lucky y Ned'); - } + $result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y'); + $this->assertEqual($result, 'Dusty, Lucky y Ned'); + } function tearDown() { unset($this->Text);