ErrorTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once 'Zend/Gdata/Gapps/Error.php';
  23. require_once 'Zend/Gdata/Gapps.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_Gapps
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Gdata
  31. * @group Zend_Gdata_Gapps
  32. */
  33. class Zend_Gdata_Gapps_ErrorTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->error = new Zend_Gdata_Gapps_Error();
  37. }
  38. public function testCanSetAndGetErrorCodeUsingConstant() {
  39. $this->error->setErrorCode(
  40. Zend_Gdata_Gapps_Error::INVALID_EMAIL_ADDRESS);
  41. $this->assertEquals(Zend_Gdata_Gapps_Error::INVALID_EMAIL_ADDRESS,
  42. $this->error->getErrorCode());
  43. }
  44. public function testCanSetAndGetErrorCodeUsingInteger() {
  45. $this->error->setErrorCode(123);
  46. $this->assertEquals(123, $this->error->getErrorCode());
  47. }
  48. public function testCanSetAndGetReason() {
  49. $text = "The foo is missing a bar.";
  50. $this->error->setReason($text);
  51. $this->assertEquals($text, $this->error->getReason());
  52. }
  53. public function testCanSetAndGetInvalidInput() {
  54. $text = "for___baz";
  55. $this->error->setInvalidInput($text);
  56. $this->assertEquals($text, $this->error->getInvalidInput());
  57. }
  58. public function testContstructorAllowsSettingAllVariables() {
  59. $this->error = new Zend_Gdata_Gapps_Error(
  60. Zend_Gdata_Gapps_Error::USER_DELETED_RECENTLY,
  61. "foo", "bar");
  62. $this->assertEquals(Zend_Gdata_Gapps_Error::USER_DELETED_RECENTLY,
  63. $this->error->getErrorCode());
  64. $this->assertEquals("foo", $this->error->getReason());
  65. $this->assertEquals("bar", $this->error->getInvalidInput());
  66. }
  67. public function testToStringProvidesHelpfulMessage() {
  68. $this->error->setErrorCode(Zend_Gdata_Gapps_Error::USER_SUSPENDED);
  69. $this->error->setReason("The foo is missing a bar.");
  70. $this->error->setInvalidInput("for___baz");
  71. $this->assertEquals("Error 1101: The foo is missing a bar.\n\tInvalid Input: \"for___baz\"", $this->error->__toString());
  72. $this->error->setErrorCode(Zend_Gdata_Gapps_Error::UNKNOWN_ERROR);
  73. $this->error->setReason("Unknown error.");
  74. $this->error->setInvalidInput("blah");
  75. $this->assertEquals("Error 1000: Unknown error.\n\tInvalid Input: \"blah\"", $this->error->__toString());
  76. }
  77. }