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

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

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

//  enable in php 7
declare(Strict_types=1);
use PHPUnit\Framework\TestCase;

/**
  * @brief Covers Service.php tests
  */
final class TrackItemTest extends \PHPUnit\Framework\TestCase
{
	public function testConstructor()
	{
		$item = new GnuBoat\TrackItem();
		$this->assertEquals(false, $item->isValid());
		$this->assertNull($item->timestamp());
		$this->assertNull($item->latitude());
		$this->assertNull($item->longitude());
		
		$item = new GnuBoat\TrackItem(1, 2, 3);
		$this->assertEquals(true, $item->isValid());
		$this->assertEquals(1, $item->timestamp());
		$this->assertEquals(2, $item->latitude());
		$this->assertEquals(3, $item->longitude());
	}

	/**
	 * @dataProvider propertiesProvider
	 */
	public function testProperties($property, $value, $result)
	{
		$item = new GnuBoat\TrackItem();
		$this->assertNull($item->getProperty($property), "Not set property ". $property ." is not null");
		$this->assertEquals($result, $item->setProperty($property, $value), "Could not set property ". $property);
		if($result)
			$this->assertEquals($value, $item->getProperty($property));
		else
			$this->assertNull($item->getProperty($property));
	}
	
	public function propertiesProvider()
	{
		return [
			["asdasd", "bla", false],
			["TIME", time(), true],
			["time", time(), true],
			["time", "abc", false],
			["latitude", 12.1, true],
			["latitude", "abc", false],
			["speedthroughwater", 12.1, true],
			["speedthroughwater", "abc", false],
			["courseoverground", 12.1, true],
			["courseoverground", "abc", false],
			["waterdepth", 12.1, true],
			["waterdepth", "abc", false],
			["watertemperature", 12.1, true],
			["watertemperature", "abc", false],
			["gpsfix", 12.1, true],
			["gpsfix", "abc", false],
		];
	}
	
	public function testDateTime()
	{
		$item = new GnuBoat\TrackItem();
		$this->assertNull($item->timestamp());
		$dateTime = new DateTime();
		$this->assertEquals(true, $item->setDateTime($dateTime));
		$this->assertEquals($dateTime->getTimestamp(), $item->timestamp());
		$this->assertEquals(true, $item->setDateTime(null));
		$this->assertNull($item->timestamp());
	}
}

?>
