Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\Tests\views\Functional\ViewTestBase;
/**
* Provides a base class for testing the Views UI.
*/
abstract class UITestBase extends ViewTestBase {
/**
* An admin user with the 'administer views' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* An admin user with administrative permissions for views, blocks, and nodes.
*
* @var \Drupal\user\UserInterface
*/
protected $fullAdminUser;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->enableViewsTestModule();
$this->adminUser = $this->drupalCreateUser(['administer views']);
$this->fullAdminUser = $this->drupalCreateUser(['administer views',
'administer blocks',
'bypass node access',
'access user profiles',
'view all revisions',
'administer permissions',
]);
$this->drupalLogin($this->fullAdminUser);
}
/**
* A helper method which creates a random view.
*/
public function randomView(array $view = []) {
// Create a new view in the UI.
$default = [];
$default['label'] = $this->randomMachineName(16);
$default['id'] = strtolower($this->randomMachineName(16));
$default['description'] = $this->randomMachineName(16);
$default['page[create]'] = TRUE;
$default['page[path]'] = $default['id'];
$view += $default;
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
return $default;
}
/**
* {@inheritdoc}
*/
protected function drupalGet($path, array $options = [], array $headers = []) {
$url = $this->buildUrl($path, $options);
// Ensure that each nojs page is accessible via ajax as well.
if (strpos($url, 'nojs') !== FALSE) {
$url = str_replace('nojs', 'ajax', $url);
$result = $this->drupalGet($url, $options);
$this->assertSession()->statusCodeEquals(200);
$this->assertEquals('application/json', $this->getSession()->getResponseHeader('Content-Type'));
$this->assertTrue(json_decode($result), 'Ensure that the AJAX request returned valid content.');
}
return parent::drupalGet($path, $options, $headers);
}
}