DbLogControllerTest.php 1.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

namespace Drupal\Tests\dblog\Kernel;

use Drupal\dblog\Controller\DbLogController;
use Drupal\KernelTests\KernelTestBase;

/**
 * Tests for the DbLogController class.
 *
 * @group dblog
 */
class DbLogControllerTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  public static $modules = ['dblog', 'user'];

  /**
   * Tests corrupted log entries can still display available data.
   */
  public function testDbLogCorrupted() {
    $this->installEntitySchema('user');
    $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);
  }

}