ErrorTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata_Gapps
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com);
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Gdata/Gapps/Error.php';
  22. require_once 'Zend/Gdata/Gapps.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. */
  27. class Zend_Gdata_Gapps_ErrorTest extends PHPUnit_Framework_TestCase
  28. {
  29. public function setUp() {
  30. $this->error = new Zend_Gdata_Gapps_Error();
  31. }
  32. public function testCanSetAndGetErrorCodeUsingConstant() {
  33. $this->error->setErrorCode(
  34. Zend_Gdata_Gapps_Error::INVALID_EMAIL_ADDRESS);
  35. $this->assertEquals(Zend_Gdata_Gapps_Error::INVALID_EMAIL_ADDRESS,
  36. $this->error->getErrorCode());
  37. }
  38. public function testCanSetAndGetErrorCodeUsingInteger() {
  39. $this->error->setErrorCode(123);
  40. $this->assertEquals(123, $this->error->getErrorCode());
  41. }
  42. public function testCanSetAndGetReason() {
  43. $text = "The foo is missing a bar.";
  44. $this->error->setReason($text);
  45. $this->assertEquals($text, $this->error->getReason());
  46. }
  47. public function testCanSetAndGetInvalidInput() {
  48. $text = "for___baz";
  49. $this->error->setInvalidInput($text);
  50. $this->assertEquals($text, $this->error->getInvalidInput());
  51. }
  52. public function testContstructorAllowsSettingAllVariables() {
  53. $this->error = new Zend_Gdata_Gapps_Error(
  54. Zend_Gdata_Gapps_Error::USER_DELETED_RECENTLY,
  55. "foo", "bar");
  56. $this->assertEquals(Zend_Gdata_Gapps_Error::USER_DELETED_RECENTLY,
  57. $this->error->getErrorCode());
  58. $this->assertEquals("foo", $this->error->getReason());
  59. $this->assertEquals("bar", $this->error->getInvalidInput());
  60. }
  61. public function testToStringProvidesHelpfulMessage() {
  62. $this->error->setErrorCode(Zend_Gdata_Gapps_Error::USER_SUSPENDED);
  63. $this->error->setReason("The foo is missing a bar.");
  64. $this->error->setInvalidInput("for___baz");
  65. $this->assertEquals("Error 1101: The foo is missing a bar.\n\tInvalid Input: \"for___baz\"", $this->error->__toString());
  66. $this->error->setErrorCode(Zend_Gdata_Gapps_Error::UNKNOWN_ERROR);
  67. $this->error->setReason("Unknown error.");
  68. $this->error->setInvalidInput("blah");
  69. $this->assertEquals("Error 1000: Unknown error.\n\tInvalid Input: \"blah\"", $this->error->__toString());
  70. }
  71. }