IpLocationTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_DeveloperGarden
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_DeveloperGarden_IpLocationTest::main');
  24. }
  25. /**
  26. * @see Zend_Service_DeveloperGarden_IpLocation
  27. */
  28. require_once 'Zend/Service/DeveloperGarden/IpLocation.php';
  29. /**
  30. * Zend_Service_DeveloperGarden test case
  31. *
  32. * @category Zend
  33. * @package Zend_Service_DeveloperGarden
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @version $Id$
  38. */
  39. class Zend_Service_DeveloperGarden_IpLocationTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * @var Zend_Service_DeveloperGarden_IpLocation_Mock
  43. */
  44. protected $_service = null;
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  48. PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. public function setUp()
  51. {
  52. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED') ||
  53. TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED !== true) {
  54. $this->markTestSkipped('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_ENABLED is not enabled');
  55. }
  56. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN')) {
  57. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN', 'Unknown');
  58. }
  59. if (!defined('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD')) {
  60. define('TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD', 'Unknown');
  61. }
  62. $config = array(
  63. 'username' => TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_LOGIN,
  64. 'password' => TESTS_ZEND_SERVICE_DEVELOPERGARDEN_ONLINE_PASSWORD,
  65. );
  66. $this->service = new Zend_Service_DeveloperGarden_IpLocation_Mock($config);
  67. }
  68. public function testLocateValid()
  69. {
  70. try {
  71. $result = $this->service->locateIP('217.7.192.1');
  72. $this->assertTrue(is_array($result->getIpAddressLocation()));
  73. } catch (Exception $e) {
  74. if ($e->getMessage() != 'quotas have exceeded') {
  75. throw $e;
  76. } else {
  77. $this->markTestSkipped('Quota exceeded.');
  78. }
  79. }
  80. }
  81. /**
  82. * @expectedException Zend_Service_DeveloperGarden_Response_Exception
  83. */
  84. public function testLocateIpNotFound()
  85. {
  86. $this->service->locateIP('127.0.0.1');
  87. }
  88. /**
  89. * @expectedException Zend_Service_DeveloperGarden_Exception
  90. */
  91. public function testLocateIpNotFoundShort()
  92. {
  93. $this->service->locateIP('127');
  94. }
  95. /**
  96. * @expectedException Zend_Service_DeveloperGarden_Exception
  97. */
  98. public function testLocateIpNotFoundString()
  99. {
  100. $this->service->locateIP('someStuff');
  101. }
  102. }
  103. class Zend_Service_DeveloperGarden_IpLocation_Mock
  104. extends Zend_Service_DeveloperGarden_IpLocation
  105. {
  106. }
  107. if (PHPUnit_MAIN_METHOD == 'Zend_Service_DeveloperGarden_IpLocationTest::main') {
  108. Zend_Service_DeveloperGarden_IpLocationTest::main();
  109. }