/usr/share/php/tests/Horde_View/Horde/View/Helper/TextTest.php is in php-horde-view 2.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | <?php
/**
* Copyright 2007-2008 Maintainable Software, LLC
* Copyright 2008-2013 Horde LLC (http://www.horde.org/)
*
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @license http://www.horde.org/licenses/bsd
* @category Horde
* @package View
* @subpackage UnitTests
*/
/**
* @group view
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
* @author Chuck Hagenbuch <chuck@horde.org>
* @license http://www.horde.org/licenses/bsd
* @category Horde
* @package View
* @subpackage UnitTests
*/
class Horde_View_Helper_TextTest extends Horde_Test_Case
{
public function setUp()
{
$this->view = new Horde_View();
$this->view->addHelper('Text');
}
// test escaping data
public function testEscape()
{
$text = "Test 'escaping html' \"quotes\" and & amps";
$expected = "Test 'escaping html' "quotes" and & amps";
$this->assertEquals($expected, $this->view->h($text));
}
// test truncate
public function testTruncate()
{
$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->view->truncate($str, 40));
}
// test truncate
public function testTruncateMiddle()
{
$str = 'The quick brown fox jumps over the lazy dog tomorrow morning.';
$expected = 'The quick brown fox... tomorrow morning.';
$this->assertEquals($expected, $this->view->truncateMiddle($str, 40));
}
// text too short to trucate
public function testTruncateMiddleTooShort()
{
$str = 'The quick brown fox jumps over the dog.';
$expected = 'The quick brown fox jumps over the dog.';
$this->assertEquals($expected, $this->view->truncateMiddle($str, 40));
}
// test highlighter
public function testHighlightDefault()
{
$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->view->highlight($str, 'brown'));
}
// test failure to highlight
public function testHighlightCustom()
{
$str = 'The quick brown fox jumps over the dog.';
$expected = 'The quick <em>brown</em> fox jumps over the dog.';
$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->view->highlight($str, 'black'));
}
public function testCycleClass()
{
$value = new Horde_View_Helper_Text_Cycle(array('one', 2, '3'));
$this->assertEquals('one', (string)$value);
$this->assertEquals('2', (string)$value);
$this->assertEquals('3', (string)$value);
$this->assertEquals('one', (string)$value);
$value->reset();
$this->assertEquals('one', (string)$value);
$this->assertEquals('2', (string)$value);
$this->assertEquals('3', (string)$value);
}
public function testCycleClassWithInvalidArguments()
{
try {
$value = new Horde_View_Helper_Text_Cycle('bad');
$this->fail();
} catch (InvalidArgumentException $e) {}
try {
$value = new Horde_View_Helper_Text_Cycle(array('foo'));
$this->fail();
} catch (InvalidArgumentException $e) {}
try {
$value = new Horde_View_Helper_Text_Cycle(array('foo', 'bar'), 'bad-arg');
$this->fail();
} catch (InvalidArgumentException $e) {}
}
public function testCycleResetsWithNewValues()
{
$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->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->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->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->view->resetCycle('colors');
}
public function testResetNamedCycle()
{
$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->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'));
}
}
|