WildfireTest.php 41 KB

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