FirePhpTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\analysis\logger\adapter;
  9. use lithium\analysis\Logger;
  10. use lithium\analysis\logger\adapter\FirePhp;
  11. use lithium\action\Response;
  12. /**
  13. * This tests make sure that the FirePhp log adapter works as expected.
  14. */
  15. class FirePhpTest extends \lithium\test\Unit {
  16. /**
  17. * Sets up and configures the logger and also the cache storage for testing.
  18. */
  19. public function setUp() {
  20. $this->firephp = new FirePhp();
  21. Logger::config(array('firephp' => array('adapter' => $this->firephp)));
  22. }
  23. /**
  24. * Test the initialization of the FirePhp log adapter.
  25. */
  26. public function testConstruct() {
  27. $expected = array('init' => true);
  28. $this->assertEqual($expected, $this->firephp->_config);
  29. }
  30. /**
  31. * Test if the configuration is correctly set in the logger.
  32. */
  33. public function testConfiguration() {
  34. $loggers = Logger::config();
  35. $result = isset($loggers['firephp']);
  36. $this->assertTrue($result);
  37. }
  38. /**
  39. * Tests the writing mechanism. At first, no Response object is bound to the logger, so
  40. * it queues up the messages. When the Response object finally gets bound, it flushes the
  41. * needed headers and all messages at once. All messages coming after this point get added
  42. * to the header immediately.
  43. */
  44. public function testWrite() {
  45. $response = new Response();
  46. $result = Logger::write('debug', 'FirePhp to the rescue!', array('name' => 'firephp'));
  47. $this->assertTrue($result);
  48. $this->assertFalse($response->headers());
  49. $host = 'meta.firephp.org';
  50. $expected = array(
  51. "X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2",
  52. "X-Wf-1-Plugin-1: http://{$host}/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3",
  53. "X-Wf-1-Structure-1: http://{$host}/Wildfire/Structure/FirePHP/FirebugConsole/0.1",
  54. "X-Wf-1-1-1-1: 41|[{\"Type\":\"LOG\"},\"FirePhp to the rescue!\"]|"
  55. );
  56. Logger::adapter('firephp')->bind($response);
  57. $this->assertEqual($expected, $response->headers());
  58. $result = Logger::write('debug', 'Add this immediately.', array('name' => 'firephp'));
  59. $this->assertTrue($result);
  60. $expected[] = 'X-Wf-1-1-1-2: 40|[{"Type":"LOG"},"Add this immediately."]|';
  61. $this->assertEqual($expected, $response->headers());
  62. }
  63. }
  64. ?>