GdataTest.php 3.9 KB

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