commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / admin_views / tests / admin_views.test
1 <?php
2
3 /**
4 * @file
5 * Tests for the Administration Views module.
6 */
7
8 /**
9 * Base class for all Administration Views web test cases.
10 */
11 class AdminViewsWebTestCase extends DrupalWebTestCase {
12 protected $profile = 'testing';
13
14 protected $permissionMap = array(
15 'user' => array('administer users', 'administer permissions'),
16 'node' => array('access content overview'),
17 'comment' => array('administer comments'),
18 'taxonomy' => array('administer taxonomy'),
19 );
20
21 function setUp() {
22 // Setup site and modules.
23 $modules = func_get_args();
24 $modules = isset($modules[0]) && is_array($modules[0]) ? $modules[0] : $modules;
25 $modules[] = 'admin_views';
26 parent::setUp($modules);
27
28 // Fix testing environment.
29 theme_enable(array('stark'));
30 variable_set('theme_default', 'stark');
31
32 // Setup permissions.
33 $permissions = array(
34 'access administration pages',
35 );
36 foreach ($this->permissionMap as $module => $module_permissions) {
37 if (module_exists($module)) {
38 $permissions = array_merge($permissions, $module_permissions);
39 }
40 }
41 $this->admin_user = $this->drupalCreateUser($permissions);
42
43 // Setup default configuration.
44 if (in_array('node', $modules)) {
45 $this->node_type = $this->drupalCreateContentType(array(
46 'type' => 'article',
47 'name' => 'Article',
48 // 2 == COMMENT_NODE_OPEN.
49 'comment' => 2,
50 ));
51 }
52 if (in_array('comment', $modules)) {
53 variable_set('comment_preview_article', DRUPAL_OPTIONAL);
54 }
55 }
56
57 protected function assertOriginalRouterItem($module, $path) {
58 // Retrieve the original router item definition.
59 $items = module_invoke($module, 'menu');
60 $original_item = $items[$path];
61 // Retrieve the computed router item definition.
62 $item = menu_get_item($path);
63
64 // Verify that basic properties are identical.
65 $title = (isset($original_item['title callback']) ? $original_item['title callback']() : $original_item['title']);
66 $this->assertEqual($title, $item['title']);
67 if (isset($original_item['description'])) {
68 $this->assertEqual($original_item['description'], $item['description']);
69 }
70
71 // Verify that the title appears.
72 $this->assertResponse(200);
73 $this->assertText($original_item['title']);
74 }
75 }
76
77 /**
78 * Tests System display functionality.
79 */
80 class AdminViewsSystemDisplayTestCase extends AdminViewsWebTestCase {
81 public static function getInfo() {
82 return array(
83 'name' => 'Views System display plugin',
84 'description' => 'Tests Views System display plugin functionality.',
85 'group' => 'Administration views',
86 );
87 }
88
89 function setUp() {
90 parent::setUp(array('node', 'comment', 'admin_views_test'));
91 }
92
93 /**
94 * Tests proper inheritance of router item properties.
95 */
96 function testRouterItemInheritance() {
97 $this->drupalLogin($this->admin_user);
98 $path = 'admin/people';
99 $out = $this->drupalGet($path);
100 $this->assertOriginalRouterItem('user', $path);
101
102 // Verify that local tasks and actions exist and can be accessed.
103 foreach (array(t('List'), t('Permissions'), t('Add user')) as $link) {
104 $this->drupalSetContent($out);
105 $this->assertLink($link);
106 $this->clickLink($link);
107 $this->assertResponse(200);
108 }
109
110 // Test that child page callbacks of a system display work.
111 $this->drupalGet('admin/content/admin_views_test');
112 $this->assertResponse(200);
113 $this->assertTitle('Administration views test | Drupal');
114 $this->assertText('Administration views test page callback');
115 }
116 }
117
118 /**
119 * Tests default views.
120 */
121 class AdminViewsDefaultViewsTestCase extends AdminViewsWebTestCase {
122 public static function getInfo() {
123 return array(
124 'name' => 'Default views',
125 'description' => 'Tests default views.',
126 'group' => 'Administration views',
127 );
128 }
129
130 function setUp() {
131 parent::setUp(array('node', 'comment'));
132 }
133
134 /**
135 * Tests basic appearance and behavior of built-in default views.
136 */
137 function testComment() {
138 $this->drupalLogin($this->admin_user);
139
140 foreach (array('admin/content/comment', 'admin/content/comment/approval') as $path) {
141 $this->drupalGet($path);
142 $this->assertOriginalRouterItem('comment', $path);
143
144 // Verify that a view with its exposed filters appears.
145 $this->assertFieldByName('subject');
146 $this->assertFieldByName('author');
147 $this->assertFieldByName('nodeTitle');
148 $this->assertFieldByName('status');
149 $this->assertFieldByXPath('//select[@name="status"]/option', 'All', 'Published: All option found.');
150 $this->assertFieldByXPath('//select[@name="status"]/option', '1', 'Published: Yes option found.');
151 $this->assertFieldByXPath('//select[@name="status"]/option', '0', 'Published: No option found.');
152 $this->assertFieldByXPath('//input[@type="submit"]', t('Apply'), 'Apply button found.');
153 $this->assertFieldByXPath('//input[@type="submit"]', t('Reset'), 'Reset button found.');
154 }
155 }
156 }
157
158 /**
159 * Tests system child page display functionality.
160 *
161 * This is important, as any other page view menu items that are children of a
162 * system view can otherwise inherit item properties they don't want.
163 */
164 class AdminViewsPageDisplayTestCase extends AdminViewsWebTestCase {
165 public static function getInfo() {
166 return array(
167 'name' => 'Views Page display plugin',
168 'description' => 'Tests views page functionality for children of system plugins.',
169 'group' => 'Administration views',
170 );
171 }
172
173 function setUp() {
174 parent::setUp(array('node'));
175
176 // Save the test page view.
177 $this->normalPageView()->save();
178
179 // Reset views static cache.
180 views_get_view('admin_views_test_normal', TRUE);
181
182 // Rebuild the menu.
183 // views_invalidate_cache only sets the rebuild variable.
184 menu_rebuild();
185 }
186
187 /**
188 * Tests creation of a view page display that is a child of "admin/content".
189 */
190 function testAddPageViewAdminContent() {
191 $this->drupalLogin($this->admin_user);
192
193 // Test the child view exists by checking for the page title.
194 $this->drupalGet('admin/content/test');
195 $this->assertText('admin_views_test_normal');
196 }
197
198 /**
199 * Returns a test page view with a path under "admin/content".
200 */
201 protected function normalPageView() {
202 views_include('view');
203 $view = new view();
204 $view->name = 'admin_views_test_normal';
205 $view->description = '';
206 $view->tag = 'default';
207 $view->base_table = 'node';
208 $view->human_name = 'admin_views_test_normal';
209 $view->core = 7;
210 $view->api_version = '3.0';
211 $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
212
213 /* Display: Master */
214 $handler = $view->new_display('default', 'Master', 'default');
215 $handler->display->display_options['title'] = 'admin_views_test_normal';
216 $handler->display->display_options['use_more_always'] = FALSE;
217 $handler->display->display_options['access']['type'] = 'perm';
218 $handler->display->display_options['cache']['type'] = 'none';
219 $handler->display->display_options['query']['type'] = 'views_query';
220 $handler->display->display_options['exposed_form']['type'] = 'basic';
221 $handler->display->display_options['pager']['type'] = 'full';
222 $handler->display->display_options['pager']['options']['items_per_page'] = '10';
223 $handler->display->display_options['style_plugin'] = 'default';
224 $handler->display->display_options['row_plugin'] = 'node';
225 /* Field: Content: Title */
226 $handler->display->display_options['fields']['title']['id'] = 'title';
227 $handler->display->display_options['fields']['title']['table'] = 'node';
228 $handler->display->display_options['fields']['title']['field'] = 'title';
229 $handler->display->display_options['fields']['title']['label'] = '';
230 $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
231 $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
232 /* Sort criterion: Content: Post date */
233 $handler->display->display_options['sorts']['created']['id'] = 'created';
234 $handler->display->display_options['sorts']['created']['table'] = 'node';
235 $handler->display->display_options['sorts']['created']['field'] = 'created';
236 $handler->display->display_options['sorts']['created']['order'] = 'DESC';
237 /* Filter criterion: Content: Published */
238 $handler->display->display_options['filters']['status']['id'] = 'status';
239 $handler->display->display_options['filters']['status']['table'] = 'node';
240 $handler->display->display_options['filters']['status']['field'] = 'status';
241 $handler->display->display_options['filters']['status']['value'] = 1;
242 $handler->display->display_options['filters']['status']['group'] = 1;
243 $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
244
245 /* Display: Page */
246 $handler = $view->new_display('page', 'Page', 'page');
247 $handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
248 $handler->display->display_options['path'] = 'admin/content/test';
249
250 return $view;
251 }
252 }
253
254 /**
255 * Tests default views.
256 */
257 class AdminViewsAccessHandlerTestCase extends AdminViewsWebTestCase {
258
259 public static function getInfo() {
260 return array(
261 'name' => 'Access handler',
262 'description' => 'Tests views_plugin_access_menu handler.',
263 'group' => 'Administration views',
264 );
265 }
266
267 function setUp() {
268 parent::setUp(array('node'));
269 }
270
271 /**
272 * Tests access handler via views/ajax.
273 */
274 function testAjaxAccess() {
275 $params = array(
276 'view_name' => 'admin_views_user',
277 'view_display_id' => 'system_1',
278 );
279 $response_data = $this->drupalGetAJAX('views/ajax', array('query' => $params));
280
281 $this->assertResponse(200);
282 // Check no views settings are returned.
283 $this->assertTrue(empty($response_data[0]['settings']['views']));
284 // The next item in the AJAX data will be the insert command containing the
285 // rendered view.
286 $this->assertTrue(empty($response_data[1]));
287
288 // Test the access again with the default display.
289 $params['views_display_id'] = 'default';
290
291 $response_data = $this->drupalGetAJAX('views/ajax', array('query' => $params));
292
293 $this->assertResponse(200);
294 // Check no views settings are returned.
295 $this->assertTrue(empty($response_data[0]['settings']['views']));
296 // The next item in the AJAX data will be the insert command containing the
297 // rendered view.
298 $this->assertTrue(empty($response_data[1]));
299 }
300 }