Merge branch 'release/0.5.5'
This commit is contained in:
commit
e5607b8c74
6 changed files with 132 additions and 15 deletions
|
@ -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')) {
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
51
tests/Feature/MicropubClientControllerTest.php
Normal file
51
tests/Feature/MicropubClientControllerTest.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
use App\IndieWebUser;
|
||||
use IndieAuth\Client as IndieClient;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\Middleware;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class MicropubClientControllerTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_json_syntax_is_created_correctly()
|
||||
{
|
||||
$container = [];
|
||||
$history = Middleware::history($container);
|
||||
|
||||
$mock = new MockHandler([
|
||||
new Response(201, ['Location' => '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());
|
||||
}
|
||||
}
|
||||
}
|
60
tests/Feature/NoteServiceTest.php
Normal file
60
tests/Feature/NoteServiceTest.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Services\NoteService;
|
||||
use App\Jobs\SyndicateToTwitter;
|
||||
use App\Jobs\SyndicateToFacebook;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class NoteServiceTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_syndicate_to_twitter_job_is_sent()
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$noteService = new NoteService();
|
||||
$note = $noteService->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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue