public function ReadOnlyConfigTest::testModulePages in Configuration Read-only mode 8
Tests switching the modules form to read-only.
File
- tests/
src/ Functional/ ReadOnlyConfigTest.php, line 76
Class
- ReadOnlyConfigTest
- Tests read-only module config functionality.
Namespace
Drupal\Tests\config_readonly\FunctionalCode
public function testModulePages() {
// Verify if we can successfully access the modules list route.
$module_url = Url::fromRoute('system.modules_list');
$this
->drupalGet($module_url);
$this
->assertSession()
->statusCodeEquals(200);
// The modules list form is not read-only.
$this
->assertSession()
->pageTextNotContains($this->message);
// Verify if we can successfully access the modules uninstall route.
$uninstall_url = Url::fromRoute('system.modules_uninstall');
$this
->drupalGet($uninstall_url);
$this
->assertSession()
->statusCodeEquals(200);
// The modules uninstall form is not read-only.
$this
->assertSession()
->pageTextNotContains($this->message);
// Enable the search module to confirm we can submit the form.
$edit = [
'modules[search][enable]' => TRUE,
];
$this
->drupalPostForm($module_url, $edit, 'Install');
$this
->assertSession()
->pageTextNotContains($this->message);
// Switch forms to read-only.
$this
->turnOnReadOnlySetting();
$this
->drupalGet($module_url);
// The modules list form is read-only.
$this
->assertSession()
->pageTextContains($this->message);
$this
->drupalGet($uninstall_url);
// The modules uninstall form is read-only.
$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.');
// Verify that a search can be run since work-around is removed.
// @see https://www.drupal.org/node/2845743
$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.');
}