You are here

function run_test in geoPHP 7

Same name in this branch
  1. 7 geoPHP/tests/test.php \run_test()
  2. 7 geoPHP/tests/postgis.php \run_test()
Same name and namespace in other branches
  1. 8 geoPHP/tests/test.php \run_test()
1 call to run_test()
test.php in geoPHP/tests/test.php

File

geoPHP/tests/postgis.php, line 5

Code

function run_test() {
  header("Content-type: text");
  include_once '../geoPHP.inc';

  // Your database test table should contain 3 columns: name (text), type (text), geom (geometry)
  $host = 'localhost';
  $database = 'phayes';
  $table = 'test';
  $column = 'geom';
  $user = 'phayes';
  $pass = 'supersecret';
  $connection = pg_connect("host={$host} dbname={$database} user={$user} password={$pass}");

  // Truncate
  pg_query($connection, "DELETE FROM {$table}");

  // Working with PostGIS and EWKB
  // ----------------------------
  foreach (scandir('./input') as $file) {
    $parts = explode('.', $file);
    if ($parts[0]) {
      $name = $parts[0];
      $format = $parts[1];
      $value = file_get_contents('./input/' . $file);
      print '---- Testing ' . $file . "\n";
      flush();
      $geometry = geoPHP::load($value, $format);
      test_postgis($name, $format, $geometry, $connection, 'wkb');
      $geometry
        ->setSRID(4326);
      test_postgis($name, $format, $geometry, $connection, 'ewkb');
    }
  }
  print "Testing Done!";
}