This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
/
HeadTitleTest.php
229 lines (195 loc) · 7.04 KB
/
HeadTitleTest.php
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_View
*/
namespace ZendTest\View\Helper;
use Zend\I18n\Translator\Translator;
use Zend\View\Helper\Placeholder\Registry;
use Zend\View\Helper;
/**
* Test class for Zend_View_Helper_HeadTitle.
*
* @category Zend
* @package Zend_View
* @subpackage UnitTests
* @group Zend_View
* @group Zend_View_Helper
*/
class HeadTitleTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Zend_View_Helper_HeadTitle
*/
public $helper;
/**
* @var string
*/
public $basePath;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
$this->basePath = __DIR__ . '/_files/modules';
$this->helper = new Helper\HeadTitle();
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @return void
*/
public function tearDown()
{
unset($this->helper);
}
public function testHeadTitleReturnsObjectInstance()
{
$placeholder = $this->helper->__invoke();
$this->assertTrue($placeholder instanceof Helper\HeadTitle);
}
public function testCanSetTitleViaHeadTitle()
{
$placeholder = $this->helper->__invoke('Foo Bar', 'SET');
$this->assertEquals('Foo Bar', $placeholder->renderTitle());
}
public function testToStringWrapsToTitleTag()
{
$placeholder = $this->helper->__invoke('Foo Bar', 'SET');
$this->assertEquals('<title>Foo Bar</title>', $placeholder->toString());
}
public function testCanAppendTitleViaHeadTitle()
{
$placeholder = $this->helper->__invoke('Foo');
$placeholder = $this->helper->__invoke('Bar');
$this->assertEquals('FooBar', $placeholder->renderTitle());
}
public function testCanPrependTitleViaHeadTitle()
{
$placeholder = $this->helper->__invoke('Foo');
$placeholder = $this->helper->__invoke('Bar', 'PREPEND');
$this->assertEquals('BarFoo', $placeholder->renderTitle());
}
public function testReturnedPlaceholderRenderTitleContainsFullTitleElement()
{
$placeholder = $this->helper->__invoke('Foo');
$placeholder = $this->helper->__invoke('Bar', 'APPEND')->setSeparator(' :: ');
$this->assertEquals('Foo :: Bar', $placeholder->renderTitle());
}
public function testRenderTitleEscapesEntries()
{
$this->helper->__invoke('<script type="text/javascript">alert("foo");</script>');
$string = $this->helper->renderTitle();
$this->assertNotContains('<script', $string);
$this->assertNotContains('</script>', $string);
}
public function testRenderTitleEscapesSeparator()
{
$this->helper->__invoke('Foo')
->__invoke('Bar')
->setSeparator(' <br /> ');
$string = $this->helper->renderTitle();
$this->assertNotContains('<br />', $string);
$this->assertContains('Foo', $string);
$this->assertContains('Bar', $string);
$this->assertContains('br /', $string);
}
public function testIndentationIsHonored()
{
$this->helper->setIndent(4);
$this->helper->__invoke('foo');
$string = $this->helper->toString();
$this->assertContains(' <title>', $string);
}
public function testAutoEscapeIsHonored()
{
$this->helper->__invoke('Some Title ©right;');
$this->assertEquals('Some Title &copyright;', $this->helper->renderTitle());
$this->assertTrue($this->helper->__invoke()->getAutoEscape());
$this->helper->__invoke()->setAutoEscape(false);
$this->assertFalse($this->helper->__invoke()->getAutoEscape());
$this->assertEquals('Some Title ©right;', $this->helper->renderTitle());
}
/**
* @issue ZF-2918
* @link http://framework.zend.com/issues/browse/ZF-2918
*/
public function testZF2918()
{
$this->helper->__invoke('Some Title');
$this->helper->setPrefix('Prefix: ');
$this->helper->setPostfix(' :Postfix');
$this->assertEquals('Prefix: Some Title :Postfix', $this->helper->renderTitle());
}
/**
* @issue ZF-3577
* @link http://framework.zend.com/issues/browse/ZF-3577
*/
public function testZF3577()
{
$this->helper->setAutoEscape(true);
$this->helper->__invoke('Some Title');
$this->helper->setPrefix('Prefix & ');
$this->helper->setPostfix(' & Postfix');
$this->assertEquals('Prefix & Some Title & Postfix', $this->helper->renderTitle());
}
public function testCanTranslateTitle()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('ext/intl not enabled');
}
$loader = new TestAsset\ArrayTranslator();
$loader->translations = array(
'Message_1' => 'Message 1 (en)',
);
$translator = new Translator();
$translator->getPluginManager()->setService('default', $loader);
$translator->addTranslationFile('default', null);
$this->helper->setTranslatorEnabled(true);
$this->helper->setTranslator($translator);
$this->helper->__invoke('Message_1');
$this->assertEquals('Message 1 (en)', $this->helper->renderTitle());
}
public function testTranslatorMethods()
{
$translatorMock = $this->getMock('Zend\I18n\Translator\Translator');
$this->helper->setTranslator($translatorMock, 'foo');
$this->assertEquals($translatorMock, $this->helper->getTranslator());
$this->assertEquals('foo', $this->helper->getTranslatorTextDomain());
$this->assertTrue($this->helper->hasTranslator());
$this->assertTrue($this->helper->isTranslatorEnabled());
$this->helper->setTranslatorEnabled(false);
$this->assertFalse($this->helper->isTranslatorEnabled());
}
/**
* @group ZF-8036
*/
public function testHeadTitleZero()
{
$this->helper->__invoke('0');
$this->assertEquals('0', $this->helper->renderTitle());
}
public function testCanPrependTitlesUsingDefaultAttachOrder()
{
$this->helper->setDefaultAttachOrder('PREPEND');
$placeholder = $this->helper->__invoke('Foo');
$placeholder = $this->helper->__invoke('Bar');
$this->assertEquals('BarFoo', $placeholder->renderTitle());
}
/**
* @group ZF-10284
*/
public function testReturnTypeDefaultAttachOrder()
{
$this->assertTrue($this->helper->setDefaultAttachOrder('PREPEND') instanceof Helper\HeadTitle);
$this->assertEquals('PREPEND', $this->helper->getDefaultAttachOrder());
}
}