TinyUrlComTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_TinyUrlCom */
  26. require_once 'Zend/Service/ShortUrl/TinyUrlCom.php';
  27. /**
  28. * @package Zend_Service
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Service_ShortUrl_TinyUrlComTest extends PHPUnit_Framework_TestCase
  32. {
  33. /**
  34. * Zend_Service_TinyUrlCom object
  35. *
  36. * @var Zend_Service_TinyUrlCom
  37. */
  38. protected $_s;
  39. /**
  40. * Creates a new Zend_Service_TinyUrlCom object for each test method
  41. *
  42. * @return void
  43. */
  44. public function setUp ()
  45. {
  46. Zend_Service_Abstract::setHttpClient(new Zend_Http_Client());
  47. $this->_s = new Zend_Service_ShortUrl_TinyUrlCom();
  48. }
  49. public function testShortenEmptyUrlException()
  50. {
  51. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  52. $this->_s->shorten('');
  53. }
  54. public function testShortenIncorrectUrlException()
  55. {
  56. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  57. $this->_s->shorten('wrongAdress.cccc');
  58. }
  59. public function testShorten()
  60. {
  61. $urls = array(
  62. 'http://framework.zend.com/' => 'http://tinyurl.com/rxtuq',
  63. 'http://framework.zend.com/manual/en/' => 'http://tinyurl.com/ynvdzf'
  64. );
  65. foreach ($urls as $url => $shortenedUrl) {
  66. $this->assertEquals($shortenedUrl, $this->_s->shorten($url));
  67. }
  68. }
  69. public function testUnshorten()
  70. {
  71. $urls = array(
  72. 'http://framework.zend.com/' => 'http://tinyurl.com/rxtuq',
  73. 'http://framework.zend.com/manual/en/' => 'http://tinyurl.com/ynvdzf'
  74. );
  75. foreach ($urls as $url => $shortenedUrl) {
  76. $this->assertEquals($url, $this->_s->unshorten($shortenedUrl));
  77. }
  78. }
  79. public function testUnshortenEmptyUrlException()
  80. {
  81. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  82. $this->_s->unshorten('');
  83. }
  84. public function testUnshortenIncorrectUrlException()
  85. {
  86. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  87. $this->_s->unshorten('wrongAdress.cccc');
  88. }
  89. public function testUnshortenWrongUrlException()
  90. {
  91. $this->setExpectedException('Zend_Service_ShortUrl_Exception');
  92. $this->_s->unshorten('http://zend.com');
  93. }
  94. }