Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / rest / tests / src / Functional / Views / RestExportAuthTest.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\Views;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Entity\View;
7
8 /**
9  * Tests authentication for REST display.
10  *
11  * @group rest
12  */
13 class RestExportAuthTest extends ViewTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['rest', 'views_ui', 'basic_auth'];
19
20   /**
21    * {@inheritdoc}
22    */
23   public function setUp($import_test_views = TRUE) {
24     parent::setUp($import_test_views);
25
26     $this->drupalLogin($this->drupalCreateUser(['administer views']));
27   }
28
29   /**
30    * Checks that correct authentication providers are available for choosing.
31    *
32    * @link https://www.drupal.org/node/2825204
33    */
34   public function testAuthProvidersOptions() {
35     $view_id = 'test_view_rest_export';
36     $view_label = 'Test view (REST export)';
37     $view_display = 'rest_export_1';
38     $view_rest_path = 'test-view/rest-export';
39
40     // Create new view.
41     $this->drupalPostForm('admin/structure/views/add', [
42       'id' => $view_id,
43       'label' => $view_label,
44       'show[wizard_key]' => 'users',
45       'rest_export[path]' => $view_rest_path,
46       'rest_export[create]' => TRUE,
47     ], t('Save and edit'));
48
49     $this->drupalGet("admin/structure/views/nojs/display/$view_id/$view_display/auth");
50     // The "basic_auth" will always be available since module,
51     // providing it, has the same name.
52     $this->assertField('edit-auth-basic-auth', 'Basic auth is available for choosing.');
53     // The "cookie" authentication provider defined by "user" module.
54     $this->assertField('edit-auth-cookie', 'Cookie-based auth can be chosen.');
55     // Wrong behavior in "getAuthOptions()" method makes this option available
56     // instead of "cookie".
57     // @see \Drupal\rest\Plugin\views\display\RestExport::getAuthOptions()
58     $this->assertNoField('edit-auth-user', 'Wrong authentication option is unavailable.');
59
60     $this->drupalPostForm(NULL, ['auth[basic_auth]' => 1, 'auth[cookie]' => 1], 'Apply');
61     $this->drupalPostForm(NULL, [], 'Save');
62
63     $view = View::load($view_id);
64     $this->assertEquals(['basic_auth', 'cookie'], $view->getDisplay('rest_export_1')['display_options']['auth']);
65   }
66
67 }