PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/suites/legacy/error/JErrorTest.php

http://github.com/joomla/joomla-platform
PHP | 473 lines | 219 code | 48 blank | 206 comment | 0 complexity | 40860836e6d5791f6fd36bb21bf0b4fa MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package Joomla.UnitTest
  4. * @subpackage Error
  5. *
  6. * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. require_once JPATH_PLATFORM . '/legacy/error/error.php';
  10. require_once JPATH_PLATFORM . '/legacy/exception/exception.php';
  11. require_once __DIR__ . '/JErrorInspector.php';
  12. /**
  13. * Test class for JError.
  14. *
  15. * @package Joomla.UnitTest
  16. * @subpackage Error
  17. *
  18. * @since 12.3
  19. */
  20. class JErrorTest extends TestCase
  21. {
  22. /**
  23. * Test JError::getError
  24. *
  25. * @return void
  26. */
  27. public function testGetError()
  28. {
  29. JErrorInspector::manipulateStack(array());
  30. $this->assertThat(
  31. JError::getError(),
  32. $this->isFalse(),
  33. 'There was no error on the error stack but getError did not return false'
  34. );
  35. // We normally couldn't have strings, but this is only a test
  36. JErrorInspector::manipulateStack(array('Error1', 'Error2'));
  37. $this->assertThat(
  38. JError::getError(),
  39. $this->equalTo('Error1'),
  40. 'We did not get the proper value back from getError - it should have returned our fake error'
  41. );
  42. $this->assertThat(
  43. JErrorInspector::inspectStack(),
  44. $this->equalTo(array('Error1', 'Error2')),
  45. 'The stack was changed by getError even though unset was false'
  46. );
  47. $this->assertThat(
  48. JError::getError(true),
  49. $this->equalTo('Error1'),
  50. 'We did not get the proper value back from getError - it should have returned our fake error'
  51. );
  52. $this->assertThat(
  53. JErrorInspector::inspectStack(),
  54. $this->equalTo(array('Error2')),
  55. 'The stack was either not changed or changed the wrong way by getError (with unset true)'
  56. );
  57. // Here we remove any junk left on the error stack
  58. JErrorInspector::manipulateStack(array());
  59. }
  60. /**
  61. * Test JError::getErrors
  62. *
  63. * @return void
  64. */
  65. public function testGetErrors()
  66. {
  67. JErrorInspector::manipulateStack(array('value1', 'value2', 'value3'));
  68. $this->assertThat(
  69. JError::getErrors(),
  70. $this->equalTo(array('value1', 'value2', 'value3')),
  71. 'Somehow a basic getter did not manage to return the static value'
  72. );
  73. JErrorInspector::manipulateStack(array());
  74. }
  75. /**
  76. * Test JError::addToStack
  77. *
  78. * @return void
  79. */
  80. public function testAddToStack()
  81. {
  82. // Remove the following lines when the framework is fixed.
  83. // $this->markTestSkipped('The framework is currently broken. Skipping this test.');
  84. JErrorInspector::manipulateStack(array('value1', 'value2', 'value3'));
  85. $exception = new JException('This is the error message', 1056, 'error');
  86. JError::addToStack($exception);
  87. $stack = JErrorInspector::inspectStack();
  88. $this->assertThat(
  89. $stack[3],
  90. $this->identicalTo($exception),
  91. 'The exception did not get properly added to the stack'
  92. );
  93. JErrorInspector::manipulateStack(array());
  94. }
  95. /**
  96. * Test JError::raise
  97. *
  98. * @todo Implement testRaise().
  99. *
  100. * @return void
  101. */
  102. public function testRaise()
  103. {
  104. // Remove the following lines when you implement this test.
  105. $this->markTestIncomplete(
  106. 'This test has not been implemented yet.'
  107. );
  108. }
  109. /**
  110. * Test JError::throwError
  111. *
  112. * @todo Implement testThrowError().
  113. *
  114. * @return void
  115. */
  116. public function testThrowError()
  117. {
  118. // Remove the following lines when you implement this test.
  119. $this->markTestIncomplete(
  120. 'This test has not been implemented yet.'
  121. );
  122. }
  123. /**
  124. * Test JError::raiseError
  125. *
  126. * @todo Implement testRaiseError().
  127. *
  128. * @return void
  129. */
  130. public function testRaiseError()
  131. {
  132. // Remove the following lines when you implement this test.
  133. $this->markTestIncomplete(
  134. 'This test has not been implemented yet.'
  135. );
  136. }
  137. /**
  138. * Test JError::raiseWarning
  139. *
  140. * @todo Implement testRaiseWarning().
  141. *
  142. * @return void
  143. */
  144. public function testRaiseWarning()
  145. {
  146. // Remove the following lines when you implement this test.
  147. $this->markTestIncomplete(
  148. 'This test has not been implemented yet.'
  149. );
  150. }
  151. /**
  152. * Test JError::raiseNotice
  153. *
  154. * @todo Implement testRaiseNotice().
  155. *
  156. * @return void
  157. */
  158. public function testRaiseNotice()
  159. {
  160. // Remove the following lines when you implement this test.
  161. $this->markTestIncomplete(
  162. 'This test has not been implemented yet.'
  163. );
  164. }
  165. /**
  166. * Test JError::getErrorHandling
  167. *
  168. * @todo Implement testGetErrorHandling().
  169. *
  170. * @return void
  171. */
  172. public function testGetErrorHandling()
  173. {
  174. // Remove the following lines when you implement this test.
  175. $this->markTestIncomplete(
  176. 'This test has not been implemented yet.'
  177. );
  178. }
  179. /**
  180. * Test JError::setErrorHandling
  181. *
  182. * @return void
  183. */
  184. public function testSetErrorHandling()
  185. {
  186. JErrorInspector::manipulateLevels(
  187. array(
  188. E_NOTICE => 'Notice',
  189. E_WARNING => 'Warning',
  190. E_ERROR => 'Error'
  191. )
  192. );
  193. $errorHandling = JErrorInspector::inspectHandlers();
  194. $this->assertThat(
  195. JError::setErrorHandling(E_NOTICE, 'message'),
  196. $this->isTrue(),
  197. 'Setting a message error handler failed'
  198. );
  199. $handlers = JErrorInspector::inspectHandlers();
  200. $this->assertThat(
  201. $handlers[E_NOTICE],
  202. $this->equalTo(array('mode' => 'message')),
  203. 'The error handler did not get set to message'
  204. );
  205. $this->assertThat(
  206. JError::setErrorHandling(E_NOTICE, 'callback', array($this, 'callbackHandler')),
  207. $this->isTrue(),
  208. 'Setting a message error handler failed'
  209. );
  210. $handlers = JErrorInspector::inspectHandlers();
  211. $this->assertThat(
  212. $handlers[E_NOTICE],
  213. $this->equalTo(array('mode' => 'callback', 'options' => array($this, 'callbackHandler'))),
  214. 'The error handler did not get set to callback'
  215. );
  216. JErrorInspector::manipulateHandlers($errorHandling);
  217. }
  218. /**
  219. * Test JError::setErrorHandling
  220. *
  221. * Callback for testSetErrorHandling
  222. *
  223. * @return void
  224. */
  225. public function callbackHandler()
  226. {
  227. return;
  228. }
  229. /**
  230. * Test JError::attachHandler
  231. *
  232. * @todo Implement testAttachHandler().
  233. *
  234. * @return void
  235. */
  236. public function testAttachHandler()
  237. {
  238. // Remove the following lines when you implement this test.
  239. $this->markTestIncomplete(
  240. 'This test has not been implemented yet.'
  241. );
  242. }
  243. /**
  244. * Test JError::detachHandler
  245. *
  246. * @todo Implement testDetachHandler().
  247. *
  248. * @return void
  249. */
  250. public function testDetachHandler()
  251. {
  252. // Remove the following lines when you implement this test.
  253. $this->markTestIncomplete(
  254. 'This test has not been implemented yet.'
  255. );
  256. }
  257. /**
  258. * Test JError::registerErrorLevel
  259. *
  260. * @todo Implement testRegisterErrorLevel().
  261. *
  262. * @return void
  263. */
  264. public function testRegisterErrorLevel()
  265. {
  266. // Remove the following lines when you implement this test.
  267. $this->markTestIncomplete(
  268. 'This test has not been implemented yet.'
  269. );
  270. }
  271. /**
  272. * Test JError::translateErrorLevel
  273. *
  274. * @todo Implement testTranslateErrorLevel().
  275. *
  276. * @return void
  277. */
  278. public function testTranslateErrorLevel()
  279. {
  280. // Remove the following lines when you implement this test.
  281. $this->markTestIncomplete(
  282. 'This test has not been implemented yet.'
  283. );
  284. }
  285. /**
  286. * Test JError::handleIgnore
  287. *
  288. * @todo Implement testHandleIgnore().
  289. *
  290. * @return void
  291. */
  292. public function testHandleIgnore()
  293. {
  294. // Remove the following lines when you implement this test.
  295. $this->markTestIncomplete(
  296. 'This test has not been implemented yet.'
  297. );
  298. }
  299. /**
  300. * Test JError::handleEcho
  301. *
  302. * @todo Implement testHandleEcho().
  303. *
  304. * @return void
  305. */
  306. public function testHandleEcho()
  307. {
  308. // Remove the following lines when you implement this test.
  309. $this->markTestIncomplete(
  310. 'This test has not been implemented yet.'
  311. );
  312. }
  313. /**
  314. * Test JError::handleVerbose
  315. *
  316. * @todo Implement testHandleVerbose().
  317. *
  318. * @return void
  319. */
  320. public function testHandleVerbose()
  321. {
  322. // Remove the following lines when you implement this test.
  323. $this->markTestIncomplete(
  324. 'This test has not been implemented yet.'
  325. );
  326. }
  327. /**
  328. * Test JError::handleDie
  329. *
  330. * @todo Implement testHandleDie().
  331. *
  332. * @return void
  333. */
  334. public function testHandleDie()
  335. {
  336. // Remove the following lines when you implement this test.
  337. $this->markTestIncomplete(
  338. 'This test has not been implemented yet.'
  339. );
  340. }
  341. /**
  342. * Test JError::handleMessage
  343. *
  344. * @todo Implement testHandleMessage().
  345. *
  346. * @return void
  347. */
  348. public function testHandleMessage()
  349. {
  350. // Remove the following lines when you implement this test.
  351. $this->markTestIncomplete(
  352. 'This test has not been implemented yet.'
  353. );
  354. }
  355. /**
  356. * Test JError::handleLog
  357. *
  358. * @todo Implement testHandleLog().
  359. *
  360. * @return void
  361. */
  362. public function testHandleLog()
  363. {
  364. // Remove the following lines when you implement this test.
  365. $this->markTestIncomplete(
  366. 'This test has not been implemented yet.'
  367. );
  368. }
  369. /**
  370. * Test JError::handleCallback
  371. *
  372. * @todo Implement testHandleCallback().
  373. *
  374. * @return void
  375. */
  376. public function testHandleCallback()
  377. {
  378. // Remove the following lines when you implement this test.
  379. $this->markTestIncomplete(
  380. 'This test has not been implemented yet.'
  381. );
  382. }
  383. /**
  384. * Test JError::customErrorPage
  385. *
  386. * @todo Implement testCustomErrorPage().
  387. *
  388. * @return void
  389. */
  390. public function testCustomErrorPage()
  391. {
  392. // Remove the following lines when you implement this test.
  393. $this->markTestIncomplete(
  394. 'This test has not been implemented yet.'
  395. );
  396. }
  397. /**
  398. * Test JError::customerErrorHandler
  399. *
  400. * @todo Implement testCustomErrorHandler().
  401. *
  402. * @return void
  403. */
  404. public function testCustomErrorHandler()
  405. {
  406. // Remove the following lines when you implement this test.
  407. $this->markTestIncomplete(
  408. 'This test has not been implemented yet.'
  409. );
  410. }
  411. /**
  412. * Test JError::renderBacktrace
  413. *
  414. * @todo Implement testRenderBacktrace().
  415. *
  416. * @return void
  417. */
  418. public function testRenderBacktrace()
  419. {
  420. // Remove the following lines when you implement this test.
  421. $this->markTestIncomplete(
  422. 'This test has not been implemented yet.'
  423. );
  424. }
  425. }