IpLocationTest.php 3.8 KB

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