/**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     Configure::write('log', true);
     DebugKitDebugger::clearTimers();
     TestFireCake::reset();
 }
Exemple #2
0
 /**
  * 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);
 }
Exemple #3
0
 /**
  * Renders view for given action and layout. If $file is given, that is used
  * for a view filename (e.g. customFunkyView.ctp).
  * Adds timers, for all subsequent rendering, and injects the debugKit toolbar.
  *
  * @param string $action Name of action to render for
  * @param string $layout Layout to use
  * @param string $file Custom filename for view
  * @return string Rendered Element
  */
 function render($action = null, $layout = null, $file = null)
 {
     DebugKitDebugger::startTimer('viewRender', __('Rendering View', true));
     $out = parent::render($action, $layout, $file);
     DebugKitDebugger::stopTimer('viewRender');
     DebugKitDebugger::stopTimer('controllerRender');
     if (isset($this->loaded['toolbar'])) {
         $this->loaded['toolbar']->postRender();
     }
     //Temporary work around to hide the SQL dump at page bottom
     Configure::write('debug', 0);
     return $this->output;
 }
Exemple #4
0
 /**
  * Renders view for given action and layout. If $file is given, that is used
  * for a view filename (e.g. customFunkyView.ctp).
  * Adds timers, for all subsequent rendering, and injects the debugKit toolbar.
  *
  * @param string $action Name of action to render for
  * @param string $layout Layout to use
  * @param string $file Custom filename for view
  * @return string Rendered Element
  */
 function render($action = null, $layout = null, $file = null)
 {
     DebugKitDebugger::startTimer('viewRender', __d('debug_kit', 'Rendering View', true));
     $out = parent::render($action, $layout, $file);
     DebugKitDebugger::stopTimer('viewRender');
     DebugKitDebugger::stopTimer('controllerRender');
     DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'View render complete', true));
     if (empty($this->params['requested']) && isset($this->loaded['toolbar'])) {
         $backend = $this->loaded['toolbar']->getName();
         $this->loaded['toolbar']->{$backend}->send();
     }
     if (empty($this->output)) {
         return $out;
     }
     return $this->output;
 }
Exemple #5
0
 /**
  * Renders view for given action and layout. If $file is given, that is used
  * for a view filename (e.g. customFunkyView.ctp).
  * Adds timers, for all subsequent rendering, and injects the debugKit toolbar.
  *
  * @param string $action Name of action to render for
  * @param string $layout Layout to use
  * @param string $file Custom filename for view
  * @return string Rendered Element
  */
 function render($action = null, $layout = null, $file = null)
 {
     DebugKitDebugger::startTimer('viewRender', __d('debug_kit', 'Rendering View', true));
     $out = parent::render($action, $layout, $file);
     DebugKitDebugger::stopTimer('viewRender');
     DebugKitDebugger::stopTimer('controllerRender');
     DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'View render complete', true));
     if (isset($this->loaded['toolbar'])) {
         $backend = $this->loaded['toolbar']->getName();
         $this->loaded['toolbar']->{$backend}->send();
     }
     if (empty($this->output)) {
         return $out;
     }
     //Temporary work around to hide the SQL dump at page bottom
     Configure::write('debug', 0);
     return $this->output;
 }
 /**
  * test making memory use markers.
  *
  * @return void
  **/
 function testMemorySettingAndGetting()
 {
     $result = DebugKitDebugger::setMemoryPoint('test marker');
     $this->assertTrue($result);
     $result = DebugKitDebugger::getMemoryPoints(true);
     $this->assertEqual(count($result), 1);
     $this->assertTrue(isset($result['test marker']));
     $this->assertTrue(is_numeric($result['test marker']));
     $result = DebugKitDebugger::getMemoryPoints();
     $this->assertTrue(empty($result));
     DebugKitDebugger::setMemoryPoint('test marker');
     DebugKitDebugger::setMemoryPoint('test marker');
     $result = DebugKitDebugger::getMemoryPoints();
     $this->assertEqual(count($result), 2);
     $this->assertTrue(isset($result['test marker']));
     $this->assertTrue(isset($result['test marker #2']));
 }
 /**
  * Clear out any existing memory points
  *
  * @return void
  **/
 function clearMemoryPoints()
 {
     $self =& DebugKitDebugger::getInstance();
     $self->__memoryPoints = array();
 }
/**
 * test that vars are gathered and state is saved on beforeRedirect
 *
 * @return void
 **/
	public function testBeforeRedirect() {
		$this->_loadController(array(
			'panels' => array('test', 'session', 'history'),
		));

		$configName = 'debug_kit';
		$this->Controller->Toolbar->cacheKey = 'toolbar_history';
		Cache::delete('toolbar_history', $configName);

		DebugKitDebugger::startTimer('controllerAction', 'testing beforeRedirect');
		$MockPanel = $this->getMock('DebugPanel');
		$MockPanel->expects($this->once())->method('beforeRender');
		$this->Controller->Toolbar->panels['test'] = $MockPanel;
		$this->Controller->Toolbar->beforeRedirect($this->Controller);

		$result = Cache::read('toolbar_history', $configName);
		$this->assertTrue(isset($result[0]['session']));
		$this->assertTrue(isset($result[0]['test']));

		$timers = DebugKitDebugger::getTimers();
		$this->assertTrue(isset($timers['controllerAction']));
	}
 /**
  * test rendering and ensure that timers are being set.
  *
  * @access public
  * @return void
  */
 function testRenderTimers()
 {
     $this->Controller->viewPath = 'posts';
     $this->Controller->action = 'index';
     $this->Controller->params = array('action' => 'index', 'controller' => 'posts', 'plugin' => null, 'url' => array('url' => 'posts/index'), 'base' => null, 'here' => '/posts/index');
     $this->Controller->layout = 'default';
     $View =& new DebugView($this->Controller, false);
     $View->render('index');
     $result = DebugKitDebugger::getTimers();
     $this->assertEqual(count($result), 4);
     $this->assertTrue(isset($result['viewRender']));
     $this->assertTrue(isset($result['render_default.ctp']));
     $this->assertTrue(isset($result['render_index.ctp']));
     $result = DebugKitDebugger::getMemoryPoints();
     $this->assertTrue(isset($result['View render complete']));
 }
 /**
  * test that vars are gathered and state is saved on beforeRedirect
  *
  * @return void
  **/
 function testBeforeRedirect()
 {
     $this->Controller->components = array('DebugKit.Toolbar' => array('panels' => array('MockDebug', 'session', 'history')));
     $this->Controller->Component->init($this->Controller);
     $this->Controller->Component->initialize($this->Controller);
     $configName = 'debug_kit';
     $this->Controller->Toolbar->cacheKey = 'toolbar_history';
     Cache::delete('toolbar_history', $configName);
     DebugKitDebugger::startTimer('controllerAction', 'testing beforeRedirect');
     $this->Controller->Toolbar->panels['MockDebug']->expectOnce('beforeRender');
     $this->Controller->Toolbar->beforeRedirect($this->Controller);
     $result = Cache::read('toolbar_history', $configName);
     $this->assertTrue(isset($result[0]['session']));
     $this->assertTrue(isset($result[0]['mock_debug']));
     $timers = DebugKitDebugger::getTimers();
     $this->assertTrue(isset($timers['controllerAction']));
 }
 /**
  * Queries the datasource and returns a result set array.
  *
  * @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
  * @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
  * @return array Array of records
  * @link http://book.cakephp.org/2.0/en/models/deleting-data.html#deleteall
  */
 public function find($type = 'first', $query = array())
 {
     DebugKitDebugger::startTimer($this->name . '::find(' . $type . ')');
     $results = parent::find($type, $query);
     DebugKitDebugger::stopTimer($this->name . '::find(' . $type . ')');
     return $results;
 }
 /**
  * test _output switch to firePHP
  *
  * @return void
  */
 function testOutput()
 {
     $firecake =& FireCake::getInstance('TestFireCake');
     Debugger::invoke(DebugKitDebugger::getInstance('DebugKitDebugger'));
     Debugger::output('fb');
     $foo .= '';
     $result = $firecake->sentHeaders;
     $this->assertPattern('/GROUP_START/', $result['X-Wf-1-1-1-1']);
     $this->assertPattern('/ERROR/', $result['X-Wf-1-1-1-2']);
     $this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-5']);
     Debugger::invoke(Debugger::getInstance('Debugger'));
     Debugger::output();
 }
Exemple #13
0
 /**
  * beforeRender Callback
  *
  * @return array
  **/
 function beforeRender(&$controller)
 {
     $this->startTime = DebugKitDebugger::requestStartTime();
     $this->currentTime = DebugKitDebugger::requestTime();
     $out = array();
     foreach ($this->logFiles as $log) {
         $file = LOGS . $log;
         if (!file_exists($file)) {
             continue;
         }
         $out[$log] = $this->_parseFile($file);
     }
     return $out;
 }
 /**
  * Get the total execution time until this point
  *
  * @access public
  * @return float elapsed time in seconds since script start.
  * @static
  */
 function requestTime()
 {
     $start = DebugKitDebugger::requestStartTime();
     $now = getMicroTime();
     return $now - $start;
 }
Exemple #15
0
 /**
  * tear down function
  *
  * @return void
  **/
 function tearDown()
 {
     unset($this->View, $this->Controller);
     DebugKitDebugger::clearTimers();
     Configure::write('debug', $this->_debug);
 }
Exemple #16
0
 /**
  * beforeRender callback
  *
  * Calls beforeRender on all the panels and set the aggregate to the controller.
  *
  * @return void
  **/
 function beforeRender(&$controller)
 {
     if (!class_exists('DebugKitDebugger')) {
         return null;
     }
     DebugKitDebugger::stopTimer('controllerAction');
     $vars = $this->_gatherVars($controller);
     $this->_saveState($controller, $vars);
     $controller->set(array('debugToolbarPanels' => $vars, 'debugToolbarJavascript' => $this->javascript));
     DebugKitDebugger::startTimer('controllerRender', __d('debug_kit', 'Render Controller Action', true));
     DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'Controller render start', true));
 }
Exemple #17
0
 /**
  * test rendering and ensure that timers are being set.
  *
  * @return void
  */
 public function testRenderTimers()
 {
     $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->viewPath = 'posts';
     $this->Controller->layout = 'default';
     $View = new DebugView($this->Controller, false);
     $View->render('index');
     $result = DebugKitDebugger::getTimers();
     $this->assertEqual(count($result), 4);
     $this->assertTrue(isset($result['viewRender']));
     $this->assertTrue(isset($result['render_default.ctp']));
     $this->assertTrue(isset($result['render_index.ctp']));
     $result = DebugKitDebugger::getMemoryPoints();
     $this->assertTrue(isset($result['View render complete']));
 }
     * @return void
     * @deprecated Use DebugMemory::clear() instead.
     */
    public static function clearMemoryPoints()
    {
        return DebugMemory::clear();
    }
    /**
     * Create a FirePHP error message
     *
     * @param array $data Data of the error
     * @param array $links  Links for the error
     * @return void
     */
    public static function fireError($data, $links)
    {
        $name = $data['error'] . ' - ' . $data['description'];
        $message = "{$data['error']} {$data['code']} {$data['description']} on line: {$data['line']} in file: {$data['file']}";
        FireCake::group($name);
        FireCake::error($message, $name);
        if (isset($data['context'])) {
            FireCake::log($data['context'], 'Context');
        }
        if (isset($data['trace'])) {
            FireCake::log($data['trace'], 'Trace');
        }
        FireCake::groupEnd();
    }
}
DebugKitDebugger::getInstance('DebugKitDebugger');
Debugger::addFormat('fb', array('callback' => 'DebugKitDebugger::fireError'));
Exemple #19
0
 /**
  * teardown
  *
  * @return void
  **/
 function tearDown()
 {
     unset($this->Controller);
     if (class_exists('DebugKitDebugger')) {
         DebugKitDebugger::clearTimers();
     }
 }
Exemple #20
0
 /**
  * Tests an action using the controller itself and skipping the dispatcher, and
  * returning the view vars.
  *
  * Since `CakeTestCase::testAction` was causing so many problems and is
  * incredibly slow, it is overwritten here to go about it a bit differently.
  * Import `CoreTestCase` from 'Lib' and extend test cases using `CoreTestCase`
  * instead to gain this functionality.
  *
  * For backwards compatibility with the original `CakeTestCase::testAction`, set
  * `testController` to `null`.
  *
  * ### Options:
  * - `data` Data to pass to the controller
  *
  * ### Limitations:
  * - only reinstantiates the default model
  * - not 100% complete, i.e., some callbacks may not be fired like they would
  *	  if regularly called through the dispatcher
  *
  * @param string $url The url to test
  * @param array $options A list of options
  * @return array The view vars
  * @link http://mark-story.com/posts/view/testing-cakephp-controllers-the-hard-way
  */
 public function testAction($url = '', $options = array())
 {
     if (is_null($this->testController)) {
         return parent::testAction($url, $options);
     }
     $Controller = $this->testController;
     // reset parameters
     $Controller->passedArgs = array();
     $Controller->params = array();
     $Controller->url = null;
     $Controller->action = null;
     $Controller->viewVars = array();
     $keys = ClassRegistry::keys();
     foreach ($keys as $key) {
         if (is_a(ClassRegistry::getObject(Inflector::camelize($key)), 'Model')) {
             ClassRegistry::getObject(Inflector::camelize($key))->create(false);
         }
     }
     $Controller->Session->delete('Message');
     $Controller->activeUser = null;
     $default = array('data' => array(), 'method' => 'post');
     $options = array_merge($default, $options);
     // set up the controller based on the url
     $urlParams = Router::parse($url);
     if (stripos('http', $url) === false) {
         $url = 'http://localhost/' . ltrim($url, '/');
     }
     parse_str(parse_url($url, PHP_URL_QUERY), $queryParams);
     if (!isset($urlParams['url'])) {
         $urlParams['url'] = array();
     }
     $urlParams['url'] = array_merge($urlParams['url'], $queryParams);
     if (strtolower($options['method']) == 'get') {
         $urlParams['url'] = array_merge($options['data'], $urlParams['url']);
     } else {
         $Controller->data = $options['data'];
     }
     $Controller->passedArgs = $urlParams['named'];
     $Controller->params = $urlParams;
     $Controller->params['url']['url'] = $url;
     $Controller->url = $urlParams;
     $Controller->action = $urlParams['plugin'] . '/' . $urlParams['controller'] . '/' . $urlParams['action'];
     $Controller->Component->initialize($Controller);
     if (isset($Controller->Toolbar)) {
         $Controller->Toolbar->enabled = false;
     }
     // configure auth
     if (isset($Controller->Auth)) {
         $Controller->Auth->initialize($Controller);
         if (!$Controller->Session->check('Auth.User') && !$Controller->Session->check('User')) {
             $this->su();
         }
     }
     // configure acl
     if (isset($Controller->Acl)) {
         $core =& Core::getInstance();
         $core->Acl = new MockAclComponent();
         $core->Acl->__construct();
         $core->Acl->enabled = true;
         $core->Acl->setReturnValue('check', true);
     }
     $Controller->beforeFilter();
     $Controller->Component->startup($Controller);
     call_user_func_array(array(&$Controller, $urlParams['action']), $urlParams['pass']);
     $Controller->beforeRender();
     $Controller->Component->triggerCallback('beforeRender', $Controller);
     // trick debugkit into skipping its __destruct method which clutters up the response
     if (class_exists('DebugKitDebugger')) {
         $_debugkit =& DebugKitDebugger::getInstance();
         $_debugkit->__benchmarks = null;
     }
     return $Controller->viewVars;
 }
 /**
  * tearDown method
  *
  * @access public
  * @return void
  */
 function tearDown()
 {
     Configure::write('log', true);
     DebugKitDebugger::clearTimers();
 }
 /**
  * afterSave, stop the timer started from a save.
  *
  * @param string $Model
  * @param string $created
  * @return void
  */
 public function afterSave(Model $Model, $created)
 {
     DebugKitDebugger::stopTimer($Model->alias . '_save');
     return true;
 }
Exemple #23
0
/**
 * Renders view for given action and layout.
 * Adds timers, for all subsequent rendering, and injects the debugKit toolbar.
 *
 * @param string $action Name of action to render for
 * @param string $layout Layout to use
 * @return string Rendered Element
 */
	public function render($action = null, $layout = null) {
		DebugKitDebugger::startTimer('viewRender', __d('debug_kit', 'Rendering View'));

		$out = parent::render($action, $layout);

		DebugKitDebugger::stopTimer('viewRender');
		DebugKitDebugger::stopTimer('controllerRender');
		DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'View render complete'));

		if (empty($this->request->params['requested']) && $this->Helpers->attached('Toolbar')) {
			$backend = $this->Helpers->Toolbar->getName();
			$this->Helpers->Toolbar->{$backend}->send();
		}
		if (empty($this->output)) {
			return $out;
		}
		return $this->output;
	}