UserSettingsTest.php in Simplify 8
File
src/Tests/UserSettingsTest.php
View source
<?php
namespace Drupal\simplify\Tests;
use Drupal\Tests\BrowserTestBase;
class UserSettingsTest extends BrowserTestBase {
public static $modules = [
'contact',
'user',
'simplify',
];
public static function getInfo() {
return [
'name' => 'Simplify user settings test.',
'description' => 'Test the Simplify module user settings.',
'group' => 'Simplify',
];
}
public function testSettingSaving() {
$admin_user = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($admin_user);
$user_edit_page = '/user/' . $admin_user
->id() . '/edit';
$this
->drupalGet($user_edit_page);
$this
->assertRaw('Status', 'Status option is defined.');
$this
->assertRaw('Contact settings', 'Contact settings option is defined.');
$this
->assertRaw('Locale settings', 'Locale settings option is defined.');
$this
->drupalLogout();
$this
->drupalGet('/user/register');
$this
->assertRaw('Contact settings', 'Contact settings option is defined.');
$this
->assertRaw('Locale settings', 'Locale settings option is defined.');
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/user-interface/simplify');
$options = [
'simplify_admin' => TRUE,
'simplify_users_global[status]' => 'status',
'simplify_users_global[timezone]' => 'timezone',
'simplify_users_global[contact]' => 'contact',
];
$this
->drupalPostForm(NULL, $options, $this
->t('Save configuration'));
$this
->assertFieldChecked('edit-simplify-admin', "Admin users can't see hidden fields too.");
drupal_flush_all_caches();
$this
->drupalGet($user_edit_page);
$this
->assertNoRaw('Status', 'Status option is not defined');
$this
->assertNoRaw('Contact settings', 'Contact settings option is not defined.');
$this
->assertNoRaw('Locale settings', 'Locale settings option is not defined.');
$this
->drupalLogout();
$this
->drupalGet('/user/register');
$this
->assertNoRaw('Contact settings', 'Contact settings option is not defined.');
$this
->assertNoRaw('Locale settings', 'Locale settings option is not defined.');
}
}