Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

imported tests

  • Loading branch information...
commit 10d29a498d5dc65442bcb1095af50233396028db 1 parent bae54de
@cadorn cadorn authored
View
181 tests/sub/firephp-core/FirePHPCore/FirePHPTest.php
@@ -0,0 +1,181 @@
+<?php
+
+class FirePHPCore_FirePHPTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * @issue http://code.google.com/p/firephp/issues/detail?id=117
+ */
+ public function testDumpArguments()
+ {
+ $firephp = new FirePHP_Test_Class();
+
+ $firephp->dump("key", "value");
+ $headers = $firephp->_getHeaders();
+ $this->assertEquals('15|{"key":"value"}|', $headers['X-Wf-1-2-1-1']);
+ $firephp->_clearHeaders();
+
+ $caught = false;
+ try {
+ $firephp->dump(array(), "value");
+ } catch(Exception $e) {
+ // Key passed to dump() is not a string
+ $caught = true;
+ }
+ if(!$caught) $this->fail('No exception thrown');
+
+ $caught = false;
+ try {
+ $firephp->dump("key \n\r value", "value");
+ } catch(Exception $e) {
+ // Key passed to dump() contains invalid characters [a-zA-Z0-9-_\.:]
+ $caught = true;
+ }
+ if(!$caught) $this->fail('No exception thrown');
+
+ $caught = false;
+ try {
+ $firephp->dump("keykeykeykkeykeykeykkeykeykeykkeykeykeykkeykeykeykkeykeykeykkeykeykeykkeykeykeykkeykeykeykkeykeykeyk1", "value");
+ } catch(Exception $e) {
+ // Key passed to dump() is longer than 100 characters
+ $caught = true;
+ }
+ if(!$caught) $this->fail('No exception thrown');
+ }
+
+ /**
+ * @issue http://code.google.com/p/firephp/issues/detail?id=123
+ */
+ public function testRegisterErrorHandler()
+ {
+ $firephp = new FirePHP_Test_Class();
+ $firephp->setOption("maxObjectDepth", 1);
+ $firephp->setOption("maxArrayDepth", 1);
+
+ $firephp->registerErrorHandler();
+ trigger_error("Hello World");
+ $headers = $firephp->_getHeaders();
+ if(!isset($headers["X-Wf-1-1-1-1"])) {
+ $this->fail("Error not in headers");
+ }
+ }
+
+ /**
+ * @issue http://code.google.com/p/firephp/issues/detail?id=122
+ */
+ public function testFirePHPClassInstanceLogging()
+ {
+ $firephp = new FirePHP_Test_Class();
+
+ $firephp->log($firephp);
+ $headers = $firephp->_getHeaders();
+ if(!preg_match_all('/"protected:objectStack":"\\*\\* Excluded by Filter \\*\\*"/', $headers['X-Wf-1-1-1-1'], $m)) {
+ $this->fail("objectStack member contains value");
+ }
+ if(!preg_match_all('/"protected:static:instance":"\\*\\* Excluded by Filter \\*\\*"/', $headers['X-Wf-1-1-1-1'], $m)) {
+ $this->fail("instance member should not be logged");
+ }
+ if(!preg_match_all('/"undeclared:json_objectStack":"\\*\\* Excluded by Filter \\*\\*"/', $headers['X-Wf-1-1-1-1'], $m)) {
+ $this->fail("json_objectStack member should not be logged");
+ }
+ }
+
+ /**
+ * @issue http://code.google.com/p/firephp/issues/detail?id=114
+ */
+ public function testCustomFileLineOptions()
+ {
+ $firephp = new FirePHP_Test_Class();
+
+ $firephp->log("message", "label", array("File"=>"/file/path", "Line"=>"1"));
+ $firephp->info("message", "label", array("File"=>"/file/path", "Line"=>"1"));
+ $firephp->warn("message", "label", array("File"=>"/file/path", "Line"=>"1"));
+ $firephp->error("message", "label", array("File"=>"/file/path", "Line"=>"1"));
+ $firephp->dump("key", "value", array("File"=>"/file/path", "Line"=>"1"));
+ $firephp->table("label", array(array("header"),array("cell")), array("File"=>"/file/path", "Line"=>"1"));
+
+ $headers = $firephp->_getHeaders();
+
+ $this->assertEquals('75|[{"File":"\/file\/path","Line":"1","Type":"LOG","Label":"label"},"message"]|', $headers['X-Wf-1-1-1-1']);
+ $this->assertEquals('76|[{"File":"\/file\/path","Line":"1","Type":"INFO","Label":"label"},"message"]|', $headers['X-Wf-1-1-1-2']);
+ $this->assertEquals('76|[{"File":"\/file\/path","Line":"1","Type":"WARN","Label":"label"},"message"]|', $headers['X-Wf-1-1-1-3']);
+ $this->assertEquals('77|[{"File":"\/file\/path","Line":"1","Type":"ERROR","Label":"label"},"message"]|', $headers['X-Wf-1-1-1-4']);
+ $this->assertEquals('15|{"key":"value"}|', $headers['X-Wf-1-2-1-5']);
+ $this->assertEquals('89|[{"File":"\/file\/path","Line":"1","Type":"TABLE","Label":"label"},[["header"],["cell"]]]|', $headers['X-Wf-1-1-1-6']);
+ }
+
+ public function testRecursiveEncode()
+ {
+ $firephp = new FirePHP_Test_Class();
+
+ $obj = new FirePHPCore_FirePHPTest__TestObject();
+ $obj->child = $obj;
+
+ $firephp->log($obj, "label", array("File"=>"/file/path", "Line"=>"1"));
+ $headers = $firephp->_getHeaders();
+ $this->assertEquals('215|[{"File":"\/file\/path","Line":"1","Type":"LOG","Label":"label"},{"__className":"FirePHPCore_FirePHPTest__TestObject","public:var":"value","undeclared:child":"** Recursion (FirePHPCore_FirePHPTest__TestObject) **"}]|', $headers['X-Wf-1-1-1-1']);
+ }
+
+ public function testOptions()
+ {
+ $firephp = new FirePHP_Test_Class();
+
+ // defaults
+ $this->assertEquals(5, $firephp->getOption("maxObjectDepth"));
+ $this->assertEquals(5, $firephp->getOption("maxArrayDepth"));
+ $this->assertEquals(true, $firephp->getOption("useNativeJsonEncode"));
+ $this->assertEquals(true, $firephp->getOption("includeLineNumbers"));
+
+ // modify
+ $firephp->setOption("maxObjectDepth", 1);
+ $this->assertEquals(1, $firephp->getOption("maxObjectDepth"));
+
+ // invalid
+ $caught = false;
+ try {
+ $firephp->setOption("invalidName", 1);
+ } catch(Exception $e) {
+ $caught = true;
+ }
+ if(!$caught) $this->fail('No exception thrown');
+
+ $caught = false;
+ try {
+ $firephp->getOption("invalidName");
+ } catch(Exception $e) {
+ $caught = true;
+ }
+ if(!$caught) $this->fail('No exception thrown');
+ }
+
+ public function testDeprecatedMethods()
+ {
+ $firephp = new FirePHP_Test_Class();
+
+ $caught = false;
+ try {
+ $firephp->setProcessorUrl('URL');
+ } catch(Exception $e) {
+ $caught = true;
+ $this->assertEquals(E_USER_DEPRECATED, $e->getCode());
+ $this->assertEquals('The FirePHP::setProcessorUrl() method is no longer supported', $e->getMessage());
+ }
+ if(!$caught) $this->fail('No deprecation error thrown');
+
+ $caught = false;
+ try {
+ $firephp->setRendererUrl('URL');
+ } catch(Exception $e) {
+ $caught = true;
+ $this->assertEquals(E_USER_DEPRECATED, $e->getCode());
+ $this->assertEquals('The FirePHP::setRendererUrl() method is no longer supported', $e->getMessage());
+ }
+ if(!$caught) $this->fail('No deprecation error thrown');
+ }
+
+}
+
+
+class FirePHPCore_FirePHPTest__TestObject
+{
+ public $var = "value";
+}
View
55 tests/sub/firephp-core/TestHelper.php
@@ -0,0 +1,55 @@
+<?php
+
+function __autoload__($class)
+{
+ if (strpos($class, 'FirePHPCore') !== 0 && $class != 'FirePHP') {
+ return;
+ }
+
+ $basePath = dirname(dirname(__FILE__)) . '/lib';
+ if (!file_exists($basePath)) {
+ $basePath = dirname(dirname(dirname(dirname(__FILE__)))) . '/lib';
+ }
+
+ if ($class == 'FirePHP') {
+ $class = 'FirePHPCore/FirePHP.class';
+ }
+
+ // find relative
+ if (file_exists($file = $basePath . '/' . str_replace('_', '/', $class) . '.php')) {
+ require_once($file);
+ }
+}
+
+spl_autoload_register('__autoload__');
+
+class FirePHP_Test_Class extends FirePHP {
+
+ private $_headers = array();
+
+
+ public function _getHeaders() {
+ return $this->_headers;
+ }
+ public function _clearHeaders() {
+ $this->_headers = array();
+ }
+
+
+ // ######################
+ // # Subclassed Methods #
+ // ######################
+
+ protected function setHeader($Name, $Value) {
+ $this->_headers[$Name] = $Value;
+ }
+
+ protected function headersSent(&$Filename, &$Linenum) {
+ return false;
+ }
+
+ public function detectClientExtension() {
+ return true;
+ }
+
+}
View
2  tests/sub/firephp-core/phpunit.xml
@@ -0,0 +1,2 @@
+<phpunit bootstrap="TestHelper.php">
+</phpunit>
View
20 tests/sub/wildfire-php/TestHelper.php
@@ -0,0 +1,20 @@
+<?php
+
+function __autoload__($class)
+{
+ if (strpos($class, 'Wildfire') !== 0) {
+ return;
+ }
+
+ $basePath = dirname(dirname(__FILE__)) . '/lib';
+ if (!file_exists($basePath)) {
+ $basePath = dirname(dirname(dirname(dirname(__FILE__)))) . '/lib';
+ }
+
+ // find relative
+ if (file_exists($file = $basePath . '/' . str_replace('_', '/', $class) . '.php')) {
+ require_once($file);
+ }
+}
+
+spl_autoload_register('__autoload__');
View
213 tests/sub/wildfire-php/Wildfire/Channel/HttpHeaderTest.php
@@ -0,0 +1,213 @@
+<?php
+
+class Wildfire_MessageTest extends PHPUnit_Framework_TestCase
+{
+
+ public function testSmall()
+ {
+ $channel = new Wildfire_MessageTest__Wildfire_Channel_HttpHeader();
+
+ $dispatcher = new Wildfire_Dispatcher();
+ $dispatcher->setChannel($channel);
+
+ $message = new Wildfire_Message();
+ $message->setData('Hello World');
+ $message->setMeta('{"line":10}');
+ $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
+ $message->setSender('http://pinf.org/cadorn.org/wildfire/packages/lib-php');
+ $message->setReceiver('http://pinf.org/cadorn.org/fireconsole');
+
+ $dispatcher->dispatch($message);
+ $dispatcher->dispatch($message);
+
+ $channel->flush();
+
+ $this->assertEquals(
+ array(
+ 'x-wf-protocol-1' => 'http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0',
+ 'x-wf-1-index' => '2',
+ 'x-wf-1-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole',
+ 'x-wf-1-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-1-1-1-1' => '23|{"line":10}|Hello World|',
+ 'x-wf-1-1-1-2' => '23|{"line":10}|Hello World|'
+ ),
+ $channel->getMessageParts()
+ );
+ }
+
+ public function testLarge()
+ {
+ $channel = new Wildfire_MessageTest__Wildfire_Channel_HttpHeader();
+ $channel->setMessagePartMaxLength(10);
+
+ $dispatcher = new Wildfire_Dispatcher();
+ $dispatcher->setChannel($channel);
+ $dispatcher->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
+ $dispatcher->setSender('http://pinf.org/cadorn.org/wildfire/packages/lib-php');
+ $dispatcher->setReceiver('http://pinf.org/cadorn.org/fireconsole');
+
+ $message = new Wildfire_Message();
+
+ $data = array();
+ for( $i=0 ; $i<3 ; $i++ ) {
+ $data[] = 'line ' . $i;
+ }
+ $message->setData(implode($data, "; "));
+
+ $dispatcher->dispatch($message);
+ $dispatcher->dispatch($message);
+
+ $channel->flush();
+
+ $this->assertEquals(
+ array(
+ 'x-wf-protocol-1' => 'http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0',
+ 'x-wf-1-index' => '6',
+ 'x-wf-1-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole',
+ 'x-wf-1-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-1-1-1-1' => '23||line 0; l|\\',
+ 'x-wf-1-1-1-2' => '|ine 1; lin|\\',
+ 'x-wf-1-1-1-3' => '|e 2|',
+ 'x-wf-1-1-1-4' => '23||line 0; l|\\',
+ 'x-wf-1-1-1-5' => '|ine 1; lin|\\',
+ 'x-wf-1-1-1-6' => '|e 2|'
+ ),
+ $channel->getMessageParts()
+ );
+ }
+
+ public function testMultipleProtocols()
+ {
+ $channel = new Wildfire_MessageTest__Wildfire_Channel_HttpHeader();
+
+ $dispatcher = new Wildfire_Dispatcher();
+ $dispatcher->setChannel($channel);
+
+ $message = new Wildfire_Message();
+ $message->setData('Hello World');
+ $message->setMeta('{"line":10}');
+ $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
+ $message->setSender('http://pinf.org/cadorn.org/wildfire/packages/lib-php');
+ $message->setReceiver('http://pinf.org/cadorn.org/fireconsole');
+
+ $dispatcher->dispatch($message);
+
+ $message->setProtocol('__TEST__');
+
+ $dispatcher->dispatch($message);
+
+ $channel->flush();
+
+ $this->assertEquals(
+ array(
+ 'x-wf-protocol-1' => 'http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0',
+ 'x-wf-1-index' => '1',
+ 'x-wf-1-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole',
+ 'x-wf-1-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-1-1-1-1' => '23|{"line":10}|Hello World|',
+ 'x-wf-protocol-2' => '__TEST__',
+ 'x-wf-2-index' => '1',
+ 'x-wf-2-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole',
+ 'x-wf-2-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-2-1-1-1' => '23|{"line":10}|Hello World|'
+ ),
+ $channel->getMessageParts()
+ );
+ }
+
+ public function testMultipleSenders()
+ {
+ $channel = new Wildfire_MessageTest__Wildfire_Channel_HttpHeader();
+
+ $dispatcher = new Wildfire_Dispatcher();
+ $dispatcher->setChannel($channel);
+
+ $message = new Wildfire_Message();
+ $message->setData('Hello World');
+ $message->setMeta('{"line":10}');
+ $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
+ $message->setSender('http://pinf.org/cadorn.org/wildfire/packages/lib-php');
+ $message->setReceiver('http://pinf.org/cadorn.org/fireconsole');
+
+ $dispatcher->dispatch($message);
+
+ $message->setSender('__TEST__');
+
+ $dispatcher->dispatch($message);
+
+ $channel->flush();
+
+ $this->assertEquals(
+ array(
+ 'x-wf-protocol-1' => 'http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0',
+ 'x-wf-1-index' => '2',
+ 'x-wf-1-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole',
+ 'x-wf-1-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-1-1-1-1' => '23|{"line":10}|Hello World|',
+ 'x-wf-1-1-2-sender' => '__TEST__',
+ 'x-wf-1-1-2-2' => '23|{"line":10}|Hello World|'
+ ),
+ $channel->getMessageParts()
+ );
+ }
+
+ public function testMultipleReceivers()
+ {
+ $channel = new Wildfire_MessageTest__Wildfire_Channel_HttpHeader();
+
+ $dispatcher = new Wildfire_Dispatcher();
+ $dispatcher->setChannel($channel);
+
+ $message = new Wildfire_Message();
+ $message->setData('Hello World');
+ $message->setMeta('{"line":10}');
+ $message->setProtocol('http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0');
+ $message->setSender('http://pinf.org/cadorn.org/wildfire/packages/lib-php');
+ $message->setReceiver('http://pinf.org/cadorn.org/fireconsole');
+
+ $dispatcher->dispatch($message);
+
+ $message->setReceiver('__TEST__');
+
+ $dispatcher->dispatch($message);
+
+ $channel->flush();
+
+ $this->assertEquals(
+ array(
+ 'x-wf-protocol-1' => 'http://registry.pinf.org/cadorn.org/wildfire/@meta/protocol/component/0.1.0',
+ 'x-wf-1-index' => '2',
+ 'x-wf-1-1-receiver' => 'http://pinf.org/cadorn.org/fireconsole',
+ 'x-wf-1-1-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-1-1-1-1' => '23|{"line":10}|Hello World|',
+ 'x-wf-1-2-receiver' => '__TEST__',
+ 'x-wf-1-2-1-sender' => 'http://pinf.org/cadorn.org/wildfire/packages/lib-php',
+ 'x-wf-1-2-1-2' => '23|{"line":10}|Hello World|'
+ ),
+ $channel->getMessageParts()
+ );
+ }
+}
+
+
+class Wildfire_MessageTest__Wildfire_Channel_HttpHeader extends Wildfire_Channel_HttpHeader
+{
+ var $parts = array();
+
+ public function getMessageParts()
+ {
+ return $this->parts;
+ }
+
+ public function setMessagePart($key, $value)
+ {
+ $this->parts[$key] = '' . $value;
+ }
+
+ public function getMessagePart($key)
+ {
+ if(isset($this->parts[$key])) return $this->parts[$key];
+ return false;
+ }
+
+}
View
2  tests/sub/wildfire-php/phpunit.xml
@@ -0,0 +1,2 @@
+<phpunit bootstrap="TestHelper.php">
+</phpunit>
Please sign in to comment.
Something went wrong with that request. Please try again.