ReadOnlyConfigTest.php in Configuration Read-only mode 8
File
tests/src/Functional/ReadOnlyConfigTest.php
View source
<?php
namespace Drupal\Tests\config_readonly\Functional;
use Behat\Mink\Element\NodeElement;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Url;
class ReadOnlyConfigTest extends BrowserTestBase {
protected $adminUser;
public static $modules = [
'config',
'config_readonly',
];
protected $message = 'This form will not be saved because the configuration active store is read-only.';
protected $defaultTheme = 'stark';
public function setUp() {
parent::setUp();
$this->adminUser = $this
->createUser([], NULL, TRUE);
$this
->drupalLogin($this->adminUser);
}
protected function turnOnReadOnlySetting() {
$settings['settings']['config_readonly'] = (object) [
'value' => TRUE,
'required' => TRUE,
];
$this
->writeSettings($settings);
}
protected function turnOffReadOnlySetting() {
$settings['settings']['config_readonly'] = (object) [
'value' => FALSE,
'required' => TRUE,
];
$this
->writeSettings($settings);
}
public function testModulePages() {
$module_url = Url::fromRoute('system.modules_list');
$this
->drupalGet($module_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($this->message);
$uninstall_url = Url::fromRoute('system.modules_uninstall');
$this
->drupalGet($uninstall_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($this->message);
$edit = [
'modules[search][enable]' => TRUE,
];
$this
->drupalPostForm($module_url, $edit, 'Install');
$this
->assertSession()
->pageTextNotContains($this->message);
$this
->turnOnReadOnlySetting();
$this
->drupalGet($module_url);
$this
->assertSession()
->pageTextContains($this->message);
$this
->drupalGet($uninstall_url);
$this
->assertSession()
->pageTextContains($this->message);
$this
->drupalGet($module_url);
$elements = $this
->xpath("//form[@id='system-modules']//input[@id='edit-submit']");
$install_button = isset($elements[0]) && $elements[0] instanceof NodeElement ? $elements[0] : FALSE;
$this
->assertTrue($install_button !== FALSE, 'Found the install form submit button.');
$this
->assertTrue($install_button
->hasAttribute('disabled'), 'The install modules form button is disabled.');
$options = [
'query' => [
'keys' => 'test',
],
];
$search_url = Url::fromRoute('search.view_user_search', [], $options);
$this
->drupalGet($search_url);
$this
->assertSession()
->pageTextNotContains($this->message);
$elements = $this
->xpath("//form[@id='search-form']//input[@id='edit-submit']");
$button = isset($elements[0]) && $elements[0] instanceof NodeElement ? $elements[0] : FALSE;
$this
->assertTrue($button !== FALSE, 'Found the search form submit button.');
$this
->assertFalse($button
->hasAttribute('disabled'), 'The search form button is not disabled.');
}
public function testSimpleConfig() {
$site_url = Url::fromRoute('system.site_information_settings');
$this
->drupalGet($site_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($this->message);
$this
->turnOnReadOnlySetting();
$this
->drupalGet($site_url);
$this
->assertSession()
->pageTextContains($this->message);
}
public function testSingleImport() {
$import_url = Url::fromRoute('config.import_single');
$this
->drupalGet($import_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextNotContains($this->message);
$this
->turnOnReadOnlySetting();
$this
->drupalGet($import_url);
$this
->assertSession()
->pageTextContains($this->message);
}
}