TinyUrlComTest.php 2.9 KB

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