BookStack/tests/Entity/PageEditorTest.php
Dan Brown f139cded78
Laravel 8 shift squash & merge (#3029)
* Temporarily moved back config path
* Apply Laravel coding style
* Shift exception handler
* Shift HTTP kernel and middleware
* Shift service providers
* Convert options array to fluent methods
* Shift to class based routes
* Shift console routes
* Ignore temporary framework files
* Shift to class based factories
* Namespace seeders
* Shift PSR-4 autoloading
* Shift config files
* Default config files
* Shift Laravel dependencies
* Shift return type of base TestCase methods
* Shift cleanup
* Applied stylci style changes
* Reverted config files location
* Applied manual changes to Laravel 8 shift

Co-authored-by: Shift <shift@laravelshift.com>
2021-10-30 21:29:59 +01:00

78 lines
2.3 KiB
PHP

<?php
namespace Tests\Entity;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Page;
use Tests\TestCase;
class PageEditorTest extends TestCase
{
/** @var Page */
protected $page;
protected function setUp(): void
{
parent::setUp();
$this->page = Page::query()->first();
}
public function test_default_editor_is_wysiwyg()
{
$this->assertEquals('wysiwyg', setting('app-editor'));
$this->asAdmin()->get($this->page->getUrl() . '/edit')
->assertElementExists('#html-editor');
}
public function test_markdown_setting_shows_markdown_editor()
{
$this->setSettings(['app-editor' => 'markdown']);
$this->asAdmin()->get($this->page->getUrl() . '/edit')
->assertElementNotExists('#html-editor')
->assertElementExists('#markdown-editor');
}
public function test_markdown_content_given_to_editor()
{
$this->setSettings(['app-editor' => 'markdown']);
$mdContent = '# hello. This is a test';
$this->page->markdown = $mdContent;
$this->page->save();
$this->asAdmin()->get($this->page->getUrl() . '/edit')
->assertElementContains('[name="markdown"]', $mdContent);
}
public function test_html_content_given_to_editor_if_no_markdown()
{
$this->setSettings(['app-editor' => 'markdown']);
$this->asAdmin()->get($this->page->getUrl() . '/edit')
->assertElementContains('[name="markdown"]', $this->page->html);
}
public function test_empty_markdown_still_saves_without_error()
{
$this->setSettings(['app-editor' => 'markdown']);
/** @var Book $book */
$book = Book::query()->first();
$this->asEditor()->get($book->getUrl('/create-page'));
$draft = Page::query()->where('book_id', '=', $book->id)
->where('draft', '=', true)->first();
$details = [
'name' => 'my page',
'markdown' => '',
];
$resp = $this->post($book->getUrl("/draft/{$draft->id}"), $details);
$resp->assertRedirect();
$this->assertDatabaseHas('pages', [
'markdown' => $details['markdown'],
'id' => $draft->id,
'draft' => false,
]);
}
}