Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / views_ui / tests / src / Functional / UITestBase.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\Functional;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6
7 /**
8  * Provides a base class for testing the Views UI.
9  */
10 abstract class UITestBase extends ViewTestBase {
11
12   /**
13    * An admin user with the 'administer views' permission.
14    *
15    * @var \Drupal\user\UserInterface
16    */
17   protected $adminUser;
18
19   /**
20    * An admin user with administrative permissions for views, blocks, and nodes.
21    *
22    * @var \Drupal\user\UserInterface
23    */
24   protected $fullAdminUser;
25
26   /**
27    * Modules to enable.
28    *
29    * @var array
30    */
31   public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function setUp($import_test_views = TRUE) {
37     parent::setUp($import_test_views);
38
39     $this->enableViewsTestModule();
40
41     $this->adminUser = $this->drupalCreateUser(['administer views']);
42
43     $this->fullAdminUser = $this->drupalCreateUser(['administer views',
44       'administer blocks',
45       'bypass node access',
46       'access user profiles',
47       'view all revisions',
48       'administer permissions',
49     ]);
50     $this->drupalLogin($this->fullAdminUser);
51   }
52
53   /**
54    * A helper method which creates a random view.
55    */
56   public function randomView(array $view = []) {
57     // Create a new view in the UI.
58     $default = [];
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'];
64
65     $view += $default;
66
67     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
68
69     return $default;
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   protected function drupalGet($path, array $options = [], array $headers = []) {
76     $url = $this->buildUrl($path, $options);
77
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.');
85     }
86
87     return parent::drupalGet($path, $options, $headers);
88   }
89
90 }