Merge pull request '[MTM] Fix relative Location header when Micropub creates an article' (#135) from develop into main

Reviewed-on: #135
This commit is contained in:
Jonny Barnes 2026-09-13 13:21:04 +02:00
commit 72ddfe739d
4 changed files with 21 additions and 1 deletions

View file

@ -93,6 +93,13 @@ class Article extends Model
);
}
protected function uri(): Attribute
{
return Attribute::get(
get: fn () => config('app.url').$this->link,
);
}
/**
* Scope a query to only include articles from a particular year/month.
*/

View file

@ -37,7 +37,7 @@ class EntryHandler implements MicropubHandlerInterface
$location = match (true) {
isset($dataArray['like-of']) => resolve(LikeService::class)->create($dataArray)->url,
isset($dataArray['bookmark-of']) => resolve(BookmarkService::class)->create($dataArray)->uri,
isset($dataArray['name']) => resolve(ArticleService::class)->create($dataArray)->link,
isset($dataArray['name']) => resolve(ArticleService::class)->create($dataArray)->uri,
default => resolve(NoteService::class)->create($dataArray)->uri,
};

View file

@ -871,6 +871,8 @@ class MicropubControllerTest extends TestCase
'main' => $content,
'published' => true,
]);
$response->assertHeader('Location');
$this->assertStringStartsWith(config('app.url').'/blog/', $response->headers->get('Location'));
}
#[Test]

View file

@ -63,6 +63,17 @@ class ArticlesTest extends TestCase
);
}
#[Test]
public function uri_is_the_absolute_form_of_the_link(): void
{
$article = Article::create([
'title' => 'Test',
'main' => 'Test',
]);
$this->assertEquals(config('app.url').$article->link, $article->uri);
}
#[Test]
public function date_scope_returns_expected_articles(): void
{