initial commit

This commit is contained in:
2026-06-25 13:03:45 +06:00
commit 4589f4a8d0
3229 changed files with 941958 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
/**
* View Group Test for DebugKit
*
* 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 1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
require_once dirname(__FILE__) . DS . 'DebugkitGroupTestCase.php';
/**
* DebugKitViewTestSuite class
*
* @since DebugKit 1.0
*/
class AllDebugKitTest extends DebugKitGroupTestCase {
/**
* Assemble Test Suite
*
* @return PHPUnit_Framework_TestSuite the instance of PHPUnit_Framework_TestSuite
*/
public static function suite() {
$suite = new self;
$files = $suite->getTestFiles();
$suite->addTestFiles($files);
return $suite;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* View Group Test for DebugKit
*
* 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 1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
require_once dirname(__FILE__) . DS . 'DebugkitGroupTestCase.php';
/**
* DebugKitViewTestSuite class
*
* @since DebugKit 1.0
*/
class AllDebugKitViewTest extends DebugkitGroupTestCase {
/**
* Assemble Test Suite
*
* @return PHPUnit_Framework_TestSuite the instance of PHPUnit_Framework_TestSuite
*/
public static function suite() {
$suite = new self;
$files = $suite->getTestFiles('View');
$suite->addTestFiles($files);
return $suite;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* View Group Test for DebugKit
*
* 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 1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
require_once dirname(__FILE__) . DS . 'DebugkitGroupTestCase.php';
/**
* DebugKitViewTestSuite class
*
* @since DebugKit 1.0
*/
class AllDebugKitWithoutViewTest extends DebugkitGroupTestCase {
/**
* Assemble Test Suite
*
* @return PHPUnit_Framework_TestSuite the instance of PHPUnit_Framework_TestSuite
*/
public static function suite() {
$suite = new self;
$files = $suite->getTestFiles(null, 'View');
$suite->addTestFiles($files);
return $suite;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* AllTestsTest For DebugKit
*
* 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 1.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
require_once dirname(__FILE__) . DS . 'DebugkitGroupTestCase.php';
/**
* AllTestsTest class
*
* @since DebugKit 1.0
*/
class AllTestsTest extends DebugkitGroupTestCase {
/**
* Assemble Test Suite
*
* @return PHPUnit_Framework_TestSuite the instance of PHPUnit_Framework_TestSuite
*/
public static function suite() {
$suite = new self;
$files = $suite->getTestFiles();
$suite->addTestFiles($files);
return $suite;
}
}

View File

@@ -0,0 +1,524 @@
<?php
/**
* 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 2.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('Router', 'Routing');
App::uses('Controller', 'Controller');
App::uses('AppController', 'Controller');
App::uses('Component', 'Controller');
App::uses('ToolbarComponent', 'DebugKit.Controller/Component');
App::uses('DebugMemory', 'DebugKit.Lib');
App::uses('DebugTimer', 'DebugKit.Lib');
/**
* Class TestToolbarComponent
*
* @since DebugKit 2.1
*/
class TestToolbarComponent extends ToolbarComponent {
/**
* Load Panels of Toolbar
*
* @param $panels
* @param array $settings
*/
public function loadPanels($panels, $settings = array()) {
$this->_loadPanels($panels, $settings);
}
}
/**
* ToolbarComponentTestCase Test case
*
*/
class ToolbarComponentTestCase extends CakeTestCase {
/**
* fixtures
*
* @var array
*/
public $fixtures = array('core.article');
/**
* url for test
*
* @var string
*/
public $url;
/**
* Start test callback
*
* @return void
*/
public function setUp() {
parent::setUp();
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
$this->_server = $_SERVER;
$this->_get = $_GET;
$this->_paths = array();
$this->_paths['plugins'] = App::path('plugins');
$this->_paths['views'] = App::path('views');
$this->_paths['vendors'] = App::path('vendors');
$this->_paths['controllers'] = App::path('controllers');
Configure::write('Cache.disable', false);
$this->url = '/';
}
/**
* endTest
*
* @return void
*/
public function tearDown() {
$_SERVER = $this->_server;
$_GET = $this->_get;
parent::tearDown();
App::build(array(
'plugins' => $this->_paths['plugins'],
'views' => $this->_paths['views'],
'controllers' => $this->_paths['controllers'],
'vendors' => $this->_paths['vendors']
), true);
Configure::write('Cache.disable', true);
unset($this->Controller);
ClassRegistry::flush();
if (class_exists('DebugMemory')) {
DebugMemory::clear();
}
if (class_exists('DebugTimer')) {
DebugTimer::clear();
}
Router::reload();
}
/**
* loading test controller
*
* @param array $settings
* @return Controller
*/
protected function _loadController($settings = array()) {
$request = new CakeRequest($this->url);
$request->addParams(Router::parse($this->url));
$this->Controller = new Controller($request);
$this->Controller->uses = null;
$this->Controller->components = array('Toolbar' => $settings + array('className' => 'TestToolbar'));
$this->Controller->constructClasses();
$this->Controller->Components->trigger('initialize', array($this->Controller));
return $this->Controller;
}
/**
* test Loading of panel classes
*
* @return void
*/
public function testLoadPanels() {
$this->_loadController();
$this->Controller->Toolbar->loadPanels(array('session', 'request'));
$this->assertInstanceOf('SessionPanel', $this->Controller->Toolbar->panels['session']);
$this->assertInstanceOf('RequestPanel', $this->Controller->Toolbar->panels['request']);
$this->Controller->Toolbar->loadPanels(array('history'), array('history' => 10));
$this->assertEquals($this->Controller->Toolbar->panels['history']->history, 10);
}
/**
* Test exceptions on bad panel names
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testLoadPanelsError() {
$this->Controller->Toolbar->loadPanels(array('randomNonExisting', 'request'));
}
/**
* test Loading of panel classes from a plugin
*
* @return void
*/
public function testLoadPluginPanels() {
$debugKitPath = App::pluginPath('DebugKit');
$noDir = (empty($debugKitPath) || !file_exists($debugKitPath));
if ($noDir) {
$this->markTestAsSkipped('Could not find DebugKit in plugin paths');
}
App::build(array(
'Plugin' => array($debugKitPath . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('DebugkitTestPlugin');
$this->_loadController();
$this->Controller->Toolbar->loadPanels(array('DebugkitTestPlugin.PluginTest'));
$this->assertInstanceOf(
'PluginTestPanel',
$this->Controller->Toolbar->panels['plugin_test']
);
}
/**
* test loading of vendor panels from test_app folder
*
* @return void
*/
public function testLibPanels() {
$debugKitPath = App::pluginPath('DebugKit');
$noDir = (empty($debugKitPath) || !file_exists($debugKitPath));
if ($noDir) {
$this->markTestAsSkipped('Could not find DebugKit in plugin paths');
}
App::build(array(
'Lib' => array($debugKitPath . 'Test' . DS . 'test_app' . DS . 'Lib' . DS)
));
$this->_loadController(array(
'panels' => array('test'),
'className' => 'DebugKit.Toolbar',
));
$this->assertTrue(isset($this->Controller->Toolbar->panels['test']));
$this->assertInstanceOf('TestPanel', $this->Controller->Toolbar->panels['test']);
}
/**
* test construct
*
* @return void
*/
public function testConstruct() {
$this->_loadController();
$this->assertFalse(empty($this->Controller->Toolbar->panels));
$memory = DebugMemory::getAll();
$this->assertTrue(isset($memory['Component initialization']));
$events = $this->Controller->getEventManager();
$this->assertNotEmpty($events->listeners('Controller.initialize'));
$this->assertNotEmpty($events->listeners('Controller.startup'));
$this->assertNotEmpty($events->listeners('Controller.beforeRender'));
$this->assertNotEmpty($events->listeners('Controller.shutdown'));
$this->assertNotEmpty($events->listeners('View.beforeRender'));
$this->assertNotEmpty($events->listeners('View.afterRender'));
$this->assertNotEmpty($events->listeners('View.beforeLayout'));
$this->assertNotEmpty($events->listeners('View.afterLayout'));
}
/**
* test initialize w/ custom panels and defaults
*
* @return void
*/
public function testInitializeCustomPanelsWithDefaults() {
$this->_loadController(array(
'panels' => array('test'),
));
$expected = array(
'history', 'session', 'request', 'sql_log', 'timer',
'log', 'variables', 'environment', 'include', 'test'
);
$this->assertEquals($expected, array_keys($this->Controller->Toolbar->panels));
}
/**
* test syntax for removing panels
*
* @return void
*/
public function testInitializeRemovingPanels() {
$this->_loadController(array(
'panels' => array(
'session' => false,
'history' => false,
)
));
$expected = array('request', 'sql_log', 'timer', 'log', 'variables', 'environment', 'include');
$this->assertEquals($expected, array_keys($this->Controller->Toolbar->panels));
}
/**
* ensure that Toolbar is not enabled when debug == 0 on initialize
*
* @return void
*/
public function testDebugDisableOnInitialize() {
$_debug = Configure::read('debug');
Configure::write('debug', 0);
$this->_loadController();
Configure::write('debug', $_debug);
$this->assertFalse($this->Controller->Components->enabled('Toolbar'));
}
/**
* test that passing in forceEnable will enable the toolbar even if debug = 0
*
* @return void
*/
public function testForceEnable() {
$_debug = Configure::read('debug');
Configure::write('debug', 0);
$this->_loadController(array(
'forceEnable' => true,
));
Configure::write('debug', $_debug);
$this->assertTrue($this->Controller->Components->enabled('Toolbar'));
}
/**
* Test disabling autoRunning of toolbar
*
* @return void
*/
public function testAutoRunSettingFalse() {
$this->_loadController(array(
'autoRun' => false,
));
$this->assertFalse($this->Controller->Components->enabled('Toolbar'));
}
/**
* test autorun = false with query string param
*
* @return void
*/
public function testAutoRunSettingWithQueryString() {
$this->url = '/?debug=1';
$_GET['debug'] = 1;
$this->_loadController(array(
'autoRun' => false,
));
$this->assertTrue($this->Controller->Components->enabled('Toolbar'));
}
/**
* test startup
*
* @return void
*/
public function testStartup() {
$this->_loadController(array(
'panels' => array('timer'),
));
$MockPanel = $this->getMock('DebugPanel');
$MockPanel->expects($this->once())->method('startup');
$this->Controller->Toolbar->panels['timer'] = $MockPanel;
$this->Controller->Toolbar->startup($this->Controller);
$timers = DebugTimer::getAll();
$this->assertTrue(isset($timers['controllerAction']));
$memory = DebugMemory::getAll();
$this->assertTrue(isset($memory['Controller action start']));
}
/**
* Test that cache config generation works.
*
* @return void
*/
public function testCacheConfigGeneration() {
$this->_loadController();
$this->Controller->Components->trigger('startup', array($this->Controller));
$results = Cache::config('debug_kit');
$this->assertTrue(is_array($results));
}
/**
* test state saving of toolbar
*
* @return void
*/
public function testStateSaving() {
$this->_loadController();
$configName = 'debug_kit';
$this->Controller->Toolbar->cacheKey = 'toolbar_history';
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->Controller->set('test', 'testing');
$this->Controller->Components->trigger('beforeRender', array($this->Controller));
$result = Cache::read('toolbar_history', $configName);
$this->assertEquals($result[0]['variables']['content']['test'], 'testing');
Cache::delete('toolbar_history', $configName);
}
/**
* Test Before Render callback
*
* @return void
*/
public function testBeforeRender() {
$this->_loadController(array(
'panels' => array('timer', 'session'),
));
$MockPanel = $this->getMock('DebugPanel');
$MockPanel->expects($this->once())->method('beforeRender');
$this->Controller->Toolbar->panels['timer'] = $MockPanel;
$this->Controller->Toolbar->beforeRender($this->Controller);
$this->assertTrue(isset($this->Controller->helpers['DebugKit.Toolbar']));
$this->assertEquals($this->Controller->helpers['DebugKit.Toolbar']['output'], 'DebugKit.HtmlToolbar');
$this->assertEquals($this->Controller->helpers['DebugKit.Toolbar']['cacheConfig'], 'debug_kit');
$this->assertTrue(isset($this->Controller->helpers['DebugKit.Toolbar']['cacheKey']));
$this->assertTrue(isset($this->Controller->viewVars['debugToolbarPanels']));
$vars = $this->Controller->viewVars['debugToolbarPanels'];
$expected = array(
'plugin' => 'DebugKit',
'elementName' => 'session_panel',
'content' => $this->Controller->Toolbar->Session->read(),
'disableTimer' => true,
'title' => ''
);
$this->assertEquals($expected, $vars['session']);
$memory = DebugMemory::getAll();
$this->assertTrue(isset($memory['Controller render start']));
}
/**
* test that vars are gathered and state is saved on beforeRedirect
*
* @return void
*/
public function testBeforeRedirect() {
$this->_loadController(array(
'panels' => array('session', 'history'),
));
$configName = 'debug_kit';
$this->Controller->Toolbar->cacheKey = 'toolbar_history';
Cache::delete('toolbar_history', $configName);
DebugTimer::start('controllerAction', 'testing beforeRedirect');
$MockPanel = $this->getMock('DebugPanel');
$MockPanel->expects($this->once())->method('beforeRender');
$this->Controller->Toolbar->panels['session'] = $MockPanel;
$this->Controller->Toolbar->beforeRedirect($this->Controller, '/another/url');
$result = Cache::read('toolbar_history', $configName);
$this->assertTrue(isset($result[0]['session']));
$this->assertFalse(isset($result[0]['history']));
$timers = DebugTimer::getAll();
$this->assertTrue(isset($timers['controllerAction']));
}
/**
* test that loading state (accessing cache) works.
*
* @return void
*/
public function testLoadState() {
$this->_loadController();
$this->Controller->Toolbar->cacheKey = 'toolbar_history';
$data = array(0 => array('my data'));
Cache::write('toolbar_history', $data, 'debug_kit');
$result = $this->Controller->Toolbar->loadState(0);
$this->assertEquals($result, $data[0]);
}
/**
* Test that history state urls set prefix = null and admin = null so generated urls do not
* adopt these params.
*
* @return void
*/
public function testHistoryUrlGenerationWithPrefixes() {
$this->url = '/debugkit_url_with_prefixes_test';
Router::connect($this->url, array(
'controller' => 'posts',
'action' => 'edit',
'admin' => 1,
'prefix' => 'admin',
'plugin' => 'cms',
));
$this->_loadController();
$this->Controller->Toolbar->cacheKey = 'url_test';
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->Controller->Components->trigger('beforeRender', array($this->Controller));
$result = $this->Controller->Toolbar->panels['history']->beforeRender($this->Controller);
$expected = array(
'plugin' => 'debug_kit',
'controller' => 'toolbar_access',
'action' => 'history_state',
0 => 1,
'admin' => false,
);
$this->assertEquals($result[0]['url'], $expected);
Cache::delete('url_test', 'debug_kit');
}
/**
* Test that the FireCake toolbar is used on AJAX requests
*
* @return void
*/
public function testAjaxToolbar() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->_loadController();
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->Controller->Components->trigger('beforeRender', array($this->Controller));
$this->assertEquals($this->Controller->helpers['DebugKit.Toolbar']['output'], 'DebugKit.FirePhpToolbar');
}
/**
* Test that the toolbar does not interfere with requestAction
*
* @return void
*/
public function testNoRequestActionInterference() {
$debugKitPath = App::pluginPath('DebugKit');
$noDir = (empty($debugKitPath) || !file_exists($debugKitPath));
if ($noDir) {
$this->markTestAsSkipped('Could not find DebugKit in plugin paths');
}
App::build(array(
'Controller' => $debugKitPath . 'Test' . DS . 'test_app' . DS . 'Controller' . DS,
'View' => array(
$debugKitPath . 'Test' . DS . 'test_app' . DS . 'View' . DS,
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS
),
'plugins' => $this->_paths['plugins']
));
Router::reload();
$this->_loadController();
$result = $this->Controller->requestAction('/debug_kit_test/request_action_return', array('return'));
$this->assertEquals($result, 'I am some value from requestAction.');
$result = $this->Controller->requestAction('/debug_kit_test/request_action_render', array('return'));
$this->assertEquals($result, 'I have been rendered.');
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* DebugKit Group 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
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* Class DebugKitGroupTestCase
*
*/
class DebugKitGroupTestCase extends PHPUnit_Framework_TestSuite {
/**
* Constructor
*/
public function __construct() {
$label = Inflector::humanize(Inflector::underscore(get_class($this)));
parent::__construct($label);
}
/**
* Get Test Files
*
* @param null $directory
* @param null $excludes
* @return array
*/
public static function getTestFiles($directory = null, $excludes = null) {
if (is_array($directory)) {
$files = array();
foreach ($directory as $d) {
$files = array_merge($files, self::getTestFiles($d, $excludes));
}
return array_unique($files);
}
if ($excludes !== null) {
$excludes = self::getTestFiles((array)$excludes);
}
if ($directory === null || $directory !== realpath($directory)) {
$basePath = App::pluginPath('DebugKit') . 'Test' . DS . 'Case' . DS;
$directory = str_replace(DS . DS, DS, $basePath . $directory);
}
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
$files = array();
while ($it->valid()) {
if (!$it->isDot()) {
$file = $it->key();
if (
preg_match('|Test\.php$|', $file) &&
$file !== __FILE__ &&
!preg_match('|^All.+?\.php$|', basename($file)) &&
($excludes === null || !in_array($file, $excludes))
) {
$files[] = $file;
}
}
$it->next();
}
return $files;
}
}

View 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');
}
}

View 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']));
}
}

View 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']));
}
}

View 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);
}
}

View 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']);
}
}

View 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']));
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* DebugKit TimedBehavior 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 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('DebugKitDebugger', 'DebugKit.Lib');
/**
* Class TimedBehaviorTestCase
*
* @since DebugKit 1.3
*/
class TimedBehaviorTestCase extends CakeTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array('core.article');
/**
* Start Test callback
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Article = ClassRegistry::init('Article');
$this->Article->Behaviors->attach('DebugKit.Timed');
}
/**
* End a test
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Article);
ClassRegistry::flush();
DebugKitDebugger::clearTimers();
}
/**
* Test find timers
*
* @return void
*/
public function testFindTimers() {
$timers = DebugKitDebugger::getTimers(false);
$this->assertEquals(count($timers), 1);
$this->Article->find('all');
$result = DebugKitDebugger::getTimers(false);
$this->assertEquals(count($result), 2);
$this->Article->find('all');
$result = DebugKitDebugger::getTimers(false);
$this->assertEquals(count($result), 3);
}
/**
* Test save timers
*
* @return void
*/
public function testSaveTimers() {
$timers = DebugKitDebugger::getTimers(false);
$this->assertEquals(count($timers), 1);
$this->Article->save(array('user_id' => 1, 'title' => 'test', 'body' => 'test'));
$result = DebugKitDebugger::getTimers(false);
$this->assertEquals(count($result), 2);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* DebugKit ToolbarAccess Model 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 1.3
* @license http://www.opensource.org/licenses/mit-license.php MIT License
**/
App::uses('ToolbarAccess', 'DebugKit.Model');
/**
* Test case for ToolbarAccess model
*
* @since DebugKit 1.3
*/
class ToolbarAccessTestCase extends CakeTestCase {
/**
* Included fixtures
*
* @var array
*/
public $fixtures = array('core.post');
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->Model = new ToolbarAccess();
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Model);
}
/**
* test that explain query returns arrays of query information.
*
* @return void
*/
public function testExplainQuery() {
$Post = new CakeTestModel(array('table' => 'posts', 'alias' => 'Post'));
$db = $Post->getDataSource();
$sql = 'SELECT * FROM ' . $db->fullTableName('posts') . ';';
$result = $this->Model->explainQuery($Post->useDbConfig, $sql);
$this->assertTrue(is_array($result));
$this->assertFalse(empty($result));
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Common test objects used in DebugKit tests
*
* 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');
/**
* TestFireCake class allows for testing of FireCake
*
* @since DebugKit 0.1
*/
class TestFireCake extends FireCake {
/**
* Headers that were sent
*
* @var array
*/
public $sentHeaders = array();
/**
* Send header
*
* @param $name
* @param $value
*/
protected function _sendHeader($name, $value) {
$_this = FireCake::getInstance();
$_this->sentHeaders[$name] = $value;
}
/**
* Skip client detection as headers are not being sent.
*
* @return boolean Always true
*/
public static function detectClientExtension() {
return true;
}
/**
* Reset FireCake
*
* @return void
*/
public static function reset() {
$_this = FireCake::getInstance();
$_this->sentHeaders = array();
$_this->_messageIndex = 1;
}
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* Toolbar Abstract Helper 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
**/
$path = CakePlugin::path('DebugKit');
App::uses('View', 'View');
App::uses('Controller', 'Controller');
App::uses('CakeResponse', 'Network');
App::uses('Router', 'Routing');
App::uses('ToolbarHelper', 'DebugKit.View/Helper');
App::uses('FirePhpToolbarHelper', 'DebugKit.View/Helper');
require_once $path . 'Test' . DS . 'Case' . DS . 'TestFireCake.php';
/**
* Class FirePhpToolbarHelperTestCase
*
* @since DebugKit 0.1
*/
class FirePhpToolbarHelperTestCase extends CakeTestCase {
/**
* setUp
*
* @return void
**/
public function setUp() {
parent::setUp();
Router::connect('/:controller/:action');
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::parse('/');
$this->Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
$this->View = new View($this->Controller);
$this->Toolbar = new ToolbarHelper($this->View, array('output' => 'DebugKit.FirePhpToolbar'));
$this->Toolbar->FirePhpToolbar = new FirePhpToolbarHelper($this->View);
$this->firecake = FireCake::getInstance('TestFireCake');
TestFireCake::reset();
}
/**
* Start test - switch view paths
*
* @return void
**/
public static function setupBeforeClass() {
App::build(array(
'View' => array(
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'View' . DS,
APP . 'Plugin' . DS . 'DebugKit' . DS . 'View' . DS,
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS
)), true);
}
/**
* End Test
*
* @return void
*/
public static function tearDownAfterClass() {
App::build();
}
/**
* TearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Toolbar, $this->Controller);
TestFireCake::reset();
}
/**
* Test neat array (dump)creation
*
* @return void
*/
public function testMakeNeatArray() {
$this->Toolbar->makeNeatArray(array(1,2,3));
$result = $this->firecake->sentHeaders;
$this->assertTrue(isset($result['X-Wf-1-1-1-1']));
$this->assertRegexp('/\[1,2,3\]/', $result['X-Wf-1-1-1-1']);
}
/**
* Test afterlayout element rendering
*
* @return void
*/
public function testAfterLayout() {
$this->Controller->viewPath = 'Posts';
$request = new CakeRequest('/posts/index');
$request->addParams(Router::parse($request->url));
$request->addPaths(array(
'webroot' => '/',
'base' => '/',
'here' => '/posts/index',
));
$this->Controller->setRequest($request);
$this->Controller->layout = 'default';
$this->Controller->uses = null;
$this->Controller->components = array('DebugKit.Toolbar');
$this->Controller->constructClasses();
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->Controller->Components->trigger('beforeRender', array($this->Controller));
$result = $this->Controller->render();
$this->assertNotRegExp('/debug-toolbar/', (string)$result);
$result = $this->firecake->sentHeaders;
$this->assertTrue(is_array($result));
}
/**
* test starting a panel
*
* @return void
**/
public function testPanelStart() {
$this->Toolbar->panelStart('My Panel', 'my_panel');
$result = $this->firecake->sentHeaders;
$this->assertPattern('/GROUP_START.+My Panel/', $result['X-Wf-1-1-1-1']);
}
/**
* test ending a panel
*
* @return void
**/
public function testPanelEnd() {
$this->Toolbar->panelEnd();
$result = $this->firecake->sentHeaders;
$this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-1']);
}
}

View File

@@ -0,0 +1,452 @@
<?php
/**
* Toolbar HTML Helper 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('View', 'View');
App::uses('Controller', 'Controller');
App::uses('Router', 'Routing');
App::uses('CakeResponse', 'Network');
App::uses('ToolbarHelper', 'DebugKit.View/Helper');
App::uses('HtmlToolbarHelper', 'DebugKit.View/Helper');
App::uses('HtmlHelper', 'View/Helper');
App::uses('FormHelper', 'View/Helper');
/**
* Class HtmlToolbarHelperTestCase
*
* @since DebugKit 0.1
*/
class HtmlToolbarHelperTestCase extends CakeTestCase {
/**
* Setup Test Case
*/
public static function setupBeforeClass() {
App::build(array(
'View' => array(
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'View' . DS,
APP . 'Plugin' . DS . 'DebugKit' . DS . 'View' . DS,
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS
)
), true);
}
/**
* Tear Down Test Case
*/
public static function tearDownAfterClass() {
App::build();
}
/**
* Setup
*
* @return void
*/
public function setUp() {
parent::setUp();
Router::connect('/:controller/:action');
$request = new CakeRequest();
$request->addParams(array('controller' => 'pages', 'action' => 'display'));
$this->Controller = new Controller($request, new CakeResponse());
$this->View = new View($this->Controller);
$this->Toolbar = new ToolbarHelper($this->View, array('output' => 'DebugKit.HtmlToolbar'));
$this->Toolbar->HtmlToolbar = new HtmlToolbarHelper($this->View);
$this->Toolbar->HtmlToolbar->Html = new HtmlHelper($this->View);
$this->Toolbar->HtmlToolbar->Form = new FormHelper($this->View);
}
/**
* Tear Down
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->Toolbar, $this->Controller);
}
/**
* Test makeNeatArray with basic types.
*
* @return void
*/
public function testMakeNeatArrayBasic() {
$in = false;
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', '0' , '/strong', '(false)', '/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = null;
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', '0' , '/strong', '(null)', '/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = true;
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', '0' , '/strong', '(true)', '/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = array();
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', '0' , '/strong', '(empty)', '/li',
'/ul'
);
$this->assertTags($result, $expected);
}
/**
* Test that cyclic references can be printed.
*
* @return void
*/
public function testMakeNeatArrayCyclicObjects() {
$a = new StdClass;
$b = new StdClass;
$a->child = $b;
$b->parent = $a;
$in = array('obj' => $a);
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
array('ul' => array('class' => 'neat-array depth-0')),
'<li', '<strong', 'obj', '/strong', '(object)',
array('ul' => array('class' => 'neat-array depth-1')),
'<li', '<strong', 'child', '/strong', '(object)',
array('ul' => array('class' => 'neat-array depth-2')),
'<li', '<strong', 'parent', '/strong',
'(object) - recursion',
'/li',
'/ul',
'/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
}
/**
* Test Neat Array formatting
*
* @return void
*/
public function testMakeNeatArray() {
$in = array('key' => 'value');
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = array('key' => null);
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', 'key', '/strong', '(null)', '/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = array('key' => 'value', 'foo' => 'bar');
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'<li', '<strong', 'foo', '/strong', 'bar', '/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = array(
'key' => 'value',
'foo' => array(
'this' => 'deep',
'another' => 'value'
)
);
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'<li', '<strong', 'foo', '/strong',
'(array)',
array('ul' => array('class' => 'neat-array depth-1')),
'<li', '<strong', 'this', '/strong', 'deep', '/li',
'<li', '<strong', 'another', '/strong', 'value', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = array(
'key' => 'value',
'foo' => array(
'this' => 'deep',
'another' => 'value'
),
'lotr' => array(
'gandalf' => 'wizard',
'bilbo' => 'hobbit'
)
);
$result = $this->Toolbar->makeNeatArray($in, 1);
$expected = array(
'ul' => array('class' => 'neat-array depth-0 expanded'),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'<li', '<strong', 'foo', '/strong',
'(array)',
array('ul' => array('class' => 'neat-array depth-1')),
'<li', '<strong', 'this', '/strong', 'deep', '/li',
'<li', '<strong', 'another', '/strong', 'value', '/li',
'/ul',
'/li',
'<li', '<strong', 'lotr', '/strong',
'(array)',
array('ul' => array('class' => 'neat-array depth-1')),
'<li', '<strong', 'gandalf', '/strong', 'wizard', '/li',
'<li', '<strong', 'bilbo', '/strong', 'hobbit', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$result = $this->Toolbar->makeNeatArray($in, 2);
$expected = array(
'ul' => array('class' => 'neat-array depth-0 expanded'),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'<li', '<strong', 'foo', '/strong',
'(array)',
array('ul' => array('class' => 'neat-array depth-1 expanded')),
'<li', '<strong', 'this', '/strong', 'deep', '/li',
'<li', '<strong', 'another', '/strong', 'value', '/li',
'/ul',
'/li',
'<li', '<strong', 'lotr', '/strong',
'(array)',
array('ul' => array('class' => 'neat-array depth-1 expanded')),
'<li', '<strong', 'gandalf', '/strong', 'wizard', '/li',
'<li', '<strong', 'bilbo', '/strong', 'hobbit', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
$in = array('key' => 'value', 'array' => array());
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
'ul' => array('class' => 'neat-array depth-0'),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'<li', '<strong', 'array', '/strong', '(empty)', '/li',
'/ul'
);
$this->assertTags($result, $expected);
}
/**
* Test makeNeatArray with object inputs.
*
* @return void
*/
public function testMakeNeatArrayObjects() {
$in = new StdClass();
$in->key = 'value';
$in->nested = new StdClass();
$in->nested->name = 'mark';
$result = $this->Toolbar->makeNeatArray($in);
$expected = array(
array('ul' => array('class' => 'neat-array depth-0')),
'<li', '<strong', 'key', '/strong', 'value', '/li',
'<li', '<strong', 'nested', '/strong',
'(object)',
array('ul' => array('class' => 'neat-array depth-1')),
'<li', '<strong', 'name', '/strong', 'mark', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected);
}
/**
* Test injection of toolbar
*
* @return void
*/
public function testInjectToolbar() {
$this->Controller->viewPath = 'Posts';
$request = new CakeRequest('/posts/index');
$request->addParams(Router::parse($request->url));
$request->addPaths(array(
'webroot' => '/',
'base' => '/',
'here' => '/posts/index',
));
$this->Controller->setRequest($request);
$this->Controller->helpers = array('Html', 'Js', 'Session', 'DebugKit.Toolbar');
$this->Controller->layout = 'default';
$this->Controller->uses = null;
$this->Controller->components = array('DebugKit.Toolbar');
$this->Controller->constructClasses();
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->Controller->Components->trigger('beforeRender', array($this->Controller));
$result = $this->Controller->render();
$result = str_replace(array("\n", "\r"), '', $result);
$this->assertPattern('#<div id\="debug-kit-toolbar">.+</div>.*</body>#', $result);
}
/**
* test injection of javascript
*
* @return void
*/
public function testJavascriptInjection() {
$this->Controller->viewPath = 'Posts';
$this->Controller->uses = null;
$request = new CakeRequest('/posts/index');
$request->addParams(Router::parse($request->url));
$request->addPaths(array(
'webroot' => '/',
'base' => '/',
'here' => '/posts/index',
));
$this->Controller->setRequest($request);
$this->Controller->helpers = array('Js', 'Html', 'Session');
$this->Controller->components = array('DebugKit.Toolbar');
$this->Controller->layout = 'default';
$this->Controller->constructClasses();
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->Controller->Components->trigger('beforeRender', array($this->Controller));
$result = $this->Controller->render();
$result = str_replace(array("\n", "\r"), '', $result);
$this->assertPattern('#<script\s*type="text/javascript"\s*src="/debug_kit/js/js_debug_toolbar.js(?:\?\d*?)?"\s*>\s?</script>#', $result);
}
/**
* test message creation
*
* @return void
*/
public function testMessage() {
$result = $this->Toolbar->message('test', 'one, two');
$expected = array(
'<p',
'<strong', 'test', '/strong',
' one, two',
'/p',
);
$this->assertTags($result, $expected);
}
/**
* Test Table generation
*
* @return void
*/
public function testTable() {
$rows = array(
array(1,2),
array(3,4),
);
$result = $this->Toolbar->table($rows);
$expected = array(
'table' => array('class' => 'debug-table'),
array('tr' => array('class' => 'odd')),
'<td', '1', '/td',
'<td', '2', '/td',
'/tr',
array('tr' => array('class' => 'even')),
'<td', '3', '/td',
'<td', '4', '/td',
'/tr',
'/table'
);
$this->assertTags($result, $expected);
}
/**
* test starting a panel
*
* @return void
*/
public function testStartPanel() {
$result = $this->Toolbar->panelStart('My Panel', 'my_panel');
$expected = array(
'a' => array('href' => '#my_panel'),
'My Panel',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* test ending a panel
*
* @return void
*/
public function testPanelEnd() {
$result = $this->Toolbar->panelEnd();
$this->assertNull($result);
}
/**
* Test generating links for query explains.
*
* @return void
*/
public function testExplainLink() {
$sql = 'SELECT * FROM tasks';
$result = $this->Toolbar->explainLink($sql, 'default');
$expected = array(
'form' => array('action' => '/debug_kit/toolbar_access/sql_explain', 'method' => 'post',
'accept-charset' => 'utf-8', 'id'),
array('div' => array('style' => 'display:none;')),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
'/div',
array('input' => array('type' => 'hidden', 'id', 'name' => 'data[log][ds]', 'value' => 'default')),
array('input' => array('type' => 'hidden', 'id', 'name' => 'data[log][sql]', 'value' => $sql)),
array('input' => array('type' => 'hidden', 'id', 'name' => 'data[log][hash]', 'value')),
array('input' => array('class' => 'sql-explain-link', 'type' => 'submit', 'value' => 'Explain')),
'/form',
);
$this->assertTags($result, $expected);
}
}

View File

@@ -0,0 +1,179 @@
<?php
/**
* Toolbar facade tests.
*
* 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('View', 'View');
App::uses('Controller', 'Controller');
App::uses('Helper', 'View');
App::uses('ToolbarHelper', 'DebugKit.View/Helper');
App::uses('ConnectionManager', 'Manager');
/**
* Class MockBackendHelper
*
* @since DebugKit 0.1
*/
class MockBackendHelper extends Helper {
}
/**
* Class ToolbarHelperTestCase
*
*/
class ToolbarHelperTestCase extends CakeTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array('core.post');
/**
* setUp
*
* @return void
*/
public function setUp() {
parent::setUp();
$db = ConnectionManager::getDatasource('test');
$db->fullDebug = true;
Configure::write('Cache.disable', false);
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::parse('/');
$this->Controller = new Controller(null);
$this->View = new View($this->Controller);
$this->Toolbar = new ToolbarHelper($this->View, array(
'output' => 'MockBackendHelper',
'cacheKey' => 'debug_kit_toolbar_test_case',
'cacheConfig' => 'default'
));
$this->Toolbar->MockBackend = $this->getMock('Helper', array('testMethod'), array($this->View));
$this->_viewPaths = App::path('views');
App::build(array(
'View' => array(
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'View' . DS,
APP . 'Plugin' . DS . 'DebugKit' . DS . 'View' . DS,
CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS
)), true);
}
/**
* tearDown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
Cache::delete('debug_kit_toolbar_test_case', 'default');
unset($this->Toolbar, $this->Controller);
}
/**
* test cache writing for views.
*
* @return void
*/
public function testCacheWrite() {
$result = $this->Toolbar->writeCache('test', array('stuff', 'to', 'cache'));
$this->assertTrue($result);
}
/**
* Ensure that the cache writing only affects the
* top most level of the history stack. As this is where the current request is stored.
*
* @return void
*/
public function testOnlyWritingToFirstElement() {
$values = array(
array('test' => array('content' => array('first', 'values'))),
array('test' => array('content' => array('second', 'values'))),
);
Cache::write('debug_kit_toolbar_test_case', $values, 'default');
$this->Toolbar->writeCache('test', array('new', 'values'));
$result = $this->Toolbar->readCache('test');
$this->assertEquals($result, array('new', 'values'));
$result = $this->Toolbar->readCache('test', 1);
$this->assertEquals($result, array('second', 'values'));
}
/**
* test cache reading for views
*
* @return void
*/
public function testCacheRead() {
$result = $this->Toolbar->writeCache('test', array('stuff', 'to', 'cache'));
$this->assertTrue($result, 'Cache write failed %s');
$result = $this->Toolbar->readCache('test');
$this->assertEquals($result, array('stuff', 'to', 'cache'), 'Cache value is wrong %s');
$result = $this->Toolbar->writeCache('test', array('new', 'stuff'));
$this->assertTrue($result, 'Cache write failed %s');
$result = $this->Toolbar->readCache('test');
$this->assertEquals($result, array('new', 'stuff'), 'Cache value is wrong %s');
}
/**
* Test that reading/writing doesn't work with no cache config.
*
* @return void
*/
public function testNoCacheConfigPresent() {
$this->Toolbar = new ToolbarHelper($this->View, array('output' => 'MockBackendHelper'));
$result = $this->Toolbar->writeCache('test', array('stuff', 'to', 'cache'));
$this->assertFalse($result, 'Writing to cache succeeded with no cache config %s');
$result = $this->Toolbar->readCache('test');
$this->assertFalse($result, 'Reading cache succeeded with no cache config %s');
}
/**
* ensure that getQueryLogs works and writes to the cache so the history panel will
* work.
*
* @return void
*/
public function testGetQueryLogs() {
$model = new CakeTestModel(array('table' => 'posts', 'alias' => 'Post'));
$model->find('all');
$model->find('first');
$result = $this->Toolbar->getQueryLogs($model->useDbConfig, array('cache' => false));
$this->assertTrue(is_array($result));
$this->assertTrue(count($result) >= 2, 'Should be more than 2 queries in the log %s');
$this->assertTrue(isset($result['queries'][0]['actions']));
$model->find('first');
Cache::delete('debug_kit_toolbar_test_case', 'default');
$result = $this->Toolbar->getQueryLogs($model->useDbConfig, array('cache' => true));
$cached = $this->Toolbar->readCache('sql_log');
$this->assertTrue(isset($cached[$model->useDbConfig]));
$this->assertEquals($cached[$model->useDbConfig]['queries'][0], $result['queries'][0]);
}
}