RequirementsTest.php in Drupal 10
File
core/modules/mysql/tests/src/Functional/RequirementsTest.php
View source
<?php
namespace Drupal\Tests\mysql\Functional;
use Drupal\Core\Database\Database;
use Drupal\Tests\BrowserTestBase;
class RequirementsTest extends BrowserTestBase {
protected static $modules = [
'mysql',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$connectionInfo = Database::getConnectionInfo();
if ($connectionInfo['default']['driver'] !== 'mysql') {
$this
->markTestSkipped("This test does not support the {$connectionInfo['default']['driver']} database driver.");
}
}
public function testIsolationLevelWarningNotDisplaying() {
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'access site reports',
]);
$this
->drupalLogin($admin_user);
$this
->writeIsolationLevelSettings('REPEATABLE READ');
$this
->drupalGet('admin/reports/status');
$elements = $this
->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'For the best performance and to minimize locking issues, the READ-COMMITTED',
]);
$this
->assertCount(1, $elements);
$this
->assertStringStartsWith('REPEATABLE-READ', $elements[0]
->getParent()
->getText());
$this
->assertStringContainsString('warning', $elements[0]
->getParent()
->getParent()
->find('css', 'summary')
->getAttribute('class'));
$this
->writeIsolationLevelSettings('READ COMMITTED');
$this
->drupalGet('admin/reports/status');
$elements = $this
->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
':text' => 'For the best performance and to minimize locking issues, the READ-COMMITTED',
]);
$this
->assertCount(1, $elements);
$this
->assertStringStartsWith('READ-COMMITTED', $elements[0]
->getParent()
->getText());
$this
->assertStringNotContainsString('warning', $elements[0]
->getParent()
->getParent()
->find('css', 'summary')
->getAttribute('class'));
}
private function writeIsolationLevelSettings(string $isolation_level) {
$settings['databases']['default']['default']['init_commands'] = (object) [
'value' => [
'isolation' => "SET SESSION TRANSACTION ISOLATION LEVEL {$isolation_level}",
],
'required' => TRUE,
];
$this
->writeSettings($settings);
}
}
Classes
Name |
Description |
RequirementsTest |
Tests isolation level warning when the config is set in settings.php. |