Version 1
[yaffs-website] / web / core / modules / dblog / tests / src / Kernel / DbLogControllerTest.php
1 <?php
2
3 namespace Drupal\Tests\dblog\Kernel;
4
5 use Drupal\dblog\Controller\DbLogController;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests for the DbLogController class.
10  *
11  * @group dblog
12  */
13 class DbLogControllerTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['dblog', 'user'];
19
20   /**
21    * Tests corrupted log entries can still display available data.
22    */
23   public function testDbLogCorrupted() {
24     $this->installEntitySchema('user');
25     $dblog_controller = DbLogController::create($this->container);
26
27     // Check message with properly serialized data.
28     $message = (object) [
29       'message' => 'Sample message with placeholder: @placeholder',
30       'variables' => serialize(['@placeholder' => 'test placeholder']),
31     ];
32
33     $this->assertEquals('Sample message with placeholder: test placeholder', $dblog_controller->formatMessage($message));
34
35     // Check that controller work with corrupted data.
36     $message->variables = 'BAD SERIALIZED DATA';
37     $formatted = $dblog_controller->formatMessage($message);
38     $this->assertEquals('Log data is corrupted and cannot be unserialized: Sample message with placeholder: @placeholder', $formatted);
39   }
40
41 }