@@ -12,339 +12,339 @@ |
||
| 12 | 12 | use Route4Me\RouteParameters; |
| 13 | 13 | |
| 14 | 14 | class AddressUnitTests extends \PHPUnit\Framework\TestCase { |
| 15 | - protected $address; |
|
| 16 | - public static $createdAddresses; |
|
| 17 | - |
|
| 18 | - public static $problem; |
|
| 19 | - public static $problemDest; |
|
| 20 | - |
|
| 21 | - public static $route_id = null; |
|
| 22 | - public static $address_id = null; |
|
| 23 | - public static $address_address = null; |
|
| 24 | - public static $address_lat = null; |
|
| 25 | - public static $address_lng = null; |
|
| 26 | - public static $address_is_depot = null; |
|
| 27 | - |
|
| 28 | - public static $addresIdMarkedAsVisited; |
|
| 29 | - |
|
| 30 | - public static $afterAddressId; |
|
| 31 | - public static $route_id_dest; |
|
| 32 | - |
|
| 33 | - public static function setUpBeforeClass() |
|
| 34 | - { |
|
| 35 | - if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 36 | - $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 37 | - self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 41 | - |
|
| 42 | - //<editor-fold desc="Prepare Addresses"> |
|
| 43 | - $addresses = []; |
|
| 44 | - $addresses[] = Address::fromArray([ |
|
| 45 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 46 | - 'is_depot' => true, |
|
| 47 | - 'lat' => 30.159341812134, |
|
| 48 | - 'lng' => -81.538619995117, |
|
| 49 | - 'time' => 300, |
|
| 50 | - 'time_window_start' => 28800, |
|
| 51 | - 'time_window_end' => 32400, |
|
| 52 | - ]); |
|
| 53 | - |
|
| 54 | - $addresses[] = Address::fromArray([ |
|
| 55 | - 'address' => '214 Edgewater Branch Drive 32259', |
|
| 56 | - 'lat' => 30.103567123413, |
|
| 57 | - 'lng' => -81.595352172852, |
|
| 58 | - 'time' => 300, |
|
| 59 | - 'time_window_start' => 36000, |
|
| 60 | - 'time_window_end' => 37200, |
|
| 61 | - ]); |
|
| 62 | - |
|
| 63 | - $addresses[] = Address::fromArray([ |
|
| 64 | - 'address' => '756 eagle point dr 32092', |
|
| 65 | - 'lat' => 30.046422958374, |
|
| 66 | - 'lng' => -81.508758544922, |
|
| 67 | - 'time' => 300, |
|
| 68 | - 'time_window_start' => 39600, |
|
| 69 | - 'time_window_end' => 41400, |
|
| 70 | - ]); |
|
| 71 | - |
|
| 72 | - $addresses[] = Address::fromArray([ |
|
| 73 | - 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 74 | - 'lat' => 30.048496, |
|
| 75 | - 'lng' => -81.558716, |
|
| 76 | - 'time' => 300, |
|
| 77 | - 'time_window_start' => 43200, |
|
| 78 | - 'time_window_end' => 45000, |
|
| 79 | - ]); |
|
| 80 | - |
|
| 81 | - $addresses[] = Address::fromArray([ |
|
| 82 | - 'address' => 'St Johns Florida 32259, USA', |
|
| 83 | - 'lat' => 30.099642, |
|
| 84 | - 'lng' => -81.547201, |
|
| 85 | - 'time' => 300, |
|
| 86 | - 'time_window_start' => 46800, |
|
| 87 | - 'time_window_end' => 48600, |
|
| 88 | - ]); |
|
| 89 | - |
|
| 90 | - $parameters = RouteParameters::fromArray([ |
|
| 91 | - 'device_type' => DeviceType::IPAD, |
|
| 92 | - 'disable_optimization' => false, |
|
| 93 | - 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 94 | - ]); |
|
| 95 | - //</editor-fold> |
|
| 96 | - |
|
| 97 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 98 | - $optimizationParameters->setAddresses($addresses); |
|
| 99 | - $optimizationParameters->setParameters($parameters); |
|
| 100 | - |
|
| 101 | - self::$problem = OptimizationProblem::optimize($optimizationParameters); |
|
| 102 | - $routes = self::$problem->getRoutes(); |
|
| 103 | - self::$route_id = $routes[0]->route_id; |
|
| 104 | - self::$createdAddresses = $routes[0]->addresses; |
|
| 105 | - |
|
| 106 | - self::$problemDest = OptimizationProblem::optimize($optimizationParameters); |
|
| 107 | - $routesDest = self::$problemDest->getRoutes(); |
|
| 108 | - $addressesDest = $routesDest[0]->addresses; |
|
| 109 | - self::$route_id_dest = $routesDest[0]->route_id; |
|
| 110 | - self::$afterAddressId = $addressesDest[2]->route_destination_id; |
|
| 111 | - |
|
| 112 | - $addresses = self::$problem->addresses; |
|
| 113 | - self::$address_id = $addresses[1]->getAddressId(); |
|
| 114 | - self::$address_address = $addresses[1]->address; |
|
| 115 | - self::$address_lat = $addresses[1]->lat; |
|
| 116 | - self::$address_lng = $addresses[1]->lng; |
|
| 117 | - self::$address_is_depot = $addresses[1]->is_depot; |
|
| 118 | - |
|
| 119 | - self::$addresIdMarkedAsVisited = $addresses[2]->getAddressId(); |
|
| 120 | - |
|
| 121 | - $params = [ |
|
| 122 | - 'route_id' => self::$route_id, |
|
| 123 | - 'address_id' => self::$addresIdMarkedAsVisited, |
|
| 124 | - 'is_visited' => 1 |
|
| 125 | - ]; |
|
| 126 | - |
|
| 127 | - $result = $addresses[2]->markAsVisited($params); |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function testAddressFromArray() |
|
| 132 | - { |
|
| 133 | - $address = Address::fromArray([ |
|
| 134 | - 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 135 | - 'lat' => 38.2513427734, |
|
| 136 | - 'lng' => -77.5993652344, |
|
| 137 | - 'time' => 300, |
|
| 138 | - 'time_window_end' => 75600, |
|
| 139 | - 'time_window_start' => 28800, |
|
| 140 | - ]); |
|
| 141 | - |
|
| 142 | - $this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407'); |
|
| 143 | - $this->assertEquals($address->lat, 38.2513427734); |
|
| 144 | - $this->assertEquals($address->lng, -77.5993652344); |
|
| 145 | - $this->assertEquals($address->time, 300); |
|
| 146 | - $this->assertEquals($address->time_window_start, 28800); |
|
| 147 | - $this->assertEquals($address->time_window_end, 75600); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function testToArray() |
|
| 151 | - { |
|
| 152 | - $address = Address::fromArray([ |
|
| 153 | - 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 154 | - 'lat' => 38.2513427734, |
|
| 155 | - 'lng' => -77.5993652344, |
|
| 156 | - 'time' => 300, |
|
| 157 | - 'time_window_end' => 75600, |
|
| 158 | - 'time_window_start' => 28800, |
|
| 159 | - 'custom_fields' => [ |
|
| 160 | - 'cf_1' => 1, |
|
| 161 | - ], |
|
| 162 | - ]); |
|
| 163 | - |
|
| 164 | - $this->assertEquals($address->toArray(), [ |
|
| 165 | - 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 166 | - 'lat' => 38.2513427734, |
|
| 167 | - 'lng' => -77.5993652344, |
|
| 168 | - 'is_depot' => false, |
|
| 169 | - 'time' => 300, |
|
| 170 | - 'time_window_end' => 75600, |
|
| 171 | - 'time_window_start' => 28800, |
|
| 172 | - 'custom_fields' => [ |
|
| 173 | - 'cf_1' => 1, |
|
| 174 | - ], |
|
| 175 | - ]); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - public function testBadParameter() |
|
| 179 | - { |
|
| 180 | - $this->expectException(BadParam::class); |
|
| 181 | - |
|
| 182 | - $address = Address::fromArray([ |
|
| 183 | - 'lat1' => 38.2513427734, |
|
| 184 | - 'lng1' => -77.5993652344, |
|
| 185 | - ]); |
|
| 186 | - |
|
| 187 | - echo "address: ".$address->lat." <br>"; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - public function testAddressFromArrayWithBadKeys() |
|
| 191 | - { |
|
| 192 | - $this->expectException(BadParam::class); |
|
| 193 | - |
|
| 194 | - $address = Address::fromArray([ |
|
| 195 | - 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 196 | - 'lat' => 38.2513427734, |
|
| 197 | - 'lng' => -77.5993652344, |
|
| 198 | - 'demoaddress' => '333333', |
|
| 199 | - ]); |
|
| 200 | - |
|
| 201 | - $this->assertNotNull($address->address); |
|
| 202 | - $this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407'); |
|
| 203 | - $this->assertEquals($address->lat, 38.2513427734); |
|
| 204 | - $this->assertEquals($address->lng, -77.5993652344); |
|
| 205 | - |
|
| 206 | - $this->assertFalse(property_exists($address, 'demoaddress')); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - public function testGetAddress() |
|
| 210 | - { |
|
| 211 | - $address = Address::getAddress(self::$route_id, self::$address_id); |
|
| 212 | - |
|
| 213 | - $this->assertNotNull($address); |
|
| 214 | - $this->assertNotNull($address->address); |
|
| 215 | - $this->assertEquals($address->address, self::$address_address); |
|
| 216 | - $this->assertEquals($address->lat, self::$address_lat); |
|
| 217 | - $this->assertEquals($address->lng, self::$address_lng); |
|
| 218 | - $this->assertEquals($address->is_depot, self::$address_is_depot); |
|
| 219 | - |
|
| 220 | - return $address; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function testUpdateAddress() |
|
| 224 | - { |
|
| 225 | - $address = Address::getAddress(self::$route_id, self::$address_id); |
|
| 226 | - $this->assertNotNull($address); |
|
| 227 | - |
|
| 228 | - $address->route_id = self::$route_id; |
|
| 229 | - |
|
| 230 | - $address->address = 'Updated address'; |
|
| 231 | - $newAddress = $address->update(); |
|
| 232 | - |
|
| 233 | - $this->assertEquals($newAddress->address, 'Updated address'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - public function testMarkAsDeparted() |
|
| 237 | - { |
|
| 238 | - $address = new Address(); |
|
| 239 | - |
|
| 240 | - $params = [ |
|
| 241 | - 'route_id' => self::$route_id, |
|
| 242 | - 'address_id' => self::$addresIdMarkedAsVisited, |
|
| 243 | - 'is_departed' => 1 |
|
| 244 | - ]; |
|
| 245 | - |
|
| 246 | - $result = $address->markAsDeparted($params); |
|
| 247 | - |
|
| 248 | - $this->assertNotNull($result); |
|
| 249 | - $this->assertIsBool($result['status']); |
|
| 250 | - $this->assertTrue($result['status']); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - public function testMarkAsVisited() |
|
| 254 | - { |
|
| 255 | - $address = new Address(); |
|
| 256 | - |
|
| 257 | - $params = [ |
|
| 258 | - 'route_id' => self::$route_id, |
|
| 259 | - 'address_id' => self::$address_id, |
|
| 260 | - 'is_visited' => 1 |
|
| 261 | - ]; |
|
| 262 | - |
|
| 263 | - $result = $address->markAsVisited($params); |
|
| 264 | - |
|
| 265 | - $this->assertNotNull($result); |
|
| 266 | - $this->assertIsInt($result); |
|
| 267 | - $this->assertEquals(1,$result); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - public function testDeleteAddress() |
|
| 271 | - { |
|
| 272 | - $lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id; |
|
| 273 | - |
|
| 274 | - $address = Address::getAddress(self::$route_id, $lastAddressId); |
|
| 275 | - $this->assertNotNull($address); |
|
| 276 | - |
|
| 277 | - $state = $address->deleteAddress(); |
|
| 278 | - $this->assertTrue($state); |
|
| 279 | - |
|
| 280 | - array_pop(self::$createdAddresses); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - public function testMoveDestinationToRoute() |
|
| 284 | - { |
|
| 285 | - $lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id; |
|
| 286 | - |
|
| 287 | - // Move the destination to the route |
|
| 288 | - $routeParams = [ |
|
| 289 | - 'to_route_id' => self::$route_id_dest, |
|
| 290 | - 'route_destination_id' => $lastAddressId, |
|
| 291 | - 'after_destination_id' => self::$afterAddressId, |
|
| 292 | - ]; |
|
| 293 | - |
|
| 294 | - $address = new Address(); |
|
| 295 | - $result = $address->moveDestinationToRoute($routeParams); |
|
| 296 | - |
|
| 297 | - $this->assertNotNull($result); |
|
| 298 | - $this->assertNotNull($result['success']); |
|
| 299 | - $this->assertEquals(true,$result['success']); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - public function testChangeRouteDepote() |
|
| 303 | - { |
|
| 304 | - $address1 = Address::getAddress( |
|
| 305 | - self::$route_id, |
|
| 306 | - self::$createdAddresses[0]->route_destination_id); |
|
| 15 | + protected $address; |
|
| 16 | + public static $createdAddresses; |
|
| 17 | + |
|
| 18 | + public static $problem; |
|
| 19 | + public static $problemDest; |
|
| 20 | + |
|
| 21 | + public static $route_id = null; |
|
| 22 | + public static $address_id = null; |
|
| 23 | + public static $address_address = null; |
|
| 24 | + public static $address_lat = null; |
|
| 25 | + public static $address_lng = null; |
|
| 26 | + public static $address_is_depot = null; |
|
| 27 | + |
|
| 28 | + public static $addresIdMarkedAsVisited; |
|
| 29 | + |
|
| 30 | + public static $afterAddressId; |
|
| 31 | + public static $route_id_dest; |
|
| 32 | + |
|
| 33 | + public static function setUpBeforeClass() |
|
| 34 | + { |
|
| 35 | + if (Constants::API_KEY == Constants::DEMO_API_KEY) { |
|
| 36 | + $className = str_replace('UnitTestFiles\\Test\\','',get_class()); |
|
| 37 | + self::markTestSkipped( 'PHPUnit will skip '. $className ." class - it impossible run with demo API key" ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 41 | + |
|
| 42 | + //<editor-fold desc="Prepare Addresses"> |
|
| 43 | + $addresses = []; |
|
| 44 | + $addresses[] = Address::fromArray([ |
|
| 45 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 46 | + 'is_depot' => true, |
|
| 47 | + 'lat' => 30.159341812134, |
|
| 48 | + 'lng' => -81.538619995117, |
|
| 49 | + 'time' => 300, |
|
| 50 | + 'time_window_start' => 28800, |
|
| 51 | + 'time_window_end' => 32400, |
|
| 52 | + ]); |
|
| 53 | + |
|
| 54 | + $addresses[] = Address::fromArray([ |
|
| 55 | + 'address' => '214 Edgewater Branch Drive 32259', |
|
| 56 | + 'lat' => 30.103567123413, |
|
| 57 | + 'lng' => -81.595352172852, |
|
| 58 | + 'time' => 300, |
|
| 59 | + 'time_window_start' => 36000, |
|
| 60 | + 'time_window_end' => 37200, |
|
| 61 | + ]); |
|
| 62 | + |
|
| 63 | + $addresses[] = Address::fromArray([ |
|
| 64 | + 'address' => '756 eagle point dr 32092', |
|
| 65 | + 'lat' => 30.046422958374, |
|
| 66 | + 'lng' => -81.508758544922, |
|
| 67 | + 'time' => 300, |
|
| 68 | + 'time_window_start' => 39600, |
|
| 69 | + 'time_window_end' => 41400, |
|
| 70 | + ]); |
|
| 71 | + |
|
| 72 | + $addresses[] = Address::fromArray([ |
|
| 73 | + 'address' => '63 Stone Creek Cir St Johns, FL 32259, USA', |
|
| 74 | + 'lat' => 30.048496, |
|
| 75 | + 'lng' => -81.558716, |
|
| 76 | + 'time' => 300, |
|
| 77 | + 'time_window_start' => 43200, |
|
| 78 | + 'time_window_end' => 45000, |
|
| 79 | + ]); |
|
| 80 | + |
|
| 81 | + $addresses[] = Address::fromArray([ |
|
| 82 | + 'address' => 'St Johns Florida 32259, USA', |
|
| 83 | + 'lat' => 30.099642, |
|
| 84 | + 'lng' => -81.547201, |
|
| 85 | + 'time' => 300, |
|
| 86 | + 'time_window_start' => 46800, |
|
| 87 | + 'time_window_end' => 48600, |
|
| 88 | + ]); |
|
| 89 | + |
|
| 90 | + $parameters = RouteParameters::fromArray([ |
|
| 91 | + 'device_type' => DeviceType::IPAD, |
|
| 92 | + 'disable_optimization' => false, |
|
| 93 | + 'route_name' => 'phpunit test '.date('Y-m-d H:i'), |
|
| 94 | + ]); |
|
| 95 | + //</editor-fold> |
|
| 96 | + |
|
| 97 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 98 | + $optimizationParameters->setAddresses($addresses); |
|
| 99 | + $optimizationParameters->setParameters($parameters); |
|
| 100 | + |
|
| 101 | + self::$problem = OptimizationProblem::optimize($optimizationParameters); |
|
| 102 | + $routes = self::$problem->getRoutes(); |
|
| 103 | + self::$route_id = $routes[0]->route_id; |
|
| 104 | + self::$createdAddresses = $routes[0]->addresses; |
|
| 105 | + |
|
| 106 | + self::$problemDest = OptimizationProblem::optimize($optimizationParameters); |
|
| 107 | + $routesDest = self::$problemDest->getRoutes(); |
|
| 108 | + $addressesDest = $routesDest[0]->addresses; |
|
| 109 | + self::$route_id_dest = $routesDest[0]->route_id; |
|
| 110 | + self::$afterAddressId = $addressesDest[2]->route_destination_id; |
|
| 111 | + |
|
| 112 | + $addresses = self::$problem->addresses; |
|
| 113 | + self::$address_id = $addresses[1]->getAddressId(); |
|
| 114 | + self::$address_address = $addresses[1]->address; |
|
| 115 | + self::$address_lat = $addresses[1]->lat; |
|
| 116 | + self::$address_lng = $addresses[1]->lng; |
|
| 117 | + self::$address_is_depot = $addresses[1]->is_depot; |
|
| 118 | + |
|
| 119 | + self::$addresIdMarkedAsVisited = $addresses[2]->getAddressId(); |
|
| 120 | + |
|
| 121 | + $params = [ |
|
| 122 | + 'route_id' => self::$route_id, |
|
| 123 | + 'address_id' => self::$addresIdMarkedAsVisited, |
|
| 124 | + 'is_visited' => 1 |
|
| 125 | + ]; |
|
| 126 | + |
|
| 127 | + $result = $addresses[2]->markAsVisited($params); |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function testAddressFromArray() |
|
| 132 | + { |
|
| 133 | + $address = Address::fromArray([ |
|
| 134 | + 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 135 | + 'lat' => 38.2513427734, |
|
| 136 | + 'lng' => -77.5993652344, |
|
| 137 | + 'time' => 300, |
|
| 138 | + 'time_window_end' => 75600, |
|
| 139 | + 'time_window_start' => 28800, |
|
| 140 | + ]); |
|
| 141 | + |
|
| 142 | + $this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407'); |
|
| 143 | + $this->assertEquals($address->lat, 38.2513427734); |
|
| 144 | + $this->assertEquals($address->lng, -77.5993652344); |
|
| 145 | + $this->assertEquals($address->time, 300); |
|
| 146 | + $this->assertEquals($address->time_window_start, 28800); |
|
| 147 | + $this->assertEquals($address->time_window_end, 75600); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function testToArray() |
|
| 151 | + { |
|
| 152 | + $address = Address::fromArray([ |
|
| 153 | + 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 154 | + 'lat' => 38.2513427734, |
|
| 155 | + 'lng' => -77.5993652344, |
|
| 156 | + 'time' => 300, |
|
| 157 | + 'time_window_end' => 75600, |
|
| 158 | + 'time_window_start' => 28800, |
|
| 159 | + 'custom_fields' => [ |
|
| 160 | + 'cf_1' => 1, |
|
| 161 | + ], |
|
| 162 | + ]); |
|
| 163 | + |
|
| 164 | + $this->assertEquals($address->toArray(), [ |
|
| 165 | + 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 166 | + 'lat' => 38.2513427734, |
|
| 167 | + 'lng' => -77.5993652344, |
|
| 168 | + 'is_depot' => false, |
|
| 169 | + 'time' => 300, |
|
| 170 | + 'time_window_end' => 75600, |
|
| 171 | + 'time_window_start' => 28800, |
|
| 172 | + 'custom_fields' => [ |
|
| 173 | + 'cf_1' => 1, |
|
| 174 | + ], |
|
| 175 | + ]); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + public function testBadParameter() |
|
| 179 | + { |
|
| 180 | + $this->expectException(BadParam::class); |
|
| 181 | + |
|
| 182 | + $address = Address::fromArray([ |
|
| 183 | + 'lat1' => 38.2513427734, |
|
| 184 | + 'lng1' => -77.5993652344, |
|
| 185 | + ]); |
|
| 186 | + |
|
| 187 | + echo "address: ".$address->lat." <br>"; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + public function testAddressFromArrayWithBadKeys() |
|
| 191 | + { |
|
| 192 | + $this->expectException(BadParam::class); |
|
| 193 | + |
|
| 194 | + $address = Address::fromArray([ |
|
| 195 | + 'address' => '10609 Mystic Pointe Dr, Fredericksburg, VA 22407', |
|
| 196 | + 'lat' => 38.2513427734, |
|
| 197 | + 'lng' => -77.5993652344, |
|
| 198 | + 'demoaddress' => '333333', |
|
| 199 | + ]); |
|
| 200 | + |
|
| 201 | + $this->assertNotNull($address->address); |
|
| 202 | + $this->assertEquals($address->address, '10609 Mystic Pointe Dr, Fredericksburg, VA 22407'); |
|
| 203 | + $this->assertEquals($address->lat, 38.2513427734); |
|
| 204 | + $this->assertEquals($address->lng, -77.5993652344); |
|
| 205 | + |
|
| 206 | + $this->assertFalse(property_exists($address, 'demoaddress')); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + public function testGetAddress() |
|
| 210 | + { |
|
| 211 | + $address = Address::getAddress(self::$route_id, self::$address_id); |
|
| 212 | + |
|
| 213 | + $this->assertNotNull($address); |
|
| 214 | + $this->assertNotNull($address->address); |
|
| 215 | + $this->assertEquals($address->address, self::$address_address); |
|
| 216 | + $this->assertEquals($address->lat, self::$address_lat); |
|
| 217 | + $this->assertEquals($address->lng, self::$address_lng); |
|
| 218 | + $this->assertEquals($address->is_depot, self::$address_is_depot); |
|
| 219 | + |
|
| 220 | + return $address; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function testUpdateAddress() |
|
| 224 | + { |
|
| 225 | + $address = Address::getAddress(self::$route_id, self::$address_id); |
|
| 226 | + $this->assertNotNull($address); |
|
| 227 | + |
|
| 228 | + $address->route_id = self::$route_id; |
|
| 229 | + |
|
| 230 | + $address->address = 'Updated address'; |
|
| 231 | + $newAddress = $address->update(); |
|
| 232 | + |
|
| 233 | + $this->assertEquals($newAddress->address, 'Updated address'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + public function testMarkAsDeparted() |
|
| 237 | + { |
|
| 238 | + $address = new Address(); |
|
| 239 | + |
|
| 240 | + $params = [ |
|
| 241 | + 'route_id' => self::$route_id, |
|
| 242 | + 'address_id' => self::$addresIdMarkedAsVisited, |
|
| 243 | + 'is_departed' => 1 |
|
| 244 | + ]; |
|
| 245 | + |
|
| 246 | + $result = $address->markAsDeparted($params); |
|
| 247 | + |
|
| 248 | + $this->assertNotNull($result); |
|
| 249 | + $this->assertIsBool($result['status']); |
|
| 250 | + $this->assertTrue($result['status']); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + public function testMarkAsVisited() |
|
| 254 | + { |
|
| 255 | + $address = new Address(); |
|
| 256 | + |
|
| 257 | + $params = [ |
|
| 258 | + 'route_id' => self::$route_id, |
|
| 259 | + 'address_id' => self::$address_id, |
|
| 260 | + 'is_visited' => 1 |
|
| 261 | + ]; |
|
| 262 | + |
|
| 263 | + $result = $address->markAsVisited($params); |
|
| 264 | + |
|
| 265 | + $this->assertNotNull($result); |
|
| 266 | + $this->assertIsInt($result); |
|
| 267 | + $this->assertEquals(1,$result); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + public function testDeleteAddress() |
|
| 271 | + { |
|
| 272 | + $lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id; |
|
| 273 | + |
|
| 274 | + $address = Address::getAddress(self::$route_id, $lastAddressId); |
|
| 275 | + $this->assertNotNull($address); |
|
| 276 | + |
|
| 277 | + $state = $address->deleteAddress(); |
|
| 278 | + $this->assertTrue($state); |
|
| 279 | + |
|
| 280 | + array_pop(self::$createdAddresses); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + public function testMoveDestinationToRoute() |
|
| 284 | + { |
|
| 285 | + $lastAddressId = self::$createdAddresses[sizeof(self::$createdAddresses)-1]->route_destination_id; |
|
| 286 | + |
|
| 287 | + // Move the destination to the route |
|
| 288 | + $routeParams = [ |
|
| 289 | + 'to_route_id' => self::$route_id_dest, |
|
| 290 | + 'route_destination_id' => $lastAddressId, |
|
| 291 | + 'after_destination_id' => self::$afterAddressId, |
|
| 292 | + ]; |
|
| 293 | + |
|
| 294 | + $address = new Address(); |
|
| 295 | + $result = $address->moveDestinationToRoute($routeParams); |
|
| 296 | + |
|
| 297 | + $this->assertNotNull($result); |
|
| 298 | + $this->assertNotNull($result['success']); |
|
| 299 | + $this->assertEquals(true,$result['success']); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + public function testChangeRouteDepote() |
|
| 303 | + { |
|
| 304 | + $address1 = Address::getAddress( |
|
| 305 | + self::$route_id, |
|
| 306 | + self::$createdAddresses[0]->route_destination_id); |
|
| 307 | 307 | |
| 308 | - $address1->route_id = self::$route_id; |
|
| 309 | - |
|
| 310 | - $address2 = Address::getAddress( |
|
| 311 | - self::$route_id, |
|
| 312 | - self::$createdAddresses[1]->route_destination_id); |
|
| 313 | - |
|
| 314 | - $address2->route_id = self::$route_id; |
|
| 308 | + $address1->route_id = self::$route_id; |
|
| 309 | + |
|
| 310 | + $address2 = Address::getAddress( |
|
| 311 | + self::$route_id, |
|
| 312 | + self::$createdAddresses[1]->route_destination_id); |
|
| 313 | + |
|
| 314 | + $address2->route_id = self::$route_id; |
|
| 315 | 315 | |
| 316 | - $this->assertEquals(true, $address1->is_depot); |
|
| 317 | - $this->assertEquals(false, $address2->is_depot); |
|
| 316 | + $this->assertEquals(true, $address1->is_depot); |
|
| 317 | + $this->assertEquals(false, $address2->is_depot); |
|
| 318 | 318 | |
| 319 | - $address1->is_depot = false; |
|
| 320 | - $updatedAddress1 = $address1->update(); |
|
| 319 | + $address1->is_depot = false; |
|
| 320 | + $updatedAddress1 = $address1->update(); |
|
| 321 | 321 | |
| 322 | - $address2->is_depot = true; |
|
| 323 | - $updatedAddress2 = $address2->update(); |
|
| 322 | + $address2->is_depot = true; |
|
| 323 | + $updatedAddress2 = $address2->update(); |
|
| 324 | 324 | |
| 325 | - $this->assertEquals(false, $updatedAddress1->is_depot); |
|
| 326 | - $this->assertEquals(true, $updatedAddress2->is_depot); |
|
| 327 | - } |
|
| 325 | + $this->assertEquals(false, $updatedAddress1->is_depot); |
|
| 326 | + $this->assertEquals(true, $updatedAddress2->is_depot); |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - public static function tearDownAfterClass() |
|
| 330 | - { |
|
| 331 | - $optimizationProblemId = self:: $problem->optimization_problem_id; |
|
| 332 | - $destOptimizationProblemId = self::$problemDest->optimization_problem_id; |
|
| 333 | - |
|
| 334 | - $params = [ |
|
| 335 | - 'optimization_problem_ids' => [ |
|
| 336 | - '0' => $optimizationProblemId, |
|
| 337 | - '1' => $destOptimizationProblemId |
|
| 338 | - ], |
|
| 339 | - 'redirect' => 0, |
|
| 340 | - ]; |
|
| 341 | - |
|
| 342 | - $result = self:: $problem->removeOptimization($params); |
|
| 329 | + public static function tearDownAfterClass() |
|
| 330 | + { |
|
| 331 | + $optimizationProblemId = self:: $problem->optimization_problem_id; |
|
| 332 | + $destOptimizationProblemId = self::$problemDest->optimization_problem_id; |
|
| 333 | + |
|
| 334 | + $params = [ |
|
| 335 | + 'optimization_problem_ids' => [ |
|
| 336 | + '0' => $optimizationProblemId, |
|
| 337 | + '1' => $destOptimizationProblemId |
|
| 338 | + ], |
|
| 339 | + 'redirect' => 0, |
|
| 340 | + ]; |
|
| 341 | + |
|
| 342 | + $result = self:: $problem->removeOptimization($params); |
|
| 343 | 343 | |
| 344 | - if ($result!=null && $result['status']==true) { |
|
| 345 | - echo "The test optimization was removed <br>"; |
|
| 346 | - } else { |
|
| 347 | - echo "Cannot remove the test optimization <br>"; |
|
| 348 | - } |
|
| 349 | - } |
|
| 344 | + if ($result!=null && $result['status']==true) { |
|
| 345 | + echo "The test optimization was removed <br>"; |
|
| 346 | + } else { |
|
| 347 | + echo "Cannot remove the test optimization <br>"; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | 350 | } |
@@ -26,260 +26,260 @@ |
||
| 26 | 26 | |
| 27 | 27 | class TrackingTests extends \PHPUnit\Framework\TestCase |
| 28 | 28 | { |
| 29 | - public static $createdProblems = []; |
|
| 30 | - public static $testRoutes = []; |
|
| 31 | - |
|
| 32 | - public static function setUpBeforeClass() |
|
| 33 | - { |
|
| 34 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 35 | - |
|
| 36 | - $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); |
|
| 37 | - |
|
| 38 | - $addresses = []; |
|
| 39 | - foreach ($json as $address) { |
|
| 40 | - $addresses[] = Address::fromArray($address); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $parameters = RouteParameters::fromArray([ |
|
| 44 | - 'algorithm_type' => AlgorithmType::CVRP_TW_MD, |
|
| 45 | - 'distance_unit' => DistanceUnit::MILES, |
|
| 46 | - 'device_type' => DeviceType::WEB, |
|
| 47 | - 'optimize' => OptimizationType::DISTANCE, |
|
| 48 | - 'metric' => Metric::GEODESIC, |
|
| 49 | - 'route_max_duration' => 86400 * 2, |
|
| 50 | - 'travel_mode' => TravelMode::DRIVING, |
|
| 51 | - 'vehicle_capacity' => 50, |
|
| 52 | - 'vehicle_max_distance_mi' => 10000, |
|
| 53 | - 'parts' => 50, |
|
| 54 | - ]); |
|
| 55 | - //endregion |
|
| 56 | - |
|
| 57 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 58 | - $optimizationParameters->setAddresses($addresses); |
|
| 59 | - $optimizationParameters->setParameters($parameters); |
|
| 60 | - |
|
| 61 | - self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); |
|
| 62 | - |
|
| 63 | - self::$testRoutes = self::$createdProblems[0]->routes; |
|
| 64 | - |
|
| 65 | - $params = TrackSetParams::fromArray([ |
|
| 66 | - 'format' => Format::SERIALIZED, |
|
| 67 | - 'route_id' => self::$testRoutes[0]->route_id, |
|
| 68 | - 'member_id' => self::$testRoutes[0]->parameters->member_id, |
|
| 69 | - 'course' => 1, |
|
| 70 | - 'speed' => 120, |
|
| 71 | - 'lat' => 41.8927521, |
|
| 72 | - 'lng' => -109.0803888, |
|
| 73 | - 'device_type' => 'android_phone', |
|
| 74 | - 'device_guid' => 'qweqweqwe', |
|
| 75 | - 'device_timestamp' => date('Y-m-d H:i:s', strtotime('-2 day')), |
|
| 76 | - ]); |
|
| 77 | - |
|
| 78 | - $status = Track ::set($params); |
|
| 79 | - |
|
| 80 | - self::assertNotNull($status, "Cannot send GPS position to the selected route"); |
|
| 81 | - self::assertTrue(isset($status['status']), "Cannot send GPS position to the selected route"); |
|
| 82 | - self::assertTrue($status['status'], "Cannot send GPS position to the selected route"); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function testFromArray() |
|
| 86 | - { |
|
| 87 | - $trackingParams = TrackSetParams::fromArray([ |
|
| 88 | - 'member_id' => 44444, |
|
| 89 | - 'format' => 'json', |
|
| 90 | - 'route_id' => '489D597EE62534C906096F1AAC278D26', |
|
| 91 | - 'course' => 72, |
|
| 92 | - 'speed' => 65, |
|
| 93 | - 'lat' => 38.218662, |
|
| 94 | - 'lng' => -85.789032, |
|
| 95 | - 'device_type' => 'android_phone', |
|
| 96 | - 'device_guid' => 'HK5454H0K454564WWER445' |
|
| 97 | - ]); |
|
| 98 | - |
|
| 99 | - $this->assertEquals(44444, $trackingParams->member_id); |
|
| 100 | - $this->assertEquals('489D597EE62534C906096F1AAC278D26', $trackingParams->route_id); |
|
| 101 | - |
|
| 102 | - $this->assertEquals(72, $trackingParams->course); |
|
| 103 | - $this->assertEquals(65, $trackingParams->speed); |
|
| 104 | - $this->assertEquals(38.218662, $trackingParams->lat); |
|
| 105 | - $this->assertEquals(-85.789032, $trackingParams->lng); |
|
| 106 | - $this->assertEquals('android_phone', $trackingParams->device_type); |
|
| 107 | - $this->assertEquals('HK5454H0K454564WWER445', $trackingParams->device_guid); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - public function testFindAsset() |
|
| 111 | - { |
|
| 112 | - $trackingNumber = null; |
|
| 113 | - |
|
| 114 | - //region -- Get a tracking number from a random route destination -- |
|
| 115 | - $routeId = self::$testRoutes[0]->route_id; |
|
| 116 | - |
|
| 117 | - $addresses = self::$testRoutes[0]->addresses; |
|
| 118 | - assert(!is_null($addresses), "Cannot retrieve a random route ID"); |
|
| 119 | - |
|
| 120 | - foreach ($addresses as $addr1) { |
|
| 121 | - if (!is_null($addr1->tracking_number)) { |
|
| 122 | - $trackingNumber = $addr1->tracking_number; |
|
| 123 | - break; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $this->assertNotNull($trackingNumber, "Cannot select a tracking number"); |
|
| 128 | - |
|
| 129 | - //endregion |
|
| 130 | - |
|
| 131 | - $params = [ |
|
| 132 | - 'tracking' => $trackingNumber, |
|
| 133 | - ]; |
|
| 134 | - |
|
| 135 | - $route = new Route(); |
|
| 136 | - |
|
| 137 | - $result = $route->GetAssetTracking($params); |
|
| 138 | - |
|
| 139 | - $this->assertNotNull($result); |
|
| 140 | - $this->assertInstanceOf(FindAssetResponse::class, FindAssetResponse::fromArray($result)); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function testGetAllUserLocations() |
|
| 144 | - { |
|
| 145 | - $track = new Track(); |
|
| 146 | - |
|
| 147 | - $userLocations = $track->getUserLocations(); |
|
| 148 | - |
|
| 149 | - $this->assertNotNull($userLocations); |
|
| 150 | - $this->assertTrue(is_array($userLocations)); |
|
| 151 | - $this->assertTrue(sizeof($userLocations)>0); |
|
| 152 | - $this->assertInstanceOf( |
|
| 153 | - UserLocation::class, |
|
| 154 | - UserLocation::fromArray($userLocations[0])); |
|
| 155 | - $this->assertInstanceOf( |
|
| 156 | - MemberData::class, |
|
| 157 | - MemberData::fromArray($userLocations[0]['member_data'])); |
|
| 158 | - $this->assertInstanceOf( |
|
| 159 | - UserTracking::class, |
|
| 160 | - UserTracking::fromArray($userLocations[0]['tracking'])); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - public function testQueryUserLocations() |
|
| 164 | - { |
|
| 165 | - $track = new Track(); |
|
| 166 | - $userLocations = $track->getUserLocations(); |
|
| 167 | - $userLocation = reset($userLocations); |
|
| 168 | - |
|
| 169 | - $email = $userLocation['member_data']['member_email']; |
|
| 170 | - |
|
| 171 | - $queriedUserLocations = $track->getUserLocations($email); |
|
| 172 | - |
|
| 173 | - $this->assertNotNull($queriedUserLocations); |
|
| 174 | - $this->assertTrue(is_array($queriedUserLocations)); |
|
| 175 | - $this->assertTrue(sizeof($queriedUserLocations)>0); |
|
| 176 | - $this->assertInstanceOf( |
|
| 177 | - UserLocation::class, |
|
| 178 | - UserLocation::fromArray($queriedUserLocations[0]) |
|
| 179 | - ); |
|
| 180 | - $this->assertInstanceOf( |
|
| 181 | - MemberData::class, |
|
| 182 | - MemberData::fromArray($queriedUserLocations[0]['member_data']) |
|
| 183 | - ); |
|
| 184 | - $this->assertInstanceOf( |
|
| 185 | - UserTracking::class, |
|
| 186 | - UserTracking::fromArray($queriedUserLocations[0]['tracking']) |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - public function testGetDeviceHistoryTimeRange() |
|
| 191 | - { |
|
| 192 | - $startDate = time() - 30 * 24 * 3600; |
|
| 193 | - $endDate = time() + 1 * 24 * 3600; |
|
| 194 | - |
|
| 195 | - $params = [ |
|
| 196 | - 'route_id' => self::$testRoutes[0]->route_id, |
|
| 197 | - 'format' => Format::JSON, |
|
| 198 | - 'time_period' => 'custom', |
|
| 199 | - 'start_date' => $startDate, |
|
| 200 | - 'end_date' => $endDate, |
|
| 201 | - ]; |
|
| 202 | - |
|
| 203 | - $route = new Route(); |
|
| 204 | - |
|
| 205 | - $result = $route->GetTrackingHistoryFromTimeRange($params); |
|
| 206 | - |
|
| 207 | - $this->assertNotNull($result); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - public function testSetGPSPosition() |
|
| 211 | - { |
|
| 212 | - $route = new Route(); |
|
| 213 | - |
|
| 214 | - $routeId = self::$testRoutes[0]->route_id; |
|
| 215 | - |
|
| 216 | - // Set GPS postion to the selected route |
|
| 217 | - // Set right member_id corresponding to the API key |
|
| 218 | - $params = TrackSetParams::fromArray([ |
|
| 219 | - 'format' => Format::CSV, |
|
| 220 | - 'route_id' => $routeId, |
|
| 221 | - 'member_id' => self::$testRoutes[0]->parameters->member_id, |
|
| 222 | - 'course' => 1, |
|
| 223 | - 'speed' => 120, |
|
| 224 | - 'lat' => 41.8927521, |
|
| 225 | - 'lng' => -109.0803888, |
|
| 226 | - 'device_type' => 'android_phone', |
|
| 227 | - 'device_guid' => 'qweqweqwe', |
|
| 228 | - 'device_timestamp' => date('Y-m-d H:i:s', strtotime('-1 day')), |
|
| 229 | - ]); |
|
| 230 | - |
|
| 231 | - $status = Track::set($params); |
|
| 232 | - |
|
| 233 | - $this->assertNotNull($status); |
|
| 234 | - $this->assertInstanceOf( |
|
| 235 | - SetGpsResponse::class, |
|
| 236 | - SetGpsResponse::fromArray($status) |
|
| 237 | - ); |
|
| 238 | - $this->assertTrue($status['status']); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - public function testTrackDeviceLastLocationHistory() |
|
| 242 | - { |
|
| 243 | - $route = new Route(); |
|
| 244 | - |
|
| 245 | - $routeId = self::$testRoutes[0]->route_id; |
|
| 246 | - |
|
| 247 | - $params = [ |
|
| 248 | - 'route_id' => $routeId, |
|
| 249 | - 'device_tracking_history' => '1', |
|
| 250 | - ]; |
|
| 251 | - |
|
| 252 | - $result = $route->GetLastLocation($params); |
|
| 253 | - |
|
| 254 | - $this->assertNotNull($result); |
|
| 255 | - $this->assertInstanceOf(Route::class, $result); |
|
| 256 | - $this->assertTrue(isset($result->tracking_history)); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - public static function tearDownAfterClass() |
|
| 260 | - { |
|
| 261 | - if (sizeof(self::$createdProblems)>0) { |
|
| 262 | - $optimizationProblemIDs = []; |
|
| 263 | - |
|
| 264 | - foreach (self::$createdProblems as $problem) { |
|
| 265 | - $optimizationProblemId = $problem->optimization_problem_id; |
|
| 266 | - |
|
| 267 | - $optimizationProblemIDs[] = $optimizationProblemId; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $params = [ |
|
| 271 | - 'optimization_problem_ids' => $optimizationProblemIDs, |
|
| 272 | - 'redirect' => 0, |
|
| 273 | - ]; |
|
| 274 | - |
|
| 275 | - $problem = new OptimizationProblem(); |
|
| 276 | - $result = $problem->removeOptimization($params); |
|
| 277 | - |
|
| 278 | - if ($result!=null && $result['status']==true) { |
|
| 279 | - echo "The test optimizations were removed <br>"; |
|
| 280 | - } else { |
|
| 281 | - echo "Cannot remove the test optimizations <br>"; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 29 | + public static $createdProblems = []; |
|
| 30 | + public static $testRoutes = []; |
|
| 31 | + |
|
| 32 | + public static function setUpBeforeClass() |
|
| 33 | + { |
|
| 34 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 35 | + |
|
| 36 | + $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses_md_tw.json'), true); |
|
| 37 | + |
|
| 38 | + $addresses = []; |
|
| 39 | + foreach ($json as $address) { |
|
| 40 | + $addresses[] = Address::fromArray($address); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $parameters = RouteParameters::fromArray([ |
|
| 44 | + 'algorithm_type' => AlgorithmType::CVRP_TW_MD, |
|
| 45 | + 'distance_unit' => DistanceUnit::MILES, |
|
| 46 | + 'device_type' => DeviceType::WEB, |
|
| 47 | + 'optimize' => OptimizationType::DISTANCE, |
|
| 48 | + 'metric' => Metric::GEODESIC, |
|
| 49 | + 'route_max_duration' => 86400 * 2, |
|
| 50 | + 'travel_mode' => TravelMode::DRIVING, |
|
| 51 | + 'vehicle_capacity' => 50, |
|
| 52 | + 'vehicle_max_distance_mi' => 10000, |
|
| 53 | + 'parts' => 50, |
|
| 54 | + ]); |
|
| 55 | + //endregion |
|
| 56 | + |
|
| 57 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 58 | + $optimizationParameters->setAddresses($addresses); |
|
| 59 | + $optimizationParameters->setParameters($parameters); |
|
| 60 | + |
|
| 61 | + self::$createdProblems[] = OptimizationProblem::optimize($optimizationParameters); |
|
| 62 | + |
|
| 63 | + self::$testRoutes = self::$createdProblems[0]->routes; |
|
| 64 | + |
|
| 65 | + $params = TrackSetParams::fromArray([ |
|
| 66 | + 'format' => Format::SERIALIZED, |
|
| 67 | + 'route_id' => self::$testRoutes[0]->route_id, |
|
| 68 | + 'member_id' => self::$testRoutes[0]->parameters->member_id, |
|
| 69 | + 'course' => 1, |
|
| 70 | + 'speed' => 120, |
|
| 71 | + 'lat' => 41.8927521, |
|
| 72 | + 'lng' => -109.0803888, |
|
| 73 | + 'device_type' => 'android_phone', |
|
| 74 | + 'device_guid' => 'qweqweqwe', |
|
| 75 | + 'device_timestamp' => date('Y-m-d H:i:s', strtotime('-2 day')), |
|
| 76 | + ]); |
|
| 77 | + |
|
| 78 | + $status = Track ::set($params); |
|
| 79 | + |
|
| 80 | + self::assertNotNull($status, "Cannot send GPS position to the selected route"); |
|
| 81 | + self::assertTrue(isset($status['status']), "Cannot send GPS position to the selected route"); |
|
| 82 | + self::assertTrue($status['status'], "Cannot send GPS position to the selected route"); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function testFromArray() |
|
| 86 | + { |
|
| 87 | + $trackingParams = TrackSetParams::fromArray([ |
|
| 88 | + 'member_id' => 44444, |
|
| 89 | + 'format' => 'json', |
|
| 90 | + 'route_id' => '489D597EE62534C906096F1AAC278D26', |
|
| 91 | + 'course' => 72, |
|
| 92 | + 'speed' => 65, |
|
| 93 | + 'lat' => 38.218662, |
|
| 94 | + 'lng' => -85.789032, |
|
| 95 | + 'device_type' => 'android_phone', |
|
| 96 | + 'device_guid' => 'HK5454H0K454564WWER445' |
|
| 97 | + ]); |
|
| 98 | + |
|
| 99 | + $this->assertEquals(44444, $trackingParams->member_id); |
|
| 100 | + $this->assertEquals('489D597EE62534C906096F1AAC278D26', $trackingParams->route_id); |
|
| 101 | + |
|
| 102 | + $this->assertEquals(72, $trackingParams->course); |
|
| 103 | + $this->assertEquals(65, $trackingParams->speed); |
|
| 104 | + $this->assertEquals(38.218662, $trackingParams->lat); |
|
| 105 | + $this->assertEquals(-85.789032, $trackingParams->lng); |
|
| 106 | + $this->assertEquals('android_phone', $trackingParams->device_type); |
|
| 107 | + $this->assertEquals('HK5454H0K454564WWER445', $trackingParams->device_guid); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + public function testFindAsset() |
|
| 111 | + { |
|
| 112 | + $trackingNumber = null; |
|
| 113 | + |
|
| 114 | + //region -- Get a tracking number from a random route destination -- |
|
| 115 | + $routeId = self::$testRoutes[0]->route_id; |
|
| 116 | + |
|
| 117 | + $addresses = self::$testRoutes[0]->addresses; |
|
| 118 | + assert(!is_null($addresses), "Cannot retrieve a random route ID"); |
|
| 119 | + |
|
| 120 | + foreach ($addresses as $addr1) { |
|
| 121 | + if (!is_null($addr1->tracking_number)) { |
|
| 122 | + $trackingNumber = $addr1->tracking_number; |
|
| 123 | + break; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $this->assertNotNull($trackingNumber, "Cannot select a tracking number"); |
|
| 128 | + |
|
| 129 | + //endregion |
|
| 130 | + |
|
| 131 | + $params = [ |
|
| 132 | + 'tracking' => $trackingNumber, |
|
| 133 | + ]; |
|
| 134 | + |
|
| 135 | + $route = new Route(); |
|
| 136 | + |
|
| 137 | + $result = $route->GetAssetTracking($params); |
|
| 138 | + |
|
| 139 | + $this->assertNotNull($result); |
|
| 140 | + $this->assertInstanceOf(FindAssetResponse::class, FindAssetResponse::fromArray($result)); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function testGetAllUserLocations() |
|
| 144 | + { |
|
| 145 | + $track = new Track(); |
|
| 146 | + |
|
| 147 | + $userLocations = $track->getUserLocations(); |
|
| 148 | + |
|
| 149 | + $this->assertNotNull($userLocations); |
|
| 150 | + $this->assertTrue(is_array($userLocations)); |
|
| 151 | + $this->assertTrue(sizeof($userLocations)>0); |
|
| 152 | + $this->assertInstanceOf( |
|
| 153 | + UserLocation::class, |
|
| 154 | + UserLocation::fromArray($userLocations[0])); |
|
| 155 | + $this->assertInstanceOf( |
|
| 156 | + MemberData::class, |
|
| 157 | + MemberData::fromArray($userLocations[0]['member_data'])); |
|
| 158 | + $this->assertInstanceOf( |
|
| 159 | + UserTracking::class, |
|
| 160 | + UserTracking::fromArray($userLocations[0]['tracking'])); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function testQueryUserLocations() |
|
| 164 | + { |
|
| 165 | + $track = new Track(); |
|
| 166 | + $userLocations = $track->getUserLocations(); |
|
| 167 | + $userLocation = reset($userLocations); |
|
| 168 | + |
|
| 169 | + $email = $userLocation['member_data']['member_email']; |
|
| 170 | + |
|
| 171 | + $queriedUserLocations = $track->getUserLocations($email); |
|
| 172 | + |
|
| 173 | + $this->assertNotNull($queriedUserLocations); |
|
| 174 | + $this->assertTrue(is_array($queriedUserLocations)); |
|
| 175 | + $this->assertTrue(sizeof($queriedUserLocations)>0); |
|
| 176 | + $this->assertInstanceOf( |
|
| 177 | + UserLocation::class, |
|
| 178 | + UserLocation::fromArray($queriedUserLocations[0]) |
|
| 179 | + ); |
|
| 180 | + $this->assertInstanceOf( |
|
| 181 | + MemberData::class, |
|
| 182 | + MemberData::fromArray($queriedUserLocations[0]['member_data']) |
|
| 183 | + ); |
|
| 184 | + $this->assertInstanceOf( |
|
| 185 | + UserTracking::class, |
|
| 186 | + UserTracking::fromArray($queriedUserLocations[0]['tracking']) |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + public function testGetDeviceHistoryTimeRange() |
|
| 191 | + { |
|
| 192 | + $startDate = time() - 30 * 24 * 3600; |
|
| 193 | + $endDate = time() + 1 * 24 * 3600; |
|
| 194 | + |
|
| 195 | + $params = [ |
|
| 196 | + 'route_id' => self::$testRoutes[0]->route_id, |
|
| 197 | + 'format' => Format::JSON, |
|
| 198 | + 'time_period' => 'custom', |
|
| 199 | + 'start_date' => $startDate, |
|
| 200 | + 'end_date' => $endDate, |
|
| 201 | + ]; |
|
| 202 | + |
|
| 203 | + $route = new Route(); |
|
| 204 | + |
|
| 205 | + $result = $route->GetTrackingHistoryFromTimeRange($params); |
|
| 206 | + |
|
| 207 | + $this->assertNotNull($result); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + public function testSetGPSPosition() |
|
| 211 | + { |
|
| 212 | + $route = new Route(); |
|
| 213 | + |
|
| 214 | + $routeId = self::$testRoutes[0]->route_id; |
|
| 215 | + |
|
| 216 | + // Set GPS postion to the selected route |
|
| 217 | + // Set right member_id corresponding to the API key |
|
| 218 | + $params = TrackSetParams::fromArray([ |
|
| 219 | + 'format' => Format::CSV, |
|
| 220 | + 'route_id' => $routeId, |
|
| 221 | + 'member_id' => self::$testRoutes[0]->parameters->member_id, |
|
| 222 | + 'course' => 1, |
|
| 223 | + 'speed' => 120, |
|
| 224 | + 'lat' => 41.8927521, |
|
| 225 | + 'lng' => -109.0803888, |
|
| 226 | + 'device_type' => 'android_phone', |
|
| 227 | + 'device_guid' => 'qweqweqwe', |
|
| 228 | + 'device_timestamp' => date('Y-m-d H:i:s', strtotime('-1 day')), |
|
| 229 | + ]); |
|
| 230 | + |
|
| 231 | + $status = Track::set($params); |
|
| 232 | + |
|
| 233 | + $this->assertNotNull($status); |
|
| 234 | + $this->assertInstanceOf( |
|
| 235 | + SetGpsResponse::class, |
|
| 236 | + SetGpsResponse::fromArray($status) |
|
| 237 | + ); |
|
| 238 | + $this->assertTrue($status['status']); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + public function testTrackDeviceLastLocationHistory() |
|
| 242 | + { |
|
| 243 | + $route = new Route(); |
|
| 244 | + |
|
| 245 | + $routeId = self::$testRoutes[0]->route_id; |
|
| 246 | + |
|
| 247 | + $params = [ |
|
| 248 | + 'route_id' => $routeId, |
|
| 249 | + 'device_tracking_history' => '1', |
|
| 250 | + ]; |
|
| 251 | + |
|
| 252 | + $result = $route->GetLastLocation($params); |
|
| 253 | + |
|
| 254 | + $this->assertNotNull($result); |
|
| 255 | + $this->assertInstanceOf(Route::class, $result); |
|
| 256 | + $this->assertTrue(isset($result->tracking_history)); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + public static function tearDownAfterClass() |
|
| 260 | + { |
|
| 261 | + if (sizeof(self::$createdProblems)>0) { |
|
| 262 | + $optimizationProblemIDs = []; |
|
| 263 | + |
|
| 264 | + foreach (self::$createdProblems as $problem) { |
|
| 265 | + $optimizationProblemId = $problem->optimization_problem_id; |
|
| 266 | + |
|
| 267 | + $optimizationProblemIDs[] = $optimizationProblemId; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $params = [ |
|
| 271 | + 'optimization_problem_ids' => $optimizationProblemIDs, |
|
| 272 | + 'redirect' => 0, |
|
| 273 | + ]; |
|
| 274 | + |
|
| 275 | + $problem = new OptimizationProblem(); |
|
| 276 | + $result = $problem->removeOptimization($params); |
|
| 277 | + |
|
| 278 | + if ($result!=null && $result['status']==true) { |
|
| 279 | + echo "The test optimizations were removed <br>"; |
|
| 280 | + } else { |
|
| 281 | + echo "Cannot remove the test optimizations <br>"; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | 285 | } |
| 286 | 286 | \ No newline at end of file |
@@ -15,490 +15,490 @@ |
||
| 15 | 15 | |
| 16 | 16 | class TelematicsGateWayApiTests extends \PHPUnit\Framework\TestCase |
| 17 | 17 | { |
| 18 | - static $createdConnections = []; |
|
| 19 | - static $firstMemberId; |
|
| 18 | + static $createdConnections = []; |
|
| 19 | + static $firstMemberId; |
|
| 20 | 20 | |
| 21 | - static $api_token; |
|
| 22 | - static $tomtom_vendor; |
|
| 21 | + static $api_token; |
|
| 22 | + static $tomtom_vendor; |
|
| 23 | 23 | |
| 24 | - public static function setUpBeforeClass() |
|
| 25 | - { |
|
| 26 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 24 | + public static function setUpBeforeClass() |
|
| 25 | + { |
|
| 26 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 27 | 27 | |
| 28 | - $member = new Member(); |
|
| 28 | + $member = new Member(); |
|
| 29 | 29 | |
| 30 | - $results = $member->getUsers(); |
|
| 30 | + $results = $member->getUsers(); |
|
| 31 | 31 | |
| 32 | - self::$firstMemberId = Member::fromArray($results['results'][0])->member_id; |
|
| 32 | + self::$firstMemberId = Member::fromArray($results['results'][0])->member_id; |
|
| 33 | 33 | |
| 34 | - print_r("\n member_id = ".self::$firstMemberId."\n"); |
|
| 35 | - |
|
| 36 | - //region Get API token |
|
| 37 | - |
|
| 38 | - $vendorParameters = new TelematicsVendorParameters(); |
|
| 39 | - $vendorParameters->member_id = self::$firstMemberId; |
|
| 40 | - $vendorParameters->api_key = Constants::API_KEY; |
|
| 41 | - |
|
| 42 | - $vendors = new TelematicsVendor(); |
|
| 43 | - $result = $vendors->RegisterTelematicsMember($vendorParameters); |
|
| 44 | - |
|
| 45 | - self::assertNotNull($result); |
|
| 46 | - self::assertInstanceOf( |
|
| 47 | - TelematicsRegisterMemberResponse::class, |
|
| 48 | - TelematicsRegisterMemberResponse::fromArray($result) |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - self::$api_token = TelematicsRegisterMemberResponse::fromArray( |
|
| 52 | - $result |
|
| 53 | - )->api_token; |
|
| 54 | - |
|
| 55 | - //endregion |
|
| 56 | - |
|
| 57 | - //region Get TomTom vendor |
|
| 58 | - |
|
| 59 | - $vendorsParameters = TelematicsVendorParameters::fromArray([ |
|
| 60 | - //"country" => "GB", // uncomment this line for searching by Country |
|
| 61 | - 'is_integrated' => 1, |
|
| 62 | - //"feature" => "satellite", // uncomment this line for searching by Feature |
|
| 63 | - 'search' => 'tomtom', |
|
| 64 | - 'page' => 1, |
|
| 65 | - 'per_page' => 5, |
|
| 66 | - ]); |
|
| 67 | - |
|
| 68 | - $vendors = new TelematicsVendor(); |
|
| 69 | - $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 70 | - |
|
| 71 | - self::assertNotNull($vendorsResults); |
|
| 72 | - self::assertTrue(is_array($vendorsResults)); |
|
| 73 | - self::assertTrue(sizeof($vendorsResults)>0); |
|
| 74 | - self::assertTrue( |
|
| 75 | - TelematicsVendor::fromArray($vendorsResults['vendors'][0]) |
|
| 76 | - instanceof |
|
| 77 | - TelematicsVendor); |
|
| 78 | - |
|
| 79 | - self::$tomtom_vendor = TelematicsVendor::fromArray($vendorsResults['vendors'][0]); |
|
| 80 | - //endregion |
|
| 81 | - |
|
| 82 | - //region Create Test Connection |
|
| 83 | - |
|
| 84 | - $vendParams = new TelematicsConnectionParameters(); |
|
| 85 | - |
|
| 86 | - $vendParams->vendor = TelematicsVendorsTypes::GEOTAB; |
|
| 87 | - $vendParams->account_id = '54321'; |
|
| 88 | - $vendParams->username = 'John Doe 0'; |
|
| 89 | - $vendParams->password = 'password0'; |
|
| 90 | - $vendParams->vehicle_position_refresh_rate = 60; |
|
| 91 | - $vendParams->name = 'Test Geotab Connection from php SDK'; |
|
| 92 | - $vendParams->validate_remote_credentials = 0; |
|
| 93 | - |
|
| 94 | - $teleConnection = new TelematicsConnection(); |
|
| 95 | - |
|
| 96 | - $result2 = $teleConnection->createTelematicsConnection( |
|
| 97 | - self::$api_token, |
|
| 98 | - $vendParams->toArray() |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - self::assertNotNull($result2); |
|
| 102 | - self::assertTrue( CreateConnectionResponse::fromArray($result2) instanceof CreateConnectionResponse); |
|
| 103 | - |
|
| 104 | - self::$createdConnections[] = TelematicsConnection::fromArray($result2); |
|
| 105 | - //endregion |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function testFromArray() |
|
| 109 | - { |
|
| 110 | - $vendorParameters = TelematicsVendor::fromArray([ |
|
| 111 | - 'id' => 14, |
|
| 112 | - 'name' => 'Borea', |
|
| 113 | - 'slug' => 'borea', |
|
| 114 | - 'description' => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 115 | - 'logo_url' => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 116 | - 'website_url' => 'https:\/\/www.borea.com\/', |
|
| 117 | - 'api_docs_url' => 'https:\/\/www.borea.com\/docs\/', |
|
| 118 | - 'is_integrated' => true, |
|
| 119 | - 'size' => 'regional', |
|
| 120 | - 'features' => [ |
|
| 121 | - 0 => [ |
|
| 122 | - 'id' => '1', |
|
| 123 | - 'name' => 'Customizable Reports', |
|
| 124 | - 'slug' => 'customizable-reports', |
|
| 125 | - 'feature_group' => 'Analytics & Reporting' |
|
| 126 | - ], |
|
| 127 | - 1 => [ |
|
| 128 | - 'id' => '2', |
|
| 129 | - 'name' => 'Publicly Accessible API Documention', |
|
| 130 | - 'slug' => 'publicly-accessible-api-doc', |
|
| 131 | - 'feature_group' => 'API & SDK' |
|
| 132 | - ] |
|
| 133 | - ], |
|
| 134 | - 'countries' => [ |
|
| 135 | - 0 => [ |
|
| 136 | - 'id' => '38', |
|
| 137 | - 'country_code' => 'CA', |
|
| 138 | - 'country_name' => 'Canada' |
|
| 139 | - ], |
|
| 140 | - 1 => [ |
|
| 141 | - 'id' => '230', |
|
| 142 | - 'country_code' => 'USA', |
|
| 143 | - 'country_name' => 'United States' |
|
| 144 | - ] |
|
| 145 | - ] |
|
| 146 | - ]); |
|
| 147 | - |
|
| 148 | - $this->assertEquals(14, $vendorParameters->id); |
|
| 149 | - $this->assertEquals('Borea', $vendorParameters->name); |
|
| 150 | - $this->assertEquals('borea', $vendorParameters->slug); |
|
| 151 | - $this->assertEquals( |
|
| 152 | - 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 153 | - $vendorParameters->description |
|
| 154 | - ); |
|
| 155 | - $this->assertEquals( |
|
| 156 | - 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 157 | - $vendorParameters->logo_url |
|
| 158 | - ); |
|
| 159 | - $this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url); |
|
| 160 | - $this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url); |
|
| 161 | - $this->assertEquals(true, $vendorParameters->is_integrated); |
|
| 162 | - $this->assertEquals('regional', $vendorParameters->size); |
|
| 163 | - $this->assertEquals( |
|
| 164 | - [ |
|
| 165 | - 0 => [ |
|
| 166 | - 'id' => '1', |
|
| 167 | - 'name' => 'Customizable Reports', |
|
| 168 | - 'slug' => 'customizable-reports', |
|
| 169 | - 'feature_group' => 'Analytics & Reporting' |
|
| 170 | - ], |
|
| 171 | - 1 => [ |
|
| 172 | - 'id' => '2', |
|
| 173 | - 'name' => 'Publicly Accessible API Documention', |
|
| 174 | - 'slug' => 'publicly-accessible-api-doc', |
|
| 175 | - 'feature_group' => 'API & SDK' |
|
| 176 | - ] |
|
| 177 | - ], |
|
| 178 | - $vendorParameters->features |
|
| 179 | - ); |
|
| 180 | - $this->assertEquals( |
|
| 181 | - [ |
|
| 182 | - 0 => [ |
|
| 183 | - 'id' => '38', |
|
| 184 | - 'country_code' => 'CA', |
|
| 185 | - 'country_name' => 'Canada' |
|
| 186 | - ], |
|
| 187 | - 1 => [ |
|
| 188 | - 'id' => '230', |
|
| 189 | - 'country_code' => 'USA', |
|
| 190 | - 'country_name' => 'United States' |
|
| 191 | - ] |
|
| 192 | - ], |
|
| 193 | - $vendorParameters->countries |
|
| 194 | - ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - public function testToArray() |
|
| 198 | - { |
|
| 199 | - $vendorParameters = TelematicsVendor::fromArray([ |
|
| 200 | - 'id' => 14, |
|
| 201 | - 'name' => 'Borea', |
|
| 202 | - 'slug' => 'borea', |
|
| 203 | - 'description' => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 204 | - 'logo_url' => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 205 | - 'website_url' => 'https:\/\/www.borea.com\/', |
|
| 206 | - 'api_docs_url' => 'https:\/\/www.borea.com\/docs\/', |
|
| 207 | - 'is_integrated' => true, |
|
| 208 | - 'size' => 'regional', |
|
| 209 | - 'features' => [ |
|
| 210 | - 0 => [ |
|
| 211 | - 'id' => '1', |
|
| 212 | - 'name' => 'Customizable Reports', |
|
| 213 | - 'slug' => 'customizable-reports', |
|
| 214 | - 'feature_group' => 'Analytics & Reporting' |
|
| 215 | - ], |
|
| 216 | - 1 => [ |
|
| 217 | - 'id' => '2', |
|
| 218 | - 'name' => 'Publicly Accessible API Documention', |
|
| 219 | - 'slug' => 'publicly-accessible-api-doc', |
|
| 220 | - 'feature_group' => 'API & SDK' |
|
| 221 | - ] |
|
| 222 | - ], |
|
| 223 | - 'countries' => [ |
|
| 224 | - 0 => [ |
|
| 225 | - 'id' => '38', |
|
| 226 | - 'country_code' => 'CA', |
|
| 227 | - 'country_name' => 'Canada' |
|
| 228 | - ], |
|
| 229 | - 1 => [ |
|
| 230 | - 'id' => '230', |
|
| 231 | - 'country_code' => 'USA', |
|
| 232 | - 'country_name' => 'United States' |
|
| 233 | - ] |
|
| 234 | - ] |
|
| 235 | - ]); |
|
| 236 | - |
|
| 237 | - $this->assertEquals(14, $vendorParameters->id); |
|
| 238 | - $this->assertEquals('Borea', $vendorParameters->name); |
|
| 239 | - $this->assertEquals('borea', $vendorParameters->slug); |
|
| 240 | - $this->assertEquals( |
|
| 241 | - 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 242 | - $vendorParameters->description |
|
| 243 | - ); |
|
| 244 | - $this->assertEquals( |
|
| 245 | - 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 246 | - $vendorParameters->logo_url |
|
| 247 | - ); |
|
| 248 | - $this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url); |
|
| 249 | - $this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url); |
|
| 250 | - $this->assertEquals(true, $vendorParameters->is_integrated); |
|
| 251 | - $this->assertEquals('regional', $vendorParameters->size); |
|
| 252 | - $this->assertEquals( |
|
| 253 | - [ |
|
| 254 | - 0 => [ |
|
| 255 | - 'id' => '1', |
|
| 256 | - 'name' => 'Customizable Reports', |
|
| 257 | - 'slug' => 'customizable-reports', |
|
| 258 | - 'feature_group' => 'Analytics & Reporting' |
|
| 259 | - ], |
|
| 260 | - 1 => [ |
|
| 261 | - 'id' => '2', |
|
| 262 | - 'name' => 'Publicly Accessible API Documention', |
|
| 263 | - 'slug' => 'publicly-accessible-api-doc', |
|
| 264 | - 'feature_group' => 'API & SDK' |
|
| 265 | - ] |
|
| 266 | - ], |
|
| 267 | - $vendorParameters->features |
|
| 268 | - ); |
|
| 269 | - $this->assertEquals( |
|
| 270 | - [ |
|
| 271 | - 0 => [ |
|
| 272 | - 'id' => '38', |
|
| 273 | - 'country_code' => 'CA', |
|
| 274 | - 'country_name' => 'Canada' |
|
| 275 | - ], |
|
| 276 | - 1 => [ |
|
| 277 | - 'id' => '230', |
|
| 278 | - 'country_code' => 'USA', |
|
| 279 | - 'country_name' => 'United States' |
|
| 280 | - ] |
|
| 281 | - ], |
|
| 282 | - $vendorParameters->countries |
|
| 283 | - ); |
|
| 284 | - |
|
| 285 | - $this->assertEquals($vendorParameters->toArray(), |
|
| 286 | - [ |
|
| 287 | - 'id' => 14, |
|
| 288 | - 'name' => 'Borea', |
|
| 289 | - 'slug' => 'borea', |
|
| 290 | - 'description' => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 291 | - 'logo_url' => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 292 | - 'website_url' => 'https:\/\/www.borea.com\/', |
|
| 293 | - 'api_docs_url' => 'https:\/\/www.borea.com\/docs\/', |
|
| 294 | - 'is_integrated' => true, |
|
| 295 | - 'size' => 'regional', |
|
| 296 | - 'features' => [ |
|
| 297 | - 0 => [ |
|
| 298 | - 'id' => '1', |
|
| 299 | - 'name' => 'Customizable Reports', |
|
| 300 | - 'slug' => 'customizable-reports', |
|
| 301 | - 'feature_group' => 'Analytics & Reporting' |
|
| 302 | - ], |
|
| 303 | - 1 => [ |
|
| 304 | - 'id' => '2', |
|
| 305 | - 'name' => 'Publicly Accessible API Documention', |
|
| 306 | - 'slug' => 'publicly-accessible-api-doc', |
|
| 307 | - 'feature_group' => 'API & SDK' |
|
| 308 | - ] |
|
| 309 | - ], |
|
| 310 | - 'countries' => [ |
|
| 311 | - 0 => [ |
|
| 312 | - 'id' => '38', |
|
| 313 | - 'country_code' => 'CA', |
|
| 314 | - 'country_name' => 'Canada' |
|
| 315 | - ], |
|
| 316 | - 1 => [ |
|
| 317 | - 'id' => '230', |
|
| 318 | - 'country_code' => 'USA', |
|
| 319 | - 'country_name' => 'United States' |
|
| 320 | - ] |
|
| 321 | - ] |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - public function testGetAllVendors() |
|
| 327 | - { |
|
| 328 | - $vendorsParameters = TelematicsVendor::fromArray( [ ] ); |
|
| 329 | - |
|
| 330 | - $vendors = new TelematicsVendor(); |
|
| 331 | - $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 332 | - |
|
| 333 | - $this->assertNotNull($vendorsResults); |
|
| 334 | - $this->assertTrue(is_array($vendorsResults)); |
|
| 335 | - $this->assertTrue(sizeof($vendorsResults)>0); |
|
| 336 | - $this->assertInstanceOf( |
|
| 337 | - TelematicsVendor::class, |
|
| 338 | - TelematicsVendor::fromArray($vendorsResults['vendors'][0]) |
|
| 339 | - ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - public function testGetVendor() |
|
| 343 | - { |
|
| 344 | - $vendorResult = TelematicsVendor::getVendorById(self::$tomtom_vendor->id); |
|
| 345 | - |
|
| 346 | - $this->assertNotNull($vendorResult); |
|
| 347 | - $this->assertTrue(is_array($vendorResult)); |
|
| 348 | - $this->assertInstanceOf( |
|
| 349 | - TelematicsVendor::class, |
|
| 350 | - TelematicsVendor::fromArray($vendorResult) |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - public function testSearchVendors() |
|
| 355 | - { |
|
| 356 | - $vendorsParameters = TelematicsVendorParameters::fromArray([ |
|
| 357 | - //"country" => "GB", // uncomment this line for searching by Country |
|
| 358 | - 'is_integrated' => 1, |
|
| 359 | - //"feature" => "satellite", // uncomment this line for searching by Feature |
|
| 360 | - 'search' => 'Fleet', |
|
| 361 | - 'page' => 1, |
|
| 362 | - 'per_page' => 5, |
|
| 363 | - ]); |
|
| 364 | - |
|
| 365 | - $vendors = new TelematicsVendor(); |
|
| 366 | - $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 367 | - |
|
| 368 | - $this->assertNotNull($vendorsResults); |
|
| 369 | - $this->assertTrue(is_array($vendorsResults)); |
|
| 370 | - $this->assertTrue(sizeof($vendorsResults)>0); |
|
| 371 | - $this->assertInstanceOf( |
|
| 372 | - TelematicsVendor::class, |
|
| 373 | - TelematicsVendor::fromArray($vendorsResults['vendors'][0]) |
|
| 374 | - ); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - public function testVendorsComparison() |
|
| 378 | - { |
|
| 379 | - $vendorsParameters = TelematicsVendorParameters::fromArray([ |
|
| 380 | - 'vendors' => '55,56,57', |
|
| 381 | - ]); |
|
| 382 | - |
|
| 383 | - $vendors = new TelematicsVendor(); |
|
| 384 | - $comparisonResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 385 | - |
|
| 386 | - $this->assertNotNull($comparisonResults); |
|
| 387 | - $this->assertTrue(is_array($comparisonResults)); |
|
| 388 | - $this->assertTrue(sizeof($comparisonResults)>0); |
|
| 389 | - $this->assertInstanceOf( |
|
| 390 | - TelematicsVendor::class, |
|
| 391 | - TelematicsVendor::fromArray($comparisonResults['vendors'][0]) |
|
| 392 | - ); |
|
| 393 | - } |
|
| 34 | + print_r("\n member_id = ".self::$firstMemberId."\n"); |
|
| 35 | + |
|
| 36 | + //region Get API token |
|
| 37 | + |
|
| 38 | + $vendorParameters = new TelematicsVendorParameters(); |
|
| 39 | + $vendorParameters->member_id = self::$firstMemberId; |
|
| 40 | + $vendorParameters->api_key = Constants::API_KEY; |
|
| 41 | + |
|
| 42 | + $vendors = new TelematicsVendor(); |
|
| 43 | + $result = $vendors->RegisterTelematicsMember($vendorParameters); |
|
| 44 | + |
|
| 45 | + self::assertNotNull($result); |
|
| 46 | + self::assertInstanceOf( |
|
| 47 | + TelematicsRegisterMemberResponse::class, |
|
| 48 | + TelematicsRegisterMemberResponse::fromArray($result) |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + self::$api_token = TelematicsRegisterMemberResponse::fromArray( |
|
| 52 | + $result |
|
| 53 | + )->api_token; |
|
| 54 | + |
|
| 55 | + //endregion |
|
| 56 | + |
|
| 57 | + //region Get TomTom vendor |
|
| 58 | + |
|
| 59 | + $vendorsParameters = TelematicsVendorParameters::fromArray([ |
|
| 60 | + //"country" => "GB", // uncomment this line for searching by Country |
|
| 61 | + 'is_integrated' => 1, |
|
| 62 | + //"feature" => "satellite", // uncomment this line for searching by Feature |
|
| 63 | + 'search' => 'tomtom', |
|
| 64 | + 'page' => 1, |
|
| 65 | + 'per_page' => 5, |
|
| 66 | + ]); |
|
| 67 | + |
|
| 68 | + $vendors = new TelematicsVendor(); |
|
| 69 | + $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 70 | + |
|
| 71 | + self::assertNotNull($vendorsResults); |
|
| 72 | + self::assertTrue(is_array($vendorsResults)); |
|
| 73 | + self::assertTrue(sizeof($vendorsResults)>0); |
|
| 74 | + self::assertTrue( |
|
| 75 | + TelematicsVendor::fromArray($vendorsResults['vendors'][0]) |
|
| 76 | + instanceof |
|
| 77 | + TelematicsVendor); |
|
| 78 | + |
|
| 79 | + self::$tomtom_vendor = TelematicsVendor::fromArray($vendorsResults['vendors'][0]); |
|
| 80 | + //endregion |
|
| 81 | + |
|
| 82 | + //region Create Test Connection |
|
| 83 | + |
|
| 84 | + $vendParams = new TelematicsConnectionParameters(); |
|
| 85 | + |
|
| 86 | + $vendParams->vendor = TelematicsVendorsTypes::GEOTAB; |
|
| 87 | + $vendParams->account_id = '54321'; |
|
| 88 | + $vendParams->username = 'John Doe 0'; |
|
| 89 | + $vendParams->password = 'password0'; |
|
| 90 | + $vendParams->vehicle_position_refresh_rate = 60; |
|
| 91 | + $vendParams->name = 'Test Geotab Connection from php SDK'; |
|
| 92 | + $vendParams->validate_remote_credentials = 0; |
|
| 93 | + |
|
| 94 | + $teleConnection = new TelematicsConnection(); |
|
| 95 | + |
|
| 96 | + $result2 = $teleConnection->createTelematicsConnection( |
|
| 97 | + self::$api_token, |
|
| 98 | + $vendParams->toArray() |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + self::assertNotNull($result2); |
|
| 102 | + self::assertTrue( CreateConnectionResponse::fromArray($result2) instanceof CreateConnectionResponse); |
|
| 103 | + |
|
| 104 | + self::$createdConnections[] = TelematicsConnection::fromArray($result2); |
|
| 105 | + //endregion |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function testFromArray() |
|
| 109 | + { |
|
| 110 | + $vendorParameters = TelematicsVendor::fromArray([ |
|
| 111 | + 'id' => 14, |
|
| 112 | + 'name' => 'Borea', |
|
| 113 | + 'slug' => 'borea', |
|
| 114 | + 'description' => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 115 | + 'logo_url' => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 116 | + 'website_url' => 'https:\/\/www.borea.com\/', |
|
| 117 | + 'api_docs_url' => 'https:\/\/www.borea.com\/docs\/', |
|
| 118 | + 'is_integrated' => true, |
|
| 119 | + 'size' => 'regional', |
|
| 120 | + 'features' => [ |
|
| 121 | + 0 => [ |
|
| 122 | + 'id' => '1', |
|
| 123 | + 'name' => 'Customizable Reports', |
|
| 124 | + 'slug' => 'customizable-reports', |
|
| 125 | + 'feature_group' => 'Analytics & Reporting' |
|
| 126 | + ], |
|
| 127 | + 1 => [ |
|
| 128 | + 'id' => '2', |
|
| 129 | + 'name' => 'Publicly Accessible API Documention', |
|
| 130 | + 'slug' => 'publicly-accessible-api-doc', |
|
| 131 | + 'feature_group' => 'API & SDK' |
|
| 132 | + ] |
|
| 133 | + ], |
|
| 134 | + 'countries' => [ |
|
| 135 | + 0 => [ |
|
| 136 | + 'id' => '38', |
|
| 137 | + 'country_code' => 'CA', |
|
| 138 | + 'country_name' => 'Canada' |
|
| 139 | + ], |
|
| 140 | + 1 => [ |
|
| 141 | + 'id' => '230', |
|
| 142 | + 'country_code' => 'USA', |
|
| 143 | + 'country_name' => 'United States' |
|
| 144 | + ] |
|
| 145 | + ] |
|
| 146 | + ]); |
|
| 147 | + |
|
| 148 | + $this->assertEquals(14, $vendorParameters->id); |
|
| 149 | + $this->assertEquals('Borea', $vendorParameters->name); |
|
| 150 | + $this->assertEquals('borea', $vendorParameters->slug); |
|
| 151 | + $this->assertEquals( |
|
| 152 | + 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 153 | + $vendorParameters->description |
|
| 154 | + ); |
|
| 155 | + $this->assertEquals( |
|
| 156 | + 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 157 | + $vendorParameters->logo_url |
|
| 158 | + ); |
|
| 159 | + $this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url); |
|
| 160 | + $this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url); |
|
| 161 | + $this->assertEquals(true, $vendorParameters->is_integrated); |
|
| 162 | + $this->assertEquals('regional', $vendorParameters->size); |
|
| 163 | + $this->assertEquals( |
|
| 164 | + [ |
|
| 165 | + 0 => [ |
|
| 166 | + 'id' => '1', |
|
| 167 | + 'name' => 'Customizable Reports', |
|
| 168 | + 'slug' => 'customizable-reports', |
|
| 169 | + 'feature_group' => 'Analytics & Reporting' |
|
| 170 | + ], |
|
| 171 | + 1 => [ |
|
| 172 | + 'id' => '2', |
|
| 173 | + 'name' => 'Publicly Accessible API Documention', |
|
| 174 | + 'slug' => 'publicly-accessible-api-doc', |
|
| 175 | + 'feature_group' => 'API & SDK' |
|
| 176 | + ] |
|
| 177 | + ], |
|
| 178 | + $vendorParameters->features |
|
| 179 | + ); |
|
| 180 | + $this->assertEquals( |
|
| 181 | + [ |
|
| 182 | + 0 => [ |
|
| 183 | + 'id' => '38', |
|
| 184 | + 'country_code' => 'CA', |
|
| 185 | + 'country_name' => 'Canada' |
|
| 186 | + ], |
|
| 187 | + 1 => [ |
|
| 188 | + 'id' => '230', |
|
| 189 | + 'country_code' => 'USA', |
|
| 190 | + 'country_name' => 'United States' |
|
| 191 | + ] |
|
| 192 | + ], |
|
| 193 | + $vendorParameters->countries |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + public function testToArray() |
|
| 198 | + { |
|
| 199 | + $vendorParameters = TelematicsVendor::fromArray([ |
|
| 200 | + 'id' => 14, |
|
| 201 | + 'name' => 'Borea', |
|
| 202 | + 'slug' => 'borea', |
|
| 203 | + 'description' => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 204 | + 'logo_url' => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 205 | + 'website_url' => 'https:\/\/www.borea.com\/', |
|
| 206 | + 'api_docs_url' => 'https:\/\/www.borea.com\/docs\/', |
|
| 207 | + 'is_integrated' => true, |
|
| 208 | + 'size' => 'regional', |
|
| 209 | + 'features' => [ |
|
| 210 | + 0 => [ |
|
| 211 | + 'id' => '1', |
|
| 212 | + 'name' => 'Customizable Reports', |
|
| 213 | + 'slug' => 'customizable-reports', |
|
| 214 | + 'feature_group' => 'Analytics & Reporting' |
|
| 215 | + ], |
|
| 216 | + 1 => [ |
|
| 217 | + 'id' => '2', |
|
| 218 | + 'name' => 'Publicly Accessible API Documention', |
|
| 219 | + 'slug' => 'publicly-accessible-api-doc', |
|
| 220 | + 'feature_group' => 'API & SDK' |
|
| 221 | + ] |
|
| 222 | + ], |
|
| 223 | + 'countries' => [ |
|
| 224 | + 0 => [ |
|
| 225 | + 'id' => '38', |
|
| 226 | + 'country_code' => 'CA', |
|
| 227 | + 'country_name' => 'Canada' |
|
| 228 | + ], |
|
| 229 | + 1 => [ |
|
| 230 | + 'id' => '230', |
|
| 231 | + 'country_code' => 'USA', |
|
| 232 | + 'country_name' => 'United States' |
|
| 233 | + ] |
|
| 234 | + ] |
|
| 235 | + ]); |
|
| 236 | + |
|
| 237 | + $this->assertEquals(14, $vendorParameters->id); |
|
| 238 | + $this->assertEquals('Borea', $vendorParameters->name); |
|
| 239 | + $this->assertEquals('borea', $vendorParameters->slug); |
|
| 240 | + $this->assertEquals( |
|
| 241 | + 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 242 | + $vendorParameters->description |
|
| 243 | + ); |
|
| 244 | + $this->assertEquals( |
|
| 245 | + 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 246 | + $vendorParameters->logo_url |
|
| 247 | + ); |
|
| 248 | + $this->assertEquals('https:\/\/www.borea.com\/', $vendorParameters->website_url); |
|
| 249 | + $this->assertEquals('https:\/\/www.borea.com\/docs\/', $vendorParameters->api_docs_url); |
|
| 250 | + $this->assertEquals(true, $vendorParameters->is_integrated); |
|
| 251 | + $this->assertEquals('regional', $vendorParameters->size); |
|
| 252 | + $this->assertEquals( |
|
| 253 | + [ |
|
| 254 | + 0 => [ |
|
| 255 | + 'id' => '1', |
|
| 256 | + 'name' => 'Customizable Reports', |
|
| 257 | + 'slug' => 'customizable-reports', |
|
| 258 | + 'feature_group' => 'Analytics & Reporting' |
|
| 259 | + ], |
|
| 260 | + 1 => [ |
|
| 261 | + 'id' => '2', |
|
| 262 | + 'name' => 'Publicly Accessible API Documention', |
|
| 263 | + 'slug' => 'publicly-accessible-api-doc', |
|
| 264 | + 'feature_group' => 'API & SDK' |
|
| 265 | + ] |
|
| 266 | + ], |
|
| 267 | + $vendorParameters->features |
|
| 268 | + ); |
|
| 269 | + $this->assertEquals( |
|
| 270 | + [ |
|
| 271 | + 0 => [ |
|
| 272 | + 'id' => '38', |
|
| 273 | + 'country_code' => 'CA', |
|
| 274 | + 'country_name' => 'Canada' |
|
| 275 | + ], |
|
| 276 | + 1 => [ |
|
| 277 | + 'id' => '230', |
|
| 278 | + 'country_code' => 'USA', |
|
| 279 | + 'country_name' => 'United States' |
|
| 280 | + ] |
|
| 281 | + ], |
|
| 282 | + $vendorParameters->countries |
|
| 283 | + ); |
|
| 284 | + |
|
| 285 | + $this->assertEquals($vendorParameters->toArray(), |
|
| 286 | + [ |
|
| 287 | + 'id' => 14, |
|
| 288 | + 'name' => 'Borea', |
|
| 289 | + 'slug' => 'borea', |
|
| 290 | + 'description' => 'Borea is a leading connected vehicle platform, helping our customers turn data about vehicles and their use into intelligence', |
|
| 291 | + 'logo_url' => 'https:\/\/storage.googleapis.com\/telematics-directory-production\/silent-passanger555555.png', |
|
| 292 | + 'website_url' => 'https:\/\/www.borea.com\/', |
|
| 293 | + 'api_docs_url' => 'https:\/\/www.borea.com\/docs\/', |
|
| 294 | + 'is_integrated' => true, |
|
| 295 | + 'size' => 'regional', |
|
| 296 | + 'features' => [ |
|
| 297 | + 0 => [ |
|
| 298 | + 'id' => '1', |
|
| 299 | + 'name' => 'Customizable Reports', |
|
| 300 | + 'slug' => 'customizable-reports', |
|
| 301 | + 'feature_group' => 'Analytics & Reporting' |
|
| 302 | + ], |
|
| 303 | + 1 => [ |
|
| 304 | + 'id' => '2', |
|
| 305 | + 'name' => 'Publicly Accessible API Documention', |
|
| 306 | + 'slug' => 'publicly-accessible-api-doc', |
|
| 307 | + 'feature_group' => 'API & SDK' |
|
| 308 | + ] |
|
| 309 | + ], |
|
| 310 | + 'countries' => [ |
|
| 311 | + 0 => [ |
|
| 312 | + 'id' => '38', |
|
| 313 | + 'country_code' => 'CA', |
|
| 314 | + 'country_name' => 'Canada' |
|
| 315 | + ], |
|
| 316 | + 1 => [ |
|
| 317 | + 'id' => '230', |
|
| 318 | + 'country_code' => 'USA', |
|
| 319 | + 'country_name' => 'United States' |
|
| 320 | + ] |
|
| 321 | + ] |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + public function testGetAllVendors() |
|
| 327 | + { |
|
| 328 | + $vendorsParameters = TelematicsVendor::fromArray( [ ] ); |
|
| 329 | + |
|
| 330 | + $vendors = new TelematicsVendor(); |
|
| 331 | + $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 332 | + |
|
| 333 | + $this->assertNotNull($vendorsResults); |
|
| 334 | + $this->assertTrue(is_array($vendorsResults)); |
|
| 335 | + $this->assertTrue(sizeof($vendorsResults)>0); |
|
| 336 | + $this->assertInstanceOf( |
|
| 337 | + TelematicsVendor::class, |
|
| 338 | + TelematicsVendor::fromArray($vendorsResults['vendors'][0]) |
|
| 339 | + ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + public function testGetVendor() |
|
| 343 | + { |
|
| 344 | + $vendorResult = TelematicsVendor::getVendorById(self::$tomtom_vendor->id); |
|
| 345 | + |
|
| 346 | + $this->assertNotNull($vendorResult); |
|
| 347 | + $this->assertTrue(is_array($vendorResult)); |
|
| 348 | + $this->assertInstanceOf( |
|
| 349 | + TelematicsVendor::class, |
|
| 350 | + TelematicsVendor::fromArray($vendorResult) |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + public function testSearchVendors() |
|
| 355 | + { |
|
| 356 | + $vendorsParameters = TelematicsVendorParameters::fromArray([ |
|
| 357 | + //"country" => "GB", // uncomment this line for searching by Country |
|
| 358 | + 'is_integrated' => 1, |
|
| 359 | + //"feature" => "satellite", // uncomment this line for searching by Feature |
|
| 360 | + 'search' => 'Fleet', |
|
| 361 | + 'page' => 1, |
|
| 362 | + 'per_page' => 5, |
|
| 363 | + ]); |
|
| 364 | + |
|
| 365 | + $vendors = new TelematicsVendor(); |
|
| 366 | + $vendorsResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 367 | + |
|
| 368 | + $this->assertNotNull($vendorsResults); |
|
| 369 | + $this->assertTrue(is_array($vendorsResults)); |
|
| 370 | + $this->assertTrue(sizeof($vendorsResults)>0); |
|
| 371 | + $this->assertInstanceOf( |
|
| 372 | + TelematicsVendor::class, |
|
| 373 | + TelematicsVendor::fromArray($vendorsResults['vendors'][0]) |
|
| 374 | + ); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + public function testVendorsComparison() |
|
| 378 | + { |
|
| 379 | + $vendorsParameters = TelematicsVendorParameters::fromArray([ |
|
| 380 | + 'vendors' => '55,56,57', |
|
| 381 | + ]); |
|
| 382 | + |
|
| 383 | + $vendors = new TelematicsVendor(); |
|
| 384 | + $comparisonResults = $vendors->GetTelematicsVendors($vendorsParameters); |
|
| 385 | + |
|
| 386 | + $this->assertNotNull($comparisonResults); |
|
| 387 | + $this->assertTrue(is_array($comparisonResults)); |
|
| 388 | + $this->assertTrue(sizeof($comparisonResults)>0); |
|
| 389 | + $this->assertInstanceOf( |
|
| 390 | + TelematicsVendor::class, |
|
| 391 | + TelematicsVendor::fromArray($comparisonResults['vendors'][0]) |
|
| 392 | + ); |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - public function testRegisterTelematicsVendor() |
|
| 396 | - { |
|
| 397 | - $vendorParameters = new TelematicsVendorParameters(); |
|
| 398 | - $vendorParameters->member_id = self::$firstMemberId; |
|
| 399 | - $vendorParameters->api_key = Constants::API_KEY; |
|
| 395 | + public function testRegisterTelematicsVendor() |
|
| 396 | + { |
|
| 397 | + $vendorParameters = new TelematicsVendorParameters(); |
|
| 398 | + $vendorParameters->member_id = self::$firstMemberId; |
|
| 399 | + $vendorParameters->api_key = Constants::API_KEY; |
|
| 400 | 400 | |
| 401 | - $vendors = new TelematicsVendor(); |
|
| 402 | - $result = $vendors->RegisterTelematicsMember($vendorParameters); |
|
| 401 | + $vendors = new TelematicsVendor(); |
|
| 402 | + $result = $vendors->RegisterTelematicsMember($vendorParameters); |
|
| 403 | 403 | |
| 404 | - $this->assertNotNull($result); |
|
| 405 | - $this->assertInstanceOf( |
|
| 406 | - TelematicsRegisterMemberResponse::class, |
|
| 407 | - TelematicsRegisterMemberResponse::fromArray($result) |
|
| 408 | - ); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - public function testGetTelematicsConnections() |
|
| 412 | - { |
|
| 413 | - $teleConnection = new TelematicsConnection(); |
|
| 414 | - |
|
| 415 | - $connections = $teleConnection->getTelematicsConnections(self::$api_token); |
|
| 416 | - |
|
| 417 | - $this->assertNotNull($connections); |
|
| 418 | - $this->assertTrue( |
|
| 419 | - TelematicsConnection::fromArray($connections[0]) |
|
| 420 | - instanceof |
|
| 421 | - TelematicsConnection); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - public function testGetTelematicsConnection() |
|
| 425 | - { |
|
| 426 | - $teleConnection = new TelematicsConnection(); |
|
| 427 | - |
|
| 428 | - $connection = $teleConnection->getTelematicsConnection( |
|
| 429 | - self::$api_token, |
|
| 430 | - self::$createdConnections[sizeof(self::$createdConnections)-1]->connection_token |
|
| 431 | - ); |
|
| 432 | - |
|
| 433 | - $this->assertNotNull($connection); |
|
| 434 | - $this->assertTrue( |
|
| 435 | - TelematicsConnection::fromArray($connection) |
|
| 436 | - instanceof |
|
| 437 | - TelematicsConnection); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - public function testCreateTelematicsConnection() |
|
| 441 | - { |
|
| 442 | - $vendorParameters = new TelematicsConnectionParameters(); |
|
| 443 | - |
|
| 444 | - $vendorParameters->vendor_id = self::$tomtom_vendor->id; |
|
| 445 | - $vendorParameters->vendor = self::$tomtom_vendor->slug; |
|
| 446 | - $vendorParameters->account_id = '12345'; |
|
| 447 | - $vendorParameters->username = 'John Doe'; |
|
| 448 | - $vendorParameters->password = 'password'; |
|
| 449 | - $vendorParameters->vehicle_position_refresh_rate = 60; |
|
| 450 | - $vendorParameters->name = 'Test Telematics Connection from php SDK'; |
|
| 451 | - $vendorParameters->validate_remote_credentials = 0; |
|
| 452 | - |
|
| 453 | - $teleConnection = new TelematicsConnection(); |
|
| 454 | - |
|
| 455 | - $result = $teleConnection->createTelematicsConnection( |
|
| 456 | - self::$api_token, |
|
| 457 | - $vendorParameters->toArray() |
|
| 458 | - ); |
|
| 459 | - |
|
| 460 | - $this->assertNotNull($result); |
|
| 461 | - $this->assertTrue( CreateConnectionResponse::fromArray($result) instanceof CreateConnectionResponse); |
|
| 462 | - |
|
| 463 | - self::$createdConnections[] = TelematicsConnection::fromArray($result); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - public function testUpdateTelematicsConnection() |
|
| 467 | - { |
|
| 468 | - $teleConParams = new TelematicsConnectionParameters(); |
|
| 469 | - |
|
| 470 | - $teleConParams->vehicle_position_refresh_rate = 50; |
|
| 471 | - $teleConParams->name = 'Test Telematics Connection from php SDK Updated'; |
|
| 472 | - $teleConParams->validate_remote_credentials = 0; |
|
| 473 | - |
|
| 474 | - $teleConnection = new TelematicsConnection(); |
|
| 475 | - |
|
| 476 | - $result = $teleConnection->updateTelematicsConnection( |
|
| 477 | - self::$api_token, |
|
| 478 | - self::$createdConnections[0]->connection_token, |
|
| 479 | - $teleConParams->toArray() |
|
| 480 | - ); |
|
| 481 | - |
|
| 482 | - $this->assertNotNull($result); |
|
| 483 | - $this->assertTrue( |
|
| 484 | - TelematicsConnection::fromArray($result) |
|
| 485 | - instanceof |
|
| 486 | - TelematicsConnection); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - public static function tearDownAfterClass() |
|
| 490 | - { |
|
| 491 | - if (sizeof(self::$createdConnections)>0) { |
|
| 492 | - |
|
| 493 | - $teleConn = new TelematicsConnection(); |
|
| 494 | - |
|
| 495 | - foreach (self::$createdConnections as $createdConn) { |
|
| 496 | - $deleted = $teleConn->deleteTelematicsConnection( |
|
| 497 | - self::$api_token, |
|
| 498 | - $createdConn->connection_token |
|
| 499 | - ); |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 404 | + $this->assertNotNull($result); |
|
| 405 | + $this->assertInstanceOf( |
|
| 406 | + TelematicsRegisterMemberResponse::class, |
|
| 407 | + TelematicsRegisterMemberResponse::fromArray($result) |
|
| 408 | + ); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + public function testGetTelematicsConnections() |
|
| 412 | + { |
|
| 413 | + $teleConnection = new TelematicsConnection(); |
|
| 414 | + |
|
| 415 | + $connections = $teleConnection->getTelematicsConnections(self::$api_token); |
|
| 416 | + |
|
| 417 | + $this->assertNotNull($connections); |
|
| 418 | + $this->assertTrue( |
|
| 419 | + TelematicsConnection::fromArray($connections[0]) |
|
| 420 | + instanceof |
|
| 421 | + TelematicsConnection); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + public function testGetTelematicsConnection() |
|
| 425 | + { |
|
| 426 | + $teleConnection = new TelematicsConnection(); |
|
| 427 | + |
|
| 428 | + $connection = $teleConnection->getTelematicsConnection( |
|
| 429 | + self::$api_token, |
|
| 430 | + self::$createdConnections[sizeof(self::$createdConnections)-1]->connection_token |
|
| 431 | + ); |
|
| 432 | + |
|
| 433 | + $this->assertNotNull($connection); |
|
| 434 | + $this->assertTrue( |
|
| 435 | + TelematicsConnection::fromArray($connection) |
|
| 436 | + instanceof |
|
| 437 | + TelematicsConnection); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + public function testCreateTelematicsConnection() |
|
| 441 | + { |
|
| 442 | + $vendorParameters = new TelematicsConnectionParameters(); |
|
| 443 | + |
|
| 444 | + $vendorParameters->vendor_id = self::$tomtom_vendor->id; |
|
| 445 | + $vendorParameters->vendor = self::$tomtom_vendor->slug; |
|
| 446 | + $vendorParameters->account_id = '12345'; |
|
| 447 | + $vendorParameters->username = 'John Doe'; |
|
| 448 | + $vendorParameters->password = 'password'; |
|
| 449 | + $vendorParameters->vehicle_position_refresh_rate = 60; |
|
| 450 | + $vendorParameters->name = 'Test Telematics Connection from php SDK'; |
|
| 451 | + $vendorParameters->validate_remote_credentials = 0; |
|
| 452 | + |
|
| 453 | + $teleConnection = new TelematicsConnection(); |
|
| 454 | + |
|
| 455 | + $result = $teleConnection->createTelematicsConnection( |
|
| 456 | + self::$api_token, |
|
| 457 | + $vendorParameters->toArray() |
|
| 458 | + ); |
|
| 459 | + |
|
| 460 | + $this->assertNotNull($result); |
|
| 461 | + $this->assertTrue( CreateConnectionResponse::fromArray($result) instanceof CreateConnectionResponse); |
|
| 462 | + |
|
| 463 | + self::$createdConnections[] = TelematicsConnection::fromArray($result); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + public function testUpdateTelematicsConnection() |
|
| 467 | + { |
|
| 468 | + $teleConParams = new TelematicsConnectionParameters(); |
|
| 469 | + |
|
| 470 | + $teleConParams->vehicle_position_refresh_rate = 50; |
|
| 471 | + $teleConParams->name = 'Test Telematics Connection from php SDK Updated'; |
|
| 472 | + $teleConParams->validate_remote_credentials = 0; |
|
| 473 | + |
|
| 474 | + $teleConnection = new TelematicsConnection(); |
|
| 475 | + |
|
| 476 | + $result = $teleConnection->updateTelematicsConnection( |
|
| 477 | + self::$api_token, |
|
| 478 | + self::$createdConnections[0]->connection_token, |
|
| 479 | + $teleConParams->toArray() |
|
| 480 | + ); |
|
| 481 | + |
|
| 482 | + $this->assertNotNull($result); |
|
| 483 | + $this->assertTrue( |
|
| 484 | + TelematicsConnection::fromArray($result) |
|
| 485 | + instanceof |
|
| 486 | + TelematicsConnection); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + public static function tearDownAfterClass() |
|
| 490 | + { |
|
| 491 | + if (sizeof(self::$createdConnections)>0) { |
|
| 492 | + |
|
| 493 | + $teleConn = new TelematicsConnection(); |
|
| 494 | + |
|
| 495 | + foreach (self::$createdConnections as $createdConn) { |
|
| 496 | + $deleted = $teleConn->deleteTelematicsConnection( |
|
| 497 | + self::$api_token, |
|
| 498 | + $createdConn->connection_token |
|
| 499 | + ); |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | 504 | } |
| 505 | 505 | \ No newline at end of file |
@@ -10,187 +10,187 @@ |
||
| 10 | 10 | |
| 11 | 11 | class MemberConfigurationTest extends \PHPUnit\Framework\TestCase |
| 12 | 12 | { |
| 13 | - public static $createdConfigurationKeys; |
|
| 14 | - |
|
| 15 | - public static function setUpBeforeClass() |
|
| 16 | - { |
|
| 17 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 13 | + public static $createdConfigurationKeys; |
|
| 14 | + |
|
| 15 | + public static function setUpBeforeClass() |
|
| 16 | + { |
|
| 17 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 18 | 18 | |
| 19 | - $memberConfiguration = new MemberConfiguration(); |
|
| 19 | + $memberConfiguration = new MemberConfiguration(); |
|
| 20 | 20 | |
| 21 | - $query = [ |
|
| 22 | - 'config_key' => 'Test My weight' |
|
| 23 | - ]; |
|
| 24 | - |
|
| 25 | - $removed = $memberConfiguration->RemoveConfigurationData($query, $errorText); |
|
| 21 | + $query = [ |
|
| 22 | + 'config_key' => 'Test My weight' |
|
| 23 | + ]; |
|
| 24 | + |
|
| 25 | + $removed = $memberConfiguration->RemoveConfigurationData($query, $errorText); |
|
| 26 | 26 | |
| 27 | - $memberConfiguration->config_key = 'Test My height'; |
|
| 28 | - $memberConfiguration->config_value = '180'; |
|
| 29 | - |
|
| 30 | - $result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText); |
|
| 27 | + $memberConfiguration->config_key = 'Test My height'; |
|
| 28 | + $memberConfiguration->config_value = '180'; |
|
| 29 | + |
|
| 30 | + $result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText); |
|
| 31 | 31 | |
| 32 | - if(isset($result['affected']) && $result['affected']==1) { |
|
| 33 | - self::$createdConfigurationKeys[] = 'Test My height'; |
|
| 34 | - } else { |
|
| 35 | - echo "$errorText <br>"; |
|
| 36 | - } |
|
| 37 | - } |
|
| 32 | + if(isset($result['affected']) && $result['affected']==1) { |
|
| 33 | + self::$createdConfigurationKeys[] = 'Test My height'; |
|
| 34 | + } else { |
|
| 35 | + echo "$errorText <br>"; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function testConfigurationMemberFromArray() |
|
| 40 | - { |
|
| 41 | - $memberConfiguration = MemberConfiguration::fromArray([ |
|
| 42 | - 'member_id' => 444444, |
|
| 43 | - 'config_key' => 'test_key', |
|
| 44 | - 'config_value' => 'test_value' |
|
| 45 | - ]); |
|
| 39 | + public function testConfigurationMemberFromArray() |
|
| 40 | + { |
|
| 41 | + $memberConfiguration = MemberConfiguration::fromArray([ |
|
| 42 | + 'member_id' => 444444, |
|
| 43 | + 'config_key' => 'test_key', |
|
| 44 | + 'config_value' => 'test_value' |
|
| 45 | + ]); |
|
| 46 | 46 | |
| 47 | - $this->assertEquals($memberConfiguration->member_id, 444444 ,"member_id != 444444"); |
|
| 48 | - $this->assertEquals($memberConfiguration->config_key, 'test_key' ,"config_key != 'test_key'"); |
|
| 49 | - $this->assertEquals($memberConfiguration->config_value, 'test_value' ,"config_value != 'test_value'"); |
|
| 50 | - } |
|
| 47 | + $this->assertEquals($memberConfiguration->member_id, 444444 ,"member_id != 444444"); |
|
| 48 | + $this->assertEquals($memberConfiguration->config_key, 'test_key' ,"config_key != 'test_key'"); |
|
| 49 | + $this->assertEquals($memberConfiguration->config_value, 'test_value' ,"config_value != 'test_value'"); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function testToArray() |
|
| 53 | - { |
|
| 54 | - $memberConfiguration = MemberConfiguration::fromArray([ |
|
| 55 | - 'member_id' => 444444, |
|
| 56 | - 'config_key' => 'test_key', |
|
| 57 | - 'config_value' => 'test_value' |
|
| 58 | - ]); |
|
| 52 | + public function testToArray() |
|
| 53 | + { |
|
| 54 | + $memberConfiguration = MemberConfiguration::fromArray([ |
|
| 55 | + 'member_id' => 444444, |
|
| 56 | + 'config_key' => 'test_key', |
|
| 57 | + 'config_value' => 'test_value' |
|
| 58 | + ]); |
|
| 59 | 59 | |
| 60 | - $this->assertEquals($memberConfiguration->toArray(), [ |
|
| 61 | - 'member_id' => 444444, |
|
| 62 | - 'config_key' => 'test_key', |
|
| 63 | - 'config_value' => 'test_value' |
|
| 64 | - ]); |
|
| 65 | - } |
|
| 60 | + $this->assertEquals($memberConfiguration->toArray(), [ |
|
| 61 | + 'member_id' => 444444, |
|
| 62 | + 'config_key' => 'test_key', |
|
| 63 | + 'config_value' => 'test_value' |
|
| 64 | + ]); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function testBadParameter() |
|
| 68 | - { |
|
| 69 | - $this->expectException(BadParam::class); |
|
| 67 | + public function testBadParameter() |
|
| 68 | + { |
|
| 69 | + $this->expectException(BadParam::class); |
|
| 70 | 70 | |
| 71 | - $memberConfiguration = MemberConfiguration::fromArray([ |
|
| 72 | - 'memberID' => 44444444, |
|
| 73 | - 'config_kkk' => 'test_key' |
|
| 74 | - ]); |
|
| 71 | + $memberConfiguration = MemberConfiguration::fromArray([ |
|
| 72 | + 'memberID' => 44444444, |
|
| 73 | + 'config_kkk' => 'test_key' |
|
| 74 | + ]); |
|
| 75 | 75 | |
| 76 | - echo "memberConfiguration: ".$memberConfiguration->memberID." <br>"; |
|
| 77 | - } |
|
| 76 | + echo "memberConfiguration: ".$memberConfiguration->memberID." <br>"; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function testGetAllConfigurationData() |
|
| 80 | - { |
|
| 81 | - $memberConfiguration = new MemberConfiguration(); |
|
| 79 | + public function testGetAllConfigurationData() |
|
| 80 | + { |
|
| 81 | + $memberConfiguration = new MemberConfiguration(); |
|
| 82 | 82 | |
| 83 | - $result = $memberConfiguration->GetConfigurationData(); |
|
| 84 | - |
|
| 85 | - $this->assertNotNull($result); |
|
| 86 | - $this->assertTrue(isset($result['result']), "Wrong response for member configuration data."); |
|
| 87 | - $this->assertEquals($result['result'], "OK", "Cannot retrieve the member configuration data."); |
|
| 88 | - } |
|
| 83 | + $result = $memberConfiguration->GetConfigurationData(); |
|
| 84 | + |
|
| 85 | + $this->assertNotNull($result); |
|
| 86 | + $this->assertTrue(isset($result['result']), "Wrong response for member configuration data."); |
|
| 87 | + $this->assertEquals($result['result'], "OK", "Cannot retrieve the member configuration data."); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function testGetSpecificConfigurationKeyData() |
|
| 91 | - { |
|
| 92 | - $memberConfiguration = new MemberConfiguration(); |
|
| 93 | - |
|
| 94 | - $allData = $memberConfiguration->GetConfigurationData(); |
|
| 95 | - |
|
| 96 | - $this->assertNotNull($allData); |
|
| 97 | - $this->assertTrue(isset($allData['data']), "Wrong response for member configuration data."); |
|
| 98 | - $this->assertTrue(sizeof($allData['data'])>0, "Retrieved member data size <1"); |
|
| 99 | - |
|
| 100 | - $query = [ |
|
| 101 | - 'config_key' => $allData['data'][0]['config_key'] |
|
| 102 | - ]; |
|
| 103 | - |
|
| 104 | - $result = $memberConfiguration->GetConfigurationData($query); |
|
| 105 | - |
|
| 106 | - $this->assertNotNull($result); |
|
| 107 | - $this->assertTrue(isset($result['data']), "Wrong response for member configuration data."); |
|
| 108 | - $this->assertTrue(sizeof($result['data'])==1, "Retrieved member data size != 1"); |
|
| 109 | - $this->assertEquals($result['data'][0]['config_key'], $allData['data'][0]['config_key']); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function testCreateConfigurationData() |
|
| 113 | - { |
|
| 114 | - $memberConfiguration = new MemberConfiguration(); |
|
| 115 | - |
|
| 116 | - $memberConfiguration->config_key = 'Test My weight'; |
|
| 117 | - $memberConfiguration->config_value = '100'; |
|
| 118 | - |
|
| 119 | - $result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText); |
|
| 120 | - |
|
| 121 | - $this->assertNotNull($result); |
|
| 122 | - $this->assertTrue(isset($result['result']), "Wrong response for member configuration data."); |
|
| 123 | - $this->assertTrue(isset($result['affected']), "Wrong response for member configuration data."); |
|
| 124 | - $this->assertEquals(1, $result['affected'], "Cannot create new member configuration data <br> $errorText"); |
|
| 125 | - |
|
| 126 | - if($result['affected']==1) { |
|
| 127 | - self::$createdConfigurationKeys[] = 'Test My weight'; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function testUpdateConfigurationData() |
|
| 132 | - { |
|
| 133 | - $memberConfiguration = new MemberConfiguration(); |
|
| 134 | - |
|
| 135 | - $memberConfiguration->config_key = 'Test My height'; |
|
| 136 | - $memberConfiguration->config_value = '120'; |
|
| 137 | - |
|
| 138 | - $result = $memberConfiguration->UpdateConfigurationData($memberConfiguration->toArray(), $errorText); |
|
| 139 | - |
|
| 140 | - $this->assertNotNull($result); |
|
| 141 | - $this->assertTrue(isset($result['result']), "Wrong response for member configuration data."); |
|
| 142 | - $this->assertTrue(isset($result['affected']), "Wrong response for member configuration data."); |
|
| 143 | - $this->assertEquals(1, $result['affected'], "Cannot update member configuration data <br> $errorText"); |
|
| 144 | - |
|
| 145 | - $query = [ |
|
| 146 | - 'config_key' => 'Test My height' |
|
| 147 | - ]; |
|
| 148 | - |
|
| 149 | - $updatedResult = $memberConfiguration->GetConfigurationData($query); |
|
| 150 | - |
|
| 151 | - $this->assertNotNull($updatedResult); |
|
| 152 | - $this->assertTrue(isset($updatedResult['data']), "Wrong response for member configuration data."); |
|
| 153 | - $this->assertTrue(sizeof($updatedResult['data'])==1, "Retrieved member data size != 1"); |
|
| 154 | - $this->assertEquals('120', $updatedResult['data'][0]['config_value'], "The config value is not updated"); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function testRemoveConfigurationData() |
|
| 158 | - { |
|
| 159 | - $memberConfiguration = new MemberConfiguration(); |
|
| 160 | - |
|
| 161 | - $query = [ |
|
| 162 | - 'config_key' => 'Test My height' |
|
| 163 | - ]; |
|
| 90 | + public function testGetSpecificConfigurationKeyData() |
|
| 91 | + { |
|
| 92 | + $memberConfiguration = new MemberConfiguration(); |
|
| 93 | + |
|
| 94 | + $allData = $memberConfiguration->GetConfigurationData(); |
|
| 95 | + |
|
| 96 | + $this->assertNotNull($allData); |
|
| 97 | + $this->assertTrue(isset($allData['data']), "Wrong response for member configuration data."); |
|
| 98 | + $this->assertTrue(sizeof($allData['data'])>0, "Retrieved member data size <1"); |
|
| 99 | + |
|
| 100 | + $query = [ |
|
| 101 | + 'config_key' => $allData['data'][0]['config_key'] |
|
| 102 | + ]; |
|
| 103 | + |
|
| 104 | + $result = $memberConfiguration->GetConfigurationData($query); |
|
| 105 | + |
|
| 106 | + $this->assertNotNull($result); |
|
| 107 | + $this->assertTrue(isset($result['data']), "Wrong response for member configuration data."); |
|
| 108 | + $this->assertTrue(sizeof($result['data'])==1, "Retrieved member data size != 1"); |
|
| 109 | + $this->assertEquals($result['data'][0]['config_key'], $allData['data'][0]['config_key']); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function testCreateConfigurationData() |
|
| 113 | + { |
|
| 114 | + $memberConfiguration = new MemberConfiguration(); |
|
| 115 | + |
|
| 116 | + $memberConfiguration->config_key = 'Test My weight'; |
|
| 117 | + $memberConfiguration->config_value = '100'; |
|
| 118 | + |
|
| 119 | + $result = $memberConfiguration->CreateNewConfigurationData($memberConfiguration->toArray(), $errorText); |
|
| 120 | + |
|
| 121 | + $this->assertNotNull($result); |
|
| 122 | + $this->assertTrue(isset($result['result']), "Wrong response for member configuration data."); |
|
| 123 | + $this->assertTrue(isset($result['affected']), "Wrong response for member configuration data."); |
|
| 124 | + $this->assertEquals(1, $result['affected'], "Cannot create new member configuration data <br> $errorText"); |
|
| 125 | + |
|
| 126 | + if($result['affected']==1) { |
|
| 127 | + self::$createdConfigurationKeys[] = 'Test My weight'; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function testUpdateConfigurationData() |
|
| 132 | + { |
|
| 133 | + $memberConfiguration = new MemberConfiguration(); |
|
| 134 | + |
|
| 135 | + $memberConfiguration->config_key = 'Test My height'; |
|
| 136 | + $memberConfiguration->config_value = '120'; |
|
| 137 | + |
|
| 138 | + $result = $memberConfiguration->UpdateConfigurationData($memberConfiguration->toArray(), $errorText); |
|
| 139 | + |
|
| 140 | + $this->assertNotNull($result); |
|
| 141 | + $this->assertTrue(isset($result['result']), "Wrong response for member configuration data."); |
|
| 142 | + $this->assertTrue(isset($result['affected']), "Wrong response for member configuration data."); |
|
| 143 | + $this->assertEquals(1, $result['affected'], "Cannot update member configuration data <br> $errorText"); |
|
| 144 | + |
|
| 145 | + $query = [ |
|
| 146 | + 'config_key' => 'Test My height' |
|
| 147 | + ]; |
|
| 148 | + |
|
| 149 | + $updatedResult = $memberConfiguration->GetConfigurationData($query); |
|
| 150 | + |
|
| 151 | + $this->assertNotNull($updatedResult); |
|
| 152 | + $this->assertTrue(isset($updatedResult['data']), "Wrong response for member configuration data."); |
|
| 153 | + $this->assertTrue(sizeof($updatedResult['data'])==1, "Retrieved member data size != 1"); |
|
| 154 | + $this->assertEquals('120', $updatedResult['data'][0]['config_value'], "The config value is not updated"); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function testRemoveConfigurationData() |
|
| 158 | + { |
|
| 159 | + $memberConfiguration = new MemberConfiguration(); |
|
| 160 | + |
|
| 161 | + $query = [ |
|
| 162 | + 'config_key' => 'Test My height' |
|
| 163 | + ]; |
|
| 164 | 164 | |
| 165 | - $removed = $memberConfiguration->RemoveConfigurationData($query, $errorText); |
|
| 165 | + $removed = $memberConfiguration->RemoveConfigurationData($query, $errorText); |
|
| 166 | 166 | |
| 167 | - echo (isset($removed['affected']) && $removed['affected']==1) |
|
| 168 | - ? "The config data with key 'Test My height' removed" |
|
| 169 | - : "The config data with key 'Test My height' cannot remove - ".$errorText; |
|
| 167 | + echo (isset($removed['affected']) && $removed['affected']==1) |
|
| 168 | + ? "The config data with key 'Test My height' removed" |
|
| 169 | + : "The config data with key 'Test My height' cannot remove - ".$errorText; |
|
| 170 | 170 | |
| 171 | - $this->assertNotNull($removed); |
|
| 172 | - $this->assertTrue(isset($removed['result']), "Wrong response for member configuration data."); |
|
| 173 | - $this->assertTrue(isset($removed['affected']), "Wrong response for member configuration data."); |
|
| 174 | - $this->assertEquals(1, $removed['affected'], "Cannot create new member configuration data"); |
|
| 171 | + $this->assertNotNull($removed); |
|
| 172 | + $this->assertTrue(isset($removed['result']), "Wrong response for member configuration data."); |
|
| 173 | + $this->assertTrue(isset($removed['affected']), "Wrong response for member configuration data."); |
|
| 174 | + $this->assertEquals(1, $removed['affected'], "Cannot create new member configuration data"); |
|
| 175 | 175 | |
| 176 | - if($removed['affected']==1) { |
|
| 177 | - $key = array_search('Test My height', self::$createdConfigurationKeys); |
|
| 178 | - array_splice(self::$createdConfigurationKeys, $key, 1); |
|
| 179 | - } |
|
| 180 | - } |
|
| 176 | + if($removed['affected']==1) { |
|
| 177 | + $key = array_search('Test My height', self::$createdConfigurationKeys); |
|
| 178 | + array_splice(self::$createdConfigurationKeys, $key, 1); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public static function tearDownAfterClass() |
|
| 183 | - { |
|
| 184 | - $memberConfiguration = new MemberConfiguration(); |
|
| 182 | + public static function tearDownAfterClass() |
|
| 183 | + { |
|
| 184 | + $memberConfiguration = new MemberConfiguration(); |
|
| 185 | 185 | |
| 186 | - if (sizeof(self::$createdConfigurationKeys)>0) { |
|
| 187 | - foreach (self::$createdConfigurationKeys as $configKey) { |
|
| 188 | - $removed = $memberConfiguration->RemoveConfigurationData(['config_key' => $configKey], $errorText); |
|
| 186 | + if (sizeof(self::$createdConfigurationKeys)>0) { |
|
| 187 | + foreach (self::$createdConfigurationKeys as $configKey) { |
|
| 188 | + $removed = $memberConfiguration->RemoveConfigurationData(['config_key' => $configKey], $errorText); |
|
| 189 | 189 | |
| 190 | - echo (isset($removed['affected']) && $removed['affected']==1) |
|
| 191 | - ? "The config data with key '$configKey' removed" |
|
| 192 | - : "The config data with key '$configKey' cannot remove - ".$errorText; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 190 | + echo (isset($removed['affected']) && $removed['affected']==1) |
|
| 191 | + ? "The config data with key '$configKey' removed" |
|
| 192 | + : "The config data with key '$configKey' cannot remove - ".$errorText; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CustomNoteTypeResponseUnitTests extends \PHPUnit\Framework\TestCase |
| 8 | 8 | { |
| 9 | - public function testFromArray() |
|
| 10 | - { |
|
| 11 | - $customNoteTypeResponse = CustomNoteTypeResponse::fromArray([ |
|
| 12 | - 'note_custom_type_id' => 10, |
|
| 13 | - 'note_custom_type' => 'Dropoff Location', |
|
| 14 | - 'root_owner_member_id' => 1, |
|
| 15 | - 'note_custom_type_values' => [ |
|
| 16 | - 'Front door', |
|
| 17 | - 'Backdoor', |
|
| 18 | - 'Roof' |
|
| 19 | - ] |
|
| 20 | - ]); |
|
| 9 | + public function testFromArray() |
|
| 10 | + { |
|
| 11 | + $customNoteTypeResponse = CustomNoteTypeResponse::fromArray([ |
|
| 12 | + 'note_custom_type_id' => 10, |
|
| 13 | + 'note_custom_type' => 'Dropoff Location', |
|
| 14 | + 'root_owner_member_id' => 1, |
|
| 15 | + 'note_custom_type_values' => [ |
|
| 16 | + 'Front door', |
|
| 17 | + 'Backdoor', |
|
| 18 | + 'Roof' |
|
| 19 | + ] |
|
| 20 | + ]); |
|
| 21 | 21 | |
| 22 | - $this->assertEquals(10, $customNoteTypeResponse->note_custom_type_id); |
|
| 23 | - $this->assertEquals('Dropoff Location', $customNoteTypeResponse->note_custom_type); |
|
| 24 | - $this->assertEquals(1, $customNoteTypeResponse->root_owner_member_id); |
|
| 25 | - $this->assertEquals([ |
|
| 26 | - 'Front door', |
|
| 27 | - 'Backdoor', |
|
| 28 | - 'Roof' |
|
| 29 | - ], |
|
| 30 | - $customNoteTypeResponse->note_custom_type_values); |
|
| 31 | - } |
|
| 22 | + $this->assertEquals(10, $customNoteTypeResponse->note_custom_type_id); |
|
| 23 | + $this->assertEquals('Dropoff Location', $customNoteTypeResponse->note_custom_type); |
|
| 24 | + $this->assertEquals(1, $customNoteTypeResponse->root_owner_member_id); |
|
| 25 | + $this->assertEquals([ |
|
| 26 | + 'Front door', |
|
| 27 | + 'Backdoor', |
|
| 28 | + 'Roof' |
|
| 29 | + ], |
|
| 30 | + $customNoteTypeResponse->note_custom_type_values); |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -6,22 +6,22 @@ |
||
| 6 | 6 | |
| 7 | 7 | class GeocodingResponseUnitTests extends \PHPUnit\Framework\TestCase |
| 8 | 8 | { |
| 9 | - public function testFromArray() |
|
| 10 | - { |
|
| 11 | - $geocodingResponse = GeocodingResponse::fromArray([ |
|
| 12 | - 'address' => 'Los Angeles International Airport (LAX), 1 World Way, Los Angeles, CA 90045, USA', |
|
| 13 | - 'lat' => 33.9415889, |
|
| 14 | - 'lng' => -118.40853, |
|
| 15 | - 'type' => 'airport, establishment, point_of_interest', |
|
| 16 | - 'confidence' => 'medium', |
|
| 17 | - 'original' => 'Los%20Angeles%20International%20Airport,%20CA' |
|
| 18 | - ]); |
|
| 9 | + public function testFromArray() |
|
| 10 | + { |
|
| 11 | + $geocodingResponse = GeocodingResponse::fromArray([ |
|
| 12 | + 'address' => 'Los Angeles International Airport (LAX), 1 World Way, Los Angeles, CA 90045, USA', |
|
| 13 | + 'lat' => 33.9415889, |
|
| 14 | + 'lng' => -118.40853, |
|
| 15 | + 'type' => 'airport, establishment, point_of_interest', |
|
| 16 | + 'confidence' => 'medium', |
|
| 17 | + 'original' => 'Los%20Angeles%20International%20Airport,%20CA' |
|
| 18 | + ]); |
|
| 19 | 19 | |
| 20 | - $this->assertEquals('Los Angeles International Airport (LAX), 1 World Way, Los Angeles, CA 90045, USA', $geocodingResponse->address); |
|
| 21 | - $this->assertEquals(33.9415889, $geocodingResponse->lat); |
|
| 22 | - $this->assertEquals(-118.40853, $geocodingResponse->lng); |
|
| 23 | - $this->assertEquals('airport, establishment, point_of_interest', $geocodingResponse->type); |
|
| 24 | - $this->assertEquals('medium', $geocodingResponse->confidence); |
|
| 25 | - $this->assertEquals('Los%20Angeles%20International%20Airport,%20CA', $geocodingResponse->original); |
|
| 26 | - } |
|
| 20 | + $this->assertEquals('Los Angeles International Airport (LAX), 1 World Way, Los Angeles, CA 90045, USA', $geocodingResponse->address); |
|
| 21 | + $this->assertEquals(33.9415889, $geocodingResponse->lat); |
|
| 22 | + $this->assertEquals(-118.40853, $geocodingResponse->lng); |
|
| 23 | + $this->assertEquals('airport, establishment, point_of_interest', $geocodingResponse->type); |
|
| 24 | + $this->assertEquals('medium', $geocodingResponse->confidence); |
|
| 25 | + $this->assertEquals('Los%20Angeles%20International%20Airport,%20CA', $geocodingResponse->original); |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -9,212 +9,212 @@ |
||
| 9 | 9 | |
| 10 | 10 | class OptimizationProblemParamsUnitTests extends \PHPUnit\Framework\TestCase |
| 11 | 11 | { |
| 12 | - public static $routeParameters = null; |
|
| 13 | - public static $addresses = []; |
|
| 14 | - |
|
| 15 | - public static function setUpBeforeClass() |
|
| 16 | - { |
|
| 17 | - //region Addresses |
|
| 18 | - self::$addresses[] = Address::fromArray([ |
|
| 19 | - 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 20 | - 'is_depot' => true, |
|
| 21 | - 'lat' => 30.159341812134, |
|
| 22 | - 'lng' => -81.538619995117, |
|
| 23 | - 'time' => 300, |
|
| 24 | - 'time_window_start' => 28800, |
|
| 25 | - 'time_window_end' => 32400, |
|
| 26 | - ]); |
|
| 27 | - |
|
| 28 | - self::$addresses[] = Address::fromArray([ |
|
| 29 | - 'address' => '214 Edgewater Branch Drive 32259', |
|
| 30 | - 'lat' => 30.103567123413, |
|
| 31 | - 'lng' => -81.595352172852, |
|
| 32 | - 'time' => 300, |
|
| 33 | - 'time_window_start' => 36000, |
|
| 34 | - 'time_window_end' => 37200, |
|
| 35 | - ]); |
|
| 36 | - |
|
| 37 | - self::$addresses[] = Address::fromArray([ |
|
| 38 | - 'address' => '756 eagle point dr 32092', |
|
| 39 | - 'lat' => 30.046422958374, |
|
| 40 | - 'lng' => -81.508758544922, |
|
| 41 | - 'time' => 300, |
|
| 42 | - 'time_window_start' => 39600, |
|
| 43 | - 'time_window_end' => 41400, |
|
| 44 | - ]); |
|
| 45 | - //endregion |
|
| 46 | - |
|
| 47 | - self::$routeParameters = RouteParameters::fromArray([ |
|
| 48 | - 'is_upload' => false, |
|
| 49 | - 'rt' => false, |
|
| 50 | - 'route_name' => 'Saturday 25th of July 2020 04 => 00 => 00 AM UTC', |
|
| 51 | - 'route_date' => 1595635200, |
|
| 52 | - 'route_time' => 25200, |
|
| 53 | - 'disable_optimization' => false, |
|
| 54 | - 'optimize' => 'Time', |
|
| 55 | - 'lock_last' => false, |
|
| 56 | - 'vehicle_capacity' => null, |
|
| 57 | - 'vehicle_max_cargo_weight' => null, |
|
| 58 | - 'vehicle_max_cargo_volume' => null, |
|
| 59 | - 'vehicle_max_distance_mi' => null, |
|
| 60 | - 'subtour_max_revenue' => null, |
|
| 61 | - 'distance_unit' => 'mi', |
|
| 62 | - 'travel_mode' => 'Driving', |
|
| 63 | - 'avoid' => '', |
|
| 64 | - 'avoidance_zones' => [], |
|
| 65 | - 'vehicle_id' => null, |
|
| 66 | - 'driver_id' => null, |
|
| 67 | - 'dev_lat' => null, |
|
| 68 | - 'dev_lng' => null, |
|
| 69 | - 'route_max_duration' => 86399, |
|
| 70 | - 'route_email' => null, |
|
| 71 | - 'store_route' => true, |
|
| 72 | - 'metric' => 4, |
|
| 73 | - 'algorithm_type' => 1, |
|
| 74 | - 'member_id' => 444333, |
|
| 75 | - 'ip' => 199911333, |
|
| 76 | - 'dm' => 12, |
|
| 77 | - 'dirm' => 10, |
|
| 78 | - 'parts' => 10, |
|
| 79 | - 'parts_min' => 1, |
|
| 80 | - 'device_id' => null, |
|
| 81 | - 'device_type' => 'web', |
|
| 82 | - 'first_drive_then_wait_between_stops' => false, |
|
| 83 | - 'has_trailer' => false, |
|
| 84 | - 'trailer_weight_t' => null, |
|
| 85 | - 'limited_weight_t' => null, |
|
| 86 | - 'weight_per_axle_t' => null, |
|
| 87 | - 'truck_height' => null, |
|
| 88 | - 'truck_width' => null, |
|
| 89 | - 'truck_length' => null, |
|
| 90 | - 'truck_hazardous_goods' => '', |
|
| 91 | - 'truck_axles' => 0, |
|
| 92 | - 'truck_toll_road_usage' => null, |
|
| 93 | - 'truck_avoid_ferries' => null, |
|
| 94 | - 'truck_hwy_only' => null, |
|
| 95 | - 'truck_lcv' => null, |
|
| 96 | - 'truck_borders' => null, |
|
| 97 | - 'truck_side_street_adherence' => null, |
|
| 98 | - 'truck_config' => null, |
|
| 99 | - 'truck_dim_unit' => null, |
|
| 100 | - 'truck_type' => null, |
|
| 101 | - 'truck_weight' => 0, |
|
| 102 | - 'optimization_quality' => 1, |
|
| 103 | - 'override_addresses' => [], |
|
| 104 | - 'max_tour_size' => null, |
|
| 105 | - 'min_tour_size' => 0, |
|
| 106 | - 'uturn' => 1, |
|
| 107 | - 'leftturn' => 1, |
|
| 108 | - 'rightturn' => 1, |
|
| 109 | - 'route_time_multiplier' => null, |
|
| 110 | - 'route_service_time_multiplier' => null, |
|
| 111 | - 'optimization_engine' => '2', |
|
| 112 | - 'is_dynamic_start_time' => false |
|
| 113 | - ]); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function testFromArray() |
|
| 117 | - { |
|
| 118 | - $routeParams = self::$routeParameters; |
|
| 119 | - $optParams = OptimizationProblemParams::fromArray([ |
|
| 120 | - 'addresses' => self::$addresses, |
|
| 121 | - 'parameters' => $routeParams |
|
| 122 | - ]); |
|
| 123 | - |
|
| 124 | - $this->assertNotNull($optParams); |
|
| 125 | - $this->assertContainsOnlyInstancesOf(OptimizationProblemParams::class, [$optParams]); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function testWithoutParameters() |
|
| 129 | - { |
|
| 130 | - $this->expectException(BadParam::class); |
|
| 131 | - |
|
| 132 | - OptimizationProblemParams::fromArray([ |
|
| 133 | - 'addresses' => self::$addresses, |
|
| 134 | - ]); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function testRedefineRedirectParam() |
|
| 138 | - { |
|
| 139 | - $optimizationParameters = OptimizationProblemParams::fromArray([ |
|
| 140 | - 'addresses' => self::$addresses, |
|
| 141 | - 'parameters' => self::$routeParameters, |
|
| 142 | - 'redirect' => false, |
|
| 143 | - ]); |
|
| 144 | - |
|
| 145 | - $this->assertObjectHasAttribute('redirect', $optimizationParameters); |
|
| 146 | - $this->assertFalse($optimizationParameters->redirect); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - public function testSetParameters() |
|
| 150 | - { |
|
| 151 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 152 | - |
|
| 153 | - $optimizationParameters->parameters = self::$routeParameters; |
|
| 154 | - |
|
| 155 | - $this->assertObjectHasAttribute('parameters', $optimizationParameters); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function testAddAddress() |
|
| 159 | - { |
|
| 160 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 161 | - |
|
| 162 | - $optimizationParameters->addAddress(self::$addresses[0]); |
|
| 163 | - |
|
| 164 | - $address = $optimizationParameters->addresses[0]; |
|
| 165 | - |
|
| 166 | - $this->assertContainsOnlyInstancesOf(Address::class, [$address]); |
|
| 167 | - $this->assertEquals(self::$addresses[0],$optimizationParameters->addresses[0]); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - public function testGetAddressesArray() |
|
| 171 | - { |
|
| 172 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 173 | - |
|
| 174 | - $optimizationParameters->addresses = self::$addresses; |
|
| 175 | - |
|
| 176 | - $addresses = $optimizationParameters->getAddressesArray(); |
|
| 177 | - |
|
| 178 | - $firstAddress = Address::fromArray( |
|
| 179 | - $addresses[0] |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - $this->assertNotNull($addresses); |
|
| 183 | - $this->assertTrue(sizeof($addresses)>0); |
|
| 184 | - $this->assertContainsOnlyInstancesOf(Address::class, [$firstAddress]); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - public function testGetParametersArray() |
|
| 188 | - { |
|
| 189 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 190 | - |
|
| 191 | - $optimizationParameters->parameters = self::$routeParameters; |
|
| 192 | - |
|
| 193 | - $routeParameters = RouteParameters::fromArray( |
|
| 194 | - $optimizationParameters->getParametersArray() |
|
| 195 | - ); |
|
| 196 | - |
|
| 197 | - $this->assertNotNull($optimizationParameters); |
|
| 198 | - $this->assertContainsOnlyInstancesOf(RouteParameters::class, [$routeParameters]); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function testSetAddresses() |
|
| 202 | - { |
|
| 203 | - $optimizationParameters = new OptimizationProblemParams(); |
|
| 12 | + public static $routeParameters = null; |
|
| 13 | + public static $addresses = []; |
|
| 14 | + |
|
| 15 | + public static function setUpBeforeClass() |
|
| 16 | + { |
|
| 17 | + //region Addresses |
|
| 18 | + self::$addresses[] = Address::fromArray([ |
|
| 19 | + 'address' => '11497 Columbia Park Dr W, Jacksonville, FL 32258', |
|
| 20 | + 'is_depot' => true, |
|
| 21 | + 'lat' => 30.159341812134, |
|
| 22 | + 'lng' => -81.538619995117, |
|
| 23 | + 'time' => 300, |
|
| 24 | + 'time_window_start' => 28800, |
|
| 25 | + 'time_window_end' => 32400, |
|
| 26 | + ]); |
|
| 27 | + |
|
| 28 | + self::$addresses[] = Address::fromArray([ |
|
| 29 | + 'address' => '214 Edgewater Branch Drive 32259', |
|
| 30 | + 'lat' => 30.103567123413, |
|
| 31 | + 'lng' => -81.595352172852, |
|
| 32 | + 'time' => 300, |
|
| 33 | + 'time_window_start' => 36000, |
|
| 34 | + 'time_window_end' => 37200, |
|
| 35 | + ]); |
|
| 36 | + |
|
| 37 | + self::$addresses[] = Address::fromArray([ |
|
| 38 | + 'address' => '756 eagle point dr 32092', |
|
| 39 | + 'lat' => 30.046422958374, |
|
| 40 | + 'lng' => -81.508758544922, |
|
| 41 | + 'time' => 300, |
|
| 42 | + 'time_window_start' => 39600, |
|
| 43 | + 'time_window_end' => 41400, |
|
| 44 | + ]); |
|
| 45 | + //endregion |
|
| 46 | + |
|
| 47 | + self::$routeParameters = RouteParameters::fromArray([ |
|
| 48 | + 'is_upload' => false, |
|
| 49 | + 'rt' => false, |
|
| 50 | + 'route_name' => 'Saturday 25th of July 2020 04 => 00 => 00 AM UTC', |
|
| 51 | + 'route_date' => 1595635200, |
|
| 52 | + 'route_time' => 25200, |
|
| 53 | + 'disable_optimization' => false, |
|
| 54 | + 'optimize' => 'Time', |
|
| 55 | + 'lock_last' => false, |
|
| 56 | + 'vehicle_capacity' => null, |
|
| 57 | + 'vehicle_max_cargo_weight' => null, |
|
| 58 | + 'vehicle_max_cargo_volume' => null, |
|
| 59 | + 'vehicle_max_distance_mi' => null, |
|
| 60 | + 'subtour_max_revenue' => null, |
|
| 61 | + 'distance_unit' => 'mi', |
|
| 62 | + 'travel_mode' => 'Driving', |
|
| 63 | + 'avoid' => '', |
|
| 64 | + 'avoidance_zones' => [], |
|
| 65 | + 'vehicle_id' => null, |
|
| 66 | + 'driver_id' => null, |
|
| 67 | + 'dev_lat' => null, |
|
| 68 | + 'dev_lng' => null, |
|
| 69 | + 'route_max_duration' => 86399, |
|
| 70 | + 'route_email' => null, |
|
| 71 | + 'store_route' => true, |
|
| 72 | + 'metric' => 4, |
|
| 73 | + 'algorithm_type' => 1, |
|
| 74 | + 'member_id' => 444333, |
|
| 75 | + 'ip' => 199911333, |
|
| 76 | + 'dm' => 12, |
|
| 77 | + 'dirm' => 10, |
|
| 78 | + 'parts' => 10, |
|
| 79 | + 'parts_min' => 1, |
|
| 80 | + 'device_id' => null, |
|
| 81 | + 'device_type' => 'web', |
|
| 82 | + 'first_drive_then_wait_between_stops' => false, |
|
| 83 | + 'has_trailer' => false, |
|
| 84 | + 'trailer_weight_t' => null, |
|
| 85 | + 'limited_weight_t' => null, |
|
| 86 | + 'weight_per_axle_t' => null, |
|
| 87 | + 'truck_height' => null, |
|
| 88 | + 'truck_width' => null, |
|
| 89 | + 'truck_length' => null, |
|
| 90 | + 'truck_hazardous_goods' => '', |
|
| 91 | + 'truck_axles' => 0, |
|
| 92 | + 'truck_toll_road_usage' => null, |
|
| 93 | + 'truck_avoid_ferries' => null, |
|
| 94 | + 'truck_hwy_only' => null, |
|
| 95 | + 'truck_lcv' => null, |
|
| 96 | + 'truck_borders' => null, |
|
| 97 | + 'truck_side_street_adherence' => null, |
|
| 98 | + 'truck_config' => null, |
|
| 99 | + 'truck_dim_unit' => null, |
|
| 100 | + 'truck_type' => null, |
|
| 101 | + 'truck_weight' => 0, |
|
| 102 | + 'optimization_quality' => 1, |
|
| 103 | + 'override_addresses' => [], |
|
| 104 | + 'max_tour_size' => null, |
|
| 105 | + 'min_tour_size' => 0, |
|
| 106 | + 'uturn' => 1, |
|
| 107 | + 'leftturn' => 1, |
|
| 108 | + 'rightturn' => 1, |
|
| 109 | + 'route_time_multiplier' => null, |
|
| 110 | + 'route_service_time_multiplier' => null, |
|
| 111 | + 'optimization_engine' => '2', |
|
| 112 | + 'is_dynamic_start_time' => false |
|
| 113 | + ]); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function testFromArray() |
|
| 117 | + { |
|
| 118 | + $routeParams = self::$routeParameters; |
|
| 119 | + $optParams = OptimizationProblemParams::fromArray([ |
|
| 120 | + 'addresses' => self::$addresses, |
|
| 121 | + 'parameters' => $routeParams |
|
| 122 | + ]); |
|
| 123 | + |
|
| 124 | + $this->assertNotNull($optParams); |
|
| 125 | + $this->assertContainsOnlyInstancesOf(OptimizationProblemParams::class, [$optParams]); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function testWithoutParameters() |
|
| 129 | + { |
|
| 130 | + $this->expectException(BadParam::class); |
|
| 131 | + |
|
| 132 | + OptimizationProblemParams::fromArray([ |
|
| 133 | + 'addresses' => self::$addresses, |
|
| 134 | + ]); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function testRedefineRedirectParam() |
|
| 138 | + { |
|
| 139 | + $optimizationParameters = OptimizationProblemParams::fromArray([ |
|
| 140 | + 'addresses' => self::$addresses, |
|
| 141 | + 'parameters' => self::$routeParameters, |
|
| 142 | + 'redirect' => false, |
|
| 143 | + ]); |
|
| 144 | + |
|
| 145 | + $this->assertObjectHasAttribute('redirect', $optimizationParameters); |
|
| 146 | + $this->assertFalse($optimizationParameters->redirect); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + public function testSetParameters() |
|
| 150 | + { |
|
| 151 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 152 | + |
|
| 153 | + $optimizationParameters->parameters = self::$routeParameters; |
|
| 154 | + |
|
| 155 | + $this->assertObjectHasAttribute('parameters', $optimizationParameters); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function testAddAddress() |
|
| 159 | + { |
|
| 160 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 161 | + |
|
| 162 | + $optimizationParameters->addAddress(self::$addresses[0]); |
|
| 163 | + |
|
| 164 | + $address = $optimizationParameters->addresses[0]; |
|
| 165 | + |
|
| 166 | + $this->assertContainsOnlyInstancesOf(Address::class, [$address]); |
|
| 167 | + $this->assertEquals(self::$addresses[0],$optimizationParameters->addresses[0]); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + public function testGetAddressesArray() |
|
| 171 | + { |
|
| 172 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 173 | + |
|
| 174 | + $optimizationParameters->addresses = self::$addresses; |
|
| 175 | + |
|
| 176 | + $addresses = $optimizationParameters->getAddressesArray(); |
|
| 177 | + |
|
| 178 | + $firstAddress = Address::fromArray( |
|
| 179 | + $addresses[0] |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + $this->assertNotNull($addresses); |
|
| 183 | + $this->assertTrue(sizeof($addresses)>0); |
|
| 184 | + $this->assertContainsOnlyInstancesOf(Address::class, [$firstAddress]); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + public function testGetParametersArray() |
|
| 188 | + { |
|
| 189 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 190 | + |
|
| 191 | + $optimizationParameters->parameters = self::$routeParameters; |
|
| 192 | + |
|
| 193 | + $routeParameters = RouteParameters::fromArray( |
|
| 194 | + $optimizationParameters->getParametersArray() |
|
| 195 | + ); |
|
| 196 | + |
|
| 197 | + $this->assertNotNull($optimizationParameters); |
|
| 198 | + $this->assertContainsOnlyInstancesOf(RouteParameters::class, [$routeParameters]); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function testSetAddresses() |
|
| 202 | + { |
|
| 203 | + $optimizationParameters = new OptimizationProblemParams(); |
|
| 204 | 204 | |
| 205 | - $optimizationParameters->setAddresses(self::$addresses); |
|
| 205 | + $optimizationParameters->setAddresses(self::$addresses); |
|
| 206 | 206 | |
| 207 | - $this->assertEquals(self::$addresses,$optimizationParameters->addresses); |
|
| 207 | + $this->assertEquals(self::$addresses,$optimizationParameters->addresses); |
|
| 208 | 208 | |
| 209 | - $address = $optimizationParameters->addresses[0]; |
|
| 209 | + $address = $optimizationParameters->addresses[0]; |
|
| 210 | 210 | |
| 211 | - $this->assertContainsOnlyInstancesOf(Address::class, [$address]); |
|
| 211 | + $this->assertContainsOnlyInstancesOf(Address::class, [$address]); |
|
| 212 | 212 | |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - public static function tearDownAfterClass() |
|
| 216 | - { |
|
| 217 | - self::$addresses[] = null; |
|
| 218 | - self::$routeParameters = null; |
|
| 219 | - } |
|
| 215 | + public static function tearDownAfterClass() |
|
| 216 | + { |
|
| 217 | + self::$addresses[] = null; |
|
| 218 | + self::$routeParameters = null; |
|
| 219 | + } |
|
| 220 | 220 | } |
| 221 | 221 | \ No newline at end of file |
@@ -13,425 +13,425 @@ |
||
| 13 | 13 | |
| 14 | 14 | class UserTests extends \PHPUnit\Framework\TestCase |
| 15 | 15 | { |
| 16 | - public static $createdMembers=[]; |
|
| 17 | - |
|
| 18 | - public static function setUpBeforeClass() |
|
| 19 | - { |
|
| 20 | - Route4Me::setApiKey(Constants::API_KEY); |
|
| 21 | - $date = new \DateTime(); |
|
| 22 | - |
|
| 23 | - $params = Member::fromArray([ |
|
| 24 | - 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 25 | - 'member_phone' => '571-259-5939', |
|
| 26 | - 'member_zipcode' => '22102', |
|
| 27 | - 'route_count' => null, |
|
| 28 | - 'member_email' => 'regression.autotests+'.$date->getTimestamp().'@gmail.com', |
|
| 29 | - 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 30 | - 'READONLY_USER' => 'FALSE', |
|
| 31 | - 'member_type' => 'SUB_ACCOUNT_DRIVER', |
|
| 32 | - 'date_of_birth' => '1994-10-01', |
|
| 33 | - 'member_first_name' => 'Clay', |
|
| 34 | - 'member_password' => '123456', |
|
| 35 | - 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 36 | - 'member_last_name' => 'Abraham', |
|
| 37 | - 'SHOW_ALL_VEHICLES' => 'FALSE', |
|
| 38 | - 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 39 | - ]); |
|
| 40 | - |
|
| 41 | - $member = new Member(); |
|
| 42 | - |
|
| 43 | - $response = $member->createMember($params); |
|
| 44 | - |
|
| 45 | - self::assertNotNull($response); |
|
| 46 | - self::assertInstanceOf( |
|
| 47 | - MemberResponseV4::class, |
|
| 48 | - MemberResponseV4::fromArray($response) |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - self::$createdMembers[] = MemberResponseV4::fromArray($response); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function testFromArray() |
|
| 55 | - { |
|
| 56 | - $memberResponseV4 = MemberResponseV4::fromArray([ |
|
| 57 | - 'member_id' => '18154', |
|
| 58 | - 'OWNER_MEMBER_ID' => '0', |
|
| 59 | - 'member_type' => 'PRIMARY_ACCOUNT', |
|
| 60 | - 'member_first_name' => 'Routeme', |
|
| 61 | - 'member_last_name' => 'QA', |
|
| 62 | - 'member_email' => '[email protected]', |
|
| 63 | - 'preferred_units' => 'MI', |
|
| 64 | - 'preferred_language' => 'en', |
|
| 65 | - 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 66 | - 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 67 | - 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 68 | - 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 69 | - 'SHOW_ALL_VEHICLES' => '0', |
|
| 70 | - 'READONLY_USER' => 'FALSE', |
|
| 71 | - 'member_phone' => null, |
|
| 72 | - 'member_zipcode' => '18002', |
|
| 73 | - 'timezone' => 'US\/Arizona', |
|
| 74 | - 'date_of_birth' => null, |
|
| 75 | - 'user_reg_state_id' => null, |
|
| 76 | - 'user_reg_country_id' => null, |
|
| 77 | - 'member_picture' => 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 78 | - 'level' => 0, |
|
| 79 | - 'custom_data' => [ |
|
| 80 | - 'animal' => 'lion', |
|
| 81 | - 'bird' => 'eagle' |
|
| 82 | - ], |
|
| 83 | - 'api_key' => '11111111111111111111111111111111' |
|
| 84 | - ]); |
|
| 85 | - |
|
| 86 | - $this->assertEquals('18154', $memberResponseV4->member_id); |
|
| 87 | - $this->assertEquals('0', $memberResponseV4->OWNER_MEMBER_ID); |
|
| 88 | - $this->assertEquals('PRIMARY_ACCOUNT', $memberResponseV4->member_type); |
|
| 89 | - $this->assertEquals('Routeme', $memberResponseV4->member_first_name); |
|
| 90 | - $this->assertEquals('QA', $memberResponseV4->member_last_name); |
|
| 91 | - $this->assertEquals('[email protected]', $memberResponseV4->member_email); |
|
| 92 | - $this->assertEquals('MI', $memberResponseV4->preferred_units); |
|
| 93 | - $this->assertEquals('en', $memberResponseV4->preferred_language); |
|
| 94 | - $this->assertEquals('FALSE', $memberResponseV4->HIDE_ROUTED_ADDRESSES); |
|
| 95 | - $this->assertEquals('FALSE', $memberResponseV4->HIDE_VISITED_ADDRESSES); |
|
| 96 | - $this->assertEquals('FALSE', $memberResponseV4->HIDE_NONFUTURE_ROUTES); |
|
| 97 | - $this->assertEquals('FALSE', $memberResponseV4->SHOW_ALL_DRIVERS); |
|
| 98 | - $this->assertEquals('0', $memberResponseV4->SHOW_ALL_VEHICLES); |
|
| 99 | - $this->assertEquals('FALSE', $memberResponseV4->READONLY_USER); |
|
| 100 | - $this->assertEquals(null, $memberResponseV4->member_phone); |
|
| 101 | - $this->assertEquals('18002', $memberResponseV4->member_zipcode); |
|
| 102 | - $this->assertEquals('US\/Arizona', $memberResponseV4->timezone); |
|
| 103 | - $this->assertEquals(null, $memberResponseV4->date_of_birth); |
|
| 104 | - |
|
| 105 | - $this->assertEquals(null, $memberResponseV4->user_reg_state_id); |
|
| 106 | - $this->assertEquals(null, $memberResponseV4->user_reg_country_id); |
|
| 107 | - $this->assertEquals( |
|
| 108 | - 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 109 | - $memberResponseV4->member_picture |
|
| 110 | - ); |
|
| 111 | - $this->assertEquals(0, $memberResponseV4->level); |
|
| 112 | - $this->assertEquals( |
|
| 113 | - [ |
|
| 114 | - 'animal' => 'lion', |
|
| 115 | - 'bird' => 'eagle' |
|
| 116 | - ], |
|
| 117 | - $memberResponseV4->custom_data); |
|
| 118 | - $this->assertEquals('11111111111111111111111111111111', $memberResponseV4->api_key); |
|
| 119 | - |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function testToArray() |
|
| 123 | - { |
|
| 124 | - $memberResponseV4 = MemberResponseV4::fromArray([ |
|
| 125 | - 'member_id' => '18154', |
|
| 126 | - 'OWNER_MEMBER_ID' => '0', |
|
| 127 | - 'member_type' => 'PRIMARY_ACCOUNT', |
|
| 128 | - 'member_first_name' => 'Routeme', |
|
| 129 | - 'member_last_name' => 'QA', |
|
| 130 | - 'member_email' => '[email protected]', |
|
| 131 | - 'preferred_units' => 'MI', |
|
| 132 | - 'preferred_language' => 'en', |
|
| 133 | - 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 134 | - 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 135 | - 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 136 | - 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 137 | - 'SHOW_ALL_VEHICLES' => '0', |
|
| 138 | - 'READONLY_USER' => 'FALSE', |
|
| 139 | - 'member_zipcode' => '18002', |
|
| 140 | - 'timezone' => 'US\/Arizona', |
|
| 141 | - 'member_picture' => 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 142 | - 'level' => 0, |
|
| 143 | - 'custom_data' => [ |
|
| 144 | - 'animal' => 'lion', |
|
| 145 | - 'bird' => 'eagle' |
|
| 146 | - ], |
|
| 147 | - 'api_key' => '11111111111111111111111111111111' |
|
| 148 | - ]); |
|
| 149 | - |
|
| 150 | - $this->assertEquals($memberResponseV4->toArray(), |
|
| 151 | - [ |
|
| 152 | - 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 153 | - 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 154 | - 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 155 | - 'member_id' => '18154', |
|
| 156 | - 'OWNER_MEMBER_ID' => '0', |
|
| 157 | - 'READONLY_USER' => 'FALSE', |
|
| 158 | - 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 159 | - 'SHOW_ALL_VEHICLES' => '0', |
|
| 160 | - 'member_email' => '[email protected]', |
|
| 161 | - 'member_first_name' => 'Routeme', |
|
| 162 | - 'member_last_name' => 'QA', |
|
| 163 | - 'member_picture' => 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 164 | - 'member_type' => 'PRIMARY_ACCOUNT', |
|
| 165 | - 'member_zipcode' => '18002', |
|
| 166 | - 'preferred_language' => 'en', |
|
| 167 | - 'preferred_units' => 'MI', |
|
| 168 | - 'timezone' => 'US\/Arizona', |
|
| 169 | - 'level' => 0, |
|
| 170 | - 'custom_data' => [ |
|
| 171 | - 'animal' => 'lion', |
|
| 172 | - 'bird' => 'eagle' |
|
| 173 | - ], |
|
| 174 | - 'api_key' => '11111111111111111111111111111111' |
|
| 175 | - ] |
|
| 176 | - ); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - public function testGetUsers() |
|
| 180 | - { |
|
| 181 | - $member = new Member(); |
|
| 182 | - |
|
| 183 | - $response = $member->getUsers(); |
|
| 184 | - |
|
| 185 | - $this->assertNotNull($response); |
|
| 186 | - $this->assertTrue(is_array($response)); |
|
| 187 | - $this->assertTrue(sizeof($response)>0); |
|
| 188 | - $this->assertInstanceOf( |
|
| 189 | - ResultsResponseV4::class, |
|
| 190 | - ResultsResponseV4::fromArray($response) |
|
| 191 | - ); |
|
| 192 | - $this->assertTrue(isset($response['total'])); |
|
| 193 | - $this->assertTrue(isset($response['results'])); |
|
| 194 | - $this->assertTrue(is_array($response['results'])); |
|
| 195 | - $this->assertInstanceOf( |
|
| 196 | - MemberResponseV4::class, |
|
| 197 | - MemberResponseV4::fromArray($response['results'][0]) |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function testGetUserById() |
|
| 202 | - { |
|
| 203 | - $member = new Member(); |
|
| 204 | - |
|
| 205 | - $param = [ |
|
| 206 | - 'member_id' => self::$createdMembers[0]->member_id, |
|
| 207 | - ]; |
|
| 208 | - |
|
| 209 | - $response = $member->getUser($param); |
|
| 210 | - |
|
| 211 | - $this->assertNotNull($response); |
|
| 212 | - $this->assertInstanceOf( |
|
| 213 | - MemberResponseV4::class, |
|
| 214 | - MemberResponseV4::fromArray($response) |
|
| 215 | - ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - public function testUpdateMember() |
|
| 219 | - { |
|
| 220 | - $member = new Member(); |
|
| 221 | - |
|
| 222 | - $params = Member::fromArray([ |
|
| 223 | - 'member_id' => self::$createdMembers[0]->member_id, |
|
| 224 | - 'member_phone' => '555-777-888', |
|
| 225 | - ]); |
|
| 226 | - |
|
| 227 | - $response = $member->updateMember($params); |
|
| 228 | - |
|
| 229 | - $this->assertNotNull($response); |
|
| 230 | - $this->assertInstanceOf( |
|
| 231 | - MemberResponseV4::class, |
|
| 232 | - MemberResponseV4::fromArray($response) |
|
| 233 | - ); |
|
| 234 | - $this->assertEquals( |
|
| 235 | - '555-777-888', |
|
| 236 | - $response['member_phone'] |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - public function testAddEditCustomDataToUser() |
|
| 241 | - { |
|
| 242 | - $member = new Member(); |
|
| 243 | - |
|
| 244 | - $params = Member::fromArray([ |
|
| 245 | - 'member_id' => self::$createdMembers[0]->member_id, |
|
| 246 | - 'custom_data' => ['Custom Key 2' => 'Custom Value 2'], |
|
| 247 | - ]); |
|
| 248 | - |
|
| 249 | - $response = $member->updateMember($params); |
|
| 250 | - |
|
| 251 | - $this->assertNotNull($response); |
|
| 252 | - $this->assertInstanceOf( |
|
| 253 | - MemberResponseV4::class, |
|
| 254 | - MemberResponseV4::fromArray($response) |
|
| 255 | - ); |
|
| 256 | - $this->assertEquals( |
|
| 257 | - ['Custom Key 2' => 'Custom Value 2'], |
|
| 258 | - $response['custom_data'] |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - public function testUserAuthentication() |
|
| 263 | - { |
|
| 264 | - $Parameters = Member::fromArray([ |
|
| 265 | - 'strEmail' => self::$createdMembers[0]->member_email, |
|
| 266 | - 'strPassword' => '123456', |
|
| 267 | - 'format' => 'json', |
|
| 268 | - ]); |
|
| 269 | - |
|
| 270 | - $member = new Member(); |
|
| 271 | - |
|
| 272 | - $response = $member->memberAuthentication($Parameters); |
|
| 273 | - |
|
| 274 | - $this->assertNotNull($response); |
|
| 275 | - $this->assertInstanceOf( |
|
| 276 | - MemberResponse::class, |
|
| 277 | - MemberResponse::fromArray($response) |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - public function testValidateSession() |
|
| 282 | - { |
|
| 283 | - $member = new Member(); |
|
| 284 | - |
|
| 285 | - //region -- Authenticate a user and get session guid -- |
|
| 286 | - |
|
| 287 | - $recordParameters = Member::fromArray([ |
|
| 288 | - 'strEmail' => self::$createdMembers[0]->member_email, |
|
| 289 | - 'strPassword' => '123456', |
|
| 290 | - 'format' => 'json', |
|
| 291 | - ]); |
|
| 292 | - |
|
| 293 | - $response = $member->memberAuthentication($recordParameters); |
|
| 294 | - |
|
| 295 | - $this->assertNotNull($response); |
|
| 296 | - $this->assertInstanceOf( |
|
| 297 | - MemberAuthenticationResponse::class, |
|
| 298 | - MemberAuthenticationResponse::fromArray($response) |
|
| 299 | - ); |
|
| 300 | - |
|
| 301 | - //endregion |
|
| 302 | - |
|
| 303 | - $sessionGuid = $response['session_guid']; |
|
| 304 | - $memberID = $response['member_id']; |
|
| 305 | - |
|
| 306 | - // Validate the session |
|
| 307 | - $params = Member::fromArray([ |
|
| 308 | - 'session_guid' => $sessionGuid, |
|
| 309 | - 'format' => 'json', |
|
| 310 | - 'user_key' => 1, |
|
| 311 | - ]); |
|
| 312 | - |
|
| 313 | - $result = $member->validateSession($params); |
|
| 314 | - |
|
| 315 | - $this->assertNotNull($result); |
|
| 316 | - $this->assertInstanceOf( |
|
| 317 | - MemberResponse::class, |
|
| 318 | - MemberResponse::fromArray($result) |
|
| 319 | - ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - public function testUserRegistration() |
|
| 323 | - { |
|
| 324 | - $this->markTestSkipped('must be revisited.'); // This test requires valid user email |
|
| 325 | - $registrParameters = Member::fromArray([ |
|
| 326 | - 'strEmail' => '[email protected]', |
|
| 327 | - 'strPassword_1' => 'ooo111111', |
|
| 328 | - 'strPassword_2' => 'ooo111111', |
|
| 329 | - 'strFirstName' => 'Driver', |
|
| 330 | - 'strLastName' => 'Driverson', |
|
| 331 | - 'format' => 'json', |
|
| 332 | - 'strIndustry' => 'Gifting', |
|
| 333 | - 'chkTerms' => 1, |
|
| 334 | - 'device_type' => 'web', |
|
| 335 | - 'plan' => 'free', |
|
| 336 | - ]); |
|
| 337 | - |
|
| 338 | - $member = new Member(); |
|
| 339 | - $errorText = ""; |
|
| 340 | - |
|
| 341 | - $response = $member->newAccountRegistration($registrParameters, $errorText); |
|
| 342 | - |
|
| 343 | - $this->assertNotNull($response); |
|
| 344 | - $this->assertInstanceOf(MemberResponse::class, $response); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - public function testCreateUser() |
|
| 348 | - { |
|
| 349 | - $date = new \DateTime(); |
|
| 350 | - |
|
| 351 | - $params = Member::fromArray([ |
|
| 352 | - 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 353 | - 'member_phone' => '571-259-5939', |
|
| 354 | - 'member_zipcode' => '22102', |
|
| 355 | - 'route_count' => null, |
|
| 356 | - 'member_email' => 'regression.autotests+'.$date->getTimestamp().'@gmail.com', |
|
| 357 | - 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 358 | - 'READONLY_USER' => 'FALSE', |
|
| 359 | - 'member_type' => 'SUB_ACCOUNT_DRIVER', |
|
| 360 | - 'date_of_birth' => '1994-10-01', |
|
| 361 | - 'member_first_name' => 'John', |
|
| 362 | - 'member_password' => '123456', |
|
| 363 | - 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 364 | - 'member_last_name' => 'Doe', |
|
| 365 | - 'SHOW_ALL_VEHICLES' => 'FALSE', |
|
| 366 | - 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 367 | - ]); |
|
| 368 | - |
|
| 369 | - $member = new Member(); |
|
| 370 | - |
|
| 371 | - $response = $member->createMember($params); |
|
| 372 | - |
|
| 373 | - self::assertNotNull($response); |
|
| 374 | - self::assertInstanceOf( |
|
| 375 | - MemberResponseV4::class, |
|
| 376 | - MemberResponseV4::fromArray($response) |
|
| 377 | - ); |
|
| 378 | - |
|
| 379 | - self::$createdMembers[] = MemberResponseV4::fromArray($response); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - public function testDeleteUser() |
|
| 383 | - { |
|
| 384 | - $member = new Member(); |
|
| 385 | - $errorText = ""; |
|
| 386 | - |
|
| 387 | - $memberID = self::$createdMembers[sizeof(self::$createdMembers)-1]->member_id; |
|
| 388 | - |
|
| 389 | - // Delete member from the user's account |
|
| 390 | - $params = Member::fromArray([ |
|
| 391 | - 'member_id' => $memberID, |
|
| 392 | - ]); |
|
| 393 | - |
|
| 394 | - $response = $member->deleteMember($params, $errorText); |
|
| 395 | - |
|
| 396 | - $this->assertNotNull($response, $errorText); |
|
| 397 | - $this->assertTrue(isset($response['status'])); |
|
| 398 | - $this->assertTrue($response['status']); |
|
| 399 | - |
|
| 400 | - self::$createdMembers[] = array_pop(self::$createdMembers); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - public function testGetMemberCapabilities() |
|
| 404 | - { |
|
| 405 | - $member = new Member(); |
|
| 406 | - |
|
| 407 | - $memberCapabalities = member::getMemberCapabilities(); |
|
| 408 | - |
|
| 409 | - $this->assertNotNull($memberCapabalities); |
|
| 410 | - $this->assertInstanceOf( |
|
| 411 | - MemberCapabilities::class, |
|
| 412 | - MemberCapabilities::fromArray($memberCapabalities) |
|
| 413 | - ); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - public static function tearDownAfterClass() |
|
| 417 | - { |
|
| 418 | - if (sizeof(self::$createdMembers)>0) { |
|
| 419 | - $member = new Member(); |
|
| 420 | - $errorText = ""; |
|
| 421 | - |
|
| 422 | - foreach (self::$createdMembers as $createdMember) { |
|
| 423 | - $params = Member::fromArray([ |
|
| 424 | - 'member_id' => $createdMember->member_id, |
|
| 425 | - ]); |
|
| 426 | - |
|
| 427 | - $response = $member->deleteMember($params, $errorText); |
|
| 428 | - |
|
| 429 | - if (!is_null($response) && isset($response['status']) && $response['status']) { |
|
| 430 | - echo "The member ".$createdMember->member_id." removed <br>"; |
|
| 431 | - } else { |
|
| 432 | - echo "Cannot remove the member ".$createdMember->member_id." <br>".$errorText; |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - } |
|
| 16 | + public static $createdMembers=[]; |
|
| 17 | + |
|
| 18 | + public static function setUpBeforeClass() |
|
| 19 | + { |
|
| 20 | + Route4Me::setApiKey(Constants::API_KEY); |
|
| 21 | + $date = new \DateTime(); |
|
| 22 | + |
|
| 23 | + $params = Member::fromArray([ |
|
| 24 | + 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 25 | + 'member_phone' => '571-259-5939', |
|
| 26 | + 'member_zipcode' => '22102', |
|
| 27 | + 'route_count' => null, |
|
| 28 | + 'member_email' => 'regression.autotests+'.$date->getTimestamp().'@gmail.com', |
|
| 29 | + 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 30 | + 'READONLY_USER' => 'FALSE', |
|
| 31 | + 'member_type' => 'SUB_ACCOUNT_DRIVER', |
|
| 32 | + 'date_of_birth' => '1994-10-01', |
|
| 33 | + 'member_first_name' => 'Clay', |
|
| 34 | + 'member_password' => '123456', |
|
| 35 | + 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 36 | + 'member_last_name' => 'Abraham', |
|
| 37 | + 'SHOW_ALL_VEHICLES' => 'FALSE', |
|
| 38 | + 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 39 | + ]); |
|
| 40 | + |
|
| 41 | + $member = new Member(); |
|
| 42 | + |
|
| 43 | + $response = $member->createMember($params); |
|
| 44 | + |
|
| 45 | + self::assertNotNull($response); |
|
| 46 | + self::assertInstanceOf( |
|
| 47 | + MemberResponseV4::class, |
|
| 48 | + MemberResponseV4::fromArray($response) |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + self::$createdMembers[] = MemberResponseV4::fromArray($response); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function testFromArray() |
|
| 55 | + { |
|
| 56 | + $memberResponseV4 = MemberResponseV4::fromArray([ |
|
| 57 | + 'member_id' => '18154', |
|
| 58 | + 'OWNER_MEMBER_ID' => '0', |
|
| 59 | + 'member_type' => 'PRIMARY_ACCOUNT', |
|
| 60 | + 'member_first_name' => 'Routeme', |
|
| 61 | + 'member_last_name' => 'QA', |
|
| 62 | + 'member_email' => '[email protected]', |
|
| 63 | + 'preferred_units' => 'MI', |
|
| 64 | + 'preferred_language' => 'en', |
|
| 65 | + 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 66 | + 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 67 | + 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 68 | + 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 69 | + 'SHOW_ALL_VEHICLES' => '0', |
|
| 70 | + 'READONLY_USER' => 'FALSE', |
|
| 71 | + 'member_phone' => null, |
|
| 72 | + 'member_zipcode' => '18002', |
|
| 73 | + 'timezone' => 'US\/Arizona', |
|
| 74 | + 'date_of_birth' => null, |
|
| 75 | + 'user_reg_state_id' => null, |
|
| 76 | + 'user_reg_country_id' => null, |
|
| 77 | + 'member_picture' => 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 78 | + 'level' => 0, |
|
| 79 | + 'custom_data' => [ |
|
| 80 | + 'animal' => 'lion', |
|
| 81 | + 'bird' => 'eagle' |
|
| 82 | + ], |
|
| 83 | + 'api_key' => '11111111111111111111111111111111' |
|
| 84 | + ]); |
|
| 85 | + |
|
| 86 | + $this->assertEquals('18154', $memberResponseV4->member_id); |
|
| 87 | + $this->assertEquals('0', $memberResponseV4->OWNER_MEMBER_ID); |
|
| 88 | + $this->assertEquals('PRIMARY_ACCOUNT', $memberResponseV4->member_type); |
|
| 89 | + $this->assertEquals('Routeme', $memberResponseV4->member_first_name); |
|
| 90 | + $this->assertEquals('QA', $memberResponseV4->member_last_name); |
|
| 91 | + $this->assertEquals('[email protected]', $memberResponseV4->member_email); |
|
| 92 | + $this->assertEquals('MI', $memberResponseV4->preferred_units); |
|
| 93 | + $this->assertEquals('en', $memberResponseV4->preferred_language); |
|
| 94 | + $this->assertEquals('FALSE', $memberResponseV4->HIDE_ROUTED_ADDRESSES); |
|
| 95 | + $this->assertEquals('FALSE', $memberResponseV4->HIDE_VISITED_ADDRESSES); |
|
| 96 | + $this->assertEquals('FALSE', $memberResponseV4->HIDE_NONFUTURE_ROUTES); |
|
| 97 | + $this->assertEquals('FALSE', $memberResponseV4->SHOW_ALL_DRIVERS); |
|
| 98 | + $this->assertEquals('0', $memberResponseV4->SHOW_ALL_VEHICLES); |
|
| 99 | + $this->assertEquals('FALSE', $memberResponseV4->READONLY_USER); |
|
| 100 | + $this->assertEquals(null, $memberResponseV4->member_phone); |
|
| 101 | + $this->assertEquals('18002', $memberResponseV4->member_zipcode); |
|
| 102 | + $this->assertEquals('US\/Arizona', $memberResponseV4->timezone); |
|
| 103 | + $this->assertEquals(null, $memberResponseV4->date_of_birth); |
|
| 104 | + |
|
| 105 | + $this->assertEquals(null, $memberResponseV4->user_reg_state_id); |
|
| 106 | + $this->assertEquals(null, $memberResponseV4->user_reg_country_id); |
|
| 107 | + $this->assertEquals( |
|
| 108 | + 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 109 | + $memberResponseV4->member_picture |
|
| 110 | + ); |
|
| 111 | + $this->assertEquals(0, $memberResponseV4->level); |
|
| 112 | + $this->assertEquals( |
|
| 113 | + [ |
|
| 114 | + 'animal' => 'lion', |
|
| 115 | + 'bird' => 'eagle' |
|
| 116 | + ], |
|
| 117 | + $memberResponseV4->custom_data); |
|
| 118 | + $this->assertEquals('11111111111111111111111111111111', $memberResponseV4->api_key); |
|
| 119 | + |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function testToArray() |
|
| 123 | + { |
|
| 124 | + $memberResponseV4 = MemberResponseV4::fromArray([ |
|
| 125 | + 'member_id' => '18154', |
|
| 126 | + 'OWNER_MEMBER_ID' => '0', |
|
| 127 | + 'member_type' => 'PRIMARY_ACCOUNT', |
|
| 128 | + 'member_first_name' => 'Routeme', |
|
| 129 | + 'member_last_name' => 'QA', |
|
| 130 | + 'member_email' => '[email protected]', |
|
| 131 | + 'preferred_units' => 'MI', |
|
| 132 | + 'preferred_language' => 'en', |
|
| 133 | + 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 134 | + 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 135 | + 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 136 | + 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 137 | + 'SHOW_ALL_VEHICLES' => '0', |
|
| 138 | + 'READONLY_USER' => 'FALSE', |
|
| 139 | + 'member_zipcode' => '18002', |
|
| 140 | + 'timezone' => 'US\/Arizona', |
|
| 141 | + 'member_picture' => 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 142 | + 'level' => 0, |
|
| 143 | + 'custom_data' => [ |
|
| 144 | + 'animal' => 'lion', |
|
| 145 | + 'bird' => 'eagle' |
|
| 146 | + ], |
|
| 147 | + 'api_key' => '11111111111111111111111111111111' |
|
| 148 | + ]); |
|
| 149 | + |
|
| 150 | + $this->assertEquals($memberResponseV4->toArray(), |
|
| 151 | + [ |
|
| 152 | + 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 153 | + 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 154 | + 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 155 | + 'member_id' => '18154', |
|
| 156 | + 'OWNER_MEMBER_ID' => '0', |
|
| 157 | + 'READONLY_USER' => 'FALSE', |
|
| 158 | + 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 159 | + 'SHOW_ALL_VEHICLES' => '0', |
|
| 160 | + 'member_email' => '[email protected]', |
|
| 161 | + 'member_first_name' => 'Routeme', |
|
| 162 | + 'member_last_name' => 'QA', |
|
| 163 | + 'member_picture' => 'https => \/\/apps-static.borea.com\/uploads\/44444444444444444444444444444444\/profile_77777777777777777777777777777777.png', |
|
| 164 | + 'member_type' => 'PRIMARY_ACCOUNT', |
|
| 165 | + 'member_zipcode' => '18002', |
|
| 166 | + 'preferred_language' => 'en', |
|
| 167 | + 'preferred_units' => 'MI', |
|
| 168 | + 'timezone' => 'US\/Arizona', |
|
| 169 | + 'level' => 0, |
|
| 170 | + 'custom_data' => [ |
|
| 171 | + 'animal' => 'lion', |
|
| 172 | + 'bird' => 'eagle' |
|
| 173 | + ], |
|
| 174 | + 'api_key' => '11111111111111111111111111111111' |
|
| 175 | + ] |
|
| 176 | + ); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + public function testGetUsers() |
|
| 180 | + { |
|
| 181 | + $member = new Member(); |
|
| 182 | + |
|
| 183 | + $response = $member->getUsers(); |
|
| 184 | + |
|
| 185 | + $this->assertNotNull($response); |
|
| 186 | + $this->assertTrue(is_array($response)); |
|
| 187 | + $this->assertTrue(sizeof($response)>0); |
|
| 188 | + $this->assertInstanceOf( |
|
| 189 | + ResultsResponseV4::class, |
|
| 190 | + ResultsResponseV4::fromArray($response) |
|
| 191 | + ); |
|
| 192 | + $this->assertTrue(isset($response['total'])); |
|
| 193 | + $this->assertTrue(isset($response['results'])); |
|
| 194 | + $this->assertTrue(is_array($response['results'])); |
|
| 195 | + $this->assertInstanceOf( |
|
| 196 | + MemberResponseV4::class, |
|
| 197 | + MemberResponseV4::fromArray($response['results'][0]) |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function testGetUserById() |
|
| 202 | + { |
|
| 203 | + $member = new Member(); |
|
| 204 | + |
|
| 205 | + $param = [ |
|
| 206 | + 'member_id' => self::$createdMembers[0]->member_id, |
|
| 207 | + ]; |
|
| 208 | + |
|
| 209 | + $response = $member->getUser($param); |
|
| 210 | + |
|
| 211 | + $this->assertNotNull($response); |
|
| 212 | + $this->assertInstanceOf( |
|
| 213 | + MemberResponseV4::class, |
|
| 214 | + MemberResponseV4::fromArray($response) |
|
| 215 | + ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + public function testUpdateMember() |
|
| 219 | + { |
|
| 220 | + $member = new Member(); |
|
| 221 | + |
|
| 222 | + $params = Member::fromArray([ |
|
| 223 | + 'member_id' => self::$createdMembers[0]->member_id, |
|
| 224 | + 'member_phone' => '555-777-888', |
|
| 225 | + ]); |
|
| 226 | + |
|
| 227 | + $response = $member->updateMember($params); |
|
| 228 | + |
|
| 229 | + $this->assertNotNull($response); |
|
| 230 | + $this->assertInstanceOf( |
|
| 231 | + MemberResponseV4::class, |
|
| 232 | + MemberResponseV4::fromArray($response) |
|
| 233 | + ); |
|
| 234 | + $this->assertEquals( |
|
| 235 | + '555-777-888', |
|
| 236 | + $response['member_phone'] |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + public function testAddEditCustomDataToUser() |
|
| 241 | + { |
|
| 242 | + $member = new Member(); |
|
| 243 | + |
|
| 244 | + $params = Member::fromArray([ |
|
| 245 | + 'member_id' => self::$createdMembers[0]->member_id, |
|
| 246 | + 'custom_data' => ['Custom Key 2' => 'Custom Value 2'], |
|
| 247 | + ]); |
|
| 248 | + |
|
| 249 | + $response = $member->updateMember($params); |
|
| 250 | + |
|
| 251 | + $this->assertNotNull($response); |
|
| 252 | + $this->assertInstanceOf( |
|
| 253 | + MemberResponseV4::class, |
|
| 254 | + MemberResponseV4::fromArray($response) |
|
| 255 | + ); |
|
| 256 | + $this->assertEquals( |
|
| 257 | + ['Custom Key 2' => 'Custom Value 2'], |
|
| 258 | + $response['custom_data'] |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + public function testUserAuthentication() |
|
| 263 | + { |
|
| 264 | + $Parameters = Member::fromArray([ |
|
| 265 | + 'strEmail' => self::$createdMembers[0]->member_email, |
|
| 266 | + 'strPassword' => '123456', |
|
| 267 | + 'format' => 'json', |
|
| 268 | + ]); |
|
| 269 | + |
|
| 270 | + $member = new Member(); |
|
| 271 | + |
|
| 272 | + $response = $member->memberAuthentication($Parameters); |
|
| 273 | + |
|
| 274 | + $this->assertNotNull($response); |
|
| 275 | + $this->assertInstanceOf( |
|
| 276 | + MemberResponse::class, |
|
| 277 | + MemberResponse::fromArray($response) |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + public function testValidateSession() |
|
| 282 | + { |
|
| 283 | + $member = new Member(); |
|
| 284 | + |
|
| 285 | + //region -- Authenticate a user and get session guid -- |
|
| 286 | + |
|
| 287 | + $recordParameters = Member::fromArray([ |
|
| 288 | + 'strEmail' => self::$createdMembers[0]->member_email, |
|
| 289 | + 'strPassword' => '123456', |
|
| 290 | + 'format' => 'json', |
|
| 291 | + ]); |
|
| 292 | + |
|
| 293 | + $response = $member->memberAuthentication($recordParameters); |
|
| 294 | + |
|
| 295 | + $this->assertNotNull($response); |
|
| 296 | + $this->assertInstanceOf( |
|
| 297 | + MemberAuthenticationResponse::class, |
|
| 298 | + MemberAuthenticationResponse::fromArray($response) |
|
| 299 | + ); |
|
| 300 | + |
|
| 301 | + //endregion |
|
| 302 | + |
|
| 303 | + $sessionGuid = $response['session_guid']; |
|
| 304 | + $memberID = $response['member_id']; |
|
| 305 | + |
|
| 306 | + // Validate the session |
|
| 307 | + $params = Member::fromArray([ |
|
| 308 | + 'session_guid' => $sessionGuid, |
|
| 309 | + 'format' => 'json', |
|
| 310 | + 'user_key' => 1, |
|
| 311 | + ]); |
|
| 312 | + |
|
| 313 | + $result = $member->validateSession($params); |
|
| 314 | + |
|
| 315 | + $this->assertNotNull($result); |
|
| 316 | + $this->assertInstanceOf( |
|
| 317 | + MemberResponse::class, |
|
| 318 | + MemberResponse::fromArray($result) |
|
| 319 | + ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + public function testUserRegistration() |
|
| 323 | + { |
|
| 324 | + $this->markTestSkipped('must be revisited.'); // This test requires valid user email |
|
| 325 | + $registrParameters = Member::fromArray([ |
|
| 326 | + 'strEmail' => '[email protected]', |
|
| 327 | + 'strPassword_1' => 'ooo111111', |
|
| 328 | + 'strPassword_2' => 'ooo111111', |
|
| 329 | + 'strFirstName' => 'Driver', |
|
| 330 | + 'strLastName' => 'Driverson', |
|
| 331 | + 'format' => 'json', |
|
| 332 | + 'strIndustry' => 'Gifting', |
|
| 333 | + 'chkTerms' => 1, |
|
| 334 | + 'device_type' => 'web', |
|
| 335 | + 'plan' => 'free', |
|
| 336 | + ]); |
|
| 337 | + |
|
| 338 | + $member = new Member(); |
|
| 339 | + $errorText = ""; |
|
| 340 | + |
|
| 341 | + $response = $member->newAccountRegistration($registrParameters, $errorText); |
|
| 342 | + |
|
| 343 | + $this->assertNotNull($response); |
|
| 344 | + $this->assertInstanceOf(MemberResponse::class, $response); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + public function testCreateUser() |
|
| 348 | + { |
|
| 349 | + $date = new \DateTime(); |
|
| 350 | + |
|
| 351 | + $params = Member::fromArray([ |
|
| 352 | + 'HIDE_ROUTED_ADDRESSES' => 'FALSE', |
|
| 353 | + 'member_phone' => '571-259-5939', |
|
| 354 | + 'member_zipcode' => '22102', |
|
| 355 | + 'route_count' => null, |
|
| 356 | + 'member_email' => 'regression.autotests+'.$date->getTimestamp().'@gmail.com', |
|
| 357 | + 'HIDE_VISITED_ADDRESSES' => 'FALSE', |
|
| 358 | + 'READONLY_USER' => 'FALSE', |
|
| 359 | + 'member_type' => 'SUB_ACCOUNT_DRIVER', |
|
| 360 | + 'date_of_birth' => '1994-10-01', |
|
| 361 | + 'member_first_name' => 'John', |
|
| 362 | + 'member_password' => '123456', |
|
| 363 | + 'HIDE_NONFUTURE_ROUTES' => 'FALSE', |
|
| 364 | + 'member_last_name' => 'Doe', |
|
| 365 | + 'SHOW_ALL_VEHICLES' => 'FALSE', |
|
| 366 | + 'SHOW_ALL_DRIVERS' => 'FALSE', |
|
| 367 | + ]); |
|
| 368 | + |
|
| 369 | + $member = new Member(); |
|
| 370 | + |
|
| 371 | + $response = $member->createMember($params); |
|
| 372 | + |
|
| 373 | + self::assertNotNull($response); |
|
| 374 | + self::assertInstanceOf( |
|
| 375 | + MemberResponseV4::class, |
|
| 376 | + MemberResponseV4::fromArray($response) |
|
| 377 | + ); |
|
| 378 | + |
|
| 379 | + self::$createdMembers[] = MemberResponseV4::fromArray($response); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + public function testDeleteUser() |
|
| 383 | + { |
|
| 384 | + $member = new Member(); |
|
| 385 | + $errorText = ""; |
|
| 386 | + |
|
| 387 | + $memberID = self::$createdMembers[sizeof(self::$createdMembers)-1]->member_id; |
|
| 388 | + |
|
| 389 | + // Delete member from the user's account |
|
| 390 | + $params = Member::fromArray([ |
|
| 391 | + 'member_id' => $memberID, |
|
| 392 | + ]); |
|
| 393 | + |
|
| 394 | + $response = $member->deleteMember($params, $errorText); |
|
| 395 | + |
|
| 396 | + $this->assertNotNull($response, $errorText); |
|
| 397 | + $this->assertTrue(isset($response['status'])); |
|
| 398 | + $this->assertTrue($response['status']); |
|
| 399 | + |
|
| 400 | + self::$createdMembers[] = array_pop(self::$createdMembers); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + public function testGetMemberCapabilities() |
|
| 404 | + { |
|
| 405 | + $member = new Member(); |
|
| 406 | + |
|
| 407 | + $memberCapabalities = member::getMemberCapabilities(); |
|
| 408 | + |
|
| 409 | + $this->assertNotNull($memberCapabalities); |
|
| 410 | + $this->assertInstanceOf( |
|
| 411 | + MemberCapabilities::class, |
|
| 412 | + MemberCapabilities::fromArray($memberCapabalities) |
|
| 413 | + ); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + public static function tearDownAfterClass() |
|
| 417 | + { |
|
| 418 | + if (sizeof(self::$createdMembers)>0) { |
|
| 419 | + $member = new Member(); |
|
| 420 | + $errorText = ""; |
|
| 421 | + |
|
| 422 | + foreach (self::$createdMembers as $createdMember) { |
|
| 423 | + $params = Member::fromArray([ |
|
| 424 | + 'member_id' => $createdMember->member_id, |
|
| 425 | + ]); |
|
| 426 | + |
|
| 427 | + $response = $member->deleteMember($params, $errorText); |
|
| 428 | + |
|
| 429 | + if (!is_null($response) && isset($response['status']) && $response['status']) { |
|
| 430 | + echo "The member ".$createdMember->member_id." removed <br>"; |
|
| 431 | + } else { |
|
| 432 | + echo "Cannot remove the member ".$createdMember->member_id." <br>".$errorText; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | 437 | } |
| 438 | 438 | \ No newline at end of file |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | Route4Me::setApiKey(Constants::API_KEY); |
| 10 | 10 | |
| 11 | 11 | $AddressBookLocationParameters = AddressBookLocation::fromArray([ |
| 12 | - 'first_name' => 'Test FirstName '.strval(rand(10000, 99999)), |
|
| 13 | - 'address_1' => 'Test Address1 '.strval(rand(10000, 99999)), |
|
| 14 | - 'cached_lat' => 38.024654, |
|
| 15 | - 'cached_lng' => -77.338814, |
|
| 12 | + 'first_name' => 'Test FirstName '.strval(rand(10000, 99999)), |
|
| 13 | + 'address_1' => 'Test Address1 '.strval(rand(10000, 99999)), |
|
| 14 | + 'cached_lat' => 38.024654, |
|
| 15 | + 'cached_lng' => -77.338814, |
|
| 16 | 16 | ]); |
| 17 | 17 | |
| 18 | 18 | $abContacts = new AddressBookLocation(); |