You are here

google_geocoder.test in Location 6.3

File

tests/google_geocoder.test
View source
<?php

/**
 * @file
 * Location saving test.
 */
require_once drupal_get_path('module', 'location') . '/tests/location_testcase.php';
require_once drupal_get_path('module', 'location') . '/tests/geocoder_api_keys.inc';
class LocationGoogleGeocoderTest extends LocationTestCase {
  function getInfo() {
    return array(
      'name' => t('Location Google Geocoder tests'),
      'description' => t('Test address mangling for the google geocoder.'),
      'group' => t('Location'),
    );
  }
  function setUp() {
    parent::setUp('location', 'location_node', 'devel');
    variable_set('location_geocode_google_apikey', TESTING_APIKEY_GOOGLE_MAPS);
    $web_admin = $this
      ->drupalCreateUser(array(
      'administer nodes',
      'submit latitude/longitude',
      'administer site configuration',
      'access administration pages',
      'administer content types',
    ));
    $this
      ->drupalLogin($web_admin);
  }

  //@todo remove this after http://drupal.org/node/1252310#comment-7109128 fix
  protected function error($message = '', $group = 'Other', array $caller = NULL) {
    if ($message == 'Undefined variable: location') {

      // change error (Notice) to debug message
      return $this
        ->assert('debug', $message, 'Debug', $caller);
    }
    if ($message == 'Undefined property: stdClass::$locations') {

      // change error (Notice) to debug message
      return $this
        ->assert('debug', $message, 'Debug', $caller);
    }
    return parent::error($message, $group, $caller);
  }
  function testUSA() {

    // Initialize the geocoder.
    $settings = array(
      'location_geocode_us' => 'google',
    );
    $this
      ->drupalPost('admin/settings/location/geocoding', $settings, 'Save configuration');
    $this
      ->refreshVariables();
    $settings = array();
    $location_type = $this
      ->addLocationContentType($settings);
    $location1_name = $this
      ->randomName();
    $node = $this
      ->drupalCreateNode(array(
      'type' => $location_type,
      'locations' => array(
        0 => array(
          'name' => $location1_name,
          'location_settings' => $settings,
          'street' => '1600 Amphitheatre Parkway',
          'city' => 'Mountain View',
          'province' => 'CA',
          'postal_code' => '94043',
          'country' => 'us',
        ),
      ),
    ));

    // Reload the node.
    $node2 = node_load($node->nid, NULL, TRUE);
    $location = $node2->locations[0];

    // @todo fixme

    //$this->assertEqual($location['source'], LOCATION_LATLON_GEOCODED_EXACT);
    $expected = array(
      37.4218378,
      -122.0846263,
    );
    $result = array(
      $location['latitude'],
      $location['longitude'],
    );

    // @todo fixme

    //$this->assertArrayEpsilon($result, $expected, 0.01, 'Google Headquarters');
  }

}

Classes