assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx10 = ' ' . $this->testTrackName . ' ' . $this->testAltitude . ' ' . $this->testAltitude . ' '; $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(0, (int) $xml->error, "Wrong error status"); $this->assertEquals(1, (int) $xml->trackid, "Wrong error message"); $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message"); $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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, "image_id" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, UNIX_TIMESTAMP(time) AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id FROM positions" ); $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, "image_id" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportGPX11() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx11 = ' ' . $this->testTrackComment . ' Track for testing ulogger Bartek Fabiszewski fabiszewski.net Test, ulogger Crafted by Bartek Fabiszewski fabiszewski.net ' . $this->testAltitude . ' 3d 300300300 '; $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(0, (int) $xml->error, "Wrong error status"); $this->assertEquals(1, (int) $xml->trackid, "Wrong error message"); $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message"); $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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, "image_id" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, UNIX_TIMESTAMP(time) AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportExtensions() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $gpx = ' ' . $this->testTrackComment . ' ' . $this->testTrackName . ' ' . $this->testAltitude . ' 1 ' . $this->testSpeed . ' ' . $this->testBearing . ' ' . $this->testAccuracy . ' ' . $this->testProvider . ' '; $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(0, (int) $xml->error, "Wrong error status"); $this->assertEquals(1, (int) $xml->trackid, "Wrong error message"); $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message"); $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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, "comment" => null, "image_id" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, UNIX_TIMESTAMP(time) AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportNoTime() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(0, (int) $xml->error, "Wrong error status"); $this->assertEquals(1, (int) $xml->trackid, "Wrong error message"); $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message"); $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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" => 0, "user_id" => 1, "track_id" => 1, "latitude" => $this->testLat, "longitude" => $this->testLon, "altitude" => null, "speed" => null, "bearing" => null, "accuracy" => null, "provider" => "gps", "comment" => null, "image_id" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, UNIX_TIMESTAMP(time) AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id FROM positions" ); $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportMultipleSegments() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(0, (int) $xml->error, "Wrong error status: $xml->message"); $this->assertEquals(1, (int) $xml->trackid, "Wrong error message"); $this->assertEquals(1, (int) $xml->trackcnt, "Wrong error message"); $this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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, "image_id" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, UNIX_TIMESTAMP(time) AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id FROM positions" ); $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, "image_id" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportMultipleTracks() { $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(0, (int) $xml->error, "Wrong error status: $xml->message"); $this->assertEquals(2, (int) $xml->trackid, "Wrong error message"); $this->assertEquals(2, (int) $xml->trackcnt, "Wrong error message"); $this->assertEquals(2, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(2, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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, "image_id" => null ]; $actual = $this->getConnection()->createQueryTable( "positions", "SELECT id, UNIX_TIMESTAMP(time) AS time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id FROM positions" ); $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, "image_id" => null ]; $this->assertTableContains($expected, $actual, "Wrong actual table data"); } public function testImportNoLongitude() { global $lang; $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(1, (int) $xml->error, "Wrong error status"); $this->assertEquals($lang["iparsefailure"], (string) $xml->message, "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } public function testImportNoLatitude() { global $lang; $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(1, (int) $xml->error, "Wrong error status"); $this->assertEquals($lang["iparsefailure"], (string) $xml->message, "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } public function testImportNoGPX() { global $lang; $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(1, (int) $xml->error, "Wrong error status"); $this->assertEquals($lang["iparsefailure"], (string) $xml->message, "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } public function testImportCorrupt() { global $lang; $this->assertTrue($this->authenticate(), "Authentication failed"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); $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); $this->assertEquals(200, $response->getStatusCode(), "Unexpected status code"); $xml = $this->getXMLfromResponse($response); $this->assertTrue($xml !== false, "XML object is false"); $this->assertEquals(1, (int) $xml->error, "Wrong error status"); $this->assertEquals(0, strpos((string) $xml->message, $lang["iparsefailure"]), "Wrong error status"); $this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count"); $this->assertEquals(0, $this->getConnection()->getRowCount("positions"), "Wrong row count"); } private function getXMLfromResponse($response) { $xml = false; libxml_use_internal_errors(true); try { $xml = new SimpleXMLElement((string) $response->getBody()); } catch (Exception $e) { /* ignore */ } return $xml; } private function getStream($string) { $stream = tmpfile(); fwrite($stream, $string); fseek($stream, 0); return $stream; } } ?>