Respect Micropub post-status when creating articles #124
3 changed files with 37 additions and 1 deletions
|
|
@ -13,7 +13,7 @@ class ArticleService
|
||||||
return Article::create([
|
return Article::create([
|
||||||
'title' => $data['name'],
|
'title' => $data['name'],
|
||||||
'main' => $data['content'],
|
'main' => $data['content'],
|
||||||
'published' => true,
|
'published' => ($data['post-status'] ?? null) !== 'draft',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ class EntryData extends MicropubData
|
||||||
public readonly mixed $checkin,
|
public readonly mixed $checkin,
|
||||||
public readonly mixed $syndication,
|
public readonly mixed $syndication,
|
||||||
public readonly ?array $photos,
|
public readonly ?array $photos,
|
||||||
|
public readonly ?string $postStatus,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public static function fromRequest(Request $request): static
|
public static function fromRequest(Request $request): static
|
||||||
|
|
@ -49,6 +50,7 @@ class EntryData extends MicropubData
|
||||||
checkin: Arr::get($data, 'properties.checkin.0'),
|
checkin: Arr::get($data, 'properties.checkin.0'),
|
||||||
syndication: Arr::get($data, 'properties.syndication.0'),
|
syndication: Arr::get($data, 'properties.syndication.0'),
|
||||||
photos: Arr::get($data, 'properties.photo'),
|
photos: Arr::get($data, 'properties.photo'),
|
||||||
|
postStatus: Arr::get($data, 'properties.post-status.0'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,6 +69,7 @@ class EntryData extends MicropubData
|
||||||
checkin: $request->input('checkin'),
|
checkin: $request->input('checkin'),
|
||||||
syndication: $request->input('syndication'),
|
syndication: $request->input('syndication'),
|
||||||
photos: $request->input('photos'),
|
photos: $request->input('photos'),
|
||||||
|
postStatus: $request->input('post-status'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,6 +103,7 @@ class EntryData extends MicropubData
|
||||||
checkin: $data['checkin'] ?? null,
|
checkin: $data['checkin'] ?? null,
|
||||||
syndication: $data['syndication'] ?? null,
|
syndication: $data['syndication'] ?? null,
|
||||||
photos: $data['photos'] ?? null,
|
photos: $data['photos'] ?? null,
|
||||||
|
postStatus: $data['post-status'] ?? null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,6 +124,7 @@ class EntryData extends MicropubData
|
||||||
'checkin' => $this->checkin,
|
'checkin' => $this->checkin,
|
||||||
'syndication' => $this->syndication,
|
'syndication' => $this->syndication,
|
||||||
'photos' => $this->photos,
|
'photos' => $this->photos,
|
||||||
|
'post-status' => $this->postStatus,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -869,6 +869,37 @@ class MicropubControllerTest extends TestCase
|
||||||
$this->assertDatabaseHas('articles', [
|
$this->assertDatabaseHas('articles', [
|
||||||
'title' => $name,
|
'title' => $name,
|
||||||
'main' => $content,
|
'main' => $content,
|
||||||
|
'published' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Test]
|
||||||
|
public function micropub_client_api_request_creates_an_unpublished_article_when_post_status_is_draft(): void
|
||||||
|
{
|
||||||
|
$faker = Factory::create();
|
||||||
|
$name = $faker->text(50);
|
||||||
|
$content = $faker->paragraphs(5, true);
|
||||||
|
|
||||||
|
$response = $this->postJson(
|
||||||
|
'/api/post',
|
||||||
|
[
|
||||||
|
'type' => ['h-entry'],
|
||||||
|
'properties' => [
|
||||||
|
'name' => [$name],
|
||||||
|
'content' => [$content],
|
||||||
|
'post-status' => ['draft'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
['HTTP_Authorization' => 'Bearer '.$this->getToken()]
|
||||||
|
);
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertJson(['response' => 'created'])
|
||||||
|
->assertStatus(201);
|
||||||
|
$this->assertDatabaseHas('articles', [
|
||||||
|
'title' => $name,
|
||||||
|
'main' => $content,
|
||||||
|
'published' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue