1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ViewListTest extends PHPUnit_Framework_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
public function testViewList() |
7
|
|
|
{ |
8
|
|
|
//execute the contructor and check for the Object type and type attribute |
9
|
|
|
$view = new ViewList(); |
10
|
|
|
$this->assertInstanceOf('ViewList',$view); |
11
|
|
|
$this->assertInstanceOf('SugarView',$view); |
12
|
|
|
$this->assertAttributeEquals('list','type', $view); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
public function testoldSearch() |
17
|
|
|
{ |
18
|
|
|
$view = new ViewList(); |
19
|
|
|
|
20
|
|
|
//execute the method and test if it works and does not throws an exception. |
21
|
|
|
try { |
22
|
|
|
$view->oldSearch(); |
23
|
|
|
|
24
|
|
|
} catch (Exception $e) { |
25
|
|
|
$this->fail(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testnewSearch() |
31
|
|
|
{ |
32
|
|
|
$view = new ViewList(); |
33
|
|
|
|
34
|
|
|
//execute the method and test if it works and does not throws an exception. |
35
|
|
|
try { |
36
|
|
|
$view->newSearch(); |
37
|
|
|
|
38
|
|
|
} catch (Exception $e) { |
39
|
|
|
$this->fail(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testlistViewPrepare() |
45
|
|
|
{ |
46
|
|
|
error_reporting(E_ERROR | E_PARSE); |
47
|
|
|
|
48
|
|
|
//test without setting parameters. it should return some html |
49
|
|
|
$view = new ViewList(); |
50
|
|
|
$view->module = "Users"; |
51
|
|
|
|
52
|
|
|
ob_start(); |
53
|
|
|
$view->listViewPrepare(); |
54
|
|
|
$renderedContent = ob_get_contents(); |
55
|
|
|
ob_end_clean(); |
56
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent)); |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
//test with some REQUEST parameters preset. it should return some html and set the REQUEST key we provided in current_query_by_page REQUEST Param. |
60
|
|
|
$view = new ViewList(); |
61
|
|
|
$view->module = "Users"; |
62
|
|
|
$GLOBALS['module']= "Users"; |
63
|
|
|
$_REQUEST["Users2_USER_offset"]= 1; |
64
|
|
|
$_REQUEST['current_query_by_page'] = base64_encode(serialize(Array("key"=>"value"))); |
65
|
|
|
$view->bean = New User(); |
66
|
|
|
|
67
|
|
|
ob_start(); |
68
|
|
|
$view->listViewPrepare(); |
69
|
|
|
$renderedContent = ob_get_contents(); |
70
|
|
|
ob_end_clean(); |
71
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent)); |
72
|
|
|
$this->assertEquals('value',$_REQUEST['key']); |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testlistViewProcess() |
77
|
|
|
{ |
78
|
|
|
//execute the method and call methods to get the required child objects set. it should return some html. |
79
|
|
|
$view = new ViewList(); |
80
|
|
|
$view->seed = new User(); |
81
|
|
|
$view->prepareSearchForm(); |
82
|
|
|
$view->preDisplay(); |
83
|
|
|
|
84
|
|
|
ob_start(); |
85
|
|
|
$view->listViewProcess(); |
86
|
|
|
$renderedContent = ob_get_contents(); |
87
|
|
|
ob_end_clean(); |
88
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent)); |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testprepareSearchForm() |
93
|
|
|
{ |
94
|
|
|
//test without any REQUEST parameters set. it will set searchform attribute to a searchform object. |
95
|
|
|
$view1 = new ViewList(); |
96
|
|
|
$view1->module = "Users"; |
97
|
|
|
$view1->prepareSearchForm(); |
98
|
|
|
$this->assertInstanceOf('SearchForm',$view1->searchForm); |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
//test with REQUEST parameters set. it will set searchform attribute to a searchform object. |
102
|
|
|
$view2 = new ViewList(); |
103
|
|
|
$view2->module = "Users"; |
104
|
|
|
$_REQUEST['search_form'] = true; |
105
|
|
|
$_REQUEST['searchFormTab'] = 'advanced_search'; |
106
|
|
|
$view2->prepareSearchForm(); |
107
|
|
|
|
108
|
|
|
$this->assertInstanceOf('SearchForm',$view2->searchForm); |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testprocessSearchForm() |
113
|
|
|
{ |
114
|
|
|
//test without use_old_search. it should return html. |
115
|
|
|
$view = new ViewList(); |
116
|
|
|
$view->prepareSearchForm(); |
117
|
|
|
|
118
|
|
|
ob_start(); |
119
|
|
|
$view->processSearchForm(); |
120
|
|
|
$renderedContent = ob_get_contents(); |
121
|
|
|
ob_end_clean(); |
122
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent)); |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
//test with use_old_search = true. there is a $view variable which is never set so it doesn't returns anything. |
126
|
|
|
$view = new ViewList(); |
127
|
|
|
$view->prepareSearchForm(); |
128
|
|
|
$view->use_old_search = true; |
129
|
|
|
|
130
|
|
|
ob_start(); |
131
|
|
|
$view->processSearchForm(); |
132
|
|
|
$renderedContent = ob_get_contents(); |
133
|
|
|
ob_end_clean(); |
134
|
|
|
$this->assertEquals(0,strlen($renderedContent)); |
135
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testpreDisplay() |
140
|
|
|
{ |
141
|
|
|
//execute the method and test if it sets the lv attribute to ListViewSmarty object. |
142
|
|
|
$view = new ViewList(); |
143
|
|
|
$view->preDisplay(); |
144
|
|
|
$this->assertInstanceOf('ListViewSmarty',$view->lv); |
145
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function testdisplay() |
149
|
|
|
{ |
150
|
|
|
$view = new ViewList(); |
151
|
|
|
|
152
|
|
|
//test without setting bean attibute. it shuold return no access html. |
153
|
|
|
ob_start(); |
154
|
|
|
$view->display(); |
155
|
|
|
$renderedContent1 = ob_get_contents(); |
156
|
|
|
ob_end_clean(); |
157
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent1)); |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
//test with bean, seed and other arrtibutes set. it shuold return html. |
161
|
|
|
$view->bean = new User(); |
162
|
|
|
$view->seed = new User(); |
163
|
|
|
$view->module = "Users"; |
164
|
|
|
$view->prepareSearchForm(); |
165
|
|
|
$view->preDisplay(); |
166
|
|
|
|
167
|
|
|
ob_start(); |
168
|
|
|
|
169
|
|
|
$view->display(); |
170
|
|
|
$renderedContent2 = ob_get_contents(); |
171
|
|
|
ob_end_clean(); |
172
|
|
|
$this->assertGreaterThan(0,strlen($renderedContent2)); |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
} |
180
|
|
|
?> |
181
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.