PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Wildfire/WildfireTest.php

https://bitbucket.org/dbaltas/zend-framework-1.x-on-git
PHP | 1210 lines | 880 code | 247 blank | 83 comment | 7 complexity | 0673be2436704e4d3ca378841c4c466e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: WildfireTest.php 24593 2012-01-05 20:35:02Z matthew $
  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-2012 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. /**
  437. * @group ZF-10761
  438. */
  439. public function testMessageGroupsWithCollapsedTrueOption()
  440. {
  441. $this->_setupWithFrontController();
  442. Zend_Wildfire_Plugin_FirePhp::group('Test Group', array('Collapsed' => true));
  443. Zend_Wildfire_Plugin_FirePhp::send('Test Message');
  444. Zend_Wildfire_Plugin_FirePhp::groupEnd();
  445. $this->_controller->dispatch();
  446. $headers = array();
  447. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  448. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  449. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  450. $headers['X-Wf-1-1-1-1'] = '69|[{"Type":"GROUP_START","Label":"Test Group","Collapsed":"true"},null]|';
  451. $headers['X-Wf-1-1-1-2'] = '31|[{"Type":"LOG"},"Test Message"]|';
  452. $headers['X-Wf-1-1-1-3'] = '27|[{"Type":"GROUP_END"},null]|';
  453. $this->assertTrue($this->_response->verifyHeaders($headers));
  454. }
  455. /**
  456. * @group ZF-10761
  457. */
  458. public function testMessageGroupsWithCollapsedFalseOption()
  459. {
  460. $this->_setupWithFrontController();
  461. Zend_Wildfire_Plugin_FirePhp::group('Test Group', array('Collapsed' => false));
  462. Zend_Wildfire_Plugin_FirePhp::send('Test Message');
  463. Zend_Wildfire_Plugin_FirePhp::groupEnd();
  464. $this->_controller->dispatch();
  465. $headers = array();
  466. $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
  467. $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
  468. $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
  469. $headers['X-Wf-1-1-1-1'] = '70|[{"Type":"GROUP_START","Label":"Test Group","Collapsed":"false"},null]|';
  470. $headers['X-Wf-1-1-1-2'] = '31|[{"Type":"LOG"},"Test Message"]|';
  471. $headers['X-Wf-1-1-1-3'] = '27|[{"Type":"GROUP_END"},null]|';
  472. $this->assertTrue($this->_response->verifyHeaders($headers));
  473. }
  474. public function testMessageComparison()
  475. {
  476. $label = 'Message';
  477. $message1 = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, $label);
  478. $message2 = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, $label);
  479. $this->assertNotEquals($message1,$message2);
  480. }
  481. public function testBufferedMessage1()
  482. {
  483. $this->_setupWithoutFrontController();
  484. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  485. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  486. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  487. $this->assertFalse($message->setBuffered(true));
  488. Zend_Wildfire_Plugin_FirePhp::send($message);
  489. $this->assertFalse($protocol->getMessages());
  490. $message->setMessage('Message 2');
  491. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  492. $messages = $protocol->getMessages();
  493. $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  494. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
  495. '[{"Type":"LOG"},"Message 2"]');
  496. }
  497. public function testBufferedMessage2()
  498. {
  499. $this->_setupWithFrontController();
  500. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  501. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  502. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  503. $this->assertFalse($message->setBuffered(true));
  504. Zend_Wildfire_Plugin_FirePhp::send($message);
  505. $this->assertFalse($protocol->getMessages());
  506. $message->setMessage('Message 2');
  507. $this->_controller->dispatch();
  508. $messages = $protocol->getMessages();
  509. $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  510. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
  511. '[{"Type":"LOG"},"Message 2"]');
  512. }
  513. public function testDestroyedBufferedMessage()
  514. {
  515. $this->_setupWithoutFrontController();
  516. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  517. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  518. $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
  519. $message->setBuffered(true);
  520. Zend_Wildfire_Plugin_FirePhp::send($message);
  521. $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::LOG);
  522. $message->setStyle(Zend_Wildfire_Plugin_FirePhp::INFO);
  523. $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::INFO);
  524. $message->setDestroy(true);
  525. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  526. $this->assertFalse($protocol->getMessages());
  527. }
  528. public function testChannelInstanciation()
  529. {
  530. $this->_setupWithoutFrontController();
  531. try {
  532. Zend_Wildfire_Channel_HttpHeaders::getInstance();
  533. Zend_Wildfire_Channel_HttpHeaders::init(null);
  534. $this->fail('Should not be able to re-initialize');
  535. } catch (Exception $e) {
  536. // success
  537. }
  538. }
  539. public function testChannelFlush()
  540. {
  541. $this->_setupWithoutFrontController(false);
  542. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  543. $this->assertFalse($channel->flush(), 'Nothing to flush - No messages');
  544. Zend_Wildfire_Plugin_FirePhp::send('Hello World');
  545. $this->assertTrue($channel->flush(), 'One message to flush');
  546. $this->_request->setUserAgentExtensionEnabled(false);
  547. $this->assertFalse($channel->flush(), 'Nothing to flush - Extension not in UserAgent');
  548. }
  549. public function testFirePhpPluginSubclass()
  550. {
  551. $firephp = Zend_Wildfire_Plugin_FirePhp::init('Zend_Wildfire_WildfireTest_FirePhpPlugin');
  552. $this->assertEquals(get_class($firephp),
  553. 'Zend_Wildfire_WildfireTest_FirePhpPlugin');
  554. Zend_Wildfire_Plugin_FirePhp::destroyInstance();
  555. try {
  556. Zend_Wildfire_Plugin_FirePhp::init('Zend_Wildfire_WildfireTest_Request');
  557. $this->fail('Should not be able to initialize');
  558. } catch (Exception $e) {
  559. // success
  560. }
  561. $this->assertNull(Zend_Wildfire_Plugin_FirePhp::getInstance(true));
  562. try {
  563. Zend_Wildfire_Plugin_FirePhp::init(array());
  564. $this->fail('Should not be able to initialize');
  565. } catch (Exception $e) {
  566. // success
  567. }
  568. $this->assertNull(Zend_Wildfire_Plugin_FirePhp::getInstance(true));
  569. }
  570. public function testHttpHeadersChannelSubclass()
  571. {
  572. $firephp = Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_HttpHeadersChannel');
  573. $this->assertEquals(get_class($firephp),
  574. 'Zend_Wildfire_WildfireTest_HttpHeadersChannel');
  575. Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
  576. try {
  577. Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_Request');
  578. $this->fail('Should not be able to initialize');
  579. } catch (Exception $e) {
  580. // success
  581. }
  582. $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
  583. try {
  584. Zend_Wildfire_Channel_HttpHeaders::init(array());
  585. $this->fail('Should not be able to initialize');
  586. } catch (Exception $e) {
  587. // success
  588. }
  589. $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
  590. }
  591. /**
  592. * @group ZF-4843
  593. */
  594. public function testResourceLogging()
  595. {
  596. $this->_setupWithoutFrontController();
  597. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  598. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  599. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  600. $firephp->send(array('file'=>tmpfile()));
  601. $messages = $protocol->getMessages();
  602. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  603. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  604. [0];
  605. $this->assertEquals(substr($message,0,41)
  606. , '[{"Type":"LOG"},{"file":"** Resource id #');
  607. }
  608. /**
  609. * @group ZF-4863
  610. */
  611. public function testLargeMessages()
  612. {
  613. $this->_setupWithoutFrontController();
  614. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  615. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  616. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  617. $data = array();
  618. for ($i=0 ; $i < 400 ; $i++) {
  619. $data[] = 'Test Data '.$i;
  620. }
  621. $firephp->send($data);
  622. Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
  623. $messages = $this->_response->getHeadersForTesting();
  624. $this->assertTrue(substr($messages[3]['value'],0,10)=='6308|[{"Ty'
  625. && substr($messages[3]['value'],-8,8)==',"Test|\\'
  626. && substr($messages[4]['value'],0,10)=='| Data 318'
  627. && substr($messages[4]['value'],-7,7)=='399"]]|');
  628. }
  629. /**
  630. * @group ZF-5540
  631. */
  632. public function testOptions()
  633. {
  634. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  635. $_options = array(
  636. 'traceOffset' => 1, /* The offset in the trace which identifies the source of the message */
  637. 'maxTraceDepth' => 99, /* Maximum depth for stack traces */
  638. 'maxObjectDepth' => 10, /* The maximum depth to traverse objects when encoding */
  639. 'maxArrayDepth' => 20, /* The maximum depth to traverse nested arrays when encoding */
  640. 'includeLineNumbers' => true /* Whether to include line and file info for each message */
  641. );
  642. $this->assertEquals($firephp->getOptions(), $_options, 'Ensure defaults stay the same');
  643. $this->assertEquals($firephp->setOption('includeLineNumbers',false),
  644. $_options['includeLineNumbers'],
  645. 'Should return old value');
  646. $this->assertEquals($firephp->getOption('includeLineNumbers'),
  647. false,
  648. 'Should contain new value');
  649. }
  650. /**
  651. * @group ZF-5540
  652. */
  653. public function testObjectFilter()
  654. {
  655. $this->_setupWithoutFrontController();
  656. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  657. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  658. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  659. $obj = new Zend_Wildfire_WildfireTest_TestObject1();
  660. $firephp->send($obj);
  661. $firephp->setObjectFilter('Zend_Wildfire_WildfireTest_TestObject1',array('value', 'protectedStatic'));
  662. $firephp->send($obj);
  663. $messages = $protocol->getMessages();
  664. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  665. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  666. [0];
  667. if (version_compare(phpversion(), '5.3' , '<')) {
  668. $this->assertEquals($message,
  669. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"Value","protected:static:protectedStatic":"** Need PHP 5.3 to get value **"}]');
  670. } else
  671. if (version_compare(phpversion(), '5.3' , '>=')) {
  672. $this->assertEquals($message,
  673. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"Value","protected:static:protectedStatic":"ProtectedStatic"}]');
  674. }
  675. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  676. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  677. [1];
  678. $this->assertEquals($message,
  679. '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"** Excluded by Filter **","protected:static:protectedStatic":"** Excluded by Filter **"}]');
  680. }
  681. public function testObjectMembers()
  682. {
  683. $this->_setupWithoutFrontController();
  684. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  685. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  686. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  687. $obj = new Zend_Wildfire_WildfireTest_TestObject2();
  688. $firephp->send($obj);
  689. $messages = $protocol->getMessages();
  690. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  691. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  692. [0];
  693. if (version_compare(phpversion(), '5.3' , '<')) {
  694. $this->assertEquals($message,
  695. '[{"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 **"}]');
  696. } else
  697. if (version_compare(phpversion(), '5.3' , '>=')) {
  698. $this->assertEquals($message,
  699. '[{"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"}]');
  700. }
  701. }
  702. /**
  703. * @group ZF-5540
  704. */
  705. public function testMaxObjectArrayDepth()
  706. {
  707. $this->_setupWithoutFrontController();
  708. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  709. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  710. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  711. $firephp->setOption('maxObjectDepth',2);
  712. $firephp->setOption('maxArrayDepth',1);
  713. $obj = new Zend_Wildfire_WildfireTest_TestObject3();
  714. $obj->testArray = array('val1',array('val2',array('Hello World')));
  715. $obj->child = clone $obj;
  716. $obj->child->child = clone $obj;
  717. $firephp->send($obj);
  718. $table = array();
  719. $table[] = array('Col1', 'Col2');
  720. $table[] = array($obj, $obj);
  721. $firephp->send($table, 'Label', Zend_Wildfire_Plugin_FirePhp::TABLE);
  722. $messages = $protocol->getMessages();
  723. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  724. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  725. [0];
  726. $this->assertEquals($message,
  727. '[{"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) **"}}]');
  728. $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
  729. [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
  730. [1];
  731. $this->assertEquals($message,
  732. '[{"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) **"}}]]]');
  733. }
  734. /**
  735. * @group ZF-10526
  736. */
  737. public function testNonHTTPRequest()
  738. {
  739. $this->_request = new Zend_Controller_Request_Simple();
  740. $this->_response = new Zend_Wildfire_WildfireTest_Response();
  741. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  742. $channel->setRequest($this->_request);
  743. $channel->setResponse($this->_response);
  744. // this should not fail with: PHP Fatal error: Call to undefined method Zend_Controller_Request_Simple::getHeader()
  745. $this->assertFalse($channel->isReady());
  746. // this should not fail with: PHP Fatal error: Call to undefined method Zend_Controller_Request_Simple::getHeader()
  747. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  748. $firephp->send('This is a log message!');
  749. }
  750. /**
  751. * @group ZF-10537
  752. */
  753. public function testFileLineOffsets()
  754. {
  755. $this->_setupWithoutFrontController();
  756. $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
  757. $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  758. $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
  759. $firephp->setOption('includeLineNumbers', true);
  760. $firephp->setOption('maxTraceDepth', 0);
  761. $lines = array();
  762. // NOTE: Do NOT separate the following pairs otherwise the line numbers will not match for the test
  763. // Message number: 1
  764. $lines[] = __LINE__+1;
  765. $firephp->send('Hello World');
  766. // Message number: 2
  767. $lines[] = __LINE__+1;
  768. $firephp->send('Hello World', null, 'TRACE');
  769. // Message number: 3
  770. $table = array('Summary line for the table',
  771. array(
  772. array('Column 1', 'Column 2'),
  773. array('Row 1 c 1',' Row 1 c 2'),
  774. array('Row 2 c 1',' Row 2 c 2')
  775. )
  776. );
  777. $lines[] = __LINE__+1;
  778. $firephp->send($table, null, 'TABLE');
  779. $messages = $protocol->getMessages();
  780. $messages = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI];
  781. for( $i=0 ; $i<sizeof($messages) ; $i++ ) {
  782. if(!preg_match_all('/WildfireTest\.php","Line":' . $lines[$i] . '/', $messages[$i], $m)) {
  783. $this->fail("File and line does not match for message number: " . ($i+1));
  784. }
  785. }
  786. }
  787. }
  788. class Zend_Wildfire_WildfireTest_TestObject1
  789. {
  790. var $name = 'Name';
  791. var $value = 'Value';
  792. protected static $protectedStatic = 'ProtectedStatic';
  793. }
  794. class Zend_Wildfire_WildfireTest_TestObject2
  795. {
  796. var $public = 'Public';
  797. private $private = 'Private';
  798. protected $protected = 'Protected';
  799. static $static = 'Static';
  800. static private $staticPrivate = 'StaticPrivate';
  801. static protected $staticProtected = 'StaticProtected';
  802. }
  803. class Zend_Wildfire_WildfireTest_TestObject3
  804. {
  805. var $name = 'Name';
  806. var $value = 'Value';
  807. }
  808. class Zend_Wildfire_WildfireTest_JsonEncodingTestClass
  809. {
  810. }
  811. class Zend_Wildfire_WildfireTest_FirePhpPlugin extends Zend_Wildfire_Plugin_FirePhp
  812. {
  813. }
  814. class Zend_Wildfire_WildfireTest_HttpHeadersChannel extends Zend_Wildfire_Channel_HttpHeaders
  815. {
  816. }
  817. class Zend_Wildfire_WildfireTest_Request extends Zend_Controller_Request_HttpTestCase
  818. {
  819. protected $_enabled = false;
  820. protected $_enabled_headerName = false;
  821. public function setUserAgentExtensionEnabled($enabled, $headerName = "User-Agent") {
  822. $this->_enabled = $enabled;
  823. $this->_enabled_headerName = $headerName;
  824. }
  825. public function getHeader($header, $default = null)
  826. {
  827. if ($header == 'User-Agent' && $this->_enabled_headerName == 'User-Agent') {
  828. if ($this->_enabled) {
  829. 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';
  830. } else {
  831. return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
  832. }
  833. } else
  834. if ($header == 'X-FirePHP-Version' && $this->_enabled_headerName == 'X-FirePHP-Version') {
  835. if ($this->_enabled) {
  836. return '0.1.0';
  837. }
  838. }
  839. return null;
  840. }
  841. }
  842. class Zend_Wildfire_WildfireTest_Response extends Zend_Controller_Response_HttpTestCase
  843. {
  844. public function getHeadersForTesting()
  845. {
  846. return $this->getHeaders();
  847. }
  848. public function verifyHeaders($headers)
  849. {
  850. $response_headers = $this->getHeaders();
  851. if (!$response_headers) {
  852. return false;
  853. }
  854. $keys1 = array_keys($headers);
  855. sort($keys1);
  856. $keys1 = serialize($keys1);
  857. $keys2 = array();
  858. foreach ($response_headers as $header ) {
  859. $keys2[] = $header['name'];
  860. }
  861. sort($keys2);
  862. $keys2 = serialize($keys2);
  863. if ($keys1 != $keys2) {
  864. return false;
  865. }
  866. $values1 = array_values($headers);
  867. sort($values1);
  868. $values1 = serialize($values1);
  869. $values2 = array();
  870. foreach ($response_headers as $header ) {
  871. $values2[] = $header['value'];
  872. }
  873. sort($values2);
  874. $values2 = serialize($values2);
  875. if ($values1 != $values2) {
  876. return false;
  877. }
  878. return true;
  879. }
  880. }
  881. if (PHPUnit_MAIN_METHOD == 'Zend_Wildfire_WildfireTest::main') {
  882. Zend_Wildfire_WildfireTest::main();
  883. }