X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews_ui%2Ftests%2Fsrc%2FFunctional%2FUITestBase.php;fp=web%2Fcore%2Fmodules%2Fviews_ui%2Ftests%2Fsrc%2FFunctional%2FUITestBase.php;h=684b91f89da69dab121a40fb7379979bd1a09565;hp=0000000000000000000000000000000000000000;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a diff --git a/web/core/modules/views_ui/tests/src/Functional/UITestBase.php b/web/core/modules/views_ui/tests/src/Functional/UITestBase.php new file mode 100644 index 000000000..684b91f89 --- /dev/null +++ b/web/core/modules/views_ui/tests/src/Functional/UITestBase.php @@ -0,0 +1,90 @@ +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); + } + +}