PageRenderTime 101ms CodeModel.GetById 41ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Wildfire/WildfireTest.php

https://bitbucket.org/ksekar/campus
PHP | 1210 lines | 880 code | 247 blank | 83 comment | 7 complexity | 95eac5e54b8e4775788bc10236f255ee MD5 | raw file
   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 24594 2012-01-05 21:27:01Z matthew $
  21 */
  22
  23if (!defined('PHPUnit_MAIN_METHOD')) {
  24    define('PHPUnit_MAIN_METHOD', 'Zend_Wildfire_WildfireTest::main');
  25}
  26
  27/** Zend_Wildfire_Channel_HttpHeaders */
  28require_once 'Zend/Wildfire/Channel/HttpHeaders.php';
  29
  30/** Zend_Wildfire_Plugin_FirePhp */
  31require_once 'Zend/Wildfire/Plugin/FirePhp.php';
  32
  33/** Zend_Wildfire_Plugin_FirePhp_Message */
  34require_once 'Zend/Wildfire/Plugin/FirePhp/Message.php';
  35
  36/** Zend_Wildfire_Plugin_FirePhp_TableMessage */
  37require_once 'Zend/Wildfire/Plugin/FirePhp/TableMessage.php';
  38
  39/** Zend_Controller_Request_HttpTestCase */
  40require_once 'Zend/Controller/Request/HttpTestCase.php';
  41
  42/** Zend_Controller_Response_Http */
  43require_once 'Zend/Controller/Response/HttpTestCase.php';
  44
  45/** Zend_Controller_Request_Simple */
  46require_once 'Zend/Controller/Request/Simple.php';
  47
  48/** Zend_Controller_Front **/
  49require_once 'Zend/Controller/Front.php';
  50
  51/** Zend_Json */
  52require_once 'Zend/Json.php';
  53
  54/** Zend_Json_Encoder */
  55require_once 'Zend/Json/Encoder.php';
  56
  57/**
  58 * @category   Zend
  59 * @package    Zend_Wildfire
  60 * @subpackage UnitTests
  61 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  62 * @license    http://framework.zend.com/license/new-bsd     New BSD License
  63 * @group      Zend_Wildfire
  64 */
  65class Zend_Wildfire_WildfireTest extends PHPUnit_Framework_TestCase
  66{
  67
  68    protected $_controller = null;
  69    protected $_request = null;
  70    protected $_response = null;
  71
  72    /**
  73     * Runs the test methods of this class.
  74     *
  75     * @access public
  76     * @static
  77     */
  78    public static function main()
  79    {
  80        $suite  = new PHPUnit_Framework_TestSuite("Zend_Wildfire_WildfireTest");
  81        $result = PHPUnit_TextUI_TestRunner::run($suite);
  82    }
  83
  84    public function setUp()
  85    {
  86        date_default_timezone_set('America/Los_Angeles');
  87        Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
  88        Zend_Wildfire_Plugin_FirePhp::destroyInstance();
  89    }
  90
  91    public function tearDown()
  92    {
  93        Zend_Controller_Front::getInstance()->resetInstance();
  94        Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
  95        Zend_Wildfire_Plugin_FirePhp::destroyInstance();
  96    }
  97
  98    protected function _setupWithFrontController()
  99    {
 100        $this->_request    = new Zend_Wildfire_WildfireTest_Request();
 101        $this->_response   = new Zend_Wildfire_WildfireTest_Response();
 102        $this->_controller = Zend_Controller_Front::getInstance();
 103        $this->_controller->resetInstance();
 104        $this->_controller->setControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files')
 105                          ->setRequest($this->_request)
 106                          ->setResponse($this->_response)
 107                          ->setParam('noErrorHandler', true)
 108                          ->setParam('noViewRenderer', true)
 109                          ->throwExceptions(false);
 110
 111        Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('includeLineNumbers', false);
 112
 113        $this->_request->setUserAgentExtensionEnabled(true);
 114    }
 115
 116    protected function _setupWithoutFrontController($ModifyOptions=true)
 117    {
 118        $this->_request = new Zend_Wildfire_WildfireTest_Request();
 119        $this->_response = new Zend_Wildfire_WildfireTest_Response();
 120
 121        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 122        $channel->setRequest($this->_request);
 123        $channel->setResponse($this->_response);
 124
 125        if ($ModifyOptions) {
 126          Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('includeLineNumbers', false);
 127        }
 128
 129        $this->_request->setUserAgentExtensionEnabled(true);
 130    }
 131
 132    public function testNoResponseObject()
 133    {
 134        Zend_Wildfire_Plugin_FirePhp::getInstance()->setEnabled(false);
 135        Zend_Wildfire_Plugin_FirePhp::send('Hello World');
 136
 137        Zend_Wildfire_Plugin_FirePhp::getInstance()->setEnabled(true);
 138        try {
 139            Zend_Wildfire_Plugin_FirePhp::send('Hello World');
 140            $this->fail('Should throw a response object not initialized error');
 141        } catch (Exception $e) {
 142            // success
 143        }
 144    }
 145
 146    public function testIsReady1()
 147    {
 148        $this->_setupWithFrontController();
 149
 150        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 151
 152        $this->assertTrue($channel->isReady(true));
 153
 154        $this->_request->setUserAgentExtensionEnabled(false);
 155
 156        $this->assertFalse($channel->isReady(true));
 157
 158        $this->_request->setUserAgentExtensionEnabled(true, 'User-Agent');
 159
 160        $this->assertTrue($channel->isReady(true));
 161
 162        $this->_request->setUserAgentExtensionEnabled(true, 'X-FirePHP-Version');
 163
 164        $this->assertTrue($channel->isReady(true));
 165    }
 166
 167    public function testIsReady2()
 168    {
 169        $this->_setupWithoutFrontController();
 170
 171        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 172
 173        $this->assertTrue($channel->isReady());
 174
 175        $this->_request->setUserAgentExtensionEnabled(false);
 176
 177        $this->assertFalse($channel->isReady());
 178
 179        $this->_request->setUserAgentExtensionEnabled(true, 'User-Agent');
 180
 181        $this->assertTrue($channel->isReady());
 182
 183        $this->_request->setUserAgentExtensionEnabled(true, 'X-FirePHP-Version');
 184
 185        $this->assertTrue($channel->isReady());
 186    }
 187
 188    public function testFirePhpPluginInstanciation()
 189    {
 190        $this->_setupWithoutFrontController();
 191        try {
 192            Zend_Wildfire_Plugin_FirePhp::getInstance();
 193            Zend_Wildfire_Plugin_FirePhp::init(null);
 194            $this->fail('Should not be able to re-initialize');
 195        } catch (Exception $e) {
 196            // success
 197        }
 198    }
 199
 200    public function testFirePhpPluginEnablement()
 201    {
 202        $this->_setupWithoutFrontController();
 203
 204        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 205        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 206        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 207
 208        $this->assertFalse($protocol->getMessages());
 209
 210        $this->assertTrue($firephp->getEnabled());
 211
 212        $this->assertTrue($firephp->send('Hello World'));
 213
 214        $messages = array(Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE=>
 215                          array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI=>
 216                                array('[{"Type":"LOG"},"Hello World"]')));
 217
 218        $this->assertEquals(serialize($protocol->getMessages()),
 219                            serialize($messages));
 220
 221        $this->assertTrue($firephp->setEnabled(false));
 222
 223        $this->assertFalse($firephp->send('Hello World'));
 224
 225        $this->assertFalse($protocol->getMessages());
 226    }
 227
 228    public function testSetControllerPluginStackIndex1()
 229    {
 230        $this->_setupWithoutFrontController();
 231        $controller = Zend_Controller_Front::getInstance();
 232        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 233
 234        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 235        $firephp->send('Hello World');
 236
 237        $plugins = $controller->getPlugins();
 238
 239        $this->assertEquals($plugins[999],$channel);
 240    }
 241
 242    public function testSetControllerPluginStackIndex2()
 243    {
 244        $this->_setupWithoutFrontController(false);
 245
 246        $controller = Zend_Controller_Front::getInstance();
 247        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 248
 249        Zend_Wildfire_Channel_HttpHeaders::setControllerPluginStackIndex(99);
 250
 251        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 252        $firephp->send('Hello World');
 253
 254        $plugins = $controller->getPlugins();
 255
 256        $this->assertEquals($plugins[99],$channel);
 257    }
 258
 259    public function testBasicLogging1()
 260    {
 261        $this->_setupWithoutFrontController();
 262
 263        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 264
 265        $message = 'This is a log message!';
 266
 267        $firephp->send($message);
 268
 269        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 270
 271        $headers = array();
 272        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 273        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 274        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 275        $headers['X-Wf-1-1-1-1'] = '41|[{"Type":"LOG"},"This is a log message!"]|';
 276
 277        $this->assertTrue($this->_response->verifyHeaders($headers));
 278    }
 279
 280    public function testBasicLogging2()
 281    {
 282        $this->_setupWithFrontController();
 283
 284        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 285
 286        $message = 'This is a log message!';
 287
 288        $firephp->send($message);
 289
 290        $this->_controller->dispatch();
 291
 292        $headers = array();
 293        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 294        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 295        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 296        $headers['X-Wf-1-1-1-1'] = '41|[{"Type":"LOG"},"This is a log message!"]|';
 297
 298        $this->assertTrue($this->_response->verifyHeaders($headers));
 299    }
 300
 301    /**
 302     * At this point UTF-8 characters are not supported as Zend_Json_Decoder
 303     * does not support them.
 304     * Once ZF-4054 is resolved this test must be updated.
 305     */
 306    public function testUTF8Logging()
 307    {
 308        $this->_setupWithFrontController();
 309
 310        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 311
 312        $encodedMessage = $message = 'Отладочный';
 313
 314        if (function_exists('json_encode') && Zend_Json::$useBuiltinEncoderDecoder !== true) {
 315          $encodedMessage = '\u041e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439';
 316        }
 317
 318        $firephp->send($message);
 319
 320        $this->_controller->dispatch();
 321
 322        $headers = array();
 323        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 324        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 325        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 326        $headers['X-Wf-1-1-1-1'] = (strlen($encodedMessage)+19).'|[{"Type":"LOG"},"'.$encodedMessage.'"]|';
 327
 328        $this->assertTrue($this->_response->verifyHeaders($headers));
 329    }
 330
 331    public function testCyclicalObjectLogging()
 332    {
 333        $this->_setupWithFrontController();
 334
 335        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 336
 337        $obj1 = new Zend_Wildfire_WildfireTest_JsonEncodingTestClass();
 338        $obj2 = new Zend_Wildfire_WildfireTest_JsonEncodingTestClass();
 339
 340        $obj1->child = $obj2;
 341        $obj2->child = $obj1;
 342
 343        $firephp->send($obj1);
 344
 345        $this->_controller->dispatch();
 346
 347        $headers = array();
 348        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 349        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 350        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 351        $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) **"}}]|';
 352
 353        $this->assertTrue($this->_response->verifyHeaders($headers));
 354    }
 355
 356    /**
 357     * @group ZF-4927
 358     */
 359    public function testAdvancedLogging()
 360    {
 361        Zend_Wildfire_Plugin_FirePhp::getInstance()->setOption('maxTraceDepth',0);
 362
 363        $this->_setupWithoutFrontController();
 364
 365        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 366
 367        $message = 'This is a log message!';
 368        $label = 'Test Label';
 369        $table = array('Summary line for the table',
 370                       array(
 371                           array('Column 1', 'Column 2'),
 372                           array('Row 1 c 1',' Row 1 c 2'),
 373                           array('Row 2 c 1',' Row 2 c 2')
 374                       )
 375                      );
 376
 377        $firephp->send($message, null, 'TRACE');
 378        $firephp->send($table, null, 'TABLE');
 379
 380        Zend_Wildfire_Plugin_FirePhp::send($message, $label);
 381        Zend_Wildfire_Plugin_FirePhp::send($message, $label, Zend_Wildfire_Plugin_FirePhp::DUMP);
 382
 383        try {
 384          throw new Exception('Test Exception');
 385        } catch (Exception $e) {
 386          Zend_Wildfire_Plugin_FirePhp::send($e);
 387        }
 388
 389        try {
 390            Zend_Wildfire_Plugin_FirePhp::send($message, $label, 'UNKNOWN');
 391            $this->fail('Should not be able to log with undefined log style');
 392        } catch (Exception $e) {
 393            // success
 394        }
 395
 396        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 397        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 398
 399        $messages = array(Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE=>
 400                          array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI=>
 401                                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"]]]]',
 402                                      2=>'[{"Type":"LOG","Label":"Test Label"},"This is a log message!"]')),
 403                          Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_DUMP=>
 404                          array(Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI=>
 405                                array('{"Test Label":"This is a log message!"}')));
 406
 407        $qued_messages = $protocol->getMessages();
 408        unset($qued_messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0]);
 409        unset($qued_messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][3]);
 410
 411        $this->assertEquals(serialize($qued_messages),
 412                            serialize($messages));
 413    }
 414
 415
 416    public function testMessage()
 417    {
 418        $this->_setupWithoutFrontController();
 419
 420        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 421        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 422
 423        $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
 424
 425
 426        $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::LOG);
 427
 428        $message->setStyle(Zend_Wildfire_Plugin_FirePhp::INFO);
 429
 430        $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::INFO);
 431
 432
 433        $this->assertNull($message->getLabel());
 434
 435        $message->setLabel('Label 1');
 436
 437        $this->assertEquals($message->getLabel(), 'Label 1');
 438
 439
 440        $this->assertFalse($message->getDestroy());
 441
 442        $message->setDestroy(true);
 443
 444        $this->assertTrue($message->getDestroy());
 445
 446
 447        $this->assertEquals($message->getMessage(), 'Message 1');
 448
 449        $message->setMessage('Message 2');
 450
 451        $this->assertEquals($message->getMessage(), 'Message 2');
 452
 453
 454
 455        $message->setDestroy(true);
 456        $this->assertfalse(Zend_Wildfire_Plugin_FirePhp::send($message));
 457
 458        $message->setDestroy(false);
 459        $this->assertTrue(Zend_Wildfire_Plugin_FirePhp::send($message));
 460
 461        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 462
 463        $messages = $protocol->getMessages();
 464
 465        $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 466                                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
 467                            '[{"Type":"INFO","Label":"Label 1"},"Message 2"]');
 468    }
 469
 470
 471    /**
 472     * @group ZF-5742
 473     */
 474    public function testTableMessage()
 475    {
 476        $table = new Zend_Wildfire_Plugin_FirePhp_TableMessage('TestMessage');
 477
 478        $this->assertEquals($table->getLabel(), 'TestMessage');
 479
 480        try {
 481            $table->getLastRow();
 482            $this->fail('Should throw exception when no rows exist');
 483        } catch (Exception $e) {
 484            // success
 485        }
 486
 487        $row = array('col1','col2');
 488
 489        $this->assertEquals($table->getRowCount(), 0);
 490
 491        try {
 492            $table->getRowAt(1);
 493            $this->fail('Should throw exception as no rows present');
 494        } catch (Exception $e) {
 495            // success
 496        }
 497
 498        try {
 499            $table->setRowAt(1,array());
 500            $this->fail('Should throw exception as no rows present');
 501        } catch (Exception $e) {
 502            // success
 503        }
 504
 505        $table->addRow($row);
 506
 507        $this->assertEquals($table->getMessage(), array($row));
 508        $this->assertEquals($table->getLastRow(), $row);
 509
 510        $this->assertEquals($table->getRowCount(), 1);
 511
 512        $table->addRow($row);
 513
 514        $this->assertEquals($table->getMessage(), array($row,
 515                                                        $row));
 516
 517        $this->assertEquals($table->getRowCount(), 2);
 518        $this->assertEquals($table->getLastRow(), $row);
 519
 520        try {
 521            $table->getRowAt(2);
 522            $this->fail('Should throw exception as index is out of bounds');
 523        } catch (Exception $e) {
 524            // success
 525        }
 526
 527        try {
 528            $table->setRowAt(2,array());
 529            $this->fail('Should throw exception as index is out of bounds');
 530        } catch (Exception $e) {
 531            // success
 532        }
 533
 534        $rowOld = $table->getRowAt(1);
 535        $this->assertEquals($rowOld, $row);
 536
 537        $rowOld[1] = 'Column2';
 538        $table->setRowAt(1, $rowOld);
 539
 540        $this->assertEquals($table->getRowAt(1), $rowOld);
 541        $this->assertEquals($table->getLastRow(), $rowOld);
 542
 543        $this->assertEquals($table->getMessage(), array($row,
 544                                                        $rowOld));
 545
 546        $header = array('hc1', 'hc2');
 547        $table->setHeader($header);
 548
 549        $this->assertEquals($table->getMessage(), array($header,
 550                                                        $row,
 551                                                        $rowOld));
 552    }
 553
 554    /**
 555     * @group ZF-6396
 556     */
 557    public function testTableMessage2()
 558    {
 559        $this->_setupWithoutFrontController();
 560
 561        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 562        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 563
 564        $table = new Zend_Wildfire_Plugin_FirePhp_TableMessage('TestMessage');
 565        $table->setHeader(array('col1','col2'));
 566        $table->setBuffered(true);
 567
 568        Zend_Wildfire_Plugin_FirePhp::send($table);
 569
 570        $cell = new ArrayObject();
 571        $cell->append("item1");
 572        $cell->append("item2");
 573
 574        $table->addRow(array("row1", $cell));
 575
 576        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 577
 578        $messages = $protocol->getMessages();
 579
 580        $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 581                                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
 582                            '[{"Type":"TABLE","Label":"TestMessage"},[["col1","col2"],["row1",{"__className":"ArrayObject","undeclared:0":"item1","undeclared:1":"item2"}]]]');
 583    }
 584
 585    public function testMessageGroups()
 586    {
 587        $this->_setupWithFrontController();
 588
 589        Zend_Wildfire_Plugin_FirePhp::group('Test Group');
 590        Zend_Wildfire_Plugin_FirePhp::send('Test Message');
 591        Zend_Wildfire_Plugin_FirePhp::groupEnd();
 592
 593        $this->_controller->dispatch();
 594
 595        $headers = array();
 596        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 597        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 598        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 599        $headers['X-Wf-1-1-1-1'] = '50|[{"Type":"GROUP_START","Label":"Test Group"},null]|';
 600        $headers['X-Wf-1-1-1-2'] = '31|[{"Type":"LOG"},"Test Message"]|';
 601        $headers['X-Wf-1-1-1-3'] = '27|[{"Type":"GROUP_END"},null]|';
 602
 603        $this->assertTrue($this->_response->verifyHeaders($headers));
 604    }
 605
 606    /**
 607     * @group ZF-10761
 608     */
 609    public function testMessageGroupsWithCollapsedTrueOption()
 610    {
 611        $this->_setupWithFrontController();
 612 
 613        Zend_Wildfire_Plugin_FirePhp::group('Test Group', array('Collapsed' => true));
 614        Zend_Wildfire_Plugin_FirePhp::send('Test Message');
 615        Zend_Wildfire_Plugin_FirePhp::groupEnd();
 616
 617        $this->_controller->dispatch();
 618
 619        $headers = array();
 620        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 621        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 622        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 623        $headers['X-Wf-1-1-1-1'] = '69|[{"Type":"GROUP_START","Label":"Test Group","Collapsed":"true"},null]|';
 624        $headers['X-Wf-1-1-1-2'] = '31|[{"Type":"LOG"},"Test Message"]|';
 625        $headers['X-Wf-1-1-1-3'] = '27|[{"Type":"GROUP_END"},null]|';
 626
 627        $this->assertTrue($this->_response->verifyHeaders($headers));
 628    }
 629
 630    /**
 631     * @group ZF-10761
 632     */
 633    public function testMessageGroupsWithCollapsedFalseOption()
 634    {
 635        $this->_setupWithFrontController();
 636 
 637        Zend_Wildfire_Plugin_FirePhp::group('Test Group', array('Collapsed' => false));
 638        Zend_Wildfire_Plugin_FirePhp::send('Test Message');
 639        Zend_Wildfire_Plugin_FirePhp::groupEnd();
 640
 641        $this->_controller->dispatch();
 642
 643        $headers = array();
 644        $headers['X-Wf-Protocol-1'] = 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2';
 645        $headers['X-Wf-1-Structure-1'] = 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1';
 646        $headers['X-Wf-1-Plugin-1'] = 'http://meta.firephp.org/Wildfire/Plugin/ZendFramework/FirePHP/1.6.2';
 647        $headers['X-Wf-1-1-1-1'] = '70|[{"Type":"GROUP_START","Label":"Test Group","Collapsed":"false"},null]|';
 648        $headers['X-Wf-1-1-1-2'] = '31|[{"Type":"LOG"},"Test Message"]|';
 649        $headers['X-Wf-1-1-1-3'] = '27|[{"Type":"GROUP_END"},null]|';
 650
 651        $this->assertTrue($this->_response->verifyHeaders($headers));
 652    }
 653
 654    public function testMessageComparison()
 655    {
 656        $label = 'Message';
 657
 658        $message1 = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, $label);
 659
 660        $message2 = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, $label);
 661
 662        $this->assertNotEquals($message1,$message2);
 663    }
 664
 665    public function testBufferedMessage1()
 666    {
 667        $this->_setupWithoutFrontController();
 668
 669        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 670        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 671
 672        $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
 673        $this->assertFalse($message->setBuffered(true));
 674
 675        Zend_Wildfire_Plugin_FirePhp::send($message);
 676
 677        $this->assertFalse($protocol->getMessages());
 678
 679        $message->setMessage('Message 2');
 680
 681        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 682
 683        $messages = $protocol->getMessages();
 684
 685        $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 686                                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
 687                            '[{"Type":"LOG"},"Message 2"]');
 688    }
 689
 690    public function testBufferedMessage2()
 691    {
 692        $this->_setupWithFrontController();
 693
 694        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 695        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 696
 697        $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
 698        $this->assertFalse($message->setBuffered(true));
 699
 700        Zend_Wildfire_Plugin_FirePhp::send($message);
 701
 702        $this->assertFalse($protocol->getMessages());
 703
 704        $message->setMessage('Message 2');
 705
 706        $this->_controller->dispatch();
 707
 708        $messages = $protocol->getMessages();
 709
 710        $this->assertEquals($messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 711                                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI][0],
 712                            '[{"Type":"LOG"},"Message 2"]');
 713    }
 714
 715    public function testDestroyedBufferedMessage()
 716    {
 717        $this->_setupWithoutFrontController();
 718
 719        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 720        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 721
 722        $message = new Zend_Wildfire_Plugin_FirePhp_Message(Zend_Wildfire_Plugin_FirePhp::LOG, 'Message 1');
 723        $message->setBuffered(true);
 724
 725        Zend_Wildfire_Plugin_FirePhp::send($message);
 726
 727        $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::LOG);
 728
 729        $message->setStyle(Zend_Wildfire_Plugin_FirePhp::INFO);
 730
 731        $this->assertEquals($message->getStyle(), Zend_Wildfire_Plugin_FirePhp::INFO);
 732
 733        $message->setDestroy(true);
 734
 735        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 736
 737        $this->assertFalse($protocol->getMessages());
 738    }
 739
 740    public function testChannelInstanciation()
 741    {
 742        $this->_setupWithoutFrontController();
 743        try {
 744            Zend_Wildfire_Channel_HttpHeaders::getInstance();
 745            Zend_Wildfire_Channel_HttpHeaders::init(null);
 746            $this->fail('Should not be able to re-initialize');
 747        } catch (Exception $e) {
 748            // success
 749        }
 750    }
 751
 752    public function testChannelFlush()
 753    {
 754        $this->_setupWithoutFrontController(false);
 755
 756        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 757
 758        $this->assertFalse($channel->flush(), 'Nothing to flush - No messages');
 759
 760        Zend_Wildfire_Plugin_FirePhp::send('Hello World');
 761
 762        $this->assertTrue($channel->flush(), 'One message to flush');
 763
 764        $this->_request->setUserAgentExtensionEnabled(false);
 765
 766        $this->assertFalse($channel->flush(), 'Nothing to flush - Extension not in UserAgent');
 767    }
 768
 769    public function testFirePhpPluginSubclass()
 770    {
 771
 772        $firephp = Zend_Wildfire_Plugin_FirePhp::init('Zend_Wildfire_WildfireTest_FirePhpPlugin');
 773
 774        $this->assertEquals(get_class($firephp),
 775                            'Zend_Wildfire_WildfireTest_FirePhpPlugin');
 776
 777        Zend_Wildfire_Plugin_FirePhp::destroyInstance();
 778
 779        try {
 780            Zend_Wildfire_Plugin_FirePhp::init('Zend_Wildfire_WildfireTest_Request');
 781            $this->fail('Should not be able to initialize');
 782        } catch (Exception $e) {
 783            // success
 784        }
 785
 786        $this->assertNull(Zend_Wildfire_Plugin_FirePhp::getInstance(true));
 787
 788        try {
 789            Zend_Wildfire_Plugin_FirePhp::init(array());
 790            $this->fail('Should not be able to initialize');
 791        } catch (Exception $e) {
 792            // success
 793        }
 794
 795        $this->assertNull(Zend_Wildfire_Plugin_FirePhp::getInstance(true));
 796    }
 797
 798    public function testHttpHeadersChannelSubclass()
 799    {
 800
 801        $firephp = Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_HttpHeadersChannel');
 802
 803        $this->assertEquals(get_class($firephp),
 804                            'Zend_Wildfire_WildfireTest_HttpHeadersChannel');
 805
 806        Zend_Wildfire_Channel_HttpHeaders::destroyInstance();
 807
 808        try {
 809            Zend_Wildfire_Channel_HttpHeaders::init('Zend_Wildfire_WildfireTest_Request');
 810            $this->fail('Should not be able to initialize');
 811        } catch (Exception $e) {
 812            // success
 813        }
 814
 815        $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
 816
 817        try {
 818            Zend_Wildfire_Channel_HttpHeaders::init(array());
 819            $this->fail('Should not be able to initialize');
 820        } catch (Exception $e) {
 821            // success
 822        }
 823
 824        $this->assertNull(Zend_Wildfire_Channel_HttpHeaders::getInstance(true));
 825    }
 826
 827    /**
 828     * @group ZF-4843
 829     */
 830    public function testResourceLogging()
 831    {
 832        $this->_setupWithoutFrontController();
 833
 834        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 835        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 836        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 837
 838        $firephp->send(array('file'=>tmpfile()));
 839
 840        $messages = $protocol->getMessages();
 841
 842        $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 843                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
 844                            [0];
 845
 846        $this->assertEquals(substr($message,0,41)
 847                            , '[{"Type":"LOG"},{"file":"** Resource id #');
 848    }
 849
 850    /**
 851     * @group ZF-4863
 852     */
 853    public function testLargeMessages()
 854    {
 855        $this->_setupWithoutFrontController();
 856
 857        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 858        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 859        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 860
 861        $data = array();
 862        for ($i=0 ; $i < 400 ; $i++) {
 863          $data[] = 'Test Data '.$i;
 864        }
 865        $firephp->send($data);
 866
 867        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
 868
 869        $messages = $this->_response->getHeadersForTesting();
 870
 871        $this->assertTrue(substr($messages[3]['value'],0,10)=='6308|[{"Ty'
 872                          && substr($messages[3]['value'],-8,8)==',"Test|\\'
 873                          && substr($messages[4]['value'],0,10)=='| Data 318'
 874                          && substr($messages[4]['value'],-7,7)=='399"]]|');
 875    }
 876
 877    /**
 878     * @group ZF-5540
 879     */
 880    public function testOptions()
 881    {
 882        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 883
 884        $_options = array(
 885            'traceOffset' => 1, /* The offset in the trace which identifies the source of the message */
 886            'maxTraceDepth' => 99, /* Maximum depth for stack traces */
 887            'maxObjectDepth' => 10, /* The maximum depth to traverse objects when encoding */
 888            'maxArrayDepth' => 20, /* The maximum depth to traverse nested arrays when encoding */
 889            'includeLineNumbers' => true /* Whether to include line and file info for each message */
 890        );
 891
 892        $this->assertEquals($firephp->getOptions(), $_options, 'Ensure defaults stay the same');
 893
 894        $this->assertEquals($firephp->setOption('includeLineNumbers',false),
 895                            $_options['includeLineNumbers'],
 896                            'Should return old value');
 897
 898        $this->assertEquals($firephp->getOption('includeLineNumbers'),
 899                            false,
 900                            'Should contain new value');
 901    }
 902
 903    /**
 904     * @group ZF-5540
 905     */
 906    public function testObjectFilter()
 907    {
 908        $this->_setupWithoutFrontController();
 909
 910        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 911        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 912        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 913
 914        $obj = new Zend_Wildfire_WildfireTest_TestObject1();
 915
 916        $firephp->send($obj);
 917
 918        $firephp->setObjectFilter('Zend_Wildfire_WildfireTest_TestObject1',array('value', 'protectedStatic'));
 919
 920        $firephp->send($obj);
 921
 922        $messages = $protocol->getMessages();
 923
 924        $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 925                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
 926                            [0];
 927
 928        if (version_compare(phpversion(), '5.3' , '<')) {
 929
 930          $this->assertEquals($message,
 931                              '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"Value","protected:static:protectedStatic":"** Need PHP 5.3 to get value **"}]');
 932        } else
 933        if (version_compare(phpversion(), '5.3' , '>=')) {
 934
 935          $this->assertEquals($message,
 936                              '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"Value","protected:static:protectedStatic":"ProtectedStatic"}]');
 937        }
 938
 939        $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 940                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
 941                            [1];
 942
 943        $this->assertEquals($message,
 944                            '[{"Type":"LOG"},{"__className":"Zend_Wildfire_WildfireTest_TestObject1","public:name":"Name","public:value":"** Excluded by Filter **","protected:static:protectedStatic":"** Excluded by Filter **"}]');
 945    }
 946
 947    public function testObjectMembers()
 948    {
 949        $this->_setupWithoutFrontController();
 950
 951        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 952        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 953        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 954
 955        $obj = new Zend_Wildfire_WildfireTest_TestObject2();
 956
 957        $firephp->send($obj);
 958
 959        $messages = $protocol->getMessages();
 960
 961        $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
 962                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
 963                            [0];
 964
 965        if (version_compare(phpversion(), '5.3' , '<')) {
 966
 967          $this->assertEquals($message,
 968                              '[{"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 **"}]');
 969
 970        } else
 971        if (version_compare(phpversion(), '5.3' , '>=')) {
 972
 973          $this->assertEquals($message,
 974                              '[{"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"}]');
 975        }
 976    }
 977
 978    /**
 979     * @group ZF-5540
 980     */
 981    public function testMaxObjectArrayDepth()
 982    {
 983        $this->_setupWithoutFrontController();
 984
 985        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
 986        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
 987        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
 988
 989        $firephp->setOption('maxObjectDepth',2);
 990        $firephp->setOption('maxArrayDepth',1);
 991
 992        $obj = new Zend_Wildfire_WildfireTest_TestObject3();
 993        $obj->testArray = array('val1',array('val2',array('Hello World')));
 994        $obj->child = clone $obj;
 995        $obj->child->child = clone $obj;
 996
 997        $firephp->send($obj);
 998
 999
1000        $table = array();
1001        $table[] = array('Col1', 'Col2');
1002        $table[] = array($obj, $obj);
1003
1004        $firephp->send($table, 'Label', Zend_Wildfire_Plugin_FirePhp::TABLE);
1005
1006
1007        $messages = $protocol->getMessages();
1008
1009        $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
1010                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
1011                            [0];
1012
1013        $this->assertEquals($message,
1014                            '[{"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) **"}}]');
1015
1016        $message = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE]
1017                            [Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI]
1018                            [1];
1019
1020        $this->assertEquals($message,
1021                            '[{"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) **"}}]]]');
1022    }
1023
1024    /**
1025     * @group ZF-10526
1026     */
1027    public function testNonHTTPRequest()
1028    {
1029        $this->_request = new Zend_Controller_Request_Simple();
1030        $this->_response = new Zend_Wildfire_WildfireTest_Response();
1031
1032        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
1033        $channel->setRequest($this->_request);
1034        $channel->setResponse($this->_response);
1035
1036        // this should not fail with: PHP Fatal error:  Call to undefined method Zend_Controller_Request_Simple::getHeader()
1037        $this->assertFalse($channel->isReady());
1038
1039        // this should not fail with: PHP Fatal error:  Call to undefined method Zend_Controller_Request_Simple::getHeader()
1040        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
1041        $firephp->send('This is a log message!');
1042    }
1043
1044    /**
1045     * @group ZF-10537
1046     */
1047    public function testFileLineOffsets()
1048    {
1049        $this->_setupWithoutFrontController();
1050
1051        $firephp = Zend_Wildfire_Plugin_FirePhp::getInstance();
1052        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
1053        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
1054        $firephp->setOption('includeLineNumbers', true);
1055        $firephp->setOption('maxTraceDepth', 0);
1056
1057        $lines = array();
1058        // NOTE: Do NOT separate the following pairs otherwise the line numbers will not match for the test
1059
1060        // Message number: 1
1061        $lines[] = __LINE__+1;
1062        $firephp->send('Hello World');
1063
1064        // Message number: 2
1065        $lines[] = __LINE__+1;
1066        $firephp->send('Hello World', null, 'TRACE');
1067
1068        // Message number: 3
1069        $table = array('Summary line for the table',
1070                       array(
1071                           array('Column 1', 'Column 2'),
1072                           array('Row 1 c 1',' Row 1 c 2'),
1073                           array('Row 2 c 1',' Row 2 c 2')
1074                       )
1075                      );
1076        $lines[] = __LINE__+1;
1077        $firephp->send($table, null, 'TABLE');
1078
1079        $messages = $protocol->getMessages();
1080        $messages = $messages[Zend_Wildfire_Plugin_FirePhp::STRUCTURE_URI_FIREBUGCONSOLE][Zend_Wildfire_Plugin_FirePhp::PLUGIN_URI];
1081
1082        for( $i=0 ; $i<sizeof($messages) ; $i++ ) {
1083            if(!preg_match_all('/WildfireTest\.php","Line":' . $lines[$i] . '/', $messages[$i], $m)) {
1084                $this->fail("File and line does not match for message number: " . ($i+1));
1085            }
1086
1087        }
1088    }
1089}
1090
1091class Zend_Wildfire_WildfireTest_TestObject1
1092{
1093  var $name = 'Name';
1094  var $value = 'Value';
1095  protected static $protectedStatic = 'ProtectedStatic';
1096}
1097
1098class Zend_Wildfire_WildfireTest_TestObject2
1099{
1100  var $public = 'Public';
1101  private $private = 'Private';
1102  protected $protected = 'Protected';
1103
1104  static $static = 'Static';
1105  static private $staticPrivate = 'StaticPrivate';
1106  static protected $staticProtected = 'StaticProtected';
1107}
1108
1109class Zend_Wildfire_WildfireTest_TestObject3
1110{
1111  var $name = 'Name';
1112  var $value = 'Value';
1113}
1114
1115class Zend_Wildfire_WildfireTest_JsonEncodingTestClass
1116{
1117}
1118
1119
1120class Zend_Wildfire_WildfireTest_FirePhpPlugin extends Zend_Wildfire_Plugin_FirePhp
1121{
1122}
1123
1124class Zend_Wildfire_WildfireTest_HttpHeadersChannel extends Zend_Wildfire_Channel_HttpHeaders
1125{
1126}
1127
1128class Zend_Wildfire_WildfireTest_Request extends Zend_Controller_Request_HttpTestCase
1129{
1130
1131    protected $_enabled = false;
1132    protected $_enabled_headerName = false;
1133
1134    public function setUserAgentExtensionEnabled($enabled, $headerName = "User-Agent") {
1135        $this->_enabled = $enabled;
1136        $this->_enabled_headerName = $headerName;
1137    }
1138
1139    public function getHeader($header, $default = null)
1140    {
1141        if ($header == 'User-Agent' && $this->_enabled_headerName == 'User-Agent') {
1142            if ($this->_enabled) {
1143                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';
1144            } else {
1145                return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14';
1146            }
1147        } else
1148        if ($header == 'X-FirePHP-Version' && $this->_enabled_headerName == 'X-FirePHP-Version') {
1149            if ($this->_enabled) {
1150                return '0.1.0';
1151            }
1152        }
1153        return null;
1154    }
1155}
1156
1157
1158class Zend_Wildfire_WildfireTest_Response extends Zend_Controller_Response_HttpTestCase
1159{
1160
1161    public function getHeadersForTesting()
1162    {
1163        return $this->getHeaders();
1164    }
1165
1166    public function verifyHeaders($headers)
1167    {
1168        $response_headers = $this->getHeaders();
1169        if (!$response_headers) {
1170            return false;
1171        }
1172
1173        $keys1 = array_keys($headers);
1174        sort($keys1);
1175        $keys1 = serialize($keys1);
1176
1177        $keys2 = array();
1178        foreach ($response_headers as $header ) {
1179            $keys2[] = $header['name'];
1180        }
1181        sort($keys2);
1182        $keys2 = serialize($keys2);
1183
1184        if ($keys1 != $keys2) {
1185            return false;
1186        }
1187
1188        $values1 = array_values($headers);
1189        sort($values1);
1190        $values1 = serialize($values1);
1191
1192        $values2 = array();
1193        foreach ($response_headers as $header ) {
1194            $values2[] = $header['value'];
1195        }
1196        sort($values2);
1197        $values2 = serialize($values2);
1198
1199        if ($values1 != $values2) {
1200            return false;
1201        }
1202
1203        return true;
1204    }
1205
1206}
1207
1208if (PHPUnit_MAIN_METHOD == 'Zend_Wildfire_WildfireTest::main') {
1209    Zend_Wildfire_WildfireTest::main();
1210}