4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Handler;
18 * @covers Monolog\Handler\BrowserConsoleHandlerTest
20 class BrowserConsoleHandlerTest extends TestCase
22 protected function setUp()
24 BrowserConsoleHandler::reset();
27 protected function generateScript()
29 $reflMethod = new \ReflectionMethod('Monolog\Handler\BrowserConsoleHandler', 'generateScript');
30 $reflMethod->setAccessible(true);
32 return $reflMethod->invoke(null);
35 public function testStyling()
37 $handler = new BrowserConsoleHandler();
38 $handler->setFormatter($this->getIdentityFormatter());
40 $handler->handle($this->getRecord(Logger::DEBUG, 'foo[[bar]]{color: red}'));
43 (function (c) {if (c && c.groupCollapsed) {
44 c.log("%cfoo%cbar%c", "font-weight: normal", "color: red", "font-weight: normal");
48 $this->assertEquals($expected, $this->generateScript());
51 public function testEscaping()
53 $handler = new BrowserConsoleHandler();
54 $handler->setFormatter($this->getIdentityFormatter());
56 $handler->handle($this->getRecord(Logger::DEBUG, "[foo] [[\"bar\n[baz]\"]]{color: red}"));
59 (function (c) {if (c && c.groupCollapsed) {
60 c.log("%c[foo] %c\"bar\\n[baz]\"%c", "font-weight: normal", "color: red", "font-weight: normal");
64 $this->assertEquals($expected, $this->generateScript());
67 public function testAutolabel()
69 $handler = new BrowserConsoleHandler();
70 $handler->setFormatter($this->getIdentityFormatter());
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}'));
77 (function (c) {if (c && c.groupCollapsed) {
78 c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
79 c.log("%c%cbar%c", "font-weight: normal", "background-color: green; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
80 c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal");
84 $this->assertEquals($expected, $this->generateScript());
87 public function testContext()
89 $handler = new BrowserConsoleHandler();
90 $handler->setFormatter($this->getIdentityFormatter());
92 $handler->handle($this->getRecord(Logger::DEBUG, 'test', array('foo' => 'bar')));
95 (function (c) {if (c && c.groupCollapsed) {
96 c.groupCollapsed("%ctest", "font-weight: normal");
97 c.log("%c%s", "font-weight: bold", "Context");
98 c.log("%s: %o", "foo", "bar");
103 $this->assertEquals($expected, $this->generateScript());
106 public function testConcurrentHandlers()
108 $handler1 = new BrowserConsoleHandler();
109 $handler1->setFormatter($this->getIdentityFormatter());
111 $handler2 = new BrowserConsoleHandler();
112 $handler2->setFormatter($this->getIdentityFormatter());
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'));
120 (function (c) {if (c && c.groupCollapsed) {
121 c.log("%ctest1", "font-weight: normal");
122 c.log("%ctest2", "font-weight: normal");
123 c.log("%ctest3", "font-weight: normal");
124 c.log("%ctest4", "font-weight: normal");
128 $this->assertEquals($expected, $this->generateScript());