source: src/webapp/webservice/tests/TrackItemTest.php@ f04997d

debian/bullseye
Last change on this file since f04997d was 0662b2d, checked in by Joachim Langenbach <joachim.langenbach@…>, 9 years ago

Improved webservice class to use TrackItem in ServiceData.php and added some tests

  • Property mode set to 100644
File size: 2.8 KB
Line 
1<?php
2/*
3 Copyright (C) 2017 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19// enable in php 7
20// declare(Strict_types=1);
21
22/**
23 * @brief Covers Service.php tests
24 */
25final class TrackItemTest extends \PHPUnit_Framework_TestCase
26{
27 public function testConstructor()
28 {
29 $item = new GnuBoat\TrackItem();
30 $this->assertEquals(false, $item->isValid());
31 $this->assertNull($item->timestamp());
32 $this->assertNull($item->latitude());
33 $this->assertNull($item->longitude());
34
35 $item = new GnuBoat\TrackItem(1, 2, 3);
36 $this->assertEquals(true, $item->isValid());
37 $this->assertEquals(1, $item->timestamp());
38 $this->assertEquals(2, $item->latitude());
39 $this->assertEquals(3, $item->longitude());
40 }
41
42 /**
43 * @dataProvider propertiesProvider
44 */
45 public function testProperties($property, $value, $result)
46 {
47 $item = new GnuBoat\TrackItem();
48 $this->assertNull($item->getProperty($property), "Not set property ". $property ." is not null");
49 $this->assertEquals($result, $item->setProperty($property, $value), "Could not set property ". $property);
50 if($result)
51 $this->assertEquals($value, $item->getProperty($property));
52 else
53 $this->assertNull($item->getProperty($property));
54 }
55
56 public function propertiesProvider()
57 {
58 return [
59 ["asdasd", "bla", false],
60 ["TIME", time(), true],
61 ["time", time(), true],
62 ["time", "abc", false],
63 ["latitude", 12.1, true],
64 ["latitude", "abc", false],
65 ["speedthroughwater", 12.1, true],
66 ["speedthroughwater", "abc", false],
67 ["courseoverground", 12.1, true],
68 ["courseoverground", "abc", false],
69 ["waterdepth", 12.1, true],
70 ["waterdepth", "abc", false],
71 ["watertemperature", 12.1, true],
72 ["watertemperature", "abc", false],
73 ["gpsfix", 12.1, true],
74 ["gpsfix", "abc", false],
75 ];
76 }
77
78 public function testDateTime()
79 {
80 $item = new GnuBoat\TrackItem();
81 $this->assertNull($item->timestamp());
82 $dateTime = new DateTime();
83 $this->assertEquals(true, $item->setDateTime($dateTime));
84 $this->assertEquals($dateTime->getTimestamp(), $item->timestamp());
85 $this->assertEquals(true, $item->setDateTime(null));
86 $this->assertNull($item->timestamp());
87 }
88}
89
90?>
Note: See TracBrowser for help on using the repository browser.