ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
BrowserConsoleHandlerTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
16
21{
22 protected function setUp()
23 {
25 }
26
27 protected function generateScript()
28 {
29 $reflMethod = new \ReflectionMethod('Monolog\Handler\BrowserConsoleHandler', 'generateScript');
30 $reflMethod->setAccessible(true);
31
32 return $reflMethod->invoke(null);
33 }
34
35 public function testStyling()
36 {
37 $handler = new BrowserConsoleHandler();
38 $handler->setFormatter($this->getIdentityFormatter());
39
40 $handler->handle($this->getRecord(Logger::DEBUG, 'foo[[bar]]{color: red}'));
41
42 $expected = <<<EOF
43(function (c) {if (c && c.groupCollapsed) {
44c.log("%cfoo%cbar%c", "font-weight: normal", "color: red", "font-weight: normal");
45}})(console);
46EOF;
47
48 $this->assertEquals($expected, $this->generateScript());
49 }
50
51 public function testEscaping()
52 {
53 $handler = new BrowserConsoleHandler();
54 $handler->setFormatter($this->getIdentityFormatter());
55
56 $handler->handle($this->getRecord(Logger::DEBUG, "[foo] [[\"bar\n[baz]\"]]{color: red}"));
57
58 $expected = <<<EOF
59(function (c) {if (c && c.groupCollapsed) {
60c.log("%c[foo] %c\"bar\\n[baz]\"%c", "font-weight: normal", "color: red", "font-weight: normal");
61}})(console);
62EOF;
63
64 $this->assertEquals($expected, $this->generateScript());
65 }
66
67 public function testAutolabel()
68 {
69 $handler = new BrowserConsoleHandler();
70 $handler->setFormatter($this->getIdentityFormatter());
71
72 $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}'));
73 $handler->handle($this->getRecord(Logger::DEBUG, '[[bar]]{macro: autolabel}'));
74 $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}'));
75
76 $expected = <<<EOF
77(function (c) {if (c && c.groupCollapsed) {
78c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
79c.log("%c%cbar%c", "font-weight: normal", "background-color: green; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
80c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
81}})(console);
82EOF;
83
84 $this->assertEquals($expected, $this->generateScript());
85 }
86
87 public function testContext()
88 {
89 $handler = new BrowserConsoleHandler();
90 $handler->setFormatter($this->getIdentityFormatter());
91
92 $handler->handle($this->getRecord(Logger::DEBUG, 'test', array('foo' => 'bar')));
93
94 $expected = <<<EOF
95(function (c) {if (c && c.groupCollapsed) {
96c.groupCollapsed("%ctest", "font-weight: normal");
97c.log("%c%s", "font-weight: bold", "Context");
98c.log("%s: %o", "foo", "bar");
99c.groupEnd();
100}})(console);
101EOF;
102
103 $this->assertEquals($expected, $this->generateScript());
104 }
105
106 public function testConcurrentHandlers()
107 {
108 $handler1 = new BrowserConsoleHandler();
109 $handler1->setFormatter($this->getIdentityFormatter());
110
111 $handler2 = new BrowserConsoleHandler();
112 $handler2->setFormatter($this->getIdentityFormatter());
113
114 $handler1->handle($this->getRecord(Logger::DEBUG, 'test1'));
115 $handler2->handle($this->getRecord(Logger::DEBUG, 'test2'));
116 $handler1->handle($this->getRecord(Logger::DEBUG, 'test3'));
117 $handler2->handle($this->getRecord(Logger::DEBUG, 'test4'));
118
119 $expected = <<<EOF
120(function (c) {if (c && c.groupCollapsed) {
121c.log("%ctest1", "font-weight: normal");
122c.log("%ctest2", "font-weight: normal");
123c.log("%ctest3", "font-weight: normal");
124c.log("%ctest4", "font-weight: normal");
125}})(console);
126EOF;
127
128 $this->assertEquals($expected, $this->generateScript());
129 }
130}
const EOF
How fgetc() reports an End Of File.
Definition: JSMin_lib.php:92
@covers Monolog\Handler\BrowserConsoleHandlerTest
Handler sending logs to browser's javascript console with no browser extension required.
static reset()
Forget all logged records.
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19