2020-01-07 17:21:40 +01:00
|
|
|
<?php /** @noinspection HtmlUnknownAttribute */
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
2019-05-23 10:58:57 +02:00
|
|
|
|
2017-09-19 22:04:40 +02:00
|
|
|
require_once(__DIR__ . "/../lib/UloggerAPITestCase.php");
|
|
|
|
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
|
|
|
|
require_once(ROOT_DIR . "/helpers/config.php");
|
2019-02-25 10:04:09 +01:00
|
|
|
require_once(ROOT_DIR . "/helpers/lang.php");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
class ImportTest extends UloggerAPITestCase {
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportGPX10(): void {
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx10 = '<?xml version="1.0"?>
|
|
|
|
<gpx version="1.0" creator="test software"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/0"
|
2021-04-22 19:47:52 +02:00
|
|
|
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
|
2017-09-19 22:04:40 +02:00
|
|
|
<time>2017-09-19T11:00:08Z</time>
|
|
|
|
<trk>
|
|
|
|
<name>' . $this->testTrackName . '</name>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '">
|
|
|
|
<ele>' . $this->testAltitude . '</ele>
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp) . '</time>
|
|
|
|
</trkpt>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . -1 * $this->testLon . '">
|
|
|
|
<ele>' . $this->testAltitude . '</ele>
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp + 1) . '</time>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx10)
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertCount(1, $json, "Wrong count of tracks");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$track = $json[0];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => null
|
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"tracks",
|
|
|
|
"SELECT * FROM tracks"
|
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"time" => $this->testTimestamp,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon,
|
|
|
|
"altitude" => $this->testAltitude,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"positions",
|
2019-01-24 19:07:41 +01:00
|
|
|
"SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude,
|
2019-07-12 21:50:21 +02:00
|
|
|
altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
|
2017-09-19 22:04:40 +02:00
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 2,
|
|
|
|
"time" => $this->testTimestamp + 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon * -1,
|
|
|
|
"altitude" => $this->testAltitude,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportGPX11(): void {
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx11 = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
|
|
|
<gpx version="1.1"
|
|
|
|
creator="test creator"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
|
|
|
<metadata>
|
|
|
|
<name>' . $this->testTrackComment . '</name>
|
|
|
|
<desc>Track for testing ulogger</desc>
|
|
|
|
<author>
|
|
|
|
<name>Bartek Fabiszewski</name>
|
2021-04-22 19:47:52 +02:00
|
|
|
<link href="https://www.fabiszewski.net"><text>fabiszewski.net</text></link>
|
2017-09-19 22:04:40 +02:00
|
|
|
</author>
|
|
|
|
<time>2017-09-19T09:22:06Z</time>
|
|
|
|
<keywords>Test, ulogger</keywords>
|
|
|
|
<bounds minlat="44.64365345" maxlat="45.341" minlon="14.452354" maxlon="24.54234"/>
|
|
|
|
</metadata>
|
|
|
|
<trk>
|
|
|
|
<src>Crafted by Bartek Fabiszewski</src>
|
2021-04-22 19:47:52 +02:00
|
|
|
<link href="https://www.fabiszewski.net"><text>fabiszewski.net</text></link>
|
2017-09-19 22:04:40 +02:00
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '">
|
|
|
|
<ele>' . $this->testAltitude . '</ele>
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp) . '</time>
|
|
|
|
<fix>3d</fix>
|
|
|
|
<hdop>300</hdop><vdop>300</vdop><pdop>300</pdop>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx11),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertCount(1, $json, "Wrong count of tracks");
|
2020-01-07 17:21:40 +01:00
|
|
|
|
|
|
|
$track = $json[0];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => $this->testTrackComment
|
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"tracks",
|
|
|
|
"SELECT * FROM tracks"
|
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"time" => $this->testTimestamp,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon,
|
|
|
|
"altitude" => $this->testAltitude,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"positions",
|
2019-01-24 19:07:41 +01:00
|
|
|
"SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude,
|
2019-07-12 21:50:21 +02:00
|
|
|
altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
|
2017-09-19 22:04:40 +02:00
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportExtensions(): void {
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1
|
|
|
|
http://www.topografix.com/GPX/1/1/gpx.xsd
|
|
|
|
https://github.com/bfabiszewski/ulogger-android/1
|
|
|
|
https://github.com/bfabiszewski/ulogger-android/gpx_extensions1.xsd"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
xmlns:ulogger="https://github.com/bfabiszewski/ulogger-android/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<metadata>
|
|
|
|
<name>' . $this->testTrackComment . '</name>
|
|
|
|
<time>2017-06-24T22:50:45Z</time>
|
|
|
|
</metadata>
|
|
|
|
<trk>
|
|
|
|
<name>' . $this->testTrackName . '</name>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '">
|
|
|
|
<ele>' . $this->testAltitude . '</ele>
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp) . '</time>
|
|
|
|
<name>1</name>
|
2020-01-07 17:21:40 +01:00
|
|
|
<desc><![CDATA[' . $this->testComment . ']]></desc>
|
2017-09-19 22:04:40 +02:00
|
|
|
<extensions>
|
|
|
|
<ulogger:speed>' . $this->testSpeed . '</ulogger:speed>
|
|
|
|
<ulogger:bearing>' . $this->testBearing . '</ulogger:bearing>
|
|
|
|
<ulogger:accuracy>' . $this->testAccuracy . '</ulogger:accuracy>
|
|
|
|
<ulogger:provider>' . $this->testProvider . '</ulogger:provider>
|
|
|
|
</extensions>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertCount(1, $json, "Wrong count of tracks");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$track = $json[0];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => $this->testTrackComment
|
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"tracks",
|
|
|
|
"SELECT * FROM tracks"
|
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"time" => $this->testTimestamp,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon,
|
|
|
|
"altitude" => $this->testAltitude,
|
|
|
|
"speed" => $this->testSpeed,
|
|
|
|
"bearing" => $this->testBearing,
|
|
|
|
"accuracy" => $this->testAccuracy,
|
|
|
|
"provider" => $this->testProvider,
|
2020-01-07 17:21:40 +01:00
|
|
|
"comment" => $this->testComment,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"positions",
|
2019-01-24 19:07:41 +01:00
|
|
|
"SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude,
|
2019-07-12 21:50:21 +02:00
|
|
|
altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
|
2017-09-19 22:04:40 +02:00
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportNoTime(): void {
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
2021-04-22 19:47:52 +02:00
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
2017-09-19 22:04:40 +02:00
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '"></trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertCount(1, $json, "Wrong count of tracks");
|
2020-01-07 17:21:40 +01:00
|
|
|
|
|
|
|
$track = $json[0];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => null
|
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"tracks",
|
|
|
|
"SELECT * FROM tracks"
|
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
2018-11-09 15:00:52 +01:00
|
|
|
"time" => 1,
|
2017-09-19 22:04:40 +02:00
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon,
|
|
|
|
"altitude" => null,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"positions",
|
2019-01-24 19:07:41 +01:00
|
|
|
"SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude,
|
2019-07-12 21:50:21 +02:00
|
|
|
altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
|
2017-09-19 22:04:40 +02:00
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportMultipleSegments(): void {
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '">
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp) . '</time>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . ($this->testLat + 1) . '" lon="' . ($this->testLon + 1) . '">
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp + 1) . '</time>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertCount(1, $json, "Wrong count of tracks");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$track = $json[0];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => null
|
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"tracks",
|
|
|
|
"SELECT * FROM tracks"
|
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"time" => $this->testTimestamp,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon,
|
|
|
|
"altitude" => null,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"positions",
|
2019-01-24 19:07:41 +01:00
|
|
|
"SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude,
|
2019-07-12 21:50:21 +02:00
|
|
|
altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
|
2017-09-19 22:04:40 +02:00
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 2,
|
|
|
|
"time" => $this->testTimestamp + 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat + 1,
|
|
|
|
"longitude" => $this->testLon + 1,
|
|
|
|
"altitude" => null,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportMultipleTracks(): void {
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '">
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp) . '</time>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . ($this->testLat + 1) . '" lon="' . ($this->testLon + 1) . '">
|
|
|
|
<time>' . gmdate("Y-m-d\TH:i:s\Z", $this->testTimestamp + 1) . '</time>
|
|
|
|
</trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertCount(2, $json, "Wrong count of tracks");
|
2020-01-07 17:21:40 +01:00
|
|
|
|
|
|
|
$track = $json[0];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(2, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2020-01-07 17:21:40 +01:00
|
|
|
|
|
|
|
$track = $json[1];
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(1, (int) $track->id, "Wrong track id");
|
|
|
|
self::assertEquals($this->testTrackName, $track->name, "Wrong track name");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => null
|
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"tracks",
|
|
|
|
"SELECT * FROM tracks"
|
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 2,
|
|
|
|
"user_id" => 1,
|
|
|
|
"name" => $this->testTrackName,
|
|
|
|
"comment" => null
|
|
|
|
];
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 1,
|
|
|
|
"time" => $this->testTimestamp,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 1,
|
|
|
|
"latitude" => $this->testLat,
|
|
|
|
"longitude" => $this->testLon,
|
|
|
|
"altitude" => null,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$actual = $this->getConnection()->createQueryTable(
|
|
|
|
"positions",
|
2019-01-24 19:07:41 +01:00
|
|
|
"SELECT id, " . $this->unix_timestamp('time') . " AS time, user_id, track_id, latitude, longitude,
|
2019-07-12 21:50:21 +02:00
|
|
|
altitude, speed, bearing, accuracy, provider, comment, image FROM positions"
|
2017-09-19 22:04:40 +02:00
|
|
|
);
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
$expected = [
|
|
|
|
"id" => 2,
|
|
|
|
"time" => $this->testTimestamp + 1,
|
|
|
|
"user_id" => 1,
|
|
|
|
"track_id" => 2,
|
|
|
|
"latitude" => $this->testLat + 1,
|
|
|
|
"longitude" => $this->testLon + 1,
|
|
|
|
"altitude" => null,
|
|
|
|
"speed" => null,
|
|
|
|
"bearing" => null,
|
|
|
|
"accuracy" => null,
|
|
|
|
"provider" => "gps",
|
|
|
|
"comment" => null,
|
2019-07-12 21:50:21 +02:00
|
|
|
"image" => null
|
2017-09-19 22:04:40 +02:00
|
|
|
];
|
|
|
|
$this->assertTableContains($expected, $actual, "Wrong actual table data");
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportNoLongitude(): void {
|
2020-02-20 17:08:47 +01:00
|
|
|
$lang = (new uLang($this->mockConfig))->getStrings();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
2021-04-22 19:47:52 +02:00
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
2017-09-19 22:04:40 +02:00
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '"></trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertEquals(1, (int) $json->error, "Wrong error status");
|
|
|
|
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportNoLatitude(): void {
|
2020-02-20 17:08:47 +01:00
|
|
|
$lang = (new uLang($this->mockConfig))->getStrings();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
2021-04-22 19:47:52 +02:00
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
2017-09-19 22:04:40 +02:00
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lon="' . $this->testLon . '"></trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>
|
|
|
|
</gpx>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertEquals(1, (int) $json->error, "Wrong error status");
|
|
|
|
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportNoGPX(): void {
|
2020-02-20 17:08:47 +01:00
|
|
|
$lang = (new uLang($this->mockConfig))->getStrings();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lat="' . $this->testLat . '" lon="' . $this->testLon . '"></trkpt>
|
|
|
|
</trkseg>
|
|
|
|
</trk>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertEquals(1, (int) $json->error, "Wrong error status");
|
|
|
|
self::assertEquals($lang["iparsefailure"], (string) $json->message, "Wrong error status");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
/**
|
|
|
|
* @throws GuzzleException
|
|
|
|
*/
|
|
|
|
public function testImportCorrupt(): void {
|
2020-02-20 17:08:47 +01:00
|
|
|
$lang = (new uLang($this->mockConfig))->getStrings();
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertTrue($this->authenticate(), "Authentication failed");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
|
|
|
$gpx = '<?xml version="1.0" encoding="UTF-8"?>
|
2021-04-22 19:47:52 +02:00
|
|
|
<gpx xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
|
2017-09-19 22:04:40 +02:00
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
xmlns="http://www.topografix.com/GPX/1/1"
|
|
|
|
creator="μlogger" version="1.1">
|
|
|
|
<trk>
|
|
|
|
<trkseg>
|
|
|
|
<trkpt lon="' . $this->testLon . '"></trkpt>
|
|
|
|
</trkseg>';
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
"http_errors" => false,
|
|
|
|
"multipart" => [
|
|
|
|
[
|
|
|
|
"name" => "gpx",
|
|
|
|
"contents" => $this->getStream($gpx),
|
|
|
|
"filename" => $this->testTrackName
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"contents" => 300000
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$response = $this->http->post("/utils/import.php", $options);
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(200, $response->getStatusCode(), "Unexpected status code");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2020-01-07 17:21:40 +01:00
|
|
|
$json = json_decode($response->getBody());
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertNotNull($json, "JSON object is null");
|
|
|
|
self::assertEquals(1, (int) $json->error, "Wrong error status");
|
|
|
|
self::assertEquals(0, strpos((string) $json->message, $lang["iparsefailure"]), "Wrong error status");
|
2017-09-19 22:04:40 +02:00
|
|
|
|
2021-04-22 19:47:52 +02:00
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
|
|
|
self::assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count");
|
2017-09-19 22:04:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getStream($string) {
|
|
|
|
$stream = tmpfile();
|
|
|
|
fwrite($stream, $string);
|
|
|
|
fseek($stream, 0);
|
|
|
|
return $stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|