3 namespace Drupal\views_ui\Tests;
5 use Drupal\views\Tests\ViewTestBase;
8 * Provides a base class for testing the Views UI.
10 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.x.
11 * Use \Drupal\Tests\views_ui\Functional\UITestBase.
13 abstract class UITestBase extends ViewTestBase {
16 * An admin user with the 'administer views' permission.
18 * @var \Drupal\user\UserInterface
23 * An admin user with administrative permissions for views, blocks, and nodes.
25 * @var \Drupal\user\UserInterface
27 protected $fullAdminUser;
34 public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
39 protected function setUp() {
42 $this->enableViewsTestModule();
44 $this->adminUser = $this->drupalCreateUser(['administer views']);
46 $this->fullAdminUser = $this->drupalCreateUser(['administer views',
49 'access user profiles',
51 'administer permissions',
53 $this->drupalLogin($this->fullAdminUser);
55 @trigger_error('\Drupal\views_ui\Tests\UITestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.x. Instead, use \Drupal\Tests\views_ui\Functional\UITestBase', E_USER_DEPRECATED);
59 * A helper method which creates a random view.
61 public function randomView(array $view = []) {
62 // Create a new view in the UI.
64 $default['label'] = $this->randomMachineName(16);
65 $default['id'] = strtolower($this->randomMachineName(16));
66 $default['description'] = $this->randomMachineName(16);
67 $default['page[create]'] = TRUE;
68 $default['page[path]'] = $default['id'];
72 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
80 protected function drupalGet($path, array $options = [], array $headers = []) {
81 $url = $this->buildUrl($path, $options);
83 // Ensure that each nojs page is accessible via ajax as well.
84 if (strpos($url, 'nojs') !== FALSE) {
85 $url = str_replace('nojs', 'ajax', $url);
86 $result = $this->drupalGet($url, $options, $headers);
87 $this->assertResponse(200);
88 $this->assertHeader('Content-Type', 'application/json');
89 $this->assertTrue(json_decode($result), 'Ensure that the AJAX request returned valid content.');
92 return parent::drupalGet($path, $options, $headers);