/code/ryzom/tools/server/www/webtt/cake/tests/cases/libs/log/file_log.test.php

https://bitbucket.org/mattraykowski/ryzomcore_demoshard · PHP · 79 lines · 33 code · 10 blank · 36 comment · 0 complexity · d9f687b5b54895ab5ec64106b3496b59 MD5 · raw file

  1. <?php
  2. /**
  3. * FileLogTest file
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The Open Group Test Suite License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @filesource
  14. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  16. * @package cake
  17. * @subpackage cake.tests.cases.libs.log
  18. * @since CakePHP(tm) v 1.3
  19. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  20. */
  21. require_once LIBS . 'log' . DS . 'file_log.php';
  22. /**
  23. * CakeLogTest class
  24. *
  25. * @package cake
  26. * @subpackage cake.tests.cases.libs
  27. */
  28. class FileLogTest extends CakeTestCase {
  29. /**
  30. * testLogFileWriting method
  31. *
  32. * @access public
  33. * @return void
  34. */
  35. function testLogFileWriting() {
  36. @unlink(LOGS . 'error.log');
  37. $log =& new FileLog();
  38. $log->write('warning', 'Test warning');
  39. $this->assertTrue(file_exists(LOGS . 'error.log'));
  40. $result = file_get_contents(LOGS . 'error.log');
  41. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning/', $result);
  42. unlink(LOGS . 'error.log');
  43. @unlink(LOGS . 'debug.log');
  44. $log->write('debug', 'Test warning');
  45. $this->assertTrue(file_exists(LOGS . 'debug.log'));
  46. $result = file_get_contents(LOGS . 'debug.log');
  47. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Debug: Test warning/', $result);
  48. unlink(LOGS . 'debug.log');
  49. @unlink(LOGS . 'random.log');
  50. $log->write('random', 'Test warning');
  51. $this->assertTrue(file_exists(LOGS . 'random.log'));
  52. $result = file_get_contents(LOGS . 'random.log');
  53. $this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Random: Test warning/', $result);
  54. unlink(LOGS . 'random.log');
  55. }
  56. /**
  57. * test using the path setting to write logs in other places.
  58. *
  59. * @return void
  60. */
  61. function testPathSetting() {
  62. $path = TMP . 'tests' . DS;
  63. @unlink($path . 'error.log');
  64. $log =& new FileLog(compact('path'));
  65. $log->write('warning', 'Test warning');
  66. $this->assertTrue(file_exists($path . 'error.log'));
  67. unlink($path . 'error.log');
  68. }
  69. }