3 namespace Tests\Entity;
5 use BookStack\Entities\Models\Page;
8 class PageTemplateTest extends TestCase
10 public function test_active_templates_visible_on_page_view()
12 $page = $this->entities->page();
15 $templateView = $this->get($page->getUrl());
16 $templateView->assertDontSee('Page Template');
18 $page->template = true;
21 $templateView = $this->get($page->getUrl());
22 $templateView->assertSee('Page Template');
25 public function test_manage_templates_permission_required_to_change_page_template_status()
27 $page = $this->entities->page();
28 $editor = $this->users->editor();
29 $this->actingAs($editor);
32 'name' => $page->name,
33 'html' => $page->html,
37 $this->put($page->getUrl(), $pageUpdateData);
38 $this->assertDatabaseHas('pages', [
43 $this->permissions->grantUserRolePermissions($editor, ['templates-manage']);
45 $this->put($page->getUrl(), $pageUpdateData);
46 $this->assertDatabaseHas('pages', [
52 public function test_templates_content_should_be_fetchable_only_if_page_marked_as_template()
54 $content = '<div>my_custom_template_content</div>';
55 $page = $this->entities->page();
56 $editor = $this->users->editor();
57 $this->actingAs($editor);
59 $templateFetch = $this->get('/templates/' . $page->id);
60 $templateFetch->assertStatus(404);
62 $page->html = $content;
63 $page->template = true;
66 $templateFetch = $this->get('/templates/' . $page->id);
67 $templateFetch->assertStatus(200);
68 $templateFetch->assertJson([
74 public function test_template_endpoint_returns_paginated_list_of_templates()
76 $editor = $this->users->editor();
77 $this->actingAs($editor);
79 $toBeTemplates = Page::query()->orderBy('name', 'asc')->take(12)->get();
80 $page = $toBeTemplates->first();
82 $emptyTemplatesFetch = $this->get('/templates');
83 $emptyTemplatesFetch->assertDontSee($page->name);
85 Page::query()->whereIn('id', $toBeTemplates->pluck('id')->toArray())->update(['template' => true]);
87 $templatesFetch = $this->get('/templates');
88 $templatesFetch->assertSee($page->name);
89 $templatesFetch->assertSee('pagination');