WildfireTest.php 41 KB

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