MetamarkNetTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Service_ShortUrl_MetamarkNet */
  22. require_once 'Zend/Service/ShortUrl/MetamarkNet.php';
  23. /**
  24. * @package Zend_Service
  25. * @subpackage UnitTests
  26. * @see http://metamark.net/docs/api/rest.html
  27. */
  28. class Zend_Service_ShortUrl_MetamarkNetTest extends PHPUnit_Framework_TestCase
  29. {
  30. /**
  31. * Zend_Service_ShortUrl_MetamarkNet object
  32. *
  33. * @var Zend_Service_ShortUrl_MetamarkNet
  34. */
  35. protected $_s;
  36. /**
  37. * Creates a new Zend_Service_ShortUrl_MetamarkNet object for each test method
  38. *
  39. * @return void
  40. */
  41. public function setUp ()
  42. {
  43. if (!defined('TESTS_ZEND_SERVICE_SHORTURL_METAMARKNET_ENABLED')
  44. || !constant('TESTS_ZEND_SERVICE_SHORTURL_METAMARKNET_ENABLED')
  45. ) {
  46. $this->markTestSkipped('Testing Zend_Service_ShortUrl_MetamarkNetTest only works when TESTS_ZEND_SERVICE_SHORTURL_METAMARKNET_ENABLED is set.');
  47. }
  48. Zend_Service_Abstract::setHttpClient(new Zend_Http_Client());
  49. $this->_s = new Zend_Service_ShortUrl_MetamarkNet();
  50. }
  51. public function testShortenEmptyUrlException()
  52. {
  53. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  54. $this->_s->shorten('');
  55. }
  56. public function testShortenIncorrectUrlException()
  57. {
  58. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  59. $this->_s->shorten('wrongAdress.cccc');
  60. }
  61. public function testShorten()
  62. {
  63. $urls = array(
  64. 'http://framework.zend.com/' => 'http://xrl.us/bh4ptf',
  65. 'http://framework.zend.com/manual/en/' => 'http://xrl.us/bh4pth'
  66. );
  67. foreach ($urls as $url => $shortenedUrl) {
  68. $this->assertEquals($shortenedUrl, $this->_s->shorten($url));
  69. }
  70. }
  71. public function testUnshorten()
  72. {
  73. $urls = array(
  74. 'http://framework.zend.com/' => 'http://xrl.us/bh4ptf',
  75. 'http://framework.zend.com/manual/en/' => 'http://xrl.us/bh4pth'
  76. );
  77. foreach ($urls as $url => $shortenedUrl) {
  78. $this->assertEquals($url, $this->_s->unshorten($shortenedUrl));
  79. }
  80. }
  81. public function testUnshortenEmptyUrlException()
  82. {
  83. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  84. $this->_s->unshorten('');
  85. }
  86. public function testUnshortenIncorrectUrlException()
  87. {
  88. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  89. $this->_s->unshorten('wrongAdress.cccc');
  90. }
  91. public function testUnshortenWrongUrlException()
  92. {
  93. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  94. $this->_s->unshorten('http://www.zend.com');
  95. }
  96. }