]> BookStack Code Mirror - bookstack/blob - tests/Entity/PageTest.php
Fixed markdown content not stored on first page save
[bookstack] / tests / Entity / PageTest.php
1 <?php namespace Tests\Entity;
2
3 use BookStack\Entities\Models\Book;
4 use BookStack\Entities\Models\Page;
5 use Tests\TestCase;
6
7 class PageTest extends TestCase
8 {
9     public function test_page_creation_with_markdown_content()
10     {
11         $this->setSettings(['app-editor' => 'markdown']);
12         $book = Book::query()->first();
13
14         $this->asEditor()->get($book->getUrl('/create-page'));
15         $draft = Page::query()->where('book_id', '=', $book->id)
16             ->where('draft', '=', true)->first();
17
18         $details = [
19             'markdown' => '# a title',
20             'html' => '<h1>a title</h1>',
21             'name' => 'my page',
22         ];
23         $resp = $this->post($book->getUrl("/draft/{$draft->id}"), $details);
24         $resp->assertRedirect();
25
26         $this->assertDatabaseHas('pages', [
27             'markdown' => $details['markdown'],
28             'name' => $details['name'],
29             'id' => $draft->id,
30             'draft' => false
31         ]);
32
33         $draft->refresh();
34         $resp = $this->get($draft->getUrl("/edit"));
35         $resp->assertSee("# a title");
36     }
37
38     public function test_page_delete()
39     {
40         $page = Page::query()->first();
41         $this->assertNull($page->deleted_at);
42
43         $deleteViewReq = $this->asEditor()->get($page->getUrl('/delete'));
44         $deleteViewReq->assertSeeText('Are you sure you want to delete this page?');
45
46         $deleteReq = $this->delete($page->getUrl());
47         $deleteReq->assertRedirect($page->getParent()->getUrl());
48         $this->assertActivityExists('page_delete', $page);
49
50         $page->refresh();
51         $this->assertNotNull($page->deleted_at);
52         $this->assertTrue($page->deletions()->count() === 1);
53
54         $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
55         $redirectReq->assertNotificationContains('Page Successfully Deleted');
56     }
57 }