RestExportAuthTest.php in Drupal 9
File
core/modules/rest/tests/src/Functional/Views/RestExportAuthTest.php
View source
<?php
namespace Drupal\Tests\rest\Functional\Views;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Entity\View;
class RestExportAuthTest extends ViewTestBase {
protected static $modules = [
'rest',
'views_ui',
'basic_auth',
];
protected $defaultTheme = 'stark';
public function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->drupalLogin($this
->drupalCreateUser([
'administer views',
]));
}
public function testAuthProvidersOptions() {
$view_id = 'test_view_rest_export';
$view_label = 'Test view (REST export)';
$view_display = 'rest_export_1';
$view_rest_path = 'test-view/rest-export';
$this
->drupalGet('admin/structure/views/add');
$this
->submitForm([
'id' => $view_id,
'label' => $view_label,
'show[wizard_key]' => 'users',
'rest_export[path]' => $view_rest_path,
'rest_export[create]' => TRUE,
], 'Save and edit');
$this
->drupalGet("admin/structure/views/nojs/display/{$view_id}/{$view_display}/auth");
$this
->assertSession()
->fieldExists('edit-auth-basic-auth');
$this
->assertSession()
->fieldExists('edit-auth-cookie');
$this
->assertSession()
->fieldNotExists('edit-auth-user');
$this
->submitForm([
'auth[basic_auth]' => 1,
'auth[cookie]' => 1,
], 'Apply');
$this
->submitForm([], 'Save');
$view = View::load($view_id);
$this
->assertEquals([
'basic_auth',
'cookie',
], $view
->getDisplay('rest_export_1')['display_options']['auth']);
}
}