Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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   public function setUp() {
21     parent::setUp();
22     $this->installEntitySchema('user');
23     $this->installSchema('dblog', ['watchdog']);
24   }
25
26   /**
27    * Tests links with non latin characters.
28    */
29   public function testNonLatinCharacters() {
30
31     $link = 'hello-
32       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
33       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
34       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
35       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
36       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
37       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
38       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
39       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
40       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
41       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
42       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
43       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
44       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰
45       科州的小九寨沟绝美高山湖泊酱凉拌素鸡照烧鸡黄玫瑰';
46
47     \Drupal::logger('my_module')->warning('test', ['link' => $link]);
48
49     $log = \Drupal::database()
50       ->select('watchdog', 'w')
51       ->fields('w', ['link'])
52       ->condition('link', '', '<>')
53       ->execute()
54       ->fetchField();
55
56     $this->assertEquals($log, $link);
57   }
58
59   /**
60    * Tests corrupted log entries can still display available data.
61    */
62   public function testDbLogCorrupted() {
63     $dblog_controller = DbLogController::create($this->container);
64
65     // Check message with properly serialized data.
66     $message = (object) [
67       'message' => 'Sample message with placeholder: @placeholder',
68       'variables' => serialize(['@placeholder' => 'test placeholder']),
69     ];
70
71     $this->assertEquals('Sample message with placeholder: test placeholder', $dblog_controller->formatMessage($message));
72
73     // Check that controller work with corrupted data.
74     $message->variables = 'BAD SERIALIZED DATA';
75     $formatted = $dblog_controller->formatMessage($message);
76     $this->assertEquals('Log data is corrupted and cannot be unserialized: Sample message with placeholder: @placeholder', $formatted);
77   }
78
79 }