View source
<?php
namespace Drupal\Tests\modules_weight\Functional;
use Drupal\Tests\BrowserTestBase;
class ModulesListFormTest extends BrowserTestBase {
protected static $modules = [
'modules_weight',
];
public function testModulesListForm() {
$this
->drupalGet('/admin/config/system/modules-weight');
$this
->assertSession()
->statusCodeEquals(403);
$account = $this
->drupalCreateUser([
'administer modules weight',
'access administration pages',
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/config/system/modules-weight');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->elementTextContains('css', 'h1', 'Modules Weight');
$this
->assertSession()
->elementTextContains('css', '#edit-modules > tbody > tr > td:nth-child(1)', 'Modules Weight');
$this
->assertSession()
->elementTextContains('css', '#edit-modules > tbody > tr > td:nth-child(2)', 'Allows to change the modules execution order.');
$this
->assertSession()
->elementTextContains('css', '#edit-modules > tbody > tr > td:nth-child(4)', 'Development');
$this
->assertEquals(0, $this
->getSession()
->getPage()
->findField('modules[modules_weight][weight]')
->getValue());
$this
->assertSession()
->elementTextNotContains('css', '#edit-modules > tbody > tr > td:nth-child(4)', 'Core');
$this
->drupalGet('/admin/config/system/modules-weight/configuration');
$edit = [
'show_system_modules' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'op');
$this
->drupalGet('/admin/config/system/modules-weight');
$this
->assertSession()
->elementTextContains('css', '#edit-modules > tbody > tr > td:nth-child(4)', 'Core');
$this
->drupalPostForm(NULL, [], 'op');
$this
->assertSession()
->elementTextContains('css', '.messages', 'You don\'t have changed the weight for any module.');
$edit = [
'modules[dynamic_page_cache][weight]' => 15,
'modules[page_cache][weight]' => 15,
'modules[modules_weight][weight]' => -3,
'modules[user][weight]' => -2,
];
$this
->drupalPostForm(NULL, $edit, 'op');
$this
->assertSession()
->pageTextContains('The modules weight was updated.');
$this
->assertSession()
->pageTextContains('Internal Dynamic Page Cache have now as weight: 15');
$this
->assertSession()
->pageTextContains('Internal Page Cache have now as weight: 15');
$this
->assertSession()
->pageTextContains('Modules Weight have now as weight: -3');
$this
->assertSession()
->pageTextContains('User have now as weight: -2');
$this
->assertEquals(15, $this
->getSession()
->getPage()
->findField('modules[dynamic_page_cache][weight]')
->getValue());
$this
->assertEquals(15, $this
->getSession()
->getPage()
->findField('modules[page_cache][weight]')
->getValue());
$this
->assertEquals(-3, $this
->getSession()
->getPage()
->findField('modules[modules_weight][weight]')
->getValue());
$this
->assertEquals(0, $this
->getSession()
->getPage()
->findField('modules[system][weight]')
->getValue());
$this
->assertEquals(-2, $this
->getSession()
->getPage()
->findField('modules[user][weight]')
->getValue());
$modules_weight = $this->container
->get('config.factory')
->get('core.extension')
->get('module');
$this
->assertEquals(15, $modules_weight['dynamic_page_cache']);
$this
->assertEquals(15, $modules_weight['page_cache']);
$this
->assertEquals(-3, $modules_weight['modules_weight']);
$this
->assertEquals(0, $modules_weight['system']);
$this
->assertEquals(-2, $modules_weight['user']);
$edit = [
'modules[system][weight]' => 15,
'modules[page_cache][weight]' => -3,
'modules[user][weight]' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'op');
$this
->assertSession()
->pageTextContains('The modules weight was updated.');
$this
->assertSession()
->pageTextContains('System have now as weight: 15');
$this
->assertSession()
->pageTextContains('Internal Page Cache have now as weight: -3');
$this
->assertSession()
->pageTextContains('User have now as weight: 0');
$this
->assertEquals(15, $this
->getSession()
->getPage()
->findField('modules[system][weight]')
->getValue());
$this
->assertEquals(-3, $this
->getSession()
->getPage()
->findField('modules[page_cache][weight]')
->getValue());
$this
->assertEquals(0, $this
->getSession()
->getPage()
->findField('modules[user][weight]')
->getValue());
$modules_weight = $this->container
->get('config.factory')
->get('core.extension')
->get('module');
$this
->assertEquals(15, $modules_weight['system']);
$this
->assertEquals(-3, $modules_weight['page_cache']);
$this
->assertEquals(0, $modules_weight['user']);
}
}