google_geocoder.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Location saving test.
  5. */
  6. require_once drupal_get_path('module', 'location') . '/tests/location_testcase.php';
  7. require_once drupal_get_path('module', 'location') . '/tests/geocoder_api_keys.inc';
  8. class LocationGoogleGeocoderTest extends LocationTestCase {
  9. function getInfo() {
  10. return array(
  11. 'name' => t('Location Google Geocoder tests'),
  12. 'description' => t('Test address mangling for the google geocoder.'),
  13. 'group' => t('Location'),
  14. );
  15. }
  16. function setUp() {
  17. parent::setUp('location', 'location_node', 'devel');
  18. variable_set('location_geocode_google_apikey', TESTING_APIKEY_GOOGLE_MAPS);
  19. $web_admin = $this->drupalCreateUser(array('administer nodes', 'submit latitude/longitude', 'administer site configuration', 'access administration pages', 'administer content types'));
  20. $this->drupalLogin($web_admin);
  21. }
  22. function testUSA() {
  23. // Initialize the geocoder.
  24. $settings = array(
  25. 'location_geocode_us' => 'google',
  26. );
  27. $this->drupalPost('admin/settings/location/geocoding', $settings, 'Save configuration');
  28. $this->refreshVariables();
  29. $settings = array();
  30. $location_type = $this->addLocationContentType($settings);
  31. $location1_name = $this->randomName();
  32. $node = $this->drupalCreateNode(array(
  33. 'type' => $location_type,
  34. 'locations' => array(
  35. 0 => array(
  36. 'name' => $location1_name,
  37. 'location_settings' => $settings,
  38. 'street' => '1600 Amphitheatre Parkway',
  39. 'city' => 'Mountain View',
  40. 'province' => 'CA',
  41. 'postal_code' => '94043',
  42. 'country' => 'us',
  43. ),
  44. ),
  45. ));
  46. // Reload the node.
  47. $node2 = node_load($node->nid, NULL, TRUE);
  48. $location = $node2->locations[0];
  49. $this->assertEqual($location['source'], LOCATION_LATLON_GEOCODED_EXACT);
  50. $expected = array(37.421972, -122.084143);
  51. $result = array($location['latitude'], $location['longitude']);
  52. $this->assertArrayEpsilon($result, $expected, 0.01, 'Google Headquarters');
  53. }
  54. }