View source
<?php
namespace Drupal\Tests\views_ui\Functional;
use Drupal\Tests\views\Functional\ViewTestBase;
abstract class UITestBase extends ViewTestBase {
protected $adminUser;
protected $fullAdminUser;
protected static $modules = [
'node',
'views_ui',
'block',
'taxonomy',
];
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$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);
}
public function randomView(array $view = []) {
$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
->drupalGet('admin/structure/views/add');
$this
->submitForm($view, 'Save and edit');
return $default;
}
protected function drupalGet($path, array $options = [], array $headers = []) {
$url = $this
->buildUrl($path, $options);
if (strpos($url, '/nojs/') !== FALSE) {
$url = preg_replace('|/nojs/|', '/ajax/', $url, 1);
$result = $this
->drupalGet($url, $options);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseHeaderEquals('Content-Type', 'application/json');
$this
->assertNotEmpty(json_decode($result), 'Ensure that the AJAX request returned valid content.');
}
return parent::drupalGet($path, $options, $headers);
}
}