MonologHandlerBrowserConsoleHandlerTest

The Gravity PDF Monolog Handler BrowserConsoleHandlerTest class.

Defined (1)

The class is defined in the following location(s).

/vendor/monolog/monolog/tests/Monolog/Handler/BrowserConsoleHandlerTest.php  
  1. class BrowserConsoleHandlerTest extends TestCase 
  2. protected function setUp() 
  3. BrowserConsoleHandler::reset(); 
  4.  
  5. protected function generateScript() 
  6. $reflMethod = new \ReflectionMethod('Monolog\Handler\BrowserConsoleHandler', 'generateScript'); 
  7. $reflMethod->setAccessible(true); 
  8.  
  9. return $reflMethod->invoke(null); 
  10.  
  11. public function testStyling() 
  12. $handler = new BrowserConsoleHandler(); 
  13. $handler->setFormatter($this->getIdentityFormatter()); 
  14.  
  15. $handler->handle($this->getRecord(Logger::DEBUG, 'foo[[bar]]{color: red}')); 
  16.  
  17. $expected = <<<EOF 
  18. (function (c) {if (c && c.groupCollapsed) { 
  19. c.log("%cfoo%cbar%c", "font-weight: normal", "color: red", "font-weight: normal"); 
  20. }})(console); 
  21. EOF; 
  22.  
  23. $this->assertEquals($expected, $this->generateScript()); 
  24.  
  25. public function testEscaping() 
  26. $handler = new BrowserConsoleHandler(); 
  27. $handler->setFormatter($this->getIdentityFormatter()); 
  28.  
  29. $handler->handle($this->getRecord(Logger::DEBUG, "[foo] [[\"bar\n[baz]\"]]{color: red}")); 
  30.  
  31. $expected = <<<EOF 
  32. (function (c) {if (c && c.groupCollapsed) { 
  33. c.log("%c[foo] %c\"bar\\n[baz]\"%c", "font-weight: normal", "color: red", "font-weight: normal"); 
  34. }})(console); 
  35. EOF; 
  36.  
  37. $this->assertEquals($expected, $this->generateScript()); 
  38.  
  39. public function testAutolabel() 
  40. $handler = new BrowserConsoleHandler(); 
  41. $handler->setFormatter($this->getIdentityFormatter()); 
  42.  
  43. $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}')); 
  44. $handler->handle($this->getRecord(Logger::DEBUG, '[[bar]]{macro: autolabel}')); 
  45. $handler->handle($this->getRecord(Logger::DEBUG, '[[foo]]{macro: autolabel}')); 
  46.  
  47. $expected = <<<EOF 
  48. (function (c) {if (c && c.groupCollapsed) { 
  49. c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal"); 
  50. c.log("%c%cbar%c", "font-weight: normal", "background-color: green; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal"); 
  51. c.log("%c%cfoo%c", "font-weight: normal", "background-color: blue; color: white; border-radius: 3px; padding: 0 2px 0 2px", "font-weight: normal"); 
  52. }})(console); 
  53. EOF; 
  54.  
  55. $this->assertEquals($expected, $this->generateScript()); 
  56.  
  57. public function testContext() 
  58. $handler = new BrowserConsoleHandler(); 
  59. $handler->setFormatter($this->getIdentityFormatter()); 
  60.  
  61. $handler->handle($this->getRecord(Logger::DEBUG, 'test', array('foo' => 'bar'))); 
  62.  
  63. $expected = <<<EOF 
  64. (function (c) {if (c && c.groupCollapsed) { 
  65. c.groupCollapsed("%ctest", "font-weight: normal"); 
  66. c.log("%c%s", "font-weight: bold", "Context"); 
  67. c.log("%s: %o", "foo", "bar"); 
  68. c.groupEnd(); 
  69. }})(console); 
  70. EOF; 
  71.  
  72. $this->assertEquals($expected, $this->generateScript()); 
  73.  
  74. public function testConcurrentHandlers() 
  75. $handler1 = new BrowserConsoleHandler(); 
  76. $handler1->setFormatter($this->getIdentityFormatter()); 
  77.  
  78. $handler2 = new BrowserConsoleHandler(); 
  79. $handler2->setFormatter($this->getIdentityFormatter()); 
  80.  
  81. $handler1->handle($this->getRecord(Logger::DEBUG, 'test1')); 
  82. $handler2->handle($this->getRecord(Logger::DEBUG, 'test2')); 
  83. $handler1->handle($this->getRecord(Logger::DEBUG, 'test3')); 
  84. $handler2->handle($this->getRecord(Logger::DEBUG, 'test4')); 
  85.  
  86. $expected = <<<EOF 
  87. (function (c) {if (c && c.groupCollapsed) { 
  88. c.log("%ctest1", "font-weight: normal"); 
  89. c.log("%ctest2", "font-weight: normal"); 
  90. c.log("%ctest3", "font-weight: normal"); 
  91. c.log("%ctest4", "font-weight: normal"); 
  92. }})(console); 
  93. EOF; 
  94.  
  95. $this->assertEquals($expected, $this->generateScript());