AudioscrobblerTest.php 3.5 KB

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