HipChatPHPTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Some simple unit tests to help test this library. These tests are not
  4. * intended to be used to verify the API response data.
  5. *
  6. * TODO: Test valid requests. What API token to use?
  7. */
  8. require_once dirname(__FILE__).'/../src/HipChat/HipChat.php';
  9. require_once 'PHPUnit/Framework.php';
  10. class HipChatPHPTest extends PHPUnit_Framework_TestCase {
  11. private $target = 'https://api.hipchat.com';
  12. public function testBadToken() {
  13. $hc = new HipChat\HipChat('hipchat-php-test-bad-token', $this->target);
  14. $this->setExpectedException('HipChat\HipChat_Exception');
  15. $hc->get_rooms();
  16. }
  17. public function testBadTargetHost() {
  18. $bad_target = 'http://does-not-exist.hipchat.com';
  19. $hc = new HipChat\HipChat('hipchat-php-test-token', $bad_target);
  20. $this->setExpectedException('HipChat\HipChat_Exception');
  21. $hc->get_rooms();
  22. }
  23. public function testBadApiMethod() {
  24. $hc = new HipChat\HipChat('hipchat-php-test-token', $this->target);
  25. $this->setExpectedException('HipChat\HipChat_Exception');
  26. $hc->make_request('bad/method');
  27. }
  28. /**
  29. * Tests for a mention at the first position in the message.
  30. *
  31. * In PHP, curl uses the syntax "@test.php" to send *the file*
  32. * test.php via curl.
  33. *
  34. * This test should actually just work (i.e. not throwing an exception)
  35. *
  36. * @link http://www.php.net/manual/en/function.curl-setopt.php see reference for CURLOPT_POSTFIELDS
  37. */
  38. public function testMentionAtFirstPosition ()
  39. {
  40. $hc = new HipChat\HipChat('hipchat-php-test-token', $this->target);
  41. $hc->message_room(123, '@sender', '@test test');
  42. }
  43. }