You are here

function test_adapters in geoPHP 7

Same name and namespace in other branches
  1. 8 geoPHP/tests/test.php \test_adapters()
1 call to test_adapters()
run_test in geoPHP/tests/test.php

File

geoPHP/tests/test.php, line 122

Code

function test_adapters($geometry, $format, $input) {

  // Test adapter output and input. Do a round-trip and re-test
  foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) {
    if ($adapter_key != 'google_geocode') {

      //Don't test google geocoder regularily. Uncomment to test
      $output = $geometry
        ->out($adapter_key);
      if ($output) {
        $adapter_loader = new $adapter_class();
        $test_geom_1 = $adapter_loader
          ->read($output);
        $test_geom_2 = $adapter_loader
          ->read($test_geom_1
          ->out($adapter_key));
        if ($test_geom_1
          ->out('wkt') != $test_geom_2
          ->out('wkt')) {
          print "Mismatched adapter output in " . $adapter_class . "\n";
        }
      }
      else {
        print "Empty output on " . $adapter_key . "\n";
      }
    }
  }

  // Test to make sure adapter work the same wether GEOS is ON or OFF
  // Cannot test methods if GEOS is not intstalled
  if (!geoPHP::geosInstalled()) {
    return;
  }
  foreach (geoPHP::getAdapterMap() as $adapter_key => $adapter_class) {
    if ($adapter_key != 'google_geocode') {

      //Don't test google geocoder regularily. Uncomment to test

      // Turn GEOS on
      geoPHP::geosInstalled(TRUE);
      $output = $geometry
        ->out($adapter_key);
      if ($output) {
        $adapter_loader = new $adapter_class();
        $test_geom_1 = $adapter_loader
          ->read($output);

        // Turn GEOS off
        geoPHP::geosInstalled(FALSE);
        $test_geom_2 = $adapter_loader
          ->read($output);

        // Turn GEOS back On
        geoPHP::geosInstalled(TRUE);

        // Check to make sure a both are the same with geos and without
        if ($test_geom_1
          ->out('wkt') != $test_geom_2
          ->out('wkt')) {
          print "Mismatched adapter output between GEOS and NORM in " . $adapter_class . "\n";
        }
      }
    }
  }
}