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

https://github.com/dextercowley/joomla-cms · PHP · 470 lines · 217 code · 48 blank · 205 comment · 0 complexity · 148ffadf463144e0472fe209962a8666 MD5 · raw file

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