initial commit
This commit is contained in:
76
exp/Plugin/DebugKit/Test/Case/Lib/DebugKitDebuggerTest.php
Normal file
76
exp/Plugin/DebugKit/Test/Case/Lib/DebugKitDebuggerTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* DebugKit Debugger Test Case File
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since debug_kit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
**/
|
||||
|
||||
App::uses('DebugKitDebugger', 'DebugKit.Lib');
|
||||
require_once CakePlugin::path('DebugKit') . 'Test' . DS . 'Case' . DS . 'TestFireCake.php';
|
||||
|
||||
/**
|
||||
* Test case for the DebugKitDebugger
|
||||
*
|
||||
* @since debug_kit 0.1
|
||||
*/
|
||||
class DebugKitDebuggerTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
Configure::write('log', false);
|
||||
$this->firecake = FireCake::getInstance('TestFireCake');
|
||||
TestFireCake::reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
Configure::write('log', true);
|
||||
DebugKitDebugger::clearTimers();
|
||||
TestFireCake::reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* test output switch to firePHP
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOutput() {
|
||||
Debugger::getInstance('DebugKitDebugger');
|
||||
Debugger::addFormat('fb', array('callback' => 'DebugKitDebugger::fireError'));
|
||||
Debugger::outputAs('fb');
|
||||
|
||||
set_error_handler('ErrorHandler::handleError');
|
||||
$foo .= '';
|
||||
restore_error_handler();
|
||||
|
||||
$result = $this->firecake->sentHeaders;
|
||||
|
||||
$this->assertRegExp('/GROUP_START/', $result['X-Wf-1-1-1-1']);
|
||||
$this->assertRegExp('/ERROR/', $result['X-Wf-1-1-1-2']);
|
||||
$this->assertRegExp('/GROUP_END/', $result['X-Wf-1-1-1-5']);
|
||||
|
||||
Debugger::getInstance('Debugger');
|
||||
Debugger::outputAs('html');
|
||||
}
|
||||
}
|
||||
65
exp/Plugin/DebugKit/Test/Case/Lib/DebugMemoryTest.php
Normal file
65
exp/Plugin/DebugKit/Test/Case/Lib/DebugMemoryTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* DebugKit Debug Memory Test Cases
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
**/
|
||||
|
||||
App::uses('DebugMemory', 'DebugKit.Lib');
|
||||
|
||||
/**
|
||||
* Class DebugMemoryTest
|
||||
*
|
||||
*/
|
||||
class DebugMemoryTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* test memory usage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMemoryUsage() {
|
||||
$result = DebugMemory::getCurrent();
|
||||
$this->assertTrue(is_int($result));
|
||||
|
||||
$result = DebugMemory::getPeak();
|
||||
$this->assertTrue(is_int($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* test making memory use markers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMemorySettingAndGetting() {
|
||||
DebugMemory::clear();
|
||||
$result = DebugMemory::record('test marker');
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = DebugMemory::getAll(true);
|
||||
$this->assertEquals(count($result), 1);
|
||||
$this->assertTrue(isset($result['test marker']));
|
||||
$this->assertTrue(is_numeric($result['test marker']));
|
||||
|
||||
$result = DebugMemory::getAll();
|
||||
$this->assertTrue(empty($result));
|
||||
|
||||
DebugMemory::record('test marker');
|
||||
DebugMemory::record('test marker');
|
||||
$result = DebugMemory::getAll();
|
||||
|
||||
$this->assertEquals(count($result), 2);
|
||||
$this->assertTrue(isset($result['test marker']));
|
||||
$this->assertTrue(isset($result['test marker #2']));
|
||||
}
|
||||
}
|
||||
169
exp/Plugin/DebugKit/Test/Case/Lib/DebugTimerTest.php
Normal file
169
exp/Plugin/DebugKit/Test/Case/Lib/DebugTimerTest.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* DebugTimer Test Case
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since debug_kit 2.0
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('DebugTimer', 'DebugKit.Lib');
|
||||
|
||||
/**
|
||||
* Class DebugTimerTest
|
||||
*
|
||||
* @since debug_kit 2.0
|
||||
*/
|
||||
class DebugTimerTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
DebugTimer::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Timer test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTimers() {
|
||||
$this->assertTrue(DebugTimer::start('test1', 'this is my first test'));
|
||||
usleep(5000);
|
||||
$this->assertTrue(DebugTimer::stop('test1'));
|
||||
$elapsed = DebugTimer::elapsedTime('test1');
|
||||
$this->assertTrue($elapsed > 0.0050);
|
||||
|
||||
$this->assertTrue(DebugTimer::start('test2', 'this is my second test'));
|
||||
sleep(1);
|
||||
$this->assertTrue(DebugTimer::stop('test2'));
|
||||
$elapsed = DebugTimer::elapsedTime('test2');
|
||||
$expected = stripos(PHP_OS, 'win') === false ? 0.999: 0.95; // Windows timer's precision is bad
|
||||
$this->assertTrue($elapsed >= $expected);
|
||||
|
||||
DebugTimer::start('test3');
|
||||
$this->assertIdentical(DebugTimer::elapsedTime('test3'), 0);
|
||||
$this->assertFalse(DebugTimer::stop('wrong'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test timers with no names.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAnonymousTimers() {
|
||||
$this->assertTrue(DebugTimer::start());
|
||||
usleep(2000);
|
||||
$this->assertTrue(DebugTimer::stop());
|
||||
$timers = DebugTimer::getAll();
|
||||
|
||||
$this->assertEquals(2, count($timers));
|
||||
end($timers);
|
||||
$key = key($timers);
|
||||
$lineNo = __LINE__ - 8;
|
||||
|
||||
$file = Debugger::trimPath(__FILE__);
|
||||
$expected = $file . ' line ' . $lineNo;
|
||||
$this->assertEquals($expected, $key);
|
||||
|
||||
$timer = $timers[$expected];
|
||||
$this->assertTrue($timer['time'] > 0.0020);
|
||||
$this->assertEquals($expected, $timers[$expected]['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that nested anonymous timers don't get mixed up.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNestedAnonymousTimers() {
|
||||
$this->assertTrue(DebugTimer::start());
|
||||
usleep(100);
|
||||
$this->assertTrue(DebugTimer::start());
|
||||
usleep(100);
|
||||
$this->assertTrue(DebugTimer::stop());
|
||||
$this->assertTrue(DebugTimer::stop());
|
||||
|
||||
$timers = DebugTimer::getAll();
|
||||
$this->assertEquals(3, count($timers), 'incorrect number of timers %s');
|
||||
$firstTimerLine = __LINE__ - 9;
|
||||
$secondTimerLine = __LINE__ - 8;
|
||||
$file = Debugger::trimPath(__FILE__);
|
||||
|
||||
$this->assertTrue(isset($timers[$file . ' line ' . $firstTimerLine]), 'first timer is not set %s');
|
||||
$this->assertTrue(isset($timers[$file . ' line ' . $secondTimerLine]), 'second timer is not set %s');
|
||||
|
||||
$firstTimer = $timers[$file . ' line ' . $firstTimerLine];
|
||||
$secondTimer = $timers[$file . ' line ' . $secondTimerLine];
|
||||
$this->assertTrue($firstTimer['time'] > $secondTimer['time']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that calling start with the same name does not overwrite previous timers
|
||||
* and instead adds new ones.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRepeatTimers() {
|
||||
DebugTimer::start('my timer', 'This is the first call');
|
||||
usleep(100);
|
||||
DebugTimer::start('my timer', 'This is the second call');
|
||||
usleep(100);
|
||||
|
||||
DebugTimer::stop('my timer');
|
||||
DebugTimer::stop('my timer');
|
||||
|
||||
$timers = DebugTimer::getAll();
|
||||
$this->assertEquals(3, count($timers), 'wrong timer count %s');
|
||||
|
||||
$this->assertTrue(isset($timers['my timer']));
|
||||
$this->assertTrue(isset($timers['my timer #2']));
|
||||
|
||||
$this->assertTrue($timers['my timer']['time'] > $timers['my timer #2']['time'], 'timer 2 is longer? %s');
|
||||
$this->assertEquals('This is the first call', $timers['my timer']['message']);
|
||||
$this->assertEquals('This is the second call #2', $timers['my timer #2']['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testRequestTime
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRequestTime() {
|
||||
$result1 = DebugTimer::requestTime();
|
||||
usleep(50);
|
||||
$result2 = DebugTimer::requestTime();
|
||||
$this->assertTrue($result1 < $result2);
|
||||
}
|
||||
|
||||
/**
|
||||
* test getting all the set timers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTimers() {
|
||||
DebugTimer::start('test1', 'this is my first test');
|
||||
DebugTimer::stop('test1');
|
||||
usleep(50);
|
||||
DebugTimer::start('test2');
|
||||
DebugTimer::stop('test2');
|
||||
$timers = DebugTimer::getAll();
|
||||
|
||||
$this->assertEquals(3, count($timers));
|
||||
$this->assertTrue(is_float($timers['test1']['time']));
|
||||
$this->assertTrue(isset($timers['test1']['message']));
|
||||
$this->assertTrue(isset($timers['test2']['message']));
|
||||
}
|
||||
}
|
||||
345
exp/Plugin/DebugKit/Test/Case/Lib/FireCakeTest.php
Normal file
345
exp/Plugin/DebugKit/Test/Case/Lib/FireCakeTest.php
Normal file
@@ -0,0 +1,345 @@
|
||||
<?php
|
||||
/**
|
||||
* CakeFirePHP Test Case
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 0.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
**/
|
||||
|
||||
App::uses('FireCake', 'DebugKit.Lib');
|
||||
require_once CakePlugin::path('DebugKit') . 'Test' . DS . 'Case' . DS . 'TestFireCake.php';
|
||||
|
||||
/**
|
||||
* Test Case For FireCake
|
||||
*
|
||||
* @since DebugKit 0.1
|
||||
*/
|
||||
class FireCakeTestCase extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* setup test
|
||||
*
|
||||
* Fill FireCake with TestFireCake instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->firecake = FireCake::getInstance('TestFireCake');
|
||||
TestFireCake::reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the FireCake counters and headers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown() {
|
||||
TestFireCake::reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getInstance cheat.
|
||||
*
|
||||
* If this fails the rest of the test is going to fail too.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetInstanceOverride() {
|
||||
$instance = FireCake::getInstance();
|
||||
$instance2 = FireCake::getInstance();
|
||||
$this->assertReference($instance, $instance2);
|
||||
$this->assertIsA($instance, 'FireCake');
|
||||
$this->assertIsA($instance, 'TestFireCake', 'Stored instance is not a copy of TestFireCake, test case is broken.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setOptions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetOptions() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
$this->assertEquals($this->firecake->options['includeLineNumbers'], false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Log()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLog() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::log('Testing');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '26|[{"Type":"LOG"},"Testing"]|');
|
||||
|
||||
FireCake::log('Testing', 'log-info');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '45|[{"Type":"LOG","Label":"log-info"},"Testing"]|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test info()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInfo() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::info('I have information');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '38|[{"Type":"INFO"},"I have information"]|');
|
||||
|
||||
FireCake::info('I have information', 'info-label');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '59|[{"Type":"INFO","Label":"info-label"},"I have information"]|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test info()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testWarn() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::warn('A Warning');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '29|[{"Type":"WARN"},"A Warning"]|');
|
||||
|
||||
FireCake::warn('A Warning', 'Bzzz');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '44|[{"Type":"WARN","Label":"Bzzz"},"A Warning"]|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testError() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::error('An error');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-Index'], 1);
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '29|[{"Type":"ERROR"},"An error"]|');
|
||||
|
||||
FireCake::error('An error', 'wonky');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '45|[{"Type":"ERROR","Label":"wonky"},"An error"]|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dump()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDump() {
|
||||
FireCake::dump('mydump', array('one' => 1, 'two' => 2));
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-2-1-1'], '28|{"mydump":{"one":1,"two":2}}|');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-2']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test table() generation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTable() {
|
||||
$table[] = array('Col 1 Heading','Col 2 Heading');
|
||||
$table[] = array('Row 1 Col 1','Row 1 Col 2');
|
||||
$table[] = array('Row 2 Col 1','Row 2 Col 2');
|
||||
$table[] = array('Row 3 Col 1','Row 3 Col 2');
|
||||
FireCake::table('myTrace', $table);
|
||||
$expected = '162|[{"Type":"TABLE","Label":"myTrace"},[["Col 1 Heading","Col 2 Heading"],["Row 1 Col 1","Row 1 Col 2"],["Row 2 Col 1","Row 2 Col 2"],["Row 3 Col 1","Row 3 Col 2"]]]|';
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* TestStringEncoding
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStringEncode() {
|
||||
$vars = array(1,2,3);
|
||||
$result = $this->firecake->stringEncode($vars);
|
||||
$this->assertEquals($result, array(1,2,3));
|
||||
|
||||
$this->firecake->setOptions(array('maxArrayDepth' => 3));
|
||||
$deep = array(1 => array(2 => array(3)));
|
||||
$result = $this->firecake->stringEncode($deep);
|
||||
$this->assertEquals($result, array(1 => array(2 => '** Max Array Depth (3) **')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test object encoding
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testStringEncodeObjects() {
|
||||
$obj = FireCake::getInstance();
|
||||
$result = $this->firecake->stringEncode($obj);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
$this->assertEquals($result['_defaultOptions']['useNativeJsonEncode'], true);
|
||||
$this->assertEquals($result['_encodedObjects'][0], '** Recursion (TestFireCake) **');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test trace()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTrace() {
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1']));
|
||||
$this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1']));
|
||||
$dump = $this->firecake->sentHeaders['X-Wf-1-1-1-1'];
|
||||
$this->assertPattern('/"Message":"myTrace"/', $dump);
|
||||
$this->assertPattern('/"Trace":\[/', $dump);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test enabling and disabling of FireCake output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnableDisable() {
|
||||
FireCake::disable();
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertTrue(empty($this->firecake->sentHeaders));
|
||||
|
||||
FireCake::enable();
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertFalse(empty($this->firecake->sentHeaders));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test correct line continuation markers on multi line headers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMultiLineOutput() {
|
||||
FireCake::trace('myTrace');
|
||||
$this->assertGreaterThan(1, $this->firecake->sentHeaders['X-Wf-1-Index']);
|
||||
$header = $this->firecake->sentHeaders['X-Wf-1-1-1-1'];
|
||||
$this->assertEquals(substr($header, -2), '|\\');
|
||||
|
||||
$endIndex = $this->firecake->sentHeaders['X-Wf-1-Index'];
|
||||
$header = $this->firecake->sentHeaders['X-Wf-1-1-1-' . $endIndex];
|
||||
$this->assertEquals(substr($header, -1), '|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test inclusion of line numbers
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncludeLineNumbers() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => true));
|
||||
FireCake::info('Testing');
|
||||
$result = $this->firecake->sentHeaders['X-Wf-1-1-1-1'];
|
||||
$this->assertPattern('/"File"\:".*FireCakeTest.php/', $result);
|
||||
$this->assertPattern('/"Line"\:\d+/', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Group messages
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGroup() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::group('test');
|
||||
FireCake::info('my info');
|
||||
FireCake::groupEnd();
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '63|[{"Collapsed":"true","Type":"GROUP_START","Label":"test"},null]|');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-3'], '27|[{"Type":"GROUP_END"},null]|');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-Index'], 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test fb() parameter parsing
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFbParameterParsing() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::fb('Test');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '23|[{"Type":"LOG"},"Test"]|');
|
||||
|
||||
FireCake::fb('Test', 'warn');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '24|[{"Type":"WARN"},"Test"]|');
|
||||
|
||||
FireCake::fb('Test', 'Custom label', 'warn');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-3'], '47|[{"Type":"WARN","Label":"Custom label"},"Test"]|');
|
||||
|
||||
$this->expectError('PHPUnit_Framework_Error');
|
||||
$this->assertFalse(FireCake::fb('Test', 'Custom label', 'warn', 'more parameters'));
|
||||
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-Index'], 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test defaulting to log if incorrect message type is used
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIncorrectMessageType() {
|
||||
FireCake::setOptions(array('includeLineNumbers' => false));
|
||||
FireCake::fb('Hello World', 'foobared');
|
||||
$this->assertEquals($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '30|[{"Type":"LOG"},"Hello World"]|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test DetectClientExtension.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDetectClientExtension() {
|
||||
$back = env('HTTP_USER_AGENT');
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 FirePHP/0.2.1';
|
||||
$this->assertTrue(FireCake::detectClientExtension());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 FirePHP/0.0.4';
|
||||
$this->assertFalse(FireCake::detectClientExtension());
|
||||
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4';
|
||||
$this->assertFalse(FireCake::detectClientExtension());
|
||||
$_SERVER['HTTP_USER_AGENT'] = $back;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of Non Native JSON encoding.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNonNativeEncoding() {
|
||||
FireCake::setOptions(array('useNativeJsonEncode' => false));
|
||||
$json = FireCake::jsonEncode(array('one' => 1, 'two' => 2));
|
||||
$this->assertEquals($json, '{"one":1,"two":2}');
|
||||
|
||||
$json = FireCake::jsonEncode(array(1,2,3));
|
||||
$this->assertEquals($json, '[1,2,3]');
|
||||
|
||||
$json = FireCake::jsonEncode(FireCake::getInstance());
|
||||
$this->assertPattern('/"options"\:\{"maxObjectDepth"\:\d*,/', $json);
|
||||
}
|
||||
|
||||
}
|
||||
63
exp/Plugin/DebugKit/Test/Case/Lib/Panel/LogPanelTest.php
Normal file
63
exp/Plugin/DebugKit/Test/Case/Lib/Panel/LogPanelTest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* DebugKit Log Panel Test Cases
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
**/
|
||||
|
||||
App::uses('LogPanel', 'DebugKit.Lib/Panel');
|
||||
App::uses('Controller', 'Controller');
|
||||
|
||||
/**
|
||||
* Class LogPanelTest
|
||||
*
|
||||
*/
|
||||
class LogPanelTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* set up
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->panel = new LogPanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that logging configs are created.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructor() {
|
||||
$result = CakeLog::configured();
|
||||
$this->assertContains('debug_kit_log_panel', $result);
|
||||
$this->assertTrue(count($result) > 1, 'Default loggers were not added.');
|
||||
}
|
||||
|
||||
/**
|
||||
* testBeforeRender
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBeforeRender() {
|
||||
$controller = new Controller();
|
||||
|
||||
CakeLog::write('error', 'Test');
|
||||
|
||||
$result = $this->panel->beforeRender($controller);
|
||||
$this->assertInstanceOf('DebugKitLog', $result);
|
||||
$this->assertTrue(isset($result->logs));
|
||||
$this->assertCount(1, $result->logs['error']);
|
||||
}
|
||||
}
|
||||
59
exp/Plugin/DebugKit/Test/Case/Lib/Panel/SqlLogPanelTest.php
Normal file
59
exp/Plugin/DebugKit/Test/Case/Lib/Panel/SqlLogPanelTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* SqlLogPanelTest
|
||||
*
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since DebugKit 2.1
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('SqlLogPanel', 'DebugKit.Lib/Panel');
|
||||
App::uses('Model', 'Model');
|
||||
App::uses('Controller', 'Controller');
|
||||
|
||||
/**
|
||||
* Class SqlLogPanelTest
|
||||
*
|
||||
* @since DebugKit 2.1
|
||||
*/
|
||||
class SqlLogPanelTest extends CakeTestCase {
|
||||
|
||||
/**
|
||||
* fixtures.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = array('core.article');
|
||||
|
||||
/**
|
||||
* Setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->panel = new SqlLogPanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the parsing of source list.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBeforeRender() {
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$Article->find('first', array('conditions' => array('Article.id' => 1)));
|
||||
|
||||
$controller = new Controller();
|
||||
$result = $this->panel->beforeRender($controller);
|
||||
|
||||
$this->assertTrue(isset($result['connections'][$Article->useDbConfig]));
|
||||
$this->assertTrue(isset($result['threshold']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user