diff --git a/app/Http/Controllers/MicropubClientController.php b/app/Http/Controllers/MicropubClientController.php index 9d6f8d6d..91d4eb5a 100644 --- a/app/Http/Controllers/MicropubClientController.php +++ b/app/Http/Controllers/MicropubClientController.php @@ -206,16 +206,16 @@ class MicropubClientController extends Controller $json['properties'] = ['content' => [$request->input('content')]]; if ($request->input('in-reply-to') != '') { - $json['properties']['in-reply-to'] = [$request->input('in-reply-to')]; + $json['properties']['in-reply-to'][] = $request->input('in-reply-to'); } if ($request->input('mp-syndicate-to')) { foreach ($request->input('mp-syndicate-to') as $syn) { - $json['properties']['mp-syndicate-to'] = [$syn]; + $json['properties']['mp-syndicate-to'][] = $syn; } } if ($request->input('location')) { if ($request->input('location') !== 'no-location') { - $json['properties']['location'] = [$request->input('location')]; + $json['properties']['location'][] = $request->input('location'); } } if ($request->input('media')) { diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index 2aba67cc..4d3f9f8e 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -98,7 +98,7 @@ class MicropubController extends Controller $data['syndicate'] = []; $targets = array_pluck(config('syndication.targets'), 'uid', 'service.name'); if (is_string($request->input('mp-syndicate-to'))) { - $service = array_search($request->input('mp-syndicate-to')); + $service = array_search($request->input('mp-syndicate-to'), $targets); if ($service == 'Twitter') { $data['syndicate'][] = 'twitter'; } diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 09dbb1c9..83cc7f2d 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -76,18 +76,20 @@ class NoteService } */ //add support for media uploaded as URLs - foreach ($data['photo'] as $photo) { - // check the media was uploaded to my endpoint, and use path - if (starts_with($photo, config('filesystems.disks.s3.url'))) { - $path = substr($photo, strlen(config('filesystems.disks.s3.url'))); - $media = Media::where('path', ltrim($path, '/'))->firstOrFail(); - } else { - $media = Media::firstOrNew(['path' => $photo]); - // currently assuming this is a photo from Swarm - $media->type = 'image'; - $media->save(); + if (array_key_exists('photo', $data)) { + foreach ($data['photo'] as $photo) { + // check the media was uploaded to my endpoint, and use path + if (starts_with($photo, config('filesystems.disks.s3.url'))) { + $path = substr($photo, strlen(config('filesystems.disks.s3.url'))); + $media = Media::where('path', ltrim($path, '/'))->firstOrFail(); + } else { + $media = Media::firstOrNew(['path' => $photo]); + // currently assuming this is a photo from Swarm + $media->type = 'image'; + $media->save(); + } + $note->media()->save($media); } - $note->media()->save($media); } $note->save(); diff --git a/changelog.md b/changelog.md index 6a0ddbcf..f2f300c1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## Version 0.5.5 (2017-05-19) + - improve test suite + - Syndication should now work + ## Version 0.5.4 (2017-05-18) - Fix issues with using the indieauth client diff --git a/tests/Feature/MicropubClientControllerTest.php b/tests/Feature/MicropubClientControllerTest.php new file mode 100644 index 00000000..19d0b407 --- /dev/null +++ b/tests/Feature/MicropubClientControllerTest.php @@ -0,0 +1,51 @@ + 'http://example.org/a'], 'Created'), + ]); + + $stack = HandlerStack::create($mock); + $stack->push($history); + $guzzleClient = new GuzzleClient(['handler' => $stack]); + + $this->app->instance(GuzzleClient::class, $guzzleClient); + + $response = $this->post( + '/micropub', + [ + 'content' => 'Hello Fred', + 'in-reply-to' => 'https://fredbloggs.com/note/abc', + 'mp-syndicate-to' => ['https://twitter.com/jonnybarnes', 'https://facebook.com/jonnybarnes'], + ] + ); + + $expected = '{"type":["h-entry"],"properties":{"content":["Hello Fred"],"in-reply-to":["https:\/\/fredbloggs.com\/note\/abc"],"mp-syndicate-to":["https:\/\/twitter.com\/jonnybarnes","https:\/\/facebook.com\/jonnybarnes"]}}'; + foreach ($container as $transaction) { + $this->assertEquals($expected, $transaction['request']->getBody()->getContents()); + } + } +} diff --git a/tests/Feature/NoteServiceTest.php b/tests/Feature/NoteServiceTest.php new file mode 100644 index 00000000..a7b44db1 --- /dev/null +++ b/tests/Feature/NoteServiceTest.php @@ -0,0 +1,60 @@ +createNote([ + 'content' => 'Hello Fred', + 'in-reply-to' => 'https://fredbloggs.com/note/abc', + 'syndicate' => ['twitter'], + ]); + + Queue::assertPushed(SyndicateToTwitter::class); + } + + public function test_syndicate_to_facebook_job_is_sent() + { + Queue::fake(); + + $noteService = new NoteService(); + $note = $noteService->createNote([ + 'content' => 'Hello Fred', + 'in-reply-to' => 'https://fredbloggs.com/note/abc', + 'syndicate' => ['facebook'], + ]); + + Queue::assertPushed(SyndicateToFacebook::class); + } + + public function test_syndicate_to_target_jobs_are_sent() + { + Queue::fake(); + + $noteService = new NoteService(); + $note = $noteService->createNote([ + 'content' => 'Hello Fred', + 'in-reply-to' => 'https://fredbloggs.com/note/abc', + 'syndicate' => ['twitter', 'facebook'], + ]); + + Queue::assertPushed(SyndicateToTwitter::class); + Queue::assertPushed(SyndicateToFacebook::class); + } +}