From 2546a92039d7c6dd13836824b0aaabd98592dd1c Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 1 Oct 2016 14:26:07 +0100 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit fa51cd728fbb13ebadfc45d90dc24c284a31f4ae Author: Jonny Barnes Date: Sat Oct 1 14:25:50 2016 +0100 Update changelog commit 93e6a92c664cb42da679c5bb2e37cabec0e7fb99 Author: Jonny Barnes Date: Sat Oct 1 14:25:00 2016 +0100 test create new place with uncertainty parameter commit 3d793801b3c0e93228ce5c6bae83c74b130127c0 Author: Jonny Barnes Date: Sat Oct 1 14:24:35 2016 +0100 Parse correctly to take into account uncertainty parameter commit d9060332a484ff414ed4dac03fa39838d7b73b54 Author: Jonny Barnes Date: Sat Oct 1 11:11:56 2016 +0100 Better comments commit 298663cf7beaf4893d326aae880d64279ce4af37 Author: Jonny Barnes Date: Fri Sep 30 22:59:08 2016 +0100 Allow tagged notes to be deleted, didn’t know that wasn’t possible before :/ commit 7f5c65c6d858321526b7f0ac84c527dc2f09614a Author: Jonny Barnes Date: Fri Sep 30 22:57:57 2016 +0100 Better test for creating a new note via mircropub, the new note gets deleted --- app/Services/PlaceService.php | 13 +++++--- changelog.md | 1 + ..._09_30_214651_cascade_delete_note_tags.php | 31 +++++++++++++++++++ tests/MicropubClientTest.php | 8 +++-- tests/MicropubTest.php | 19 ++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 database/migrations/2016_09_30_214651_cascade_delete_note_tags.php 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();