function DbLogControllerTest::testDbLogCorrupted

Same name in other branches
  1. 9 core/modules/dblog/tests/src/Kernel/DbLogControllerTest.php \Drupal\Tests\dblog\Kernel\DbLogControllerTest::testDbLogCorrupted()
  2. 8.9.x core/modules/dblog/tests/src/Kernel/DbLogControllerTest.php \Drupal\Tests\dblog\Kernel\DbLogControllerTest::testDbLogCorrupted()
  3. 10 core/modules/dblog/tests/src/Kernel/DbLogControllerTest.php \Drupal\Tests\dblog\Kernel\DbLogControllerTest::testDbLogCorrupted()

Tests corrupted log entries can still display available data.

File

core/modules/dblog/tests/src/Kernel/DbLogControllerTest.php, line 67

Class

DbLogControllerTest
Tests for the DbLogController class.

Namespace

Drupal\Tests\dblog\Kernel

Code

public function testDbLogCorrupted() : void {
    $dblog_controller = DbLogController::create($this->container);
    // Check message with properly serialized data.
    $message = (object) [
        'message' => 'Sample message with placeholder: @placeholder',
        'variables' => serialize([
            '@placeholder' => 'test placeholder',
        ]),
    ];
    $this->assertEquals('Sample message with placeholder: test placeholder', $dblog_controller->formatMessage($message));
    // Check that controller work with corrupted data.
    $message->variables = 'BAD SERIALIZED DATA';
    $formatted = $dblog_controller->formatMessage($message);
    $this->assertEquals('Log data is corrupted and cannot be unserialized: Sample message with placeholder: @placeholder', $formatted);
}

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