3 namespace Drupal\Tests\rest\Functional\Views;
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Entity\View;
9 * Tests authentication for REST display.
13 class RestExportAuthTest extends ViewTestBase {
18 public static $modules = ['rest', 'views_ui', 'basic_auth'];
23 public function setUp($import_test_views = TRUE) {
24 parent::setUp($import_test_views);
26 $this->drupalLogin($this->drupalCreateUser(['administer views']));
30 * Checks that correct authentication providers are available for choosing.
32 * @link https://www.drupal.org/node/2825204
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';
41 $this->drupalPostForm('admin/structure/views/add', [
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'));
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.');
60 $this->drupalPostForm(NULL, ['auth[basic_auth]' => 1, 'auth[cookie]' => 1], 'Apply');
61 $this->drupalPostForm(NULL, [], 'Save');
63 $view = View::load($view_id);
64 $this->assertEquals(['basic_auth', 'cookie'], $view->getDisplay('rest_export_1')['display_options']['auth']);