This repository was archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathPartialTest.php
188 lines (163 loc) · 5.42 KB
/
PartialTest.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
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\View\Helper;
use ArrayObject;
use PHPUnit\Framework\TestCase;
use Zend\View\Helper\Partial;
use Zend\View\Model\ViewModel;
use Zend\View\Renderer\PhpRenderer as View;
use ZendTest\View\Helper\TestAsset\Aggregate;
/**
* Test class for Partial view helper.
*
* @group Zend_View
* @group Zend_View_Helper
*/
class PartialTest extends TestCase
{
/**
* @var Partial
*/
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 Partial();
}
/**
* 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);
}
/**
* @return void
*/
public function testPartialRendersScript()
{
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke('partialOne.phtml');
$this->assertContains('This is the first test partial', $return);
}
/**
* @return void
*/
public function testPartialRendersScriptWithVars()
{
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$view->vars()->message = 'This should never be read';
$this->helper->setView($view);
$return = $this->helper->__invoke('partialThree.phtml', ['message' => 'This message should be read']);
$this->assertNotContains('This should never be read', $return);
$this->assertContains('This message should be read', $return, $return);
}
/**
* @return void
*/
public function testSetViewSetsViewProperty()
{
$view = new View();
$this->helper->setView($view);
$this->assertSame($view, $this->helper->getView());
}
public function testObjectModelWithPublicPropertiesSetsViewVariables()
{
$model = new \stdClass();
$model->foo = 'bar';
$model->bar = 'baz';
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke('partialVars.phtml', $model);
foreach (get_object_vars($model) as $key => $value) {
$string = sprintf('%s: %s', $key, $value);
$this->assertContains($string, $return);
}
}
public function testObjectModelWithToArraySetsViewVariables()
{
$model = new Aggregate();
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke('partialVars.phtml', $model);
foreach ($model->toArray() as $key => $value) {
$string = sprintf('%s: %s', $key, $value);
$this->assertContains($string, $return);
}
}
public function testPassingNoArgsReturnsHelperInstance()
{
$test = $this->helper->__invoke();
$this->assertSame($this->helper, $test);
}
public function testCanPassViewModelAsSecondArgument()
{
$model = new ViewModel([
'foo' => 'bar',
'bar' => 'baz',
]);
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke('partialVars.phtml', $model);
foreach ($model->getVariables() as $key => $value) {
$string = sprintf('%s: %s', $key, $value);
$this->assertContains($string, $return);
}
}
public function testCanPassArrayObjectAsSecondArgument()
{
$model = new ArrayObject([
'foo' => 'bar',
'bar' => 'baz',
]);
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke('partialVars.phtml', $model);
foreach ($model as $key => $value) {
$string = sprintf('%s: %s', $key, $value);
$this->assertContains($string, $return);
}
}
public function testCanPassViewModelAsSoleArgument()
{
$model = new ViewModel([
'foo' => 'bar',
'bar' => 'baz',
]);
$model->setTemplate('partialVars.phtml');
$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke($model);
foreach ($model->getVariables() as $key => $value) {
$string = sprintf('%s: %s', $key, $value);
$this->assertContains($string, $return);
}
}
}