<?php
/*
    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    MA 02110-1301  USA.
*/

$file = __DIR__ ."/testconfig/testconfig.php";
require($file);
require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
		
class GeoLocatorTest extends PHPUnit_Framework_TestCase
{
	public function testConfigured(){
		$this->assertTrue(\SiWeather\Webservice\GeoLocator::configured());
	}

	/**
	  * @dataProvider testLocations_data
	  */
	public function testLocations($latiude, $longitude, $radius, $results){
		$errorMessage = "";
		$locations = \SiWeather\Webservice\GeoLocator::locations($latiude, $longitude, $radius, $errorMessage);

		$this->assertInternalType("array", $locations, $errorMessage);
		$this->assertTrue(empty($errorMessage));

		$this->assertEquals(count($locations), count($results));

		for($i = 0; $i < count($locations); $i++){
			$this->assertEquals($locations[$i]->city(), $results[$i]->city());
			$this->assertEquals($locations[$i]->postalCode(), $results[$i]->postalCode());
			$this->assertEquals($locations[$i]->regionName(), $results[$i]->regionName());
			$this->assertEquals($locations[$i]->regionCode(), $results[$i]->regionCode());
			$this->assertEquals($locations[$i]->countryName(), $results[$i]->countryName());
			$this->assertEquals($locations[$i]->countryCode(), $results[$i]->countryCode());
			$this->assertEquals($locations[$i]->latitude(), $results[$i]->latitude());
			$this->assertEquals($locations[$i]->longitude(), $results[$i]->longitude());
			$this->assertEquals($locations[$i]->locationWkt(), $results[$i]->locationWkt());
			$this->assertEquals($locations[$i]->timeZone(), $results[$i]->timeZone());
		}
	}
	
	public function testLocations_data(){
		$radius = 5;
		$result = array();
		$result[] = array
		(
			51.828056,
			10.2825,
			$radius,
			array
			(
				new \SiWeather\Webservice\Location("Wildemann", "", "Niedersachsen", "06", "Deutschland", "DE", 51.8281, 10.28152, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Bad Grund", "", "Niedersachsen", "06", "Deutschland", "DE", 51.81021, 10.23694, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Zellerfeld", "", "Niedersachsen", "06", "Deutschland", "DE", 51.81846, 10.33532, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Clausthal-Zellerfeld", "", "Niedersachsen", "06", "Deutschland", "DE", 51.80949, 10.33821, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Clausthal", "", "Niedersachsen", "06", "Deutschland", "DE", 51.80441, 10.33384, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Hahnenklee-Bockswiese", "", "Niedersachsen", "06", "Deutschland", "DE", 51.85487, 10.33178, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Lautenthal", "", "Niedersachsen", "06", "Deutschland", "DE", 51.86934, 10.28741, "Europe/Berlin"),
				new \SiWeather\Webservice\Location("Laubhütte", "", "Niedersachsen", "06", "Deutschland", "DE", 51.79609, 10.23479, "Europe/Berlin"),
			)
		);
		return $result;
	}
}
?>
