1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of ViewsArgumentDefaultTest.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Basic test for pluggable argument default.
|
10
|
*/
|
11
|
class ViewsArgumentDefaultTest extends ViewsSqlTest {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'Argument_default',
|
15
|
'description' => 'Tests pluggable argument_default for views.',
|
16
|
'group' => 'Views Plugins',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
public function setUp() {
|
21
|
parent::setUp('views');
|
22
|
|
23
|
$this->random = $this->randomString();
|
24
|
}
|
25
|
|
26
|
/**
|
27
|
* Tests the use of a default argument plugin that provides no options.
|
28
|
*/
|
29
|
function testArgumentDefaultNoOptions() {
|
30
|
module_enable(array('views_ui', 'views_test'));
|
31
|
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
32
|
$this->drupalLogin($admin_user);
|
33
|
|
34
|
// The current_user plugin has no options form, and should pass validation.
|
35
|
$argument_type = 'current_user';
|
36
|
$edit = array(
|
37
|
'options[default_argument_type]' => $argument_type,
|
38
|
);
|
39
|
$this->drupalPost('admin/structure/views/nojs/config-item/test_argument_default_current_user/default/argument/uid', $edit, t('Apply'));
|
40
|
|
41
|
// Note, the undefined index error has two spaces after it.
|
42
|
$error = array(
|
43
|
'%type' => 'Notice',
|
44
|
'!message' => 'Undefined index: ' . $argument_type,
|
45
|
'%function' => 'views_handler_argument->options_validate()',
|
46
|
);
|
47
|
$message = t('%type: !message in %function', $error);
|
48
|
$this->assertNoRaw($message, t('Did not find error message: !message.', array('!message' => $message)));
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Tests fixed default argument.
|
53
|
*/
|
54
|
function testArgumentDefaultFixed() {
|
55
|
$view = $this->view_argument_default_fixed();
|
56
|
|
57
|
$view->set_display('default');
|
58
|
$view->pre_execute();
|
59
|
$view->init_handlers();
|
60
|
|
61
|
$this->assertEqual($view->argument['null']->get_default_argument(), $this->random, 'Fixed argument should be used by default.');
|
62
|
|
63
|
$view->destroy();
|
64
|
|
65
|
// Make sure that a normal argument provided is used.
|
66
|
$view = $this->view_argument_default_fixed();
|
67
|
|
68
|
$view->set_display('default');
|
69
|
$random_string = $this->randomString();
|
70
|
$view->execute_display('default', array($random_string));
|
71
|
|
72
|
$this->assertEqual($view->args[0], $random_string, 'Provided argument should be used.');
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* @todo Test php default argument.
|
77
|
*/
|
78
|
function testArgumentDefaultPhp() {
|
79
|
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* @todo Test node default argument.
|
84
|
*/
|
85
|
function testArgumentDefaultNode() {
|
86
|
|
87
|
}
|
88
|
|
89
|
function view_argument_default_fixed() {
|
90
|
$view = new view();
|
91
|
$view->name = 'test_argument_default_fixed';
|
92
|
$view->description = '';
|
93
|
$view->tag = '';
|
94
|
$view->view_php = '';
|
95
|
$view->base_table = 'node';
|
96
|
$view->is_cacheable = FALSE;
|
97
|
$view->api_version = 2;
|
98
|
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
99
|
|
100
|
/* Display: Master */
|
101
|
$handler = $view->new_display('default', 'Master', 'default');
|
102
|
$handler->display->display_options['access']['type'] = 'none';
|
103
|
$handler->display->display_options['cache']['type'] = 'none';
|
104
|
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
105
|
$handler->display->display_options['pager']['type'] = 'full';
|
106
|
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
107
|
$handler->display->display_options['pager']['options']['offset'] = '0';
|
108
|
$handler->display->display_options['pager']['options']['id'] = '0';
|
109
|
$handler->display->display_options['style_plugin'] = 'default';
|
110
|
$handler->display->display_options['row_plugin'] = 'fields';
|
111
|
/* Field: Content: Title */
|
112
|
$handler->display->display_options['fields']['title']['id'] = 'title';
|
113
|
$handler->display->display_options['fields']['title']['table'] = 'node';
|
114
|
$handler->display->display_options['fields']['title']['field'] = 'title';
|
115
|
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
116
|
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
117
|
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
118
|
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
119
|
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
120
|
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
121
|
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
122
|
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
123
|
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
124
|
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
125
|
/* Argument: Global: Null */
|
126
|
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
127
|
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
128
|
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
129
|
$handler->display->display_options['arguments']['null']['default_action'] = 'default';
|
130
|
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
131
|
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
132
|
$handler->display->display_options['arguments']['null']['default_argument_options']['argument'] = $this->random;
|
133
|
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
134
|
|
135
|
return $view;
|
136
|
}
|
137
|
|
138
|
}
|