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); } }