View source
<?php
namespace Drupal\site_settings\Tests;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class SiteSettingsUiTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'site_settings',
'site_settings_sample_data',
'field_ui',
'user',
];
private $adminUser;
public function setUp() {
parent::setUp();
$this->adminUser = $this
->createUser([], NULL, TRUE);
$this
->drupalLogin($this->adminUser);
}
public function testSiteSettingsAdminVisibility() {
$this
->drupalGet('admin/content/site-settings');
$this
->assertRaw('<strong>Images</strong>');
$this
->assertRaw('<strong>Other</strong>');
$this
->assertText('Test plain text');
$this
->assertText('Test textarea name');
$this
->assertText('Test multiple entries');
$this
->assertText('Test multiple entries name 2');
$this
->assertText('Test multiple entries and fields name 1');
$this
->assertText('Test multiple entries and fields name 2');
$this
->assertText('Test multiple fields name');
$this
->assertText('Test image');
$this
->assertText('Test images 1');
$this
->assertText('Test file');
}
public function testSiteSettingsAddAnother() {
$this
->drupalGet('admin/content/site-settings');
$this
->clickLink('Add another', 2);
$this
->assertText('Test multiple entries');
$this
->assertText('Testing');
$params = [
'field_testing[0][value]' => 'testSiteSettingsAddAnother',
];
$this
->drupalPostForm(NULL, $params, $this
->t('Save'));
$this
->assertText('Created the Test multiple entries Site Setting.');
$this
->assertText('testSiteSettingsAddAnother');
}
public function testSiteSettingsEditExisting() {
$this
->drupalGet('admin/content/site-settings');
$this
->clickLink('Edit', 5);
$this
->assertText('Test plain text');
$this
->assertText('Testing');
$params = [
'field_testing[0][value]' => 'testSiteSettingsEditExisting',
];
$this
->drupalPostForm(NULL, $params, $this
->t('Save'));
$this
->assertText('Saved the Test plain text Site Setting.');
$this
->assertText('testSiteSettingsEditExisting');
}
public function testSiteSettingsCreateNewTypeAndSetting() {
$this
->drupalGet('admin/structure/site_setting_entity_type/add');
$params = [
'label' => 'testSiteSettingsCreateNewTypeAndSetting',
'id' => 'testsitesettingscreatenew',
'existing_fieldset' => 'Other',
];
$this
->drupalPostForm(NULL, $params, $this
->t('Save'));
$this
->assertText('Created the testSiteSettingsCreateNewTypeAndSetting Site Setting type.');
$this
->drupalGet('admin/structure/site_setting_entity_type/testsitesettingscreatenew/edit/fields/add-field');
$params = [
'existing_storage_name' => 'field_testing',
'existing_storage_label' => 'testSiteSettingsCreateNewTypeAndSettingLabel',
];
$this
->drupalPostForm(NULL, $params, $this
->t('Save and continue'));
$params = [];
$this
->drupalPostForm(NULL, $params, $this
->t('Save settings'));
$this
->assertText('Saved testSiteSettingsCreateNewTypeAndSettingLabel configuration.');
$this
->assertText('field_testing');
$this
->drupalGet('admin/content/site-settings');
$this
->clickLink('Create setting');
$this
->assertText('testSiteSettingsCreateNewTypeAndSettingLabel');
$params = [
'field_testing[0][value]' => 'testSiteSettingsCreateNewTypeAndSettingValue',
];
$this
->drupalPostForm(NULL, $params, $this
->t('Save'));
$this
->assertText('Created the testSiteSettingsCreateNewTypeAndSetting Site Setting.');
$this
->assertText('testSiteSettingsCreateNewTypeAndSettingValue');
}
}