AudioscrobblerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_Service_Audioscrobbler
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @see Zend_Service_Audioscrobbler
  28. */
  29. require_once 'Zend/Service/Audioscrobbler.php';
  30. require_once 'AudioscrobblerTestCase.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_Service_Audioscrobbler
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Service
  38. * @group Zend_Service_Audioscrobbler
  39. */
  40. class Zend_Service_Audioscrobbler_AudioscrobblerTest extends Zend_Service_Audioscrobbler_AudioscrobblerTestCase
  41. {
  42. public function testRequestThrowsHttpClientExceptionWithNoUserError()
  43. {
  44. $this->setAudioscrobblerResponse(self::readTestResponse('errorNoUserExists'));
  45. $as = $this->getAudioscrobblerService();
  46. $as->set('user', 'foobarfoo');
  47. try {
  48. $response = $as->userGetProfileInformation();
  49. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  50. } catch(Zend_Http_Client_Exception $e) {
  51. $this->assertContains("No user exists with this name", $e->getMessage());
  52. }
  53. }
  54. public function testRequestThrowsHttpClientExceptionWithoutSuccessfulResponse()
  55. {
  56. $this->setAudioscrobblerResponse(self::readTestResponse('errorResponseStatusError'));
  57. $as = $this->getAudioscrobblerService();
  58. $as->set('user', 'foobarfoo');
  59. try {
  60. $response = $as->userGetProfileInformation();
  61. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  62. } catch(Zend_Http_Client_Exception $e) {
  63. $this->assertContains("404", $e->getMessage());
  64. }
  65. }
  66. /**
  67. * @group ZF-4509
  68. */
  69. public function testSetViaCallIntercept()
  70. {
  71. $as = new Zend_Service_Audioscrobbler();
  72. $as->setUser("foobar");
  73. $as->setAlbum("Baz");
  74. $this->assertEquals("foobar", $as->get("user"));
  75. $this->assertEquals("Baz", $as->get("album"));
  76. }
  77. /**
  78. * @group ZF-6251
  79. */
  80. public function testUnknownMethodViaCallInterceptThrowsException()
  81. {
  82. $this->setExpectedException("Zend_Service_Exception");
  83. $as = new Zend_Service_Audioscrobbler();
  84. $as->someInvalidMethod();
  85. }
  86. /**
  87. * @group ZF-6251
  88. */
  89. public function testCallInterceptMethodsRequireExactlyOneParameterAndThrowExceptionOtherwise()
  90. {
  91. $this->setExpectedException("Zend_Service_Exception");
  92. $as = new Zend_Service_Audioscrobbler();
  93. $as->setUser();
  94. }
  95. public static function readTestResponse($file)
  96. {
  97. return file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . $file);
  98. }
  99. }