class RestExportAuthTest
Same name and namespace in other branches
- 11.x core/modules/rest/tests/src/Functional/Views/RestExportAuthTest.php \Drupal\Tests\rest\Functional\Views\RestExportAuthTest
- 10 core/modules/rest/tests/src/Functional/Views/RestExportAuthTest.php \Drupal\Tests\rest\Functional\Views\RestExportAuthTest
- 8.9.x core/modules/rest/tests/src/Kernel/Views/RestExportAuthTest.php \Drupal\Tests\rest\Kernel\Views\RestExportAuthTest
- 8.9.x core/modules/rest/tests/src/Functional/Views/RestExportAuthTest.php \Drupal\Tests\rest\Functional\Views\RestExportAuthTest
Tests authentication for REST display.
@group rest
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\rest\Functional\Views\RestExportAuthTest extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of RestExportAuthTest
File
-
core/
modules/ rest/ tests/ src/ Functional/ Views/ RestExportAuthTest.php, line 13
Namespace
Drupal\Tests\rest\Functional\ViewsView source
class RestExportAuthTest extends ViewTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'rest',
'views_ui',
'basic_auth',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
public function setUp($import_test_views = TRUE, $modules = []) : void {
parent::setUp($import_test_views, $modules);
$this->drupalLogin($this->drupalCreateUser([
'administer views',
]));
}
/**
* Checks that correct authentication providers are available for choosing.
*
* @link https://www.drupal.org/node/2825204
*/
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';
// Create new view.
$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");
// The "basic_auth" will always be available since module,
// providing it, has the same name.
$this->assertSession()
->fieldExists('edit-auth-basic-auth');
// The "cookie" authentication provider defined by "user" module.
$this->assertSession()
->fieldExists('edit-auth-cookie');
// Wrong behavior in "getAuthOptions()" method makes this option available
// instead of "cookie".
// @see \Drupal\rest\Plugin\views\display\RestExport::getAuthOptions()
$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']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.