Server IP : 180.180.241.3 / Your IP : 216.73.216.252 Web Server : Microsoft-IIS/7.5 System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 User : IUSR ( 0) PHP Version : 5.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /AppServ/www/app/Plugin/DebugKit/Test/Case/View/Helper/ |
Upload File : |
<?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 * @package DebugKit.Test.Case.View.Helper * @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'); /** * Class MockBackendHelper * * @package DebugKit.Test.Case.View.Helper * @since DebugKit 0.1 */ class MockBackendHelper extends Helper { } /** * Class ToolbarHelperTestCase * * @package DebugKit.Test.Case.View.Helper */ class ToolbarHelperTestCase extends CakeTestCase { /** * Fixtures * * @var array */ public $fixtures = array('core.post'); /** * setUp * * @return void **/ public function setUp() { 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)); if (isset($this->_debug)) { Configure::write('debug', $this->_debug); } $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); $this->_debug = Configure::read('debug'); } /** * 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]); } /** * tearDown * * @return void */ public function tearDown() { parent::tearDown(); Cache::delete('debug_kit_toolbar_test_case', 'default'); unset($this->Toolbar, $this->Controller); } }