Added test & update to prevent page creation w/ empty slug
Caused by changes to page repo in reference work, This adds back in the slug generate although at a more central place. Adds a test case to cover the problematic scenario.
This commit is contained in:
parent
f092c97748
commit
34c63e1c30
2 changed files with 29 additions and 1 deletions
|
@ -56,7 +56,7 @@ class BaseRepo
|
||||||
$entity->fill($input);
|
$entity->fill($input);
|
||||||
$entity->updated_by = user()->id;
|
$entity->updated_by = user()->id;
|
||||||
|
|
||||||
if ($entity->isDirty('name')) {
|
if ($entity->isDirty('name') || empty($entity->slug)) {
|
||||||
$entity->refreshSlug();
|
$entity->refreshSlug();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,4 +204,32 @@ class PageDraftTest extends TestCase
|
||||||
$draft->refresh();
|
$draft->refresh();
|
||||||
$this->assertStringContainsString('href="https://example.com"', $draft->html);
|
$this->assertStringContainsString('href="https://example.com"', $draft->html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_slug_generated_on_draft_publish_to_page_when_no_name_change()
|
||||||
|
{
|
||||||
|
/** @var Book $book */
|
||||||
|
$book = Book::query()->first();
|
||||||
|
$this->asEditor()->get($book->getUrl('/create-page'));
|
||||||
|
/** @var Page $draft */
|
||||||
|
$draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail();
|
||||||
|
|
||||||
|
$this->put('/ajax/page/' . $draft->id . '/save-draft', [
|
||||||
|
'name' => 'My page',
|
||||||
|
'markdown' => "Update test",
|
||||||
|
])->assertOk();
|
||||||
|
|
||||||
|
$draft->refresh();
|
||||||
|
$this->assertEmpty($draft->slug);
|
||||||
|
|
||||||
|
$this->post($draft->getUrl(), [
|
||||||
|
'name' => 'My page',
|
||||||
|
'markdown' => "# My markdown page"
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('pages', [
|
||||||
|
'id' => $draft->id,
|
||||||
|
'draft' => false,
|
||||||
|
'slug' => 'my-page',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue