diff --git a/app/Services/PlaceService.php b/app/Services/PlaceService.php index 85a27972..602e097b 100644 --- a/app/Services/PlaceService.php +++ b/app/Services/PlaceService.php @@ -25,10 +25,15 @@ class PlaceService $description = $request->input('description'); $geo = $request->input('geo'); } - $parts = explode(':', $geo); - $latlng = explode(',', $parts[1]); - $latitude = $latlng[0]; - $longitude = $latlng[1]; + if ($geo) { + preg_match_all( + '/([0-9\.\-]+)/', + $geo, + $matches + ); + $latitude = $matches[0][0]; + $longitude = $matches[0][1]; + } if ($request->input('latitude') !== null) { $latitude = $request->input('latitude'); $longitude = $request->input('longitude'); diff --git a/changelog.md b/changelog.md index c73cd982..e6a5e269 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Version {next} - Add support for accuracy/uncertainty in geo URIs (issue#20,issue#9) + - Add some places tests ## Version 0.0.13 (2016-09-26) - Better places support, particularly with micropub (issue#9) diff --git a/database/migrations/2016_09_30_214651_cascade_delete_note_tags.php b/database/migrations/2016_09_30_214651_cascade_delete_note_tags.php new file mode 100644 index 00000000..8100b161 --- /dev/null +++ b/database/migrations/2016_09_30_214651_cascade_delete_note_tags.php @@ -0,0 +1,31 @@ +dropForeign('note_tag_note_id_foreign'); + $table->foreign('note_id')->references('id')->on('notes')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/tests/MicropubClientTest.php b/tests/MicropubClientTest.php index 14a6da5a..c948e815 100644 --- a/tests/MicropubClientTest.php +++ b/tests/MicropubClientTest.php @@ -46,9 +46,6 @@ class MicropubClientTest extends TestCase ->see('https://twitter.com/jonnybarnes'); } - /** - * This currently creates a new note that stays in the database. - */ public function testClientCreatesNewNoteWithTag() { $faker = \Faker\Factory::create(); @@ -62,6 +59,11 @@ class MicropubClientTest extends TestCase $this->seeInDatabase('notes', ['note' => $note]); $this->visit($this->appurl . '/notes/tagged/PHPUnit') ->see('PHPUnit'); + //my client has made a request to my endpoint, which then adds + //to the db, so database transaction don’t work + //so lets manually delete the new entry + $newNote = \App\Note::where('note', $note); + $newNote->forceDelete(); } diff --git a/tests/MicropubTest.php b/tests/MicropubTest.php index 5462a73c..7e5830e4 100644 --- a/tests/MicropubTest.php +++ b/tests/MicropubTest.php @@ -222,6 +222,25 @@ class MicropubTest extends TestCase ]); } + public function testMicropubJSONRequestCreateNewPlaceWithUncertaintyParam() + { + $faker = \Faker\Factory::create(); + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => $faker->name, + 'geo' => 'geo:' . $faker->latitude . ',' . $faker->longitude . ';u=35' + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + )->seeJson([ + 'response' => 'created' + ])->assertResponseStatus(201); + } + private function getToken() { $signer = new Sha256();