function RequirementsTest::testIsolationLevelWarningNotDisplaying

Same name in other branches
  1. 9 core/modules/mysql/tests/src/Functional/RequirementsTest.php \Drupal\Tests\mysql\Functional\RequirementsTest::testIsolationLevelWarningNotDisplaying()
  2. 10 core/modules/mysql/tests/src/Functional/RequirementsTest.php \Drupal\Tests\mysql\Functional\RequirementsTest::testIsolationLevelWarningNotDisplaying()

Test the isolation level warning message on status page.

File

core/modules/mysql/tests/src/Functional/RequirementsTest.php, line 43

Class

RequirementsTest
Tests isolation level warning when the config is set in settings.php.

Namespace

Drupal\Tests\mysql\Functional

Code

public function testIsolationLevelWarningNotDisplaying() : void {
    $admin_user = $this->drupalCreateUser([
        'administer site configuration',
        'access site reports',
    ]);
    $this->drupalLogin($admin_user);
    $connection = Database::getConnection();
    // Set the isolation level to a level that produces a warning.
    $this->writeIsolationLevelSettings('REPEATABLE READ');
    // Check the message is not a warning.
    $this->drupalGet('admin/reports/status');
    $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), "REPEATABLE-READ")]');
    $this->assertCount(1, $elements);
    // Ensure it is a warning.
    $this->assertStringContainsString('warning', $elements[0]->getParent()
        ->getParent()
        ->find('css', 'summary')
        ->getAttribute('class'));
    // Rollback the isolation level to read committed.
    $this->writeIsolationLevelSettings('READ COMMITTED');
    // Check the message is not a warning.
    $this->drupalGet('admin/reports/status');
    $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), "READ-COMMITTED")]');
    $this->assertCount(1, $elements);
    // Ensure it is a not a warning.
    $this->assertStringNotContainsString('warning', $elements[0]->getParent()
        ->getParent()
        ->find('css', 'summary')
        ->getAttribute('class'));
    $specification = [
        'fields' => [
            'text' => [
                'type' => 'text',
                'description' => 'A text field',
            ],
        ],
    ];
    $connection->schema()
        ->createTable('test_table_without_primary_key', $specification);
    // Set the isolation level to a level that produces a warning.
    $this->writeIsolationLevelSettings('REPEATABLE READ');
    // Check the message is not a warning.
    $this->drupalGet('admin/reports/status');
    $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
        ':text' => 'The recommended level for Drupal is "READ COMMITTED". For this to work correctly, all tables must have a primary key. The following table(s) do not have a primary key: test_table_without_primary_key.',
    ]);
    $this->assertCount(1, $elements);
    $this->assertStringStartsWith('REPEATABLE-READ', $elements[0]->getParent()
        ->getText());
    // Ensure it is a warning.
    $this->assertStringContainsString('warning', $elements[0]->getParent()
        ->getParent()
        ->find('css', 'summary')
        ->getAttribute('class'));
    // Rollback the isolation level to read committed.
    $this->writeIsolationLevelSettings('READ COMMITTED');
    // Check the message is not a warning.
    $this->drupalGet('admin/reports/status');
    $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
        ':text' => 'For this to work correctly, all tables must have a primary key. The following table(s) do not have a primary key: test_table_without_primary_key.',
    ]);
    $this->assertCount(1, $elements);
    $this->assertStringStartsWith('READ-COMMITTED', $elements[0]->getParent()
        ->getText());
    // Ensure it is an error.
    $this->assertStringContainsString('error', $elements[0]->getParent()
        ->getParent()
        ->find('css', 'summary')
        ->getAttribute('class'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.