XMPPTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_XMPP */
  29. require_once CLASS_DIR . 'XMPPHP' . DIRECTORY_SEPARATOR . 'XMPP.php';
  30. /**
  31. * XMPPHP XMPPTest
  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_XMPPTest extends PHPUnit_Framework_TestCase
  41. {
  42. public function testConnectException()
  43. {
  44. try {
  45. $xmpp = new XMPPHP_XMPP('talk.google.com', 1234, 'invalidusername', 'invalidpassword', 'xmpphp', 'talk.google.com', false, XMPPHP_Log::LEVEL_VERBOSE);
  46. $xmpp->useEncryption(false);
  47. $xmpp->connect(10);
  48. $xmpp->processUntil('session_start');
  49. $xmpp->presence();
  50. $xmpp->message('stephan@jabber.wentz.it', 'This is a test message!');
  51. $xmpp->disconnect();
  52. } catch (XMPPHP_Exception $e) {
  53. return;
  54. } catch (Exception $e) {
  55. $this->fail('Unexpected Exception thrown: ' . $e->getMessage());
  56. }
  57. $this->fail('Expected XMPPHP_Exception not thrown!');
  58. }
  59. public function testAuthException()
  60. {
  61. try {
  62. $xmpp = new XMPPHP_XMPP('jabber.wentz.it', 5222, 'invalidusername', 'invalidpassword', 'xmpphp', 'jabber.wentz.it', true, XMPPHP_Log::LEVEL_VERBOSE);
  63. $xmpp->useEncryption(false);
  64. $xmpp->connect(10);
  65. $xmpp->processUntil('session_start');
  66. $xmpp->presence();
  67. $xmpp->message('stephan@jabber.wentz.it', 'This is a test message!');
  68. $xmpp->disconnect();
  69. } catch (XMPPHP_Exception $e) {
  70. return;
  71. } catch (Exception $e) {
  72. $this->fail('Unexpected Exception thrown: ' . $e->getMessage());
  73. }
  74. $this->fail('Expected XMPPHP_Exception not thrown!');
  75. }
  76. }