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