1 <?php namespace Tests\Entity;
3 use BookStack\Entities\Models\Page;
6 class PageTemplateTest extends TestCase
8 public function test_active_templates_visible_on_page_view()
10 $page = Page::first();
13 $templateView = $this->get($page->getUrl());
14 $templateView->assertDontSee('Page Template');
16 $page->template = true;
19 $templateView = $this->get($page->getUrl());
20 $templateView->assertSee('Page Template');
23 public function test_manage_templates_permission_required_to_change_page_template_status()
25 $page = Page::first();
26 $editor = $this->getEditor();
27 $this->actingAs($editor);
30 'name' => $page->name,
31 'html' => $page->html,
35 $this->put($page->getUrl(), $pageUpdateData);
36 $this->assertDatabaseHas('pages', [
41 $this->giveUserPermissions($editor, ['templates-manage']);
43 $this->put($page->getUrl(), $pageUpdateData);
44 $this->assertDatabaseHas('pages', [
50 public function test_templates_content_should_be_fetchable_only_if_page_marked_as_template()
52 $content = '<div>my_custom_template_content</div>';
53 $page = Page::first();
54 $editor = $this->getEditor();
55 $this->actingAs($editor);
57 $templateFetch = $this->get('/templates/' . $page->id);
58 $templateFetch->assertStatus(404);
60 $page->html = $content;
61 $page->template = true;
64 $templateFetch = $this->get('/templates/' . $page->id);
65 $templateFetch->assertStatus(200);
66 $templateFetch->assertJson([
72 public function test_template_endpoint_returns_paginated_list_of_templates()
74 $editor = $this->getEditor();
75 $this->actingAs($editor);
77 $toBeTemplates = Page::query()->orderBy('name', 'asc')->take(12)->get();
78 $page = $toBeTemplates->first();
80 $emptyTemplatesFetch = $this->get('/templates');
81 $emptyTemplatesFetch->assertDontSee($page->name);
83 Page::query()->whereIn('id', $toBeTemplates->pluck('id')->toArray())->update(['template' => true]);
85 $templatesFetch = $this->get('/templates');
86 $templatesFetch->assertSee($page->name);
87 $templatesFetch->assertSee('pagination');