3 namespace Drupal\Tests\views_ui\Functional;
5 use Drupal\Tests\views\Functional\ViewTestBase;
8 * Provides a base class for testing the Views UI.
10 abstract class UITestBase extends ViewTestBase {
13 * An admin user with the 'administer views' permission.
15 * @var \Drupal\user\UserInterface
20 * An admin user with administrative permissions for views, blocks, and nodes.
22 * @var \Drupal\user\UserInterface
24 protected $fullAdminUser;
31 public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
36 protected function setUp($import_test_views = TRUE) {
37 parent::setUp($import_test_views);
39 $this->enableViewsTestModule();
41 $this->adminUser = $this->drupalCreateUser(['administer views']);
43 $this->fullAdminUser = $this->drupalCreateUser(['administer views',
46 'access user profiles',
48 'administer permissions',
50 $this->drupalLogin($this->fullAdminUser);
54 * A helper method which creates a random view.
56 public function randomView(array $view = []) {
57 // Create a new view in the UI.
59 $default['label'] = $this->randomMachineName(16);
60 $default['id'] = strtolower($this->randomMachineName(16));
61 $default['description'] = $this->randomMachineName(16);
62 $default['page[create]'] = TRUE;
63 $default['page[path]'] = $default['id'];
67 $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
75 protected function drupalGet($path, array $options = [], array $headers = []) {
76 $url = $this->buildUrl($path, $options);
78 // Ensure that each nojs page is accessible via ajax as well.
79 if (strpos($url, 'nojs') !== FALSE) {
80 $url = str_replace('nojs', 'ajax', $url);
81 $result = $this->drupalGet($url, $options);
82 $this->assertSession()->statusCodeEquals(200);
83 $this->assertEquals('application/json', $this->getSession()->getResponseHeader('Content-Type'));
84 $this->assertTrue(json_decode($result), 'Ensure that the AJAX request returned valid content.');
87 return parent::drupalGet($path, $options, $headers);