| 1 |
|
<?php |
| 2 |
|
/** |
| 3 |
|
* Unit testing class for retrieving Openstreetmap user data. |
| 4 |
|
* |
| 5 |
|
* PHP Version 5 |
| 6 |
|
* |
| 7 |
|
* @category Services |
| 8 |
|
* @package Services_Openstreetmap |
| 9 |
|
* @subpackage UnitTesting |
| 10 |
|
* @author Ken Guest <kguest@php.net> |
| 11 |
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php |
| 12 |
|
* @version Release: @package_version@ |
| 13 |
|
* @link UserTest.php |
| 14 |
|
*/ |
| 15 |
|
|
| 16 |
|
$version = '@package_version@'; |
| 17 |
|
if (strstr($version, 'package_version')) { |
| 18 |
|
set_include_path(dirname(dirname(__FILE__)) . ':' . get_include_path()); |
| 19 |
|
} |
| 20 |
|
|
| 21 |
|
require_once 'Services/Openstreetmap.php'; |
| 22 |
|
|
| 23 |
|
require_once 'HTTP/Request2.php'; |
| 24 |
|
require_once 'HTTP/Request2/Adapter/Mock.php'; |
| 25 |
|
require_once 'PHPUnit/Framework/TestCase.php'; |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* Unit test class for user related functionality. |
| 29 |
|
* |
| 30 |
|
* @category Services |
| 31 |
|
* @package Services_Openstreetmap |
| 32 |
|
* @subpackage UnitTesting |
| 33 |
|
* @author Ken Guest <kguest@php.net> |
| 34 |
|
* @license BSD http://www.opensource.org/licenses/bsd-license.php |
| 35 |
|
* @link UserTest.php |
| 36 |
|
*/ |
| 37 |
|
class UserTest extends PHPUnit_Framework_TestCase |
| 38 |
|
{ |
| 39 |
|
/** |
| 40 |
|
* Test that user data is parsed correctly. |
| 41 |
|
*/ |
| 42 |
|
public function testUser() |
| 43 |
|
{ |
| 44 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 45 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 46 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user.xml', 'rb')); |
| 47 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_preferences.xml', 'rb')); |
| 48 |
|
$config = array( |
| 49 |
1 |
'adapter' => $mock, |
| 50 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 51 |
1 |
'user' => 'fred@example.com', |
| 52 |
|
'password' => 'w1lma4evah' |
| 53 |
1 |
); |
| 54 |
|
|
| 55 |
1 |
$osm = new Services_Openstreetmap($config); |
| 56 |
1 |
$user = $osm->getUser(); |
| 57 |
1 |
$this->assertEquals($user->getDisplayName(), 'fredflintstone'); |
| 58 |
1 |
$this->assertEquals($user->getId(), 124); |
| 59 |
1 |
$this->assertEquals($user->getImage(), 'http://www.openstreetmap.org/user/image/124/me.jpg'); |
| 60 |
1 |
$this->assertEquals($user->getAccountCreated(), "2003-09-02T15:27:52Z"); |
| 61 |
1 |
$this->assertEquals($user->getDescription(), "Yabba dabba do!"); |
| 62 |
1 |
$this->assertEquals($user->getLon(), null); |
| 63 |
1 |
$this->assertEquals($user->getLat(), null); |
| 64 |
1 |
$this->assertEquals($user->getLanguages(), array('en-US','en')); |
| 65 |
1 |
$this->assertEquals( |
| 66 |
1 |
$user->getPreferences(), |
| 67 |
1 |
array( "diary.default_language" => "en") |
| 68 |
1 |
); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
/** |
| 72 |
|
* If there is no image set for a user, then getImage should return null. |
| 73 |
|
*/ |
| 74 |
|
public function testUserNoImage() |
| 75 |
|
{ |
| 76 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 77 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 78 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_no_image.xml', 'rb')); |
| 79 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_preferences.xml', 'rb')); |
| 80 |
|
$config = array( |
| 81 |
1 |
'adapter' => $mock, |
| 82 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 83 |
1 |
'user' => 'fred@example.com', |
| 84 |
|
'password' => 'w1lma4evah' |
| 85 |
1 |
); |
| 86 |
|
|
| 87 |
1 |
$osm = new Services_Openstreetmap($config); |
| 88 |
1 |
$user = $osm->getUser(); |
| 89 |
1 |
$this->assertEquals($user->getImage(), null); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
/** |
| 93 |
|
* Test the getLat and getLon methods of the User object. |
| 94 |
|
*/ |
| 95 |
|
public function testUserHomeSet() |
| 96 |
|
{ |
| 97 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
| 98 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
| 99 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_home_set.xml', 'rb')); |
| 100 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_preferences.xml', 'rb')); |
| 101 |
|
$config = array( |
| 102 |
1 |
'adapter' => $mock, |
| 103 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
| 104 |
1 |
'user' => 'fred@example.com', |
| 105 |
|
'password' => 'w1lma4evah' |
| 106 |
1 |
); |
| 107 |
|
|
| 108 |
1 |
$osm = new Services_Openstreetmap($config); |
| 109 |
1 |
$user = $osm->getUser(); |
| 110 |
1 |
$this->assertEquals($user->getLat(), 1.234567); |
| 111 |
1 |
$this->assertEquals($user->getLon(), -1.234567); |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
// vim:set et ts=4 sw=4: |
| 115 |
|
?> |