Mercurial > hg > isophonics-drupal-site
comparison core/modules/syslog/tests/src/Kernel/SyslogTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\syslog\Kernel; | |
4 | |
5 use Drupal\KernelTests\KernelTestBase; | |
6 use Symfony\Component\HttpFoundation\Request; | |
7 use Symfony\Component\HttpFoundation\RequestStack; | |
8 | |
9 /** | |
10 * Test syslog logger functionality. | |
11 * | |
12 * @group syslog | |
13 * @coversDefaultClass \Drupal\syslog\Logger\SysLog | |
14 */ | |
15 class SyslogTest extends KernelTestBase { | |
16 | |
17 public static $modules = ['syslog', 'syslog_test']; | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 protected function setUp() { | |
23 parent::setUp(); | |
24 $this->installConfig(['syslog']); | |
25 } | |
26 | |
27 /** | |
28 * @covers ::log | |
29 */ | |
30 public function testSyslogWriting() { | |
31 | |
32 $request = Request::create('/page-not-found', 'GET', [], [], [], ['REMOTE_ADDR' => '1.2.3.4']); | |
33 $request->headers->set('Referer', 'other-site'); | |
34 \Drupal::requestStack()->push($request); | |
35 | |
36 $user = $this->getMockBuilder('Drupal\Core\Session\AccountInterface')->getMock(); | |
37 $user->method('id')->willReturn(42); | |
38 $this->container->set('current_user', $user); | |
39 | |
40 \Drupal::logger('my_module')->warning('My warning message.', ['link' => '/my-link']); | |
41 | |
42 $log_filename = $this->container->get('file_system')->realpath('public://syslog.log'); | |
43 $logs = explode(PHP_EOL, file_get_contents($log_filename)); | |
44 $log = explode('|', $logs[0]); | |
45 | |
46 global $base_url; | |
47 $this->assertEquals($base_url, $log[0]); | |
48 $this->assertEquals('my_module', $log[2]); | |
49 $this->assertEquals('1.2.3.4', $log[3]); | |
50 $this->assertEquals($base_url . '/page-not-found', $log[4]); | |
51 $this->assertEquals('other-site', $log[5]); | |
52 $this->assertEquals('42', $log[6]); | |
53 $this->assertEquals('/my-link', $log[7]); | |
54 $this->assertEquals('My warning message.', $log[8]); | |
55 } | |
56 | |
57 } |