WildfireTest.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Wildfire
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  23. /** Zend_Wildfire_Channel_HttpHeaders */
  24. require_once 'Zend/Wildfire/Channel/HttpHeaders.php';
  25. /** Zend_Wildfire_Plugin_FirePhp */
  26. require_once 'Zend/Wildfire/Plugin/FirePhp.php';
  27. /** Zend_Wildfire_Plugin_FirePhp_Message */
  28. require_once 'Zend/Wildfire/Plugin/FirePhp/Message.php';
  29. /** Zend_Wildfire_Plugin_FirePhp_TableMessage */
  30. require_once 'Zend/Wildfire/Plugin/FirePhp/TableMessage.php';
  31. /** Zend_Controller_Request_Http */
  32. require_once 'Zend/Controller/Request/Http.php';
  33. /** Zend_Controller_Response_Http */
  34. require_once 'Zend/Controller/Response/Http.php';
  35. /** Zend_Controller_Front **/
  36. require_once 'Zend/Controller/Front.php';
  37. /** Zend_Json */
  38. require_once 'Zend/Json.php';
  39. /** Zend_Json_Encoder */
  40. require_once 'Zend/Json/Encoder.php';
  41. /**
  42. * @category Zend
  43. * @package Zend_Wildfire
  44. * @subpackage UnitTests
  45. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  46. * @license http://framework.zend.com/license/new-bsd New BSD License
  47. */
  48. class Zend_Wildfire_WildfireTest extends PHPUnit_Framework_TestCase
  49. {
  50. protected $_controller = null;
  51. protected $_request = null;
  52. protected $_response = null;
  53. /**
  54. * Runs the test methods of this class.
  55. *
  56. * @access public
  57. * @static
  58. */
  59. public static function main()
  60. {
  61. require_once "PHPUnit/TextUI/TestRunner.php";
  62. $suite = new PHPUnit_Framework_TestSuite("Zend_Wildfire_WildfireTest");
  63. $result = PHPUnit_TextUI_TestRunner::run($suite);
  64. }
  65. public function setUp()
  66. {
  67. date_default_timezone_set('America/Los_Angeles');
  68. }
  69. public function tearDown()
  70. {
  71. Zend_Controller_Front::getInstance()->resetInstance();
  72. Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
  73. Zend_Wildfire_Plugin_FirePhp::destroyInstance();
  74. }
  75. protected function _setupWithFrontController()
  76. {
  77. $this->_request = new Zend_Wildfire_WildfireTest_Request();
  78. $this->_response = new Zend_Wildfire_WildfireTest_Response();
  79. $this->_controller = Zend_Controller_Front::getInstance();
  80. $this->_controller->resetInstance();
  81. $this->_controller->setControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files')
  82. ->setRequest($this->_request)
  83. ->setResponse($this->_response)
  84. ->setParam('noErrorHandler', true)
  85. ->setParam('noViewRenderer', true)
  86. ->throwExceptions(false);
  87. Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('includeLineNumbers', false);
  88. $this->_request->setUserAgentExtensionEnabled(true);
  89. }
  90. protected function _setupWithoutFrontController($ModifyOptions=true)
  91. {
  92. $this->_request = new Zend_Wildfire_WildfireTest_Request();
  93. $this->_response = new Zend_Wildfire_WildfireTest_Response();
  94. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  95. $channel->setRequest($this->_request);
  96. $channel->setResponse($this->_response);
  97. if ($ModifyOptions) {
  98. Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('includeLineNumbers', false);
  99. }
  100. $this->_request->setUserAgentExtensionEnabled(true);
  101. }
  102. public function testNoResponseObject()
  103. {
  104. Zend_Wildfire_Plugin_FirePhp::getInstance()->setEnabled(false);
  105. Zend_Wildfire_Plugin_FirePhp::send('Hello World');
  106. Zend_Wildfire_Plugin_FirePhp::getInstance()->setEnabled(true);
  107. try {
  108. Zend_Wildfire_Plugin_FirePhp::send('Hello World');
  109. $this->fail('Should throw a response object not initialized error');
  110. } catch (Exception $e) {
  111. // success
  112. }
  113. }
  114. public function testIsReady1()
  115. {
  116. $this->_setupWithFrontController();
  117. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  118. $this->assertTrue($channel->isReady(true));
  119. $this->_request->setUserAgentExtensionEnabled(false);
  120. $this->assertFalse($channel->isReady(true));
  121. }
  122. public function testIsReady2()
  123. {
  124. $this->_setupWithoutFrontController();
  125. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  126. $this->assertTrue($channel->isReady());
  127. $this->_request->setUserAgentExtensionEnabled(false);
  128. $this->assertFalse($channel->isReady());
  129. }
  130. public function testFirePhpPluginInstanciation()
  131. {
  132. $this->_setupWithoutFrontController();
  133. try {
  134. Zend_Wildfire_Plugin_FirePhp::getInstance();
  135. Zend_Wildfire_Plugin_FirePhp::init(null);
  136. $this->fail('Should not be able to re-initialize');
  137. } catch (Exception $e) {
  138. // success
  139. }
  140. }
  141. public function testFirePhpPluginEnablement()
  142. {
  143. $this->_setupWithoutFrontController();
  144. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  145. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  146. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  147. $this->assertFalse($protocol->getMessages());
  148. $this->assertTrue($firephp->getEnabled());
  149. $this->assertTrue($firephp->send('Hello World'));
  150. $messages = array(Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE=>
  151. array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI=>
  152. array('[{"Type":"LOG"},"Hello World"]')));
  153. $this->assertEquals(serialize($protocol->getMessages()),
  154. serialize($messages));
  155. $this->assertTrue($firephp->setEnabled(false));
  156. $this->assertFalse($firephp->send('Hello World'));
  157. $this->assertFalse($protocol->getMessages());
  158. }
  159. public function testSetControllerPluginStackIndex1()
  160. {
  161. $this->_setupWithoutFrontController();
  162. $controller = Zend_Controller_Front::getInstance();
  163. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  164. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  165. $firephp->send('Hello World');
  166. $plugins = $controller->getPlugins();
  167. $this->assertEquals($plugins[999],$channel);
  168. }
  169. public function testSetControllerPluginStackIndex2()
  170. {
  171. $this->_setupWithoutFrontController(false);
  172. $controller = Zend_Controller_Front::getInstance();
  173. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  174. Zend_Wildfire_Channel_HttpHeaders::setControllerPluginStackIndex(99);
  175. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  176. $firephp->send('Hello World');
  177. $plugins = $controller->getPlugins();
  178. $this->assertEquals($plugins[99],$channel);
  179. }
  180. public function testBasicLogging1()
  181. {
  182. $this->_setupWithoutFrontController();
  183. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  184. $message = 'This is a log message!';
  185. $firephp->send($message);
  186. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  187. $headers = array();
  188. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  189. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  190. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  191. $headers['X-Wf-1-1-1-1'] = '41|[{"Type":"LOG"},"This is a log message!"]|';
  192. $this->assertTrue($this->_response->verifyHeaders($headers));
  193. }
  194. public function testBasicLogging2()
  195. {
  196. $this->_setupWithFrontController();
  197. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  198. $message = 'This is a log message!';
  199. $firephp->send($message);
  200. $this->_controller->dispatch();
  201. $headers = array();
  202. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  203. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  204. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  205. $headers['X-Wf-1-1-1-1'] = '41|[{"Type":"LOG"},"This is a log message!"]|';
  206. $this->assertTrue($this->_response->verifyHeaders($headers));
  207. }
  208. /**
  209. * At this point UTF-8 characters are not supported as Zend_Json_Decoder
  210. * does not support them.
  211. * Once ZF-4054 is resolved this test must be updated.
  212. */
  213. public function testUTF8Logging()
  214. {
  215. $this->_setupWithFrontController();
  216. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  217. $encodedMessage = $message = 'Отладочный';
  218. if (function_exists('json_encode') && Zend_Json::$useBuiltinEncoderDecoder !== true) {
  219. $encodedMessage = '\u041e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439';
  220. }
  221. $firephp->send($message);
  222. $this->_controller->dispatch();
  223. $headers = array();
  224. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  225. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  226. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  227. $headers['X-Wf-1-1-1-1'] = (strlen($encodedMessage)+19).'|[{"Type":"LOG"},"'.$encodedMessage.'"]|';
  228. $this->assertTrue($this->_response->verifyHeaders($headers));
  229. }
  230. public function testCyclicalObjectLogging()
  231. {
  232. $this->_setupWithFrontController();
  233. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  234. $obj1 = new Zend_Wildfire_WildfireTest_JsonEncodingTestClass();
  235. $obj2 = new Zend_Wildfire_WildfireTest_JsonEncodingTestClass();
  236. $obj1->child = $obj2;
  237. $obj2->child = $obj1;
  238. $firephp->send($obj1);
  239. $this->_controller->dispatch();
  240. $headers = array();
  241. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  242. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  243. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  244. $headers['X-Wf-1-1-1-1'] = '257|[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_JsonEncodingTestClass","undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_JsonEncodingTestClass","undeclared:child":"** Recursion (Zend_Wildfire_WildfireTest_JsonEncodingTestClass) **"}}]|';
  245. $this->assertTrue($this->_response->verifyHeaders($headers));
  246. }
  247. /**
  248. * @group ZF-4927
  249. */
  250. public function testAdvancedLogging()
  251. {
  252. Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('maxTraceDepth',0);
  253. $this->_setupWithoutFrontController();
  254. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  255. $message = 'This is a log message!';
  256. $label = 'Test Label';
  257. $table = array('Summary line for the table',
  258. array(
  259. array('Column 1', 'Column 2'),
  260. array('Row 1 c 1',' Row 1 c 2'),
  261. array('Row 2 c 1',' Row 2 c 2')
  262. )
  263. );
  264. $firephp->send($message, null, 'TRACE');
  265. $firephp->send($table, null, 'TABLE');
  266. Zend_Wildfire_Plugin_FirePhp::send($message, $label);
  267. Zend_Wildfire_Plugin_FirePhp::send($message, $label, Zend_Wildfire_Plugin_FirePhp::DUMP);
  268. try {
  269. throw new Exception('Test Exception');
  270. } catch (Exception $e) {
  271. Zend_Wildfire_Plugin_FirePhp::send($e);
  272. }
  273. try {
  274. Zend_Wildfire_Plugin_FirePhp::send($message, $label, 'UNKNOWN');
  275. $this->fail('Should not be able to log with undefined log style');
  276. } catch (Exception $e) {
  277. // success
  278. }
  279. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  280. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  281. $messages = array(Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE=>
  282. array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI=>
  283. array(1=>'[{"Type":"TABLE"},["Summary line for the table",[["Column 1","Column 2"],["Row 1 c 1"," Row 1 c 2"],["Row 2 c 1"," Row 2 c 2"]]]]',
  284. 2=>'[{"Type":"LOG","Label":"Test Label"},"This is a log message!"]')),
  285. Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_DUMP=>
  286. array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI=>
  287. array('{"Test Label":"This is a log message!"}')));
  288. $qued_messages = $protocol->getMessages();
  289. unset($qued_messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0]);
  290. unset($qued_messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][3]);
  291. $this->assertEquals(serialize($qued_messages),
  292. serialize($messages));
  293. }
  294. public function testMessage()
  295. {
  296. $this->_setupWithoutFrontController();
  297. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  298. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  299. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  300. $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::LOG);
  301. $message->setStyle(Zend_Wildfire_Plugin_FirePhp::INFO);
  302. $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::INFO);
  303. $this->assertNull($message->getLabel());
  304. $message->setLabel('Label 1');
  305. $this->assertEquals($message->getLabel(), 'Label 1');
  306. $this->assertFalse($message->getDestroy());
  307. $message->setDestroy(true);
  308. $this->assertTrue($message->getDestroy());
  309. $this->assertEquals($message->getMessage(), 'Message 1');
  310. $message->setMessage('Message 2');
  311. $this->assertEquals($message->getMessage(), 'Message 2');
  312. $message->setDestroy(true);
  313. $this->assertfalse(Zend_Wildfire_Plugin_FirePhp::send($message));
  314. $message->setDestroy(false);
  315. $this->assertTrue(Zend_Wildfire_Plugin_FirePhp::send($message));
  316. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  317. $messages = $protocol->getMessages();
  318. $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  319. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
  320. '[{"Type":"INFO","Label":"Label 1"},"Message 2"]');
  321. }
  322. /**
  323. * @group ZF-5742
  324. */
  325. public function testTableMessage()
  326. {
  327. $table = new Zend_Wildfire_Plugin_FirePhp_TableMessage('TestMessage');
  328. $this->assertEquals($table->getLabel(), 'TestMessage');
  329. try {
  330. $table->getLastRow();
  331. $this->fail('Should throw exception when no rows exist');
  332. } catch (Exception $e) {
  333. // success
  334. }
  335. $row = array('col1','col2');
  336. $this->assertEquals($table->getRowCount(), 0);
  337. try {
  338. $table->getRowAt(1);
  339. $this->fail('Should throw exception as no rows present');
  340. } catch (Exception $e) {
  341. // success
  342. }
  343. try {
  344. $table->setRowAt(1,array());
  345. $this->fail('Should throw exception as no rows present');
  346. } catch (Exception $e) {
  347. // success
  348. }
  349. $table->addRow($row);
  350. $this->assertEquals($table->getMessage(), array($row));
  351. $this->assertEquals($table->getLastRow(), $row);
  352. $this->assertEquals($table->getRowCount(), 1);
  353. $table->addRow($row);
  354. $this->assertEquals($table->getMessage(), array($row,
  355. $row));
  356. $this->assertEquals($table->getRowCount(), 2);
  357. $this->assertEquals($table->getLastRow(), $row);
  358. try {
  359. $table->getRowAt(2);
  360. $this->fail('Should throw exception as index is out of bounds');
  361. } catch (Exception $e) {
  362. // success
  363. }
  364. try {
  365. $table->setRowAt(2,array());
  366. $this->fail('Should throw exception as index is out of bounds');
  367. } catch (Exception $e) {
  368. // success
  369. }
  370. $rowOld = $table->getRowAt(1);
  371. $this->assertEquals($rowOld, $row);
  372. $rowOld[1] = 'Column2';
  373. $table->setRowAt(1, $rowOld);
  374. $this->assertEquals($table->getRowAt(1), $rowOld);
  375. $this->assertEquals($table->getLastRow(), $rowOld);
  376. $this->assertEquals($table->getMessage(), array($row,
  377. $rowOld));
  378. $header = array('hc1', 'hc2');
  379. $table->setHeader($header);
  380. $this->assertEquals($table->getMessage(), array($header,
  381. $row,
  382. $rowOld));
  383. }
  384. public function testMessageGroups()
  385. {
  386. $this->_setupWithFrontController();
  387. Zend_Wildfire_Plugin_FirePhp::group('Test Group');
  388. Zend_Wildfire_Plugin_FirePhp::send('Test Message');
  389. Zend_Wildfire_Plugin_FirePhp::groupEnd();
  390. $this->_controller->dispatch();
  391. $headers = array();
  392. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  393. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  394. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  395. $headers['X-Wf-1-1-1-1'] = '50|[{"Type":"GROUP_START","Label":"Test Group"},null]|';
  396. $headers['X-Wf-1-1-1-2'] = '31|[{"Type":"LOG"},"Test Message"]|';
  397. $headers['X-Wf-1-1-1-3'] = '27|[{"Type":"GROUP_END"},null]|';
  398. $this->assertTrue($this->_response->verifyHeaders($headers));
  399. }
  400. public function testMessageComparison()
  401. {
  402. $label = 'Message';
  403. $message1 = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, $label);
  404. $message2 = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, $label);
  405. $this->assertNotEquals($message1,$message2);
  406. }
  407. public function testBufferedMessage1()
  408. {
  409. $this->_setupWithoutFrontController();
  410. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  411. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  412. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  413. $this->assertFalse($message->setBuffered(true));
  414. Zend_Wildfire_Plugin_FirePhp::send($message);
  415. $this->assertFalse($protocol->getMessages());
  416. $message->setMessage('Message 2');
  417. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  418. $messages = $protocol->getMessages();
  419. $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  420. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
  421. '[{"Type":"LOG"},"Message 2"]');
  422. }
  423. public function testBufferedMessage2()
  424. {
  425. $this->_setupWithFrontController();
  426. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  427. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  428. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  429. $this->assertFalse($message->setBuffered(true));
  430. Zend_Wildfire_Plugin_FirePhp::send($message);
  431. $this->assertFalse($protocol->getMessages());
  432. $message->setMessage('Message 2');
  433. $this->_controller->dispatch();
  434. $messages = $protocol->getMessages();
  435. $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  436. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
  437. '[{"Type":"LOG"},"Message 2"]');
  438. }
  439. public function testDestroyedBufferedMessage()
  440. {
  441. $this->_setupWithoutFrontController();
  442. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  443. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  444. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  445. $message->setBuffered(true);
  446. Zend_Wildfire_Plugin_FirePhp::send($message);
  447. $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::LOG);
  448. $message->setStyle(Zend_Wildfire_Plugin_FirePhp::INFO);
  449. $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::INFO);
  450. $message->setDestroy(true);
  451. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  452. $this->assertFalse($protocol->getMessages());
  453. }
  454. public function testChannelInstanciation()
  455. {
  456. $this->_setupWithoutFrontController();
  457. try {
  458. Zend_Wildfire_Channel_HttpHeaders::getInstance();
  459. Zend_Wildfire_Channel_HttpHeaders::init(null);
  460. $this->fail('Should not be able to re-initialize');
  461. } catch (Exception $e) {
  462. // success
  463. }
  464. }
  465. public function testChannelFlush()
  466. {
  467. $this->_setupWithoutFrontController(false);
  468. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  469. $this->assertFalse($channel->flush(), 'Nothing to flush - No messages');
  470. Zend_Wildfire_Plugin_FirePhp::send('Hello World');
  471. $this->assertTrue($channel->flush(), 'One message to flush');
  472. $this->_request->setUserAgentExtensionEnabled(false);
  473. $this->assertFalse($channel->flush(), 'Nothing to flush - Extension not in UserAgent');
  474. }
  475. public function testFirePhpPluginSubclass()
  476. {
  477. $firephp = Zend_Wildfire_Plugin_FirePhp::init('Zend_Wildfire_WildfireTest_FirePhpPlugin');
  478. $this->assertEquals(get_class($firephp),
  479. 'Zend_Wildfire_WildfireTest_FirePhpPlugin');
  480. Zend_Wildfire_Plugin_FirePhp::destroyInstance();
  481. try {
  482. Zend_Wildfire_Plugin_FirePhp::init('Zend_Wildfire_WildfireTest_Request');
  483. $this->fail('Should not be able to initialize');
  484. } catch (Exception $e) {
  485. // success
  486. }
  487. $this->assertNull(Zend_Wildfire_Plugin_FirePhp::getInstance(true));
  488. try {
  489. Zend_Wildfire_Plugin_FirePhp::init(array());
  490. $this->fail('Should not be able to initialize');
  491. } catch (Exception $e) {
  492. // success
  493. }
  494. $this->assertNull(Zend_Wildfire_Plugin_FirePhp::getInstance(true));
  495. }
  496. public function testHttpHeadersChannelSubclass()
  497. {
  498. $firephp = Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_HttpHeadersChannel');
  499. $this->assertEquals(get_class($firephp),
  500. 'Zend_Wildfire_WildfireTest_HttpHeadersChannel');
  501. Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
  502. try {
  503. Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_Request');
  504. $this->fail('Should not be able to initialize');
  505. } catch (Exception $e) {
  506. // success
  507. }
  508. $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
  509. try {
  510. Zend_Wildfire_Channel_HttpHeaders::init(array());
  511. $this->fail('Should not be able to initialize');
  512. } catch (Exception $e) {
  513. // success
  514. }
  515. $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
  516. }
  517. /**
  518. * @group ZF-4843
  519. */
  520. public function testResourceLogging()
  521. {
  522. $this->_setupWithoutFrontController();
  523. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  524. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  525. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  526. $firephp->send(array('file'=>tmpfile()));
  527. $messages = $protocol->getMessages();
  528. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  529. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  530. [0];
  531. $this->assertEquals(substr($message,0,41)
  532. , '[{"Type":"LOG"},{"file":"** Resource id #');
  533. }
  534. /**
  535. * @group ZF-4863
  536. */
  537. public function testLargeMessages()
  538. {
  539. $this->_setupWithoutFrontController();
  540. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  541. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  542. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  543. $data = array();
  544. for ($i=0 ; $i < 400 ; $i++) {
  545. $data[] = 'Test Data '.$i;
  546. }
  547. $firephp->send($data);
  548. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  549. $messages = $this->_response->getHeadersForTesting();
  550. $this->assertTrue(substr($messages[3]['value'],0,10)=='6308|[{"Ty'
  551. && substr($messages[3]['value'],-8,8)==',"Test|\\'
  552. && substr($messages[4]['value'],0,10)=='| Data 318'
  553. && substr($messages[4]['value'],-7,7)=='399"]]|');
  554. }
  555. /**
  556. * @group ZF-5540
  557. */
  558. public function testOptions()
  559. {
  560. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  561. $_options = array(
  562. 'traceOffset' => 1, /* The offset in the trace which identifies the source of the message */
  563. 'maxTraceDepth' => 99, /* Maximum depth for stack traces */
  564. 'maxObjectDepth' => 10, /* The maximum depth to traverse objects when encoding */
  565. 'maxArrayDepth' => 20, /* The maximum depth to traverse nested arrays when encoding */
  566. 'includeLineNumbers' => true /* Whether to include line and file info for each message */
  567. );
  568. $this->assertEquals($firephp->getOptions(), $_options, 'Ensure defaults stay the same');
  569. $this->assertEquals($firephp->setOption('includeLineNumbers',false),
  570. $_options['includeLineNumbers'],
  571. 'Should return old value');
  572. $this->assertEquals($firephp->getOption('includeLineNumbers'),
  573. false,
  574. 'Should contain new value');
  575. }
  576. /**
  577. * @group ZF-5540
  578. */
  579. public function testObjectFilter()
  580. {
  581. $this->_setupWithoutFrontController();
  582. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  583. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  584. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  585. $obj = new Zend_Wildfire_WildfireTest_TestObject1();
  586. $firephp->send($obj);
  587. $firephp->setObjectFilter('Zend_Wildfire_WildfireTest_TestObject1',array('value', 'protectedStatic'));
  588. $firephp->send($obj);
  589. $messages = $protocol->getMessages();
  590. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  591. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  592. [0];
  593. if (version_compare(phpversion(), '5.3' , '<')) {
  594. $this->assertEquals($message,
  595. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"Value","protected:static:protectedStatic":"** Need PHP 5.3 to get value **"}]');
  596. } else
  597. if (version_compare(phpversion(), '5.3' , '>=')) {
  598. $this->assertEquals($message,
  599. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"Value","protected:static:protectedStatic":"ProtectedStatic"}]');
  600. }
  601. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  602. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  603. [1];
  604. $this->assertEquals($message,
  605. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"** Excluded by Filter **","protected:static:protectedStatic":"** Excluded by Filter **"}]');
  606. }
  607. public function testObjectMembers()
  608. {
  609. $this->_setupWithoutFrontController();
  610. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  611. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  612. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  613. $obj = new Zend_Wildfire_WildfireTest_TestObject2();
  614. $firephp->send($obj);
  615. $messages = $protocol->getMessages();
  616. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  617. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  618. [0];
  619. if (version_compare(phpversion(), '5.3' , '<')) {
  620. $this->assertEquals($message,
  621. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject2","public:public":"Public","private:private":"Private","protected:protected":"Protected","public:static:static":"Static","private:static:staticPrivate":"** Need PHP 5.3 to get value **","protected:static:staticProtected":"** Need PHP 5.3 to get value **"}]');
  622. } else
  623. if (version_compare(phpversion(), '5.3' , '>=')) {
  624. $this->assertEquals($message,
  625. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject2","public:public":"Public","private:private":"Private","protected:protected":"Protected","public:static:static":"Static","private:static:staticPrivate":"StaticPrivate","protected:static:staticProtected":"StaticProtected"}]');
  626. }
  627. }
  628. /**
  629. * @group ZF-5540
  630. */
  631. public function testMaxObjectArrayDepth()
  632. {
  633. $this->_setupWithoutFrontController();
  634. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  635. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  636. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  637. $firephp->setOption('maxObjectDepth',2);
  638. $firephp->setOption('maxArrayDepth',1);
  639. $obj = new Zend_Wildfire_WildfireTest_TestObject3();
  640. $obj->testArray = array('val1',array('val2',array('Hello World')));
  641. $obj->child = clone $obj;
  642. $obj->child->child = clone $obj;
  643. $firephp->send($obj);
  644. $table = array();
  645. $table[] = array('Col1', 'Col2');
  646. $table[] = array($obj, $obj);
  647. $firephp->send($table, 'Label', Zend_Wildfire_Plugin_FirePhp::TABLE);
  648. $messages = $protocol->getMessages();
  649. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  650. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  651. [0];
  652. $this->assertEquals($message,
  653. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":"** Max Object Depth (2) **"}}]');
  654. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  655. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  656. [1];
  657. $this->assertEquals($message,
  658. '[{"Type":"TABLE","Label":"Label"},[["Col1","Col2"],[{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":"** Max Object Depth (2) **"}},{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":{"__className":"Zend_Wildfire_WildfireTest_TestObject3","public:name":"Name","public:value":"Value","undeclared:testArray":["val1","** Max Array Depth (1) **"],"undeclared:child":"** Max Object Depth (2) **"}}]]]');
  659. }
  660. }
  661. class Zend_Wildfire_WildfireTest_TestObject1
  662. {
  663. var $name = 'Name';
  664. var $value = 'Value';
  665. protected static $protectedStatic = 'ProtectedStatic';
  666. }
  667. class Zend_Wildfire_WildfireTest_TestObject2
  668. {
  669. var $public = 'Public';
  670. private $private = 'Private';
  671. protected $protected = 'Protected';
  672. static $static = 'Static';
  673. static private $staticPrivate = 'StaticPrivate';
  674. static protected $staticProtected = 'StaticProtected';
  675. }
  676. class Zend_Wildfire_WildfireTest_TestObject3
  677. {
  678. var $name = 'Name';
  679. var $value = 'Value';
  680. }
  681. class Zend_Wildfire_WildfireTest_JsonEncodingTestClass
  682. {
  683. }
  684. class Zend_Wildfire_WildfireTest_FirePhpPlugin extends Zend_Wildfire_Plugin_FirePhp
  685. {
  686. }
  687. class Zend_Wildfire_WildfireTest_HttpHeadersChannel extends Zend_Wildfire_Channel_HttpHeaders
  688. {
  689. }
  690. class Zend_Wildfire_WildfireTest_Request extends Zend_Controller_Request_Http
  691. {
  692. protected $_enabled = false;
  693. public function setUserAgentExtensionEnabled($enabled) {
  694. $this->_enabled = $enabled;
  695. }
  696. public function getHeader($header)
  697. {
  698. if ($header == 'User-Agent') {
  699. if ($this->_enabled) {
  700. return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14 FirePHP/0.1.0';
  701. } else {
  702. return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
  703. }
  704. }
  705. }
  706. }
  707. class Zend_Wildfire_WildfireTest_Response extends Zend_Controller_Response_Http
  708. {
  709. public function getHeadersForTesting()
  710. {
  711. return $this->getHeaders();
  712. }
  713. public function verifyHeaders($headers)
  714. {
  715. $response_headers = $this->getHeaders();
  716. if (!$response_headers) {
  717. return false;
  718. }
  719. $keys1 = array_keys($headers);
  720. sort($keys1);
  721. $keys1 = serialize($keys1);
  722. $keys2 = array();
  723. foreach ($response_headers as $header ) {
  724. $keys2[] = $header['name'];
  725. }
  726. sort($keys2);
  727. $keys2 = serialize($keys2);
  728. if ($keys1 != $keys2) {
  729. return false;
  730. }
  731. $values1 = array_values($headers);
  732. sort($values1);
  733. $values1 = serialize($values1);
  734. $values2 = array();
  735. foreach ($response_headers as $header ) {
  736. $values2[] = $header['value'];
  737. }
  738. sort($values2);
  739. $values2 = serialize($values2);
  740. if ($values1 != $values2) {
  741. return false;
  742. }
  743. return true;
  744. }
  745. }