PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/tests/cases/libs/debugger.test.php

https://github.com/phpbug/Informaster
PHP | 280 lines | 203 code | 6 blank | 71 comment | 3 complexity | aebfb6b2438b7bc7e140f22359a98056 MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * DebuggerTest file
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake
  20. * @subpackage cake.tests.cases.libs
  21. * @since CakePHP(tm) v 1.2.0.5432
  22. * @version $Revision$
  23. * @modifiedby $LastChangedBy$
  24. * @lastmodified $Date$
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. App::import('Core', 'Debugger');
  28. /**
  29. * DebugggerTestCaseDebuggger class
  30. *
  31. * @package cake
  32. * @subpackage cake.tests.cases.libs
  33. */
  34. class DebuggerTestCaseDebugger extends Debugger {
  35. }
  36. /**
  37. * DebuggerTest class
  38. *
  39. * @package cake
  40. * @subpackage cake.tests.cases.libs
  41. */
  42. class DebuggerTest extends CakeTestCase {
  43. // !!!
  44. // !!! Be careful with changing code below as it may
  45. // !!! change line numbers which are used in the tests
  46. // !!!
  47. /**
  48. * setUp method
  49. *
  50. * @access public
  51. * @return void
  52. */
  53. function setUp() {
  54. Configure::write('log', false);
  55. if (!defined('SIMPLETESTVENDORPATH')) {
  56. if (file_exists(APP . DS . 'vendors' . DS . 'simpletest' . DS . 'reporter.php')) {
  57. define('SIMPLETESTVENDORPATH', 'APP' . DS . 'vendors');
  58. } else {
  59. define('SIMPLETESTVENDORPATH', 'CORE' . DS . 'vendors');
  60. }
  61. }
  62. }
  63. /**
  64. * tearDown method
  65. *
  66. * @access public
  67. * @return void
  68. */
  69. function tearDown() {
  70. Configure::write('log', true);
  71. }
  72. /**
  73. * testDocRef method
  74. *
  75. * @access public
  76. * @return void
  77. */
  78. function testDocRef() {
  79. ini_set('docref_root', '');
  80. $this->assertEqual(ini_get('docref_root'), '');
  81. $debugger = new Debugger();
  82. $this->assertEqual(ini_get('docref_root'), 'http://php.net/');
  83. }
  84. /**
  85. * test Excerpt writing
  86. *
  87. * @access public
  88. * @return void
  89. */
  90. function testExcerpt() {
  91. $return = Debugger::excerpt(__FILE__, 2, 2);
  92. $this->assertTrue(is_array($return));
  93. $this->assertEqual(count($return), 4);
  94. $this->assertPattern('#/*&nbsp;SVN&nbsp;FILE:&nbsp;\$Id\$#', $return[1]);
  95. $return = Debugger::excerpt('[internal]', 2, 2);
  96. $this->assertTrue(empty($return));
  97. }
  98. /**
  99. * testOutput method
  100. *
  101. * @access public
  102. * @return void
  103. */
  104. function testOutput() {
  105. Debugger::invoke(Debugger::getInstance());
  106. $result = Debugger::output(false);
  107. $this->assertEqual($result, '');
  108. $out .= '';
  109. $result = Debugger::output(true);
  110. $this->assertEqual($result[0]['error'], 'Notice');
  111. $this->assertEqual($result[0]['description'], 'Undefined variable: out');
  112. $this->assertPattern('/DebuggerTest::testOutput/', $result[0]['trace']);
  113. $this->assertPattern('/SimpleInvoker::invoke/', $result[0]['trace']);
  114. ob_start();
  115. Debugger::output('txt');
  116. $other .= '';
  117. $result = ob_get_clean();
  118. $this->assertPattern('/Undefined variable: other/', $result);
  119. $this->assertPattern('/Context:/', $result);
  120. $this->assertPattern('/DebuggerTest::testOutput/', $result);
  121. $this->assertPattern('/SimpleInvoker::invoke/', $result);
  122. ob_start();
  123. Debugger::output('html');
  124. $wrong .= '';
  125. $result = ob_get_clean();
  126. $this->assertPattern('/<pre class="cake-debug">.+<\/pre>/', $result);
  127. $this->assertPattern('/<b>Notice<\/b>/', $result);
  128. $this->assertPattern('/variable: wrong/', $result);
  129. ob_start();
  130. Debugger::output('js');
  131. $buzz .= '';
  132. $result = ob_get_clean();
  133. $this->assertPattern("/<a href\='javascript:void\(0\);' onclick\='/", $result);
  134. $this->assertPattern('/<b>Notice<\/b>/', $result);
  135. $this->assertPattern('/Undefined variable: buzz/', $result);
  136. $this->assertPattern('/<a[^>]+>Code<\/a>/', $result);
  137. $this->assertPattern('/<a[^>]+>Context<\/a>/', $result);
  138. set_error_handler('simpleTestErrorHandler');
  139. }
  140. /**
  141. * testTrimPath method
  142. *
  143. * @access public
  144. * @return void
  145. */
  146. function testTrimPath() {
  147. $this->assertEqual(Debugger::trimPath(APP), 'APP' . DS);
  148. $this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
  149. }
  150. /**
  151. * testExportVar method
  152. *
  153. * @access public
  154. * @return void
  155. */
  156. function testExportVar() {
  157. App::import('Controller');
  158. $Controller = new Controller();
  159. $Controller->helpers = array('Html', 'Form');
  160. $View = new View($Controller);
  161. $result = Debugger::exportVar($View);
  162. $expected = 'ViewView::$base = NULL
  163. View::$here = NULL
  164. View::$plugin = NULL
  165. View::$name = ""
  166. View::$action = NULL
  167. View::$params = array
  168. View::$passedArgs = array
  169. View::$data = array
  170. View::$helpers = array
  171. View::$viewPath = ""
  172. View::$viewVars = array
  173. View::$layout = "default"
  174. View::$layoutPath = NULL
  175. View::$pageTitle = false
  176. View::$autoRender = true
  177. View::$autoLayout = true
  178. View::$ext = ".ctp"
  179. View::$subDir = NULL
  180. View::$themeWeb = NULL
  181. View::$cacheAction = false
  182. View::$validationErrors = array
  183. View::$hasRendered = false
  184. View::$loaded = array
  185. View::$modelScope = false
  186. View::$model = NULL
  187. View::$association = NULL
  188. View::$field = NULL
  189. View::$fieldSuffix = NULL
  190. View::$modelId = NULL
  191. View::$uuids = array
  192. View::$output = false
  193. View::$__passedVars = array
  194. View::$__scripts = array
  195. View::$__paths = array
  196. View::$_log = NULL
  197. View::$webroot = NULL';
  198. $result = str_replace(array("\t", "\r\n", "\n"), "", $result);
  199. $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
  200. $this->assertEqual($result, $expected);
  201. }
  202. /**
  203. * testLog method
  204. *
  205. * @access public
  206. * @return void
  207. */
  208. function testLog() {
  209. if (file_exists(LOGS . 'debug.log')) {
  210. unlink(LOGS . 'debug.log');
  211. }
  212. Debugger::log('cool');
  213. $result = file_get_contents(LOGS . 'debug.log');
  214. $this->assertPattern('/DebuggerTest\:\:testLog/', $result);
  215. $this->assertPattern('/"cool"/', $result);
  216. unlink(TMP . 'logs' . DS . 'debug.log');
  217. Debugger::log(array('whatever', 'here'));
  218. $result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
  219. $this->assertPattern('/DebuggerTest\:\:testLog/', $result);
  220. $this->assertPattern('/\[main\]/', $result);
  221. $this->assertPattern('/array/', $result);
  222. $this->assertPattern('/"whatever",/', $result);
  223. $this->assertPattern('/"here"/', $result);
  224. }
  225. /**
  226. * testDump method
  227. *
  228. * @access public
  229. * @return void
  230. */
  231. function testDump() {
  232. $var = array('People' => array(
  233. array(
  234. 'name' => 'joeseph',
  235. 'coat' => 'technicolor',
  236. 'hair_color' => 'brown'
  237. ),
  238. array(
  239. 'name' => 'Shaft',
  240. 'coat' => 'black',
  241. 'hair' => 'black'
  242. )
  243. )
  244. );
  245. ob_start();
  246. Debugger::dump($var);
  247. $result = ob_get_clean();
  248. $expected = "<pre>array(\n\t\"People\" => array()\n)</pre>";
  249. $this->assertEqual($expected, $result);
  250. }
  251. /**
  252. * test getInstance.
  253. *
  254. * @access public
  255. * @return void
  256. */
  257. function testGetInstance() {
  258. $result = Debugger::getInstance();
  259. $this->assertIsA($result, 'Debugger');
  260. $result = Debugger::getInstance('DebuggerTestCaseDebugger');
  261. $this->assertIsA($result, 'DebuggerTestCaseDebugger');
  262. $result = Debugger::getInstance();
  263. $this->assertIsA($result, 'DebuggerTestCaseDebugger');
  264. $result = Debugger::getInstance('Debugger');
  265. $this->assertIsA($result, 'Debugger');
  266. }
  267. }
  268. ?>