{
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 < 2 & 3', $this->helper->escapeOnce('1 < 2 & 3'));
+ $this->assertEquals('1 < 2 & 3', $this->view->escapeOnce('1 < 2 & 3'));
}
public function testDoubleEscapingAttributes()
$attributes = array('1&2', '1 < 2', '“test“');
foreach ($attributes as $escaped) {
$this->assertEquals("<a href=\"$escaped\" />",
- $this->helper->tag('a', array('href' => $escaped)));
+ $this->view->tag('a', array('href' => $escaped)));
}
}
$attributes = array('&1;', 'dfa3;', '& #123;');
foreach ($attributes as $escaped) {
$this->assertEquals('<a href="' . str_replace('&', '&', $escaped) . '" />',
- $this->helper->tag('a', array('href' => $escaped)));
+ $this->view->tag('a', array('href' => $escaped)));
}
}
{
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
{
$text = "Test 'escaping html' \"quotes\" and & amps";
$expected = "Test 'escaping html' "quotes" and & amps";
- $this->assertEquals($expected, $this->helper->h($text));
+ $this->assertEquals($expected, $this->view->h($text));
}
// test truncate
{
$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
{
$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
{
$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));
}
{
$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
{
$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()
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'));
}
}