1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsUserArgumentValidate.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Tests views user argument argument handler.
|
10
|
*/
|
11
|
class ViewsUserArgumentValidate extends ViewsSqlTest {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Tests user argument validator',
|
15
|
'description' => 'Tests user argument validator',
|
16
|
'group' => 'Views Plugins',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
public function setUp(array $modules = array()) {
|
24
|
$modules[] = 'views';
|
25
|
parent::setUp($modules);
|
26
|
|
27
|
$this->account = $this->drupalCreateUser();
|
28
|
}
|
29
|
|
30
|
function testArgumentValidateUserUid() {
|
31
|
$account = $this->account;
|
32
|
// test 'uid' case.
|
33
|
$view = $this->view_argument_validate_user('uid');
|
34
|
$view->set_display('default');
|
35
|
$view->pre_execute();
|
36
|
$view->init_handlers();
|
37
|
$this->assertTrue($view->argument['null']->validate_arg($account->uid));
|
38
|
// Reset safed argument validation.
|
39
|
$view->argument['null']->argument_validated = NULL;
|
40
|
// Fail for a string variable since type is 'uid'
|
41
|
$this->assertFalse($view->argument['null']->validate_arg($account->name));
|
42
|
// Reset safed argument validation.
|
43
|
$view->argument['null']->argument_validated = NULL;
|
44
|
// Fail for a valid numeric, but for a user that doesn't exist.
|
45
|
$this->assertFalse($view->argument['null']->validate_arg(32));
|
46
|
}
|
47
|
|
48
|
function testArgumentValidateUserName() {
|
49
|
$account = $this->account;
|
50
|
// test 'name' case.
|
51
|
$view = $this->view_argument_validate_user('name');
|
52
|
$view->set_display('default');
|
53
|
$view->pre_execute();
|
54
|
$view->init_handlers();
|
55
|
$this->assertTrue($view->argument['null']->validate_arg($account->name));
|
56
|
// Reset safed argument validation.
|
57
|
$view->argument['null']->argument_validated = NULL;
|
58
|
// Fail for a uid variable since type is 'name'
|
59
|
$this->assertFalse($view->argument['null']->validate_arg($account->uid));
|
60
|
// Reset safed argument validation.
|
61
|
$view->argument['null']->argument_validated = NULL;
|
62
|
// Fail for a valid string, but for a user that doesn't exist.
|
63
|
$this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
|
64
|
}
|
65
|
|
66
|
function testArgumentValidateUserEither() {
|
67
|
$account = $this->account;
|
68
|
// test 'either' case.
|
69
|
$view = $this->view_argument_validate_user('either');
|
70
|
$view->set_display('default');
|
71
|
$view->pre_execute();
|
72
|
$view->init_handlers();
|
73
|
$this->assertTrue($view->argument['null']->validate_arg($account->name));
|
74
|
// Reset safed argument validation.
|
75
|
$view->argument['null']->argument_validated = NULL;
|
76
|
// Fail for a uid variable since type is 'name'
|
77
|
$this->assertTrue($view->argument['null']->validate_arg($account->uid));
|
78
|
// Reset safed argument validation.
|
79
|
$view->argument['null']->argument_validated = NULL;
|
80
|
// Fail for a valid string, but for a user that doesn't exist.
|
81
|
$this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
|
82
|
// Reset safed argument validation.
|
83
|
$view->argument['null']->argument_validated = NULL;
|
84
|
// Fail for a valid uid, but for a user that doesn't exist.
|
85
|
$this->assertFalse($view->argument['null']->validate_arg(32));
|
86
|
}
|
87
|
|
88
|
function view_argument_validate_user($argtype) {
|
89
|
$view = new view();
|
90
|
$view->name = 'view_argument_validate_user';
|
91
|
$view->description = '';
|
92
|
$view->tag = '';
|
93
|
$view->view_php = '';
|
94
|
$view->base_table = 'node';
|
95
|
$view->is_cacheable = FALSE;
|
96
|
$view->api_version = 2;
|
97
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
98
|
|
99
|
/* Display: Master */
|
100
|
$handler = $view->new_display('default', 'Master', 'default');
|
101
|
$handler->display->display_options['access']['type'] = 'none';
|
102
|
$handler->display->display_options['cache']['type'] = 'none';
|
103
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
104
|
$handler->display->display_options['pager']['type'] = 'full';
|
105
|
$handler->display->display_options['style_plugin'] = 'default';
|
106
|
$handler->display->display_options['row_plugin'] = 'fields';
|
107
|
/* Argument: Global: Null */
|
108
|
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
109
|
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
110
|
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
111
|
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
112
|
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
113
|
$handler->display->display_options['arguments']['null']['validate']['type'] = 'user';
|
114
|
$handler->display->display_options['arguments']['null']['validate_options']['type'] = $argtype;
|
115
|
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
116
|
|
117
|
return $view;
|
118
|
}
|
119
|
|
120
|
}
|