Updated pages API to not clear content if not provided

Can now update page details without supplying page content.
Added test to cover.

Closes #2856
This commit is contained in:
Dan Brown 2021-08-21 18:54:38 +01:00
parent 822fea4303
commit b005acdd6c
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 23 additions and 2 deletions

View File

@ -218,8 +218,8 @@ class PageRepo
$pageContent = new PageContent($page);
if (!empty($input['markdown'] ?? '')) {
$pageContent->setNewMarkdown($input['markdown']);
} else {
$pageContent->setNewHTML($input['html'] ?? '');
} else if (isset($input['html'])) {
$pageContent->setNewHTML($input['html']);
}
}

View File

@ -219,6 +219,27 @@ class PagesApiTest extends TestCase
$resp->assertStatus(403);
}
public function test_update_endpoint_does_not_wipe_content_if_no_html_or_md_provided()
{
$this->actingAsApiEditor();
$page = Page::visible()->first();
$originalContent = $page->html;
$details = [
'name' => 'My updated API page',
'tags' => [
[
'name' => 'freshtag',
'value' => 'freshtagval',
],
],
];
$this->putJson($this->baseEndpoint . "/{$page->id}", $details);
$page->refresh();
$this->assertEquals($originalContent, $page->html);
}
public function test_delete_endpoint()
{
$this->actingAsApiEditor();