2
0

GdataTest.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  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/Http/Client.php';
  22. require_once 'Zend/Gdata.php';
  23. /**
  24. * @package Zend_Gdata
  25. * @subpackage UnitTests
  26. */
  27. class Zend_Gdata_GdataTest extends PHPUnit_Framework_TestCase
  28. {
  29. public function testDefaultHttpClient()
  30. {
  31. $gdata = new Zend_Gdata();
  32. $client = $gdata->getHttpClient();
  33. $this->assertTrue($client instanceof Zend_Http_Client,
  34. 'Expecting object of type Zend_Http_Client, got '
  35. . (gettype($client) == 'object' ? get_class($client) : gettype($client))
  36. );
  37. }
  38. public function testSpecificHttpClient()
  39. {
  40. $client = new Zend_Http_Client();
  41. $gdata = new Zend_Gdata($client);
  42. $client2 = $gdata->getHttpClient();
  43. $this->assertTrue($client2 instanceof Zend_Http_Client,
  44. 'Expecting object of type Zend_Http_Client, got '
  45. . (gettype($client) == 'object' ? get_class($client) : gettype($client))
  46. );
  47. $this->assertSame($client, $client2);
  48. }
  49. public function testExceptionNotHttpClient()
  50. {
  51. $obj = new ArrayObject();
  52. try {
  53. $gdata = new Zend_Gdata($obj);
  54. $this->fail('Expecting to catch Zend_Gdata_App_HttpException');
  55. } catch (Exception $e) {
  56. $this->assertThat($e, $this->isInstanceOf('Zend_Gdata_App_HttpException'),
  57. 'Expecting Zend_Gdata_App_HttpException, got '.get_class($e));
  58. $this->assertEquals('Argument is not an instance of Zend_Http_Client.', $e->getMessage());
  59. }
  60. }
  61. public function testGetFeedExceptionInvalidLocationType()
  62. {
  63. $gdata = new Zend_Gdata();
  64. try {
  65. // give it neither a string nor a Zend_Gdata_Query object,
  66. // and see if it throws an exception.
  67. $feed = $gdata->getFeed(new stdClass());
  68. $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException');
  69. } catch (Zend_Exception $e) {
  70. $this->assertType('Zend_Gdata_App_InvalidArgumentException', $e,
  71. 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e));
  72. $this->assertEquals('You must specify the location as either a string URI or a child of Zend_Gdata_Query', $e->getMessage());
  73. }
  74. }
  75. public function testGetEntryExceptionInvalidLocationType()
  76. {
  77. $gdata = new Zend_Gdata();
  78. try {
  79. // give it neither a string nor a Zend_Gdata_Query object,
  80. // and see if it throws an exception.
  81. $feed = $gdata->getEntry(new stdClass());
  82. $this->fail('Expecting to catch Zend_Gdata_App_InvalidArgumentException');
  83. } catch (Zend_Exception $e) {
  84. $this->assertType('Zend_Gdata_App_InvalidArgumentException', $e,
  85. 'Expecting Zend_Gdata_App_InvalidArgumentException, got '.get_class($e));
  86. $this->assertEquals('You must specify the location as either a string URI or a child of Zend_Gdata_Query', $e->getMessage());
  87. }
  88. }
  89. }