Changeset 02fbeb8 for src/webservice/tests/StationsTest.php
- Timestamp:
- Aug 31, 2015, 11:04:02 PM (11 years ago)
- Branches:
- master
- Children:
- d55ec21
- Parents:
- 69c8290
- File:
-
- 1 edited
-
src/webservice/tests/StationsTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/webservice/tests/StationsTest.php
r69c8290 r02fbeb8 19 19 */ 20 20 21 /** 22 * @todo Reset database before this test is run 23 */ 21 24 class StationsTest extends PHPUnit_Framework_TestCase 22 25 { … … 52 55 } 53 56 57 public function testRegisterStationUnprovenLocation() 58 { 59 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl(); 60 $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl); 61 $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl); 62 $client = new GuzzleHttp\Client 63 ( 64 [ 65 "base_uri" => $baseUrl, 66 "timeout" => 5.0, 67 "http_errors" => false, 68 ] 69 ); 70 71 // sending must failing register request, caused by unproven location 72 $response = $client->post("index.php/stations/register", 73 [ "json" => ["name" => "Cool Station", "longitude" => 23.2, "latitude" => 90, "city" => "Nice town", "email" => "test@example.org"]] 74 ); 75 $this->assertEquals($response->getStatusCode(), 200, $response->getReasonPhrase()); 76 $json = json_decode($response->getBody(), true); 77 $this->assertTrue(array_key_exists("result", $json)); 78 $this->assertTrue(array_key_exists("message", $json)); 79 $this->assertEquals("unprovenlocation", $json["result"], $json["message"]); 80 } 81 54 82 public function testRegisterStation() 55 83 { … … 61 89 [ 62 90 "base_uri" => $baseUrl, 63 "timeout" => 2.0,91 "timeout" => 5.0, 64 92 "http_errors" => false, 65 93 ] … … 68 96 // sending must failing register request, caused by unproven location 69 97 $response = $client->post("index.php/stations/register", 70 [ "json" => ["name" => " Cool Station", "longitude" => 23.2, "latitude" => 90, "city" => "Nice town"]]98 [ "json" => ["name" => "My Weather Station", "city" => "Clausthal-Zellerfeld", "longitude" => 10.28152, "latitude" => 51.8281, "email" => "test@example.org"]] 71 99 ); 72 100 $this->assertEquals($response->getStatusCode(), 200, $response->getReasonPhrase()); 73 101 $json = json_decode($response->getBody(), true); 74 102 $this->assertTrue(array_key_exists("result", $json)); 75 $this->assertTrue(array_key_exists("message", $json)); 76 $this->assertEquals("unprovenlocation", $json["result"]); 77 78 // try again with set "locationchecked" to true 79 $response = $client->post("index.php/stations/register", 80 [ "json" => ["name" => "Cool Station", "longitude" => 23.2, 81 "latitude" => 90, "city" => "Nice town", "locationchecked" => true]] 82 ); 83 $this->assertEquals($response->getStatusCode(), 200, $response->getReasonPhrase()); 84 $json = json_decode($response->getBody(), true); 85 $this->assertTrue(array_key_exists("result", $json)); 103 $this->assertEquals("success", $json["result"]); 86 104 $this->assertTrue(array_key_exists("uuid", $json)); 87 $this->assertEquals("success", $json["result"]);88 105 $this->assertTrue(!empty($json["uuid"])); 89 106 107 $stations = $this->query("stations"); 108 $this->assertInternalType("array", $stations); 109 $this->assertEquals(1, count($stations)); 110 $this->assertTrue(array_key_exists("uuid", $stations[0])); 111 $this->assertEquals($json["uuid"], $stations[0]["uuid"]); 90 112 } 91 113
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/siweather/chrome/site/your_project_logo.png)