1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsArgumentValidatorTest.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests Views argument validators.
|
10
|
*/
|
11
|
class ViewsArgumentValidatorTest extends ViewsSqlTest {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Argument validator',
|
15
|
'group' => 'Views Plugins',
|
16
|
'description' => 'Test argument validator tests.',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
function testArgumentValidatePhp() {
|
21
|
$string = $this->randomName();
|
22
|
$view = $this->view_test_argument_validate_php($string);
|
23
|
$view->set_display('default');
|
24
|
$view->pre_execute();
|
25
|
$view->init_handlers();
|
26
|
$this->assertTrue($view->argument['null']->validate_arg($string));
|
27
|
// Reset safed argument validation.
|
28
|
$view->argument['null']->argument_validated = NULL;
|
29
|
$this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
|
30
|
}
|
31
|
|
32
|
function testArgumentValidateNumeric() {
|
33
|
$view = $this->view_argument_validate_numeric();
|
34
|
$view->set_display('default');
|
35
|
$view->pre_execute();
|
36
|
$view->init_handlers();
|
37
|
$this->assertFalse($view->argument['null']->validate_arg($this->randomString()));
|
38
|
// Reset safed argument validation.
|
39
|
$view->argument['null']->argument_validated = NULL;
|
40
|
$this->assertTrue($view->argument['null']->validate_arg(12));
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Make sure argument validation works properly.
|
45
|
*/
|
46
|
function testArgumentValidatePhpFailure() {
|
47
|
$view = $this->view_test_argument_validate_php_failure();
|
48
|
$view->save();
|
49
|
$this->drupalGet('test-php-failure');
|
50
|
|
51
|
// This should return a 403, indicating that the arguments validation fails.
|
52
|
$this->assertResponse(403);
|
53
|
|
54
|
$this->drupalGet('test-php-failure-feed');
|
55
|
|
56
|
// This should return a 403, indicating that the arguments validation fails.
|
57
|
$this->assertResponse(403);
|
58
|
}
|
59
|
|
60
|
function view_test_argument_validate_php($string) {
|
61
|
$code = 'return $argument == \'' . $string . '\';';
|
62
|
$view = new view();
|
63
|
$view->name = 'view_argument_validate_php';
|
64
|
$view->description = '';
|
65
|
$view->tag = '';
|
66
|
$view->view_php = '';
|
67
|
$view->base_table = 'node';
|
68
|
$view->is_cacheable = FALSE;
|
69
|
$view->api_version = 2;
|
70
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
71
|
|
72
|
/* Display: Master */
|
73
|
$handler = $view->new_display('default', 'Master', 'default');
|
74
|
$handler->display->display_options['access']['type'] = 'none';
|
75
|
$handler->display->display_options['cache']['type'] = 'none';
|
76
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
77
|
$handler->display->display_options['pager']['type'] = 'full';
|
78
|
$handler->display->display_options['style_plugin'] = 'default';
|
79
|
$handler->display->display_options['row_plugin'] = 'fields';
|
80
|
/* Argument: Global: Null */
|
81
|
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
82
|
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
83
|
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
84
|
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
85
|
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
86
|
$handler->display->display_options['arguments']['null']['validate_type'] = 'php';
|
87
|
$handler->display->display_options['arguments']['null']['validate_options']['code'] = $code;
|
88
|
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
89
|
|
90
|
return $view;
|
91
|
}
|
92
|
|
93
|
function view_argument_validate_numeric() {
|
94
|
$view = new view();
|
95
|
$view->name = 'view_argument_validate_numeric';
|
96
|
$view->description = '';
|
97
|
$view->tag = '';
|
98
|
$view->view_php = '';
|
99
|
$view->base_table = 'node';
|
100
|
$view->is_cacheable = FALSE;
|
101
|
$view->api_version = 2;
|
102
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
103
|
|
104
|
/* Display: Master */
|
105
|
$handler = $view->new_display('default', 'Master', 'default');
|
106
|
$handler->display->display_options['access']['type'] = 'none';
|
107
|
$handler->display->display_options['cache']['type'] = 'none';
|
108
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
109
|
$handler->display->display_options['pager']['type'] = 'full';
|
110
|
$handler->display->display_options['style_plugin'] = 'default';
|
111
|
$handler->display->display_options['row_plugin'] = 'fields';
|
112
|
/* Argument: Global: Null */
|
113
|
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
114
|
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
115
|
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
116
|
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
117
|
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
118
|
$handler->display->display_options['arguments']['null']['validate_type'] = 'numeric';
|
119
|
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
120
|
|
121
|
return $view;
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
*
|
126
|
*
|
127
|
* @return view $view
|
128
|
* The required view object.
|
129
|
*/
|
130
|
function view_test_argument_validate_php_failure() {
|
131
|
$view = new view();
|
132
|
$view->name = 'view_argument_validate_php_failure';
|
133
|
$view->description = '';
|
134
|
$view->tag = '';
|
135
|
$view->base_table = 'node';
|
136
|
$view->human_name = '';
|
137
|
$view->core = 0;
|
138
|
$view->api_version = '3.0';
|
139
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
140
|
|
141
|
/* Display: Master */
|
142
|
$handler = $view->new_display('default', 'Master', 'default');
|
143
|
$handler->display->display_options['use_more_always'] = FALSE;
|
144
|
$handler->display->display_options['access']['type'] = 'none';
|
145
|
$handler->display->display_options['cache']['type'] = 'none';
|
146
|
$handler->display->display_options['query']['type'] = 'views_query';
|
147
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
148
|
$handler->display->display_options['pager']['type'] = 'none';
|
149
|
$handler->display->display_options['style_plugin'] = 'default';
|
150
|
$handler->display->display_options['row_plugin'] = 'fields';
|
151
|
/* Field: Content: Title */
|
152
|
$handler->display->display_options['fields']['title']['id'] = 'title';
|
153
|
$handler->display->display_options['fields']['title']['table'] = 'node';
|
154
|
$handler->display->display_options['fields']['title']['field'] = 'title';
|
155
|
$handler->display->display_options['fields']['title']['label'] = '';
|
156
|
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
|
157
|
$handler->display->display_options['fields']['title']['link_to_node'] = FALSE;
|
158
|
/* Contextual filter: Global: Null */
|
159
|
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
160
|
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
161
|
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
162
|
$handler->display->display_options['arguments']['null']['default_action'] = 'default';
|
163
|
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
164
|
$handler->display->display_options['arguments']['null']['default_argument_options']['argument'] = 'No filter';
|
165
|
$handler->display->display_options['arguments']['null']['summary']['number_of_records'] = '0';
|
166
|
$handler->display->display_options['arguments']['null']['summary']['format'] = 'default_summary';
|
167
|
$handler->display->display_options['arguments']['null']['summary_options']['items_per_page'] = '25';
|
168
|
$handler->display->display_options['arguments']['null']['specify_validation'] = TRUE;
|
169
|
$handler->display->display_options['arguments']['null']['validate']['type'] = 'php';
|
170
|
$handler->display->display_options['arguments']['null']['validate_options']['code'] = 'return FALSE;';
|
171
|
$handler->display->display_options['arguments']['null']['validate']['fail'] = 'access denied';
|
172
|
|
173
|
/* Display: Page */
|
174
|
$handler = $view->new_display('page', 'Page', 'page_1');
|
175
|
$handler->display->display_options['path'] = 'test-php-failure';
|
176
|
|
177
|
/* Display: Feed */
|
178
|
$handler = $view->new_display('feed', 'Feed', 'feed_1');
|
179
|
$handler->display->display_options['path'] = 'test-php-failure-feed';
|
180
|
$handler->display->display_options['pager']['type'] = 'none';
|
181
|
$handler->display->display_options['pager']['options']['offset'] = '0';
|
182
|
$handler->display->display_options['style_plugin'] = 'rss';
|
183
|
$handler->display->display_options['row_plugin'] = 'node_rss';
|
184
|
|
185
|
return $view;
|
186
|
}
|
187
|
|
188
|
}
|