| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
$app = 'main'; |
|---|
| 4 |
$sf_root = dirname(__FILE__).'/../..'; |
|---|
| 5 |
require_once($sf_root.'/lib/symfony/vendor/lime/lime.php'); |
|---|
| 6 |
include($sf_root.'/test/bootstrap/functional.php'); |
|---|
| 7 |
|
|---|
| 8 |
$t = new lime_test(39, new lime_output_color()); |
|---|
| 9 |
|
|---|
| 10 |
$t->diag('Testing query with separate setters'); |
|---|
| 11 |
$client = new YahooGeocodingApiClient(); |
|---|
| 12 |
$client->setStreet('15bis, rue Victor Carmignac'); |
|---|
| 13 |
$t->ok($client->hasFieldSet('street'), 'hasFieldSet() finds that a street has been set'); |
|---|
| 14 |
$client->setCity('Arcueil'); |
|---|
| 15 |
$t->ok($client->hasFieldSet('city'), 'hasFieldSet() finds that a city has been set'); |
|---|
| 16 |
$client->setZip(94110); |
|---|
| 17 |
$t->ok($client->hasFieldSet('zip'), 'hasFieldSet() finds that a zip has been set'); |
|---|
| 18 |
$t->ok(!$client->hasFieldSet('state'), 'hasFieldSet() does not find that a state has been set'); |
|---|
| 19 |
$results = $client->query()->getResults(); |
|---|
| 20 |
$t->isa_ok($results, 'array', 'getResults() returns an array'); |
|---|
| 21 |
$t->is(count($results), 1, 'getResults() retrieves a correct number of results'); |
|---|
| 22 |
$t->ok(array_key_exists(0, $results), 'getResults() returns true indexed array'); |
|---|
| 23 |
$result = $results[0]; |
|---|
| 24 |
$t->is($result['latitude'], 48.801275, 'getResults() retrieves correct latitude'); |
|---|
| 25 |
$t->is($result['longitude'], 2.32632, 'getResults() retrieves correct longitude'); |
|---|
| 26 |
$t->is($result['country'], 'FR', 'getResults() retrieves correct country code'); |
|---|
| 27 |
|
|---|
| 28 |
$t->diag('Testing empty queries'); |
|---|
| 29 |
$client->initFields(); |
|---|
| 30 |
try |
|---|
| 31 |
{ |
|---|
| 32 |
$client->query()->getResults(); |
|---|
| 33 |
$t->fail('getResults() does not throw YahooGeocodingApiClientException when parameters are empty'); |
|---|
| 34 |
} |
|---|
| 35 |
catch (YahooGeocodingApiClientException $e) |
|---|
| 36 |
{ |
|---|
| 37 |
$t->pass('getResults() throws exception: '.$e->getMessage()); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
$t->diag('Testing tainted string parameters'); |
|---|
| 41 |
$client->initFields(); |
|---|
| 42 |
$client->setStreet("<p>15<em>bis</em> ,\r\n rue Victor <b>Carmignac</b></p>\n"); |
|---|
| 43 |
$client->setCity("Arcueil\t"); |
|---|
| 44 |
$client->setZip(94110); |
|---|
| 45 |
$results = $client->query()->getResults(); |
|---|
| 46 |
$t->isa_ok($results, 'array', 'getResults() returns an array'); |
|---|
| 47 |
$t->is(count($results), 1, 'getResults() retrieves a correct number of results'); |
|---|
| 48 |
$t->ok(array_key_exists(0, $results), 'getResults() returns true indexed array'); |
|---|
| 49 |
$result = $results[0]; |
|---|
| 50 |
$t->is($result['latitude'], 48.801275, 'getResults() retrieves correct latitude'); |
|---|
| 51 |
$t->is($result['longitude'], 2.32632, 'getResults() retrieves correct longitude'); |
|---|
| 52 |
$t->is($result['country'], 'FR', 'getResults() retrieves correct country code'); |
|---|
| 53 |
|
|---|
| 54 |
$t->diag('Testing halt on warning'); |
|---|
| 55 |
$client->initFields(); |
|---|
| 56 |
$client->setStreet("jkhjkhjkh"); |
|---|
| 57 |
$client->setCity("London"); |
|---|
| 58 |
$client->setHaltOnWarning(true); |
|---|
| 59 |
try |
|---|
| 60 |
{ |
|---|
| 61 |
$results = $client->query()->getResults(); |
|---|
| 62 |
$t->fail('getResults() does not throw YahooGeocodingApiClientException when halt on warning is set to true'); |
|---|
| 63 |
} |
|---|
| 64 |
catch (YahooGeocodingApiClientException $e) |
|---|
| 65 |
{ |
|---|
| 66 |
$t->pass('getResults() throws exception: '.$e->getMessage()); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$t->diag('Testing location search'); |
|---|
| 70 |
$client = new YahooGeocodingApiClient(); |
|---|
| 71 |
$client->setLocation('15bis, rue Victor Carmignac, 94110 Arcueil, France'); |
|---|
| 72 |
$results = $client->query()->getResults(); |
|---|
| 73 |
$t->isa_ok($results, 'array', 'getResults() returns an array'); |
|---|
| 74 |
$t->is(count($results), 1, 'getResults() retrieves a correct number of results'); |
|---|
| 75 |
$t->ok(array_key_exists(0, $results), 'getResults() returns true indexed array'); |
|---|
| 76 |
$result = $results[0]; |
|---|
| 77 |
$t->is($result['latitude'], 48.801275, 'getResults() retrieves correct latitude'); |
|---|
| 78 |
$t->is($result['longitude'], 2.32632, 'getResults() retrieves correct longitude'); |
|---|
| 79 |
$t->is($result['country'], 'FR', 'getResults() retrieves correct country code'); |
|---|
| 80 |
|
|---|
| 81 |
$t->diag('Testing wrong queries'); |
|---|
| 82 |
$client = new YahooGeocodingApiClient(); |
|---|
| 83 |
$client->setLocation('dskjfhdjkh'); |
|---|
| 84 |
try |
|---|
| 85 |
{ |
|---|
| 86 |
$client->query()->getResults(); |
|---|
| 87 |
$t->fail('getResults() does not throw YahooGeocodingApiClientException when wrong location provided'); |
|---|
| 88 |
} |
|---|
| 89 |
catch (YahooGeocodingApiClientException $e) |
|---|
| 90 |
{ |
|---|
| 91 |
$t->pass('getResults() throws exception: '.$e->getMessage()); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
$t->diag('Testing min precision setting'); |
|---|
| 95 |
$client = new YahooGeocodingApiClient(); |
|---|
| 96 |
$client->setMinPrecision('address'); |
|---|
| 97 |
$client->setLocation('Paris, France'); |
|---|
| 98 |
$result = $client->query()->getFirst(); |
|---|
| 99 |
$t->is_deeply($result, null, 'setMinPrecision() excludes approximative results'); |
|---|
| 100 |
|
|---|
| 101 |
$t->diag('Testing chained methods query'); |
|---|
| 102 |
$client = new YahooGeocodingApiClient(); |
|---|
| 103 |
$results = $client->setStreet('15bis, rue Victor Carmignac')->setCity('Arcueil')->setZip(94110)->query()->getResults(); |
|---|
| 104 |
$t->ok($client->hasFieldSet('street'), 'hasFieldSet() finds that a street has been set'); |
|---|
| 105 |
$t->ok($client->hasFieldSet('city'), 'hasFieldSet() finds that a city has been set'); |
|---|
| 106 |
$t->ok($client->hasFieldSet('zip'), 'hasFieldSet() finds that a zip has been set'); |
|---|
| 107 |
$t->ok(!$client->hasFieldSet('state'), 'hasFieldSet() does not find that a state has been set'); |
|---|
| 108 |
$t->isa_ok($results, 'array', 'getResults() returns an array'); |
|---|
| 109 |
$t->is(count($results), 1, 'getResults() retrieves a correct number of results'); |
|---|
| 110 |
$t->ok(array_key_exists(0, $results), 'getResults() returns true indexed array'); |
|---|
| 111 |
$result = $results[0]; |
|---|
| 112 |
$t->is($result['latitude'], 48.801275, 'getResults() retrieves correct latitude'); |
|---|
| 113 |
$t->is($result['longitude'], 2.32632, 'getResults() retrieves correct longitude'); |
|---|
| 114 |
$t->is($result['country'], 'FR', 'getResults() retrieves correct country code'); |
|---|
| 115 |
|
|---|
| 116 |
$result = $client->setStreet('15bis, rue Victor Carmignac')->setCity('Arcueil')->setZip(94110)->query()->getFirst(); |
|---|
| 117 |
$t->is($result['latitude'], 48.801275, 'getFirst() retrieves correct latitude'); |
|---|
| 118 |
$t->is($result['longitude'], 2.32632, 'getFirst() retrieves correct longitude'); |
|---|
| 119 |
$t->is($result['country'], 'FR', 'getFirst() retrieves correct country code'); |
|---|