LogTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * XMPPHP: The PHP XMPP Library
  4. * Copyright (C) 2008 Nathanael C. Fritz
  5. * This file is part of SleekXMPP.
  6. *
  7. * XMPPHP is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * XMPPHP is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with XMPPHP; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category xmpphp
  22. * @package XMPPHP
  23. * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
  24. * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
  25. * @author Michael Garvin <JID: gar@netflint.net>
  26. * @copyright 2008 Nathanael C. Fritz
  27. */
  28. /** XMPPHP_Log */
  29. require_once CLASS_DIR . 'XMPPHP' . DIRECTORY_SEPARATOR . 'Log.php';
  30. /**
  31. * XMPPHP LogTest
  32. *
  33. * @package XMPPHP
  34. * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
  35. * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
  36. * @author Michael Garvin <JID: gar@netflint.net>
  37. * @copyright 2008 Nathanael C. Fritz
  38. * @version $Id$
  39. */
  40. class XMPPHP_LogTest extends PHPUnit_Framework_TestCase
  41. {
  42. public function testPrintoutNoOutput()
  43. {
  44. $log = new XMPPHP_Log();
  45. $msg = 'I am a test log message';
  46. ob_start();
  47. $log->log('test');
  48. $result = ob_get_clean();
  49. $this->assertEquals('', $result);
  50. }
  51. public function testPrintoutOutput()
  52. {
  53. $log = new XMPPHP_Log(true);
  54. $msg = 'I am a test log message';
  55. ob_start();
  56. $log->log($msg);
  57. $result = ob_get_clean();
  58. $this->assertContains($msg, $result);
  59. }
  60. public function testPrintoutNoOutputWithDefaultLevel()
  61. {
  62. $log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_ERROR);
  63. $msg = 'I am a test log message';
  64. ob_start();
  65. $log->log($msg);
  66. $result = ob_get_clean();
  67. $this->assertSame('', $result);
  68. }
  69. public function testPrintoutOutputWithDefaultLevel()
  70. {
  71. $log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_INFO);
  72. $msg = 'I am a test log message';
  73. ob_start();
  74. $log->log($msg);
  75. $result = ob_get_clean();
  76. $this->assertContains($msg, $result);
  77. }
  78. public function testPrintoutNoOutputWithCustomLevel()
  79. {
  80. $log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_INFO);
  81. $msg = 'I am a test log message';
  82. ob_start();
  83. $log->log($msg, XMPPHP_Log::LEVEL_DEBUG);
  84. $result = ob_get_clean();
  85. $this->assertSame('', $result);
  86. }
  87. public function testPrintoutOutputWithCustomLevel()
  88. {
  89. $log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_INFO);
  90. $msg = 'I am a test log message';
  91. ob_start();
  92. $log->log($msg, XMPPHP_Log::LEVEL_INFO);
  93. $result = ob_get_clean();
  94. $this->assertContains($msg, $result);
  95. }
  96. public function testExplicitPrintout()
  97. {
  98. $log = new XMPPHP_Log(false);
  99. $msg = 'I am a test log message';
  100. ob_start();
  101. $log->log($msg);
  102. $result = ob_get_clean();
  103. $this->assertSame('', $result);
  104. }
  105. public function testExplicitPrintoutResult()
  106. {
  107. $log = new XMPPHP_Log(false);
  108. $msg = 'I am a test log message';
  109. ob_start();
  110. $log->log($msg);
  111. $result = ob_get_clean();
  112. $this->assertSame('', $result);
  113. ob_start();
  114. $log->printout();
  115. $result = ob_get_clean();
  116. $this->assertContains($msg, $result);
  117. }
  118. public function testExplicitPrintoutClear()
  119. {
  120. $log = new XMPPHP_Log(false);
  121. $msg = 'I am a test log message';
  122. ob_start();
  123. $log->log($msg);
  124. $result = ob_get_clean();
  125. $this->assertSame('', $result);
  126. ob_start();
  127. $log->printout();
  128. $result = ob_get_clean();
  129. $this->assertContains($msg, $result);
  130. ob_start();
  131. $log->printout();
  132. $result = ob_get_clean();
  133. $this->assertSame('', $result);
  134. }
  135. public function testExplicitPrintoutLevel()
  136. {
  137. $log = new XMPPHP_Log(false, XMPPHP_Log::LEVEL_ERROR);
  138. $msg = 'I am a test log message';
  139. ob_start();
  140. $log->log($msg);
  141. $result = ob_get_clean();
  142. $this->assertSame('', $result);
  143. ob_start();
  144. $log->printout(true, XMPPHP_Log::LEVEL_INFO);
  145. $result = ob_get_clean();
  146. $this->assertSame('', $result);
  147. }
  148. }