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