~ubuntu-branches/ubuntu/trusty/php-horde-view/trusty-proposed

« back to all changes in this revision

Viewing changes to Horde_View-1.0.1/test/Horde/View/Helper/TextTest.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2012-11-30 22:14:57 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20121130221457-n9gb5mxywd01k800
Tags: 2.0.1-1
* New upstream version 2.0.1
* Fixed watchfile
* Updated Standards-Version to 3.9.3: no change
* Updated copyright format URL
* Updated debian/pearrc to install Horde apps in /usr/share/horde
  instead of /usr/share/horde4
* Updated Homepage
* Added Vcs-* fields

Show diffs side-by-side

added added

removed removed

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