2
0

MetamarkNetTest.php 3.1 KB

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