Ignore:
Timestamp:
Aug 31, 2015, 11:04:02 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
d55ec21
Parents:
69c8290
Message:

Implmented and started testing of /stations/register

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/webservice/tests/StationsTest.php

    r69c8290 r02fbeb8  
    1919*/
    2020
     21/**
     22        * @todo Reset database before this test is run
     23        */
    2124class StationsTest extends PHPUnit_Framework_TestCase
    2225{
    … …  
    5255        }
    5356       
     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
    5482        public function testRegisterStation()
    5583        {
    … …  
    6189                        [
    6290                                "base_uri" => $baseUrl,
    63                                 "timeout" => 2.0,
     91                                "timeout" => 5.0,
    6492                                "http_errors" => false,
    6593                        ]
    … …  
    6896                // sending must failing register request, caused by unproven location
    6997                $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"]]
    7199                );
    72100                $this->assertEquals($response->getStatusCode(), 200, $response->getReasonPhrase());
    73101                $json = json_decode($response->getBody(), true);
    74102                $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"]);
    86104                $this->assertTrue(array_key_exists("uuid", $json));
    87                 $this->assertEquals("success", $json["result"]);
    88105                $this->assertTrue(!empty($json["uuid"]));
    89106
     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"]);
    90112        }
    91113       
Note: See TracChangeset for help on using the changeset viewer.