-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSingletonViewBlockHtmlHelperMethodTest.php
More file actions
184 lines (159 loc) · 5.7 KB
/
SingletonViewBlockHtmlHelperMethodTest.php
File metadata and controls
184 lines (159 loc) · 5.7 KB
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
<?php
/**
* SingletonViewBlockHtmlHelper Test Case
*
* @copyright Copyright 2014, NetCommons Project
* @author Kohei Teraguchi <kteraguchi@commonsnet.org>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('SingletonViewBlockHtmlHelperTestBase', 'NetCommons.Test/Case/View/Helper/SingletonViewBlockHtml');
/**
* Summary for TokenHelper Test Case
*
*/
class SingletonViewBlockHtmlHelperMethodTest extends SingletonViewBlockHtmlHelperTestBase {
/**
* testMeta method
*
* @return void
*/
public function testMeta() {
$expected = '<meta name="keywords" content="these, are, some, meta, keywords"/>';
$actual = $this->SingletonViewBlockHtml->meta('keywords', 'these, are, some, meta, keywords');
$this->assertEquals($expected, $actual);
$needle = $expected;
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('meta'));
}
/**
* testMetaWithBlock method
*
* @return void
*/
public function testMetaWithBlock() {
$options = array('inline' => false);
$actual = $this->SingletonViewBlockHtml->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, $options);
$this->assertNull($actual);
$needle = '<meta name="ROBOTS" content="ALL"/>';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertContains($needle, $viewBlock->get('meta'));
}
/**
* testCss method
*
* @return void
*/
public function testCss() {
$expected = '/<link rel="stylesheet" type="text\/css" href=".*\/css\/cssFile\.css"\/>/';
$actual = $this->SingletonViewBlockHtml->css('cssFile');
$this->assertRegExp($expected, $actual);
$needle = '/css/cssFile.css';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('css'));
$actual = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticIncludedAssets');
$actual = $actual['HtmlHelper::css'];
$this->assertArrayHasKey('cssFile', $actual);
$this->assertTrue($actual['cssFile']);
}
/**
* testCssWithBlockSamePath method
*
* @return void
*/
public function testCssWithBlockSamePath() {
$options = array(
'inline' => false,
'once' => true
);
$actual = $this->SingletonViewBlockHtml->css('cssFile', $options);
$this->assertNull($actual);
$needle = '/css/cssFile.css';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('css'));
}
/**
* testCssWithBlockAnotherPath method
*
* Unnecessary if under 2.6.0
*
* @return void
*/
public function testCssWithBlockAnotherPath() {
$options = array('inline' => false);
$actual = $this->SingletonViewBlockHtml->css('cssFileAnother', $options);
$this->assertNull($actual);
$needle = '/css/cssFileAnother.css';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertContains($needle, $viewBlock->get('css'));
}
/**
* testScript method
*
* @return void
*/
public function testScript() {
$expected = '/<script type="text\/javascript" src=".*\/js\/scriptFile\.js"><\/script>/';
$actual = $this->SingletonViewBlockHtml->script('scriptFile');
$this->assertRegExp($expected, $actual);
$needle = $expected;
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('script'));
$actual = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticIncludedAssets');
$actual = $actual['HtmlHelper::script'];
$this->assertArrayHasKey('scriptFile', $actual);
$this->assertTrue($actual['scriptFile']);
}
/**
* testScriptWithBlockSameUrl method
*
* @return void
*/
public function testScriptWithBlockSameUrl() {
$options = array('inline' => false);
$actual = $this->SingletonViewBlockHtml->script('scriptFile', $options);
$this->assertNull($actual);
$needle = '/js/scriptFile.js';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('script'));
}
/**
* testScriptWithBlockAnotherUrl method
*
* @return void
*/
public function testScriptWithBlockAnotherUrl() {
$options = array('inline' => false);
$actual = $this->SingletonViewBlockHtml->script('scriptFileAnother', $options);
$this->assertNull($actual);
$needle = '/js/scriptFileAnother.js';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertContains($needle, $viewBlock->get('script'));
}
/**
* testScriptBlock method
*
* @return void
*/
public function testScriptBlock() {
$expected = 'window.foo = 2';
$actual = $this->SingletonViewBlockHtml->scriptBlock('window.foo = 2;');
$this->assertContains($expected, $actual);
$needle = $expected;
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('script'));
}
/**
* testMetaReturnWithBlock method
*
* @return void
*/
public function testScriptBlockWithBlock() {
$options = array('inline' => false);
$actual = $this->SingletonViewBlockHtml->scriptBlock('window.foo = 3;', $options);
$this->assertNull($actual);
$needle = '<script>window.foo = 3</script>';
$viewBlock = PHPUnit_Framework_Assert::readAttribute($this->SingletonViewBlockHtml, '__staticViewBlock');
$this->assertNotContains($needle, $viewBlock->get('script'));
}
}