| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | $file = __DIR__ ."/testconfig/testconfig.php";
|
|---|
| 22 | require($file);
|
|---|
| 23 | require($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
|
|---|
| 24 |
|
|---|
| 25 | class LocationTest extends PHPUnit_Framework_TestCase
|
|---|
| 26 | {
|
|---|
| 27 | public function testCity(){
|
|---|
| 28 | $location = new \SiWeather\Webservice\Location("", "");
|
|---|
| 29 |
|
|---|
| 30 | $value = "testCity";
|
|---|
| 31 | $location->setCity($value);
|
|---|
| 32 | $this->assertEquals($location->city(), $value);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | public function testPostalCode(){
|
|---|
| 36 | $location = new \SiWeather\Webservice\Location("", "");
|
|---|
| 37 |
|
|---|
| 38 | $value = "12345";
|
|---|
| 39 | $location->setPostalCode($value);
|
|---|
| 40 | $this->assertEquals($location->postalCode(), $value);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public function testRegion(){
|
|---|
| 44 | $location = new \SiWeather\Webservice\Location("", "");
|
|---|
| 45 |
|
|---|
| 46 | $value1 = "Wallhall";
|
|---|
| 47 | $value2 = "WH";
|
|---|
| 48 | $location->setRegion($value1, $value2);
|
|---|
| 49 | $this->assertEquals($location->regionName(), $value1);
|
|---|
| 50 | $this->assertEquals($location->regionCode(), $value2);
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | public function testCountry(){
|
|---|
| 54 | $location = new \SiWeather\Webservice\Location("", "");
|
|---|
| 55 |
|
|---|
| 56 | $value1 = "Wallhall";
|
|---|
| 57 | $value2 = "WH";
|
|---|
| 58 | $location->setCountry($value1, $value2);
|
|---|
| 59 | $this->assertEquals($location->countryName(), $value1);
|
|---|
| 60 | $this->assertEquals($location->countryCode(), $value2);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | public function testValidLatitude_data(){
|
|---|
| 64 | $result = array();
|
|---|
| 65 | $result[] = array(null, false);
|
|---|
| 66 | $result[] = array("asdasd", false);
|
|---|
| 67 | $result[] = array(0, true);
|
|---|
| 68 | $result[] = array(-90, true);
|
|---|
| 69 | $result[] = array(90, true);
|
|---|
| 70 | $result[] = array(85.1234, true);
|
|---|
| 71 | $result[] = array(-90.0001, false);
|
|---|
| 72 | $result[] = array(90.0001, false);
|
|---|
| 73 | return $result;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * @dataProvider testValidLatitude_data
|
|---|
| 78 | */
|
|---|
| 79 | public function testValidLatitude($latitude, $result){
|
|---|
| 80 | $this->assertEquals(\SiWeather\Webservice\Location::validLatitude($latitude), $result);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | public function testValidLongitude_data(){
|
|---|
| 84 | $result = array();
|
|---|
| 85 | $result[] = array(null, false);
|
|---|
| 86 | $result[] = array("asdasd", false);
|
|---|
| 87 | $result[] = array(0, true);
|
|---|
| 88 | $result[] = array(-90, true);
|
|---|
| 89 | $result[] = array(90, true);
|
|---|
| 90 | $result[] = array(85.1234, true);
|
|---|
| 91 | $result[] = array(-180.0001, false);
|
|---|
| 92 | $result[] = array(180.0001, false);
|
|---|
| 93 | return $result;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /**
|
|---|
| 97 | * @dataProvider testValidLongitude_data
|
|---|
| 98 | */
|
|---|
| 99 | public function testValidLongitude($longitude, $result){
|
|---|
| 100 | $this->assertEquals(\SiWeather\Webservice\Location::validLongitude($longitude), $result);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | public function testLocation(){
|
|---|
| 104 | $location = new \SiWeather\Webservice\Location("", "");
|
|---|
| 105 |
|
|---|
| 106 | $latitude = -59.0;
|
|---|
| 107 | $longitude = 33;
|
|---|
| 108 | $location->setLocation($latitude, $longitude);
|
|---|
| 109 | $this->assertEquals($location->latitude(), $latitude);
|
|---|
| 110 | $this->assertEquals($location->longitude(), $longitude);
|
|---|
| 111 | $this->assertEquals($location->locationWKT(), $longitude ." ". $latitude);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | public function testTimeZone(){
|
|---|
| 115 | $location = new \SiWeather\Webservice\Location("", "");
|
|---|
| 116 |
|
|---|
| 117 | $value = "Europe/Berlin";
|
|---|
| 118 | $location->setTimeZone($value);
|
|---|
| 119 | $this->assertEquals($location->timeZone(), $value);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | public function constructor(){
|
|---|
| 123 | $city = "Nice Place";
|
|---|
| 124 | $postalCode = "0001";
|
|---|
| 125 | $regionName = "Nice Region";
|
|---|
| 126 | $regionCode = "NR";
|
|---|
| 127 | $countryName = "Nice Country";
|
|---|
| 128 | $countryCode = "NC";
|
|---|
| 129 | $longitude = 50;
|
|---|
| 130 | $latitude = 20;
|
|---|
| 131 | $location = new \SiWeather\Webservice\Location($city, $postalCode, $regionName,
|
|---|
| 132 | $regionCode, $countryName, $countryCode,
|
|---|
| 133 | $latitude, $longitude);
|
|---|
| 134 |
|
|---|
| 135 | $this->assertEquals($location->city(), $city);
|
|---|
| 136 | $this->assertEquals($location->postalCode(), $postalCode);
|
|---|
| 137 | $this->assertEquals($location->regionName(), $regionName);
|
|---|
| 138 | $this->assertEquals($location->regionCode(), $regionCode);
|
|---|
| 139 | $this->assertEquals($location->countryName(), $countryName);
|
|---|
| 140 | $this->assertEquals($location->countryCode(), $countryCode);
|
|---|
| 141 | $this->assertEquals($location->latitude(), $latitude);
|
|---|
| 142 | $this->assertEquals($location->longitude(), $longitude);
|
|---|
| 143 | $this->assertEquals($location->locationWkt(), $longitude ." ". $latitude);
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 | ?>
|
|---|