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 |
|
* @return void |
43 |
|
*/ |
44 |
|
public function testUser() |
45 |
|
{ |
46 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
47 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
48 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user.xml', 'rb')); |
49 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_preferences.xml', 'rb')); |
50 |
|
$config = array( |
51 |
1 |
'adapter' => $mock, |
52 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
53 |
1 |
'user' => 'fred@example.com', |
54 |
|
'password' => 'w1lma4evah' |
55 |
1 |
); |
56 |
|
|
57 |
1 |
$osm = new Services_OpenStreetMap($config); |
58 |
1 |
$user = $osm->getUser(); |
59 |
1 |
$this->assertEquals($user->getDisplayName(), 'fredflintstone'); |
60 |
1 |
$this->assertEquals($user->getId(), 124); |
61 |
1 |
$this->assertEquals( |
62 |
1 |
$user->getImage(), |
63 |
|
'http://www.openstreetmap.org/user/image/124/me.jpg' |
64 |
1 |
); |
65 |
1 |
$this->assertEquals($user->getAccountCreated(), "2003-09-02T15:27:52Z"); |
66 |
1 |
$this->assertEquals($user->getDescription(), "Yabba dabba do!"); |
67 |
1 |
$this->assertEquals($user->getLon(), -8.2284600830085); |
68 |
1 |
$this->assertEquals($user->getLat(), 52.222687925572); |
69 |
1 |
$this->assertEquals($user->getZoom(), 3); |
70 |
1 |
$this->assertEquals($user->getChangesets(), 1910); |
71 |
1 |
$this->assertEquals($user->getTraces(), 115); |
72 |
1 |
$this->assertEquals($user->getBlocksReceived(), 1); |
73 |
1 |
$this->assertEquals($user->getBlocksIssued(), 15); |
74 |
1 |
$this->assertEquals($user->getActiveBlocksReceived(), 0); |
75 |
1 |
$this->assertEquals($user->getActiveBlocksIssued(), 4); |
76 |
1 |
$this->assertEquals($user->getLanguages(), array('en-US','en')); |
77 |
1 |
$this->assertEquals($user->getRoles(), array('moderator')); |
78 |
1 |
$this->assertEquals( |
79 |
1 |
$user->getPreferences(), |
80 |
1 |
array( "diary.default_language" => "en") |
81 |
1 |
); |
82 |
|
} |
83 |
|
|
84 |
|
/** |
85 |
|
* If there is no image set for a user, then getImage should return null. |
86 |
|
* |
87 |
|
* @return void |
88 |
|
*/ |
89 |
|
public function testUserNoImage() |
90 |
|
{ |
91 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
92 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
93 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_no_image.xml', 'rb')); |
94 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_preferences.xml', 'rb')); |
95 |
|
$config = array( |
96 |
1 |
'adapter' => $mock, |
97 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
98 |
1 |
'user' => 'fred@example.com', |
99 |
|
'password' => 'w1lma4evah' |
100 |
1 |
); |
101 |
|
|
102 |
1 |
$osm = new Services_OpenStreetMap($config); |
103 |
1 |
$user = $osm->getUser(); |
104 |
1 |
$this->assertEquals($user->getImage(), null); |
105 |
|
} |
106 |
|
|
107 |
|
/** |
108 |
|
* Test the getLat and getLon methods of the User object. |
109 |
|
* |
110 |
|
* @return void |
111 |
|
*/ |
112 |
|
public function testUserHomeSet() |
113 |
|
{ |
114 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
115 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
116 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_home_set.xml', 'rb')); |
117 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user_preferences.xml', 'rb')); |
118 |
|
$config = array( |
119 |
1 |
'adapter' => $mock, |
120 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
121 |
1 |
'user' => 'fred@example.com', |
122 |
|
'password' => 'w1lma4evah' |
123 |
1 |
); |
124 |
|
|
125 |
1 |
$osm = new Services_OpenStreetMap($config); |
126 |
1 |
$user = $osm->getUser(); |
127 |
1 |
$this->assertEquals($user->getLat(), 1.234567); |
128 |
1 |
$this->assertEquals($user->getLon(), -1.234567); |
129 |
|
} |
130 |
|
|
131 |
|
public function testUser11324() |
132 |
|
{ |
133 |
1 |
$mock = new HTTP_Request2_Adapter_Mock(); |
134 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/capabilities.xml', 'rb')); |
135 |
1 |
$mock->addResponse(fopen(__DIR__ . '/responses/user11324.xml', 'rb')); |
136 |
|
$config = array( |
137 |
1 |
'adapter' => $mock, |
138 |
1 |
'server' => 'http://api06.dev.openstreetmap.org/', |
139 |
1 |
'user' => 'fred@example.com', |
140 |
|
'password' => 'w1lma4evah' |
141 |
1 |
); |
142 |
|
|
143 |
1 |
$osm = new Services_OpenStreetMap($config); |
144 |
1 |
$user = $osm->getUser(6367); |
145 |
|
$this->assertEquals($user->getDisplayName(), 'kenguest'); |
146 |
|
$this->assertEquals($user->getId(), 11324); |
147 |
|
$this->assertEquals($user->getChangesets(), 1910); |
148 |
|
$this->assertEquals($user->getTraces(), 115); |
149 |
|
$this->assertEquals($user->getBlocksReceived(), 0); |
150 |
|
$this->assertEquals($user->getActiveBlocksReceived(), 0); |
151 |
|
$this->assertNull($user->getBlocksIssued()); |
152 |
|
$this->assertNull($user->getActiveBlocksIssued()); |
153 |
|
$this->assertNull($user->getLanguages()); |
154 |
|
$this->assertEquals($user->getRoles(), array()); |
155 |
|
} |
156 |
|
} |
157 |
|
// vim:set et ts=4 sw=4: |
158 |
|
?> |