RestExampleSettingsTest.php in Examples for Developers 3.x
File
modules/rest_example/tests/src/Functional/RestExampleSettingsTest.php
View source
<?php
namespace Drupal\Tests\rest_example\Funtional;
use Drupal\Tests\BrowserTestBase;
class RestExampleSettingsTest extends BrowserTestBase {
public static $modules = [
'rest_example',
];
protected $profile = 'minimal';
public function testRestExampleSettings() {
global $base_url;
$account = $this
->drupalCreateUser();
$this
->drupalLogin($account);
$this
->drupalGet('examples/rest-client-settings');
$edit = [
'server_url' => $base_url,
'server_username' => $account
->get('name')->value,
'server_password' => $account->passRaw,
];
$this
->drupalPostForm(base_path() . 'examples/rest-client-settings', $edit, t('Save configuration'));
$this
->assertText('The configuration options have been saved.');
$config_factory = \Drupal::configFactory();
$rest_config = $config_factory
->get('rest_example.settings');
self::assertEquals($base_url, $rest_config
->get('server_url'));
self::assertEquals($account
->get('name')->value, $rest_config
->get('server_username'));
self::assertEquals($account->passRaw, $rest_config
->get('server_password'));
}
}