83f2f85980c42d4824fa618913e5e6cd77878b30
[yaffs-website] / web / core / modules / views_ui / src / Tests / UITestBase.php
1 <?php
2
3 namespace Drupal\views_ui\Tests;
4
5 use Drupal\views\Tests\ViewTestBase;
6
7 /**
8  * Provides a base class for testing the Views UI.
9  *
10  * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.x.
11  *   Use \Drupal\Tests\views_ui\Functional\UITestBase.
12  */
13 abstract class UITestBase extends ViewTestBase {
14
15   /**
16    * An admin user with the 'administer views' permission.
17    *
18    * @var \Drupal\user\UserInterface
19    */
20   protected $adminUser;
21
22   /**
23    * An admin user with administrative permissions for views, blocks, and nodes.
24    *
25    * @var \Drupal\user\UserInterface
26    */
27   protected $fullAdminUser;
28
29   /**
30    * Modules to enable.
31    *
32    * @var array
33    */
34   public static $modules = ['node', 'views_ui', 'block', 'taxonomy'];
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     parent::setUp();
41
42     $this->enableViewsTestModule();
43
44     $this->adminUser = $this->drupalCreateUser(['administer views']);
45
46     $this->fullAdminUser = $this->drupalCreateUser(['administer views',
47       'administer blocks',
48       'bypass node access',
49       'access user profiles',
50       'view all revisions',
51       'administer permissions',
52     ]);
53     $this->drupalLogin($this->fullAdminUser);
54
55     @trigger_error('\Drupal\views_ui\Tests\UITestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.x. Instead, use \Drupal\Tests\views_ui\Functional\UITestBase', E_USER_DEPRECATED);
56   }
57
58   /**
59    * A helper method which creates a random view.
60    */
61   public function randomView(array $view = []) {
62     // Create a new view in the UI.
63     $default = [];
64     $default['label'] = $this->randomMachineName(16);
65     $default['id'] = strtolower($this->randomMachineName(16));
66     $default['description'] = $this->randomMachineName(16);
67     $default['page[create]'] = TRUE;
68     $default['page[path]'] = $default['id'];
69
70     $view += $default;
71
72     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
73
74     return $default;
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   protected function drupalGet($path, array $options = [], array $headers = []) {
81     $url = $this->buildUrl($path, $options);
82
83     // Ensure that each nojs page is accessible via ajax as well.
84     if (strpos($url, 'nojs') !== FALSE) {
85       $url = str_replace('nojs', 'ajax', $url);
86       $result = $this->drupalGet($url, $options, $headers);
87       $this->assertResponse(200);
88       $this->assertHeader('Content-Type', 'application/json');
89       $this->assertTrue(json_decode($result), 'Ensure that the AJAX request returned valid content.');
90     }
91
92     return parent::drupalGet($path, $options, $headers);
93   }
94
95 }