use addHelper('string') syntax; test helpers through the views
authorChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:32:48 +0000 (11:32 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:32:48 +0000 (11:32 -0400)
framework/View/test/Horde/View/Helper/FormTest.php
framework/View/test/Horde/View/Helper/JavascriptTest.php
framework/View/test/Horde/View/Helper/TagTest.php
framework/View/test/Horde/View/Helper/TextTest.php

index 163ec79..7e5ccdd 100644 (file)
@@ -27,9 +27,9 @@ class Horde_View_Helper_FormTest extends Horde_Test_Case
     public function setUp()
     {
         $this->view = new Horde_View();
-        $this->view->addHelper(new Horde_View_Helper_Form($this->view));
-        $this->view->addHelper(new Horde_View_Helper_FormTag($this->view));
-        $this->view->addHelper(new Horde_View_Helper_Tag($this->view));
+        $this->view->addHelper('Form');
+        $this->view->addHelper('FormTag');
+        $this->view->addHelper('Tag');
         $this->view->addHelper(new Horde_View_Helper_FormTest_MockUrlHelper($this->view));
 
         $this->post = (object)array('title', 'authorName', 'body',
index a7e99d4..6003680 100644 (file)
@@ -27,8 +27,8 @@ class Horde_View_Helper_JavascriptTest extends Horde_Test_Case
     public function setUp()
     {
         $this->view = new Horde_View();
-        $this->view->addHelper(new Horde_View_Helper_Tag($this->view));
-        $this->view->addHelper(new Horde_View_Helper_Javascript($this->view));
+        $this->view->addHelper('Javascript');
+        $this->view->addHelper('Tag');
     }
 
     public function testJavascriptTag()
index 61ca02f..098f44e 100644 (file)
@@ -26,59 +26,60 @@ class Horde_View_Helper_TagTest extends Horde_Test_Case
 {
     public function setUp()
     {
-        $this->helper = new Horde_View_Helper_Tag(new Horde_View());
+        $this->view = new Horde_View();
+        $this->view->addHelper('Tag');
     }
 
     public function testTag()
     {
-        $this->assertEquals('<br />', $this->helper->tag('br'));
+        $this->assertEquals('<br />', $this->view->tag('br'));
         $this->assertEquals('<br clear="left" />',
-                            $this->helper->tag('br', array('clear' => 'left')));
+                            $this->view->tag('br', array('clear' => 'left')));
         $this->assertEquals('<br>',
-                            $this->helper->tag('br', null, true));
+                            $this->view->tag('br', null, true));
     }
 
     public function testTagOptions()
     {
         $this->assertRegExp('/\A<p class="(show|elsewhere)" \/>\z/',
-                            $this->helper->tag('p', array('class' => 'show',
-                                                          'class' => 'elsewhere')));
+                            $this->view->tag('p', array('class' => 'show',
+                                                        'class' => 'elsewhere')));
     }
 
     public function testTagOptionsRejectsNullOption()
     {
         $this->assertEquals('<p />',
-                            $this->helper->tag('p', array('ignored' => null)));
+                            $this->view->tag('p', array('ignored' => null)));
     }
 
     public function testTagOptionsAcceptsBlankOption()
     {
         $this->assertEquals('<p included="" />',
-                            $this->helper->tag('p', array('included' => '')));
+                            $this->view->tag('p', array('included' => '')));
     }
 
     public function testTagOptionsConvertsBooleanOption()
     {
         $this->assertEquals('<p disabled="disabled" multiple="multiple" readonly="readonly" />',
-                            $this->helper->tag('p', array('disabled' => true,
-                                                          'multiple' => true,
-                                                          'readonly' => true)));
+                            $this->view->tag('p', array('disabled' => true,
+                                                        'multiple' => true,
+                                                        'readonly' => true)));
     }
 
     public function testContentTag()
     {
         $this->assertEquals('<a href="create">Create</a>',
-                            $this->helper->contentTag('a', 'Create', array('href' => 'create')));
+                            $this->view->contentTag('a', 'Create', array('href' => 'create')));
     }
 
     public function testCdataSection()
     {
-        $this->assertEquals('<![CDATA[<hello world>]]>', $this->helper->cdataSection('<hello world>'));
+        $this->assertEquals('<![CDATA[<hello world>]]>', $this->view->cdataSection('<hello world>'));
     }
 
     public function testEscapeOnce()
     {
-        $this->assertEquals('1 &lt; 2 &amp; 3', $this->helper->escapeOnce('1 < 2 &amp; 3'));
+        $this->assertEquals('1 &lt; 2 &amp; 3', $this->view->escapeOnce('1 < 2 &amp; 3'));
     }
 
     public function testDoubleEscapingAttributes()
@@ -86,7 +87,7 @@ class Horde_View_Helper_TagTest extends Horde_Test_Case
         $attributes = array('1&amp;2', '1 &lt; 2', '&#8220;test&#8220;');
         foreach ($attributes as $escaped) {
             $this->assertEquals("<a href=\"$escaped\" />",
-                                $this->helper->tag('a', array('href' => $escaped)));
+                                $this->view->tag('a', array('href' => $escaped)));
         }
     }
 
@@ -95,7 +96,7 @@ class Horde_View_Helper_TagTest extends Horde_Test_Case
         $attributes = array('&1;', '&#1dfa3;', '& #123;');
         foreach ($attributes as $escaped) {
             $this->assertEquals('<a href="' . str_replace('&', '&amp;', $escaped) . '" />',
-                                $this->helper->tag('a', array('href' => $escaped)));
+                                $this->view->tag('a', array('href' => $escaped)));
         }
     }
 
index 215fad1..5af98fd 100644 (file)
@@ -26,7 +26,8 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
 {
     public function setUp()
     {
-        $this->helper = new Horde_View_Helper_Text(new Horde_View());
+        $this->view = new Horde_View();
+        $this->view->addHelper('Text');
     }
 
     // test escaping data
@@ -34,7 +35,7 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
     {
         $text = "Test 'escaping html' \"quotes\" and & amps";
         $expected = "Test &#039;escaping html&#039; &quot;quotes&quot; and &amp; amps";
-        $this->assertEquals($expected, $this->helper->h($text));
+        $this->assertEquals($expected, $this->view->h($text));
     }
 
     // test truncate
@@ -42,7 +43,7 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
     {
         $str = 'The quick brown fox jumps over the lazy dog tomorrow morning.';
         $expected = 'The quick brown fox jumps over the la...';
-        $this->assertEquals($expected, $this->helper->truncate($str, 40));
+        $this->assertEquals($expected, $this->view->truncate($str, 40));
     }
 
     // test truncate
@@ -50,7 +51,7 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
     {
         $str = 'The quick brown fox jumps over the lazy dog tomorrow morning.';
         $expected = 'The quick brown fox... tomorrow morning.';
-        $this->assertEquals($expected, $this->helper->truncateMiddle($str, 40));
+        $this->assertEquals($expected, $this->view->truncateMiddle($str, 40));
     }
 
     // text too short to trucate
@@ -58,7 +59,7 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
     {
         $str = 'The quick brown fox jumps over the dog.';
         $expected = 'The quick brown fox jumps over the dog.';
-        $this->assertEquals($expected, $this->helper->truncateMiddle($str, 40));
+        $this->assertEquals($expected, $this->view->truncateMiddle($str, 40));
     }
 
 
@@ -67,7 +68,7 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
     {
         $str = 'The quick brown fox jumps over the dog.';
         $expected = 'The quick <strong class="highlight">brown</strong> fox jumps over the dog.';
-        $this->assertEquals($expected, $this->helper->highlight($str, 'brown'));
+        $this->assertEquals($expected, $this->view->highlight($str, 'brown'));
     }
 
     // test failure to highlight
@@ -75,14 +76,14 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
     {
         $str = 'The quick brown fox jumps over the dog.';
         $expected = 'The quick <em>brown</em> fox jumps over the dog.';
-        $this->assertEquals($expected, $this->helper->highlight($str, 'brown', '<em>$1</em>'));
+        $this->assertEquals($expected, $this->view->highlight($str, 'brown', '<em>$1</em>'));
     }
 
     // test failure to highlight
     public function testHighlightNoMatch()
     {
         $str = 'The quick brown fox jumps over the dog.';
-        $this->assertEquals($str, $this->helper->highlight($str, 'black'));
+        $this->assertEquals($str, $this->view->highlight($str, 'black'));
     }
 
     public function testCycleClass()
@@ -119,64 +120,64 @@ class Horde_View_Helper_TextTest extends Horde_Test_Case
 
     public function testCycleResetsWithNewValues()
     {
-        $this->assertEquals('even', (string)$this->helper->cycle('even', 'odd'));
-        $this->assertEquals('odd',  (string)$this->helper->cycle('even', 'odd'));
-        $this->assertEquals('even', (string)$this->helper->cycle('even', 'odd'));
-        $this->assertEquals('1',    (string)$this->helper->cycle(1, 2, 3));
-        $this->assertEquals('2',    (string)$this->helper->cycle(1, 2, 3));
-        $this->assertEquals('3',    (string)$this->helper->cycle(1, 2, 3));
+        $this->assertEquals('even', (string)$this->view->cycle('even', 'odd'));
+        $this->assertEquals('odd',  (string)$this->view->cycle('even', 'odd'));
+        $this->assertEquals('even', (string)$this->view->cycle('even', 'odd'));
+        $this->assertEquals('1',    (string)$this->view->cycle(1, 2, 3));
+        $this->assertEquals('2',    (string)$this->view->cycle(1, 2, 3));
+        $this->assertEquals('3',    (string)$this->view->cycle(1, 2, 3));
     }
 
     public function testNamedCycles()
     {
-        $this->assertEquals('1',    (string)$this->helper->cycle(1, 2, 3, array('name' => 'numbers')));
-        $this->assertEquals('red',  (string)$this->helper->cycle('red', 'blue', array('name' => 'colors')));
-        $this->assertEquals('2',    (string)$this->helper->cycle(1, 2, 3, array('name' => 'numbers')));
-        $this->assertEquals('blue', (string)$this->helper->cycle('red', 'blue', array('name' => 'colors')));
-        $this->assertEquals('3',    (string)$this->helper->cycle(1, 2, 3, array('name' => 'numbers')));
-        $this->assertEquals('red',  (string)$this->helper->cycle('red', 'blue', array('name' => 'colors')));
+        $this->assertEquals('1',    (string)$this->view->cycle(1, 2, 3, array('name' => 'numbers')));
+        $this->assertEquals('red',  (string)$this->view->cycle('red', 'blue', array('name' => 'colors')));
+        $this->assertEquals('2',    (string)$this->view->cycle(1, 2, 3, array('name' => 'numbers')));
+        $this->assertEquals('blue', (string)$this->view->cycle('red', 'blue', array('name' => 'colors')));
+        $this->assertEquals('3',    (string)$this->view->cycle(1, 2, 3, array('name' => 'numbers')));
+        $this->assertEquals('red',  (string)$this->view->cycle('red', 'blue', array('name' => 'colors')));
     }
 
     public function testDefaultNamedCycle()
     {
-        $this->assertEquals('1', (string)$this->helper->cycle(1, 2, 3));
-        $this->assertEquals('2', (string)$this->helper->cycle(1, 2, 3, array('name' => 'default')));
-        $this->assertEquals('3', (string)$this->helper->cycle(1, 2, 3));
+        $this->assertEquals('1', (string)$this->view->cycle(1, 2, 3));
+        $this->assertEquals('2', (string)$this->view->cycle(1, 2, 3, array('name' => 'default')));
+        $this->assertEquals('3', (string)$this->view->cycle(1, 2, 3));
     }
 
     public function testResetCycle()
     {
-        $this->assertEquals('1', (string)$this->helper->cycle(1, 2, 3));
-        $this->assertEquals('2', (string)$this->helper->cycle(1, 2, 3));
-        $this->helper->resetCycle();
-        $this->assertEquals('1', (string)$this->helper->cycle(1, 2, 3));
+        $this->assertEquals('1', (string)$this->view->cycle(1, 2, 3));
+        $this->assertEquals('2', (string)$this->view->cycle(1, 2, 3));
+        $this->view->resetCycle();
+        $this->assertEquals('1', (string)$this->view->cycle(1, 2, 3));
     }
 
     public function testResetUnknownCycle()
     {
-        $this->helper->resetCycle('colors');
+        $this->view->resetCycle('colors');
     }
 
     public function testResetNamedCycle()
     {
-        $this->assertEquals('1',    (string)$this->helper->cycle(1, 2, 3, array('name' => 'numbers')));
-        $this->assertEquals('red',  (string)$this->helper->cycle('red', 'blue', array('name' => 'colors')));
-        $this->helper->resetCycle('numbers');
-        $this->assertEquals('1',    (string)$this->helper->cycle(1, 2, 3, array('name' => 'numbers')));
-        $this->assertEquals('blue', (string)$this->helper->cycle('red', 'blue', array('name' => 'colors')));
-        $this->assertEquals('2',    (string)$this->helper->cycle(1, 2, 3, array('name' => 'numbers')));
-        $this->assertEquals('red',  (string)$this->helper->cycle('red', 'blue', array('name' => 'colors')));
+        $this->assertEquals('1',    (string)$this->view->cycle(1, 2, 3, array('name' => 'numbers')));
+        $this->assertEquals('red',  (string)$this->view->cycle('red', 'blue', array('name' => 'colors')));
+        $this->view->resetCycle('numbers');
+        $this->assertEquals('1',    (string)$this->view->cycle(1, 2, 3, array('name' => 'numbers')));
+        $this->assertEquals('blue', (string)$this->view->cycle('red', 'blue', array('name' => 'colors')));
+        $this->assertEquals('2',    (string)$this->view->cycle(1, 2, 3, array('name' => 'numbers')));
+        $this->assertEquals('red',  (string)$this->view->cycle('red', 'blue', array('name' => 'colors')));
     }
 
     public function testPluralization()
     {
-        $this->assertEquals('1 count',  $this->helper->pluralize(1, 'count'));
-        $this->assertEquals('2 counts', $this->helper->pluralize(2, 'count'));
-        $this->assertEquals('1 count',  $this->helper->pluralize('1', 'count'));
-        $this->assertEquals('2 counts', $this->helper->pluralize('2', 'count'));
-        $this->assertEquals('1,066 counts', $this->helper->pluralize('1,066', 'count'));
-        $this->assertEquals('1.25 counts',  $this->helper->pluralize('1.25', 'count'));
-        $this->assertEquals('2 counters',   $this->helper->pluralize('2', 'count', 'counters'));
+        $this->assertEquals('1 count',  $this->view->pluralize(1, 'count'));
+        $this->assertEquals('2 counts', $this->view->pluralize(2, 'count'));
+        $this->assertEquals('1 count',  $this->view->pluralize('1', 'count'));
+        $this->assertEquals('2 counts', $this->view->pluralize('2', 'count'));
+        $this->assertEquals('1,066 counts', $this->view->pluralize('1,066', 'count'));
+        $this->assertEquals('1.25 counts',  $this->view->pluralize('1.25', 'count'));
+        $this->assertEquals('2 counters',   $this->view->pluralize('2', 'count', 'counters'));
     }
 
 }