-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathPageTemplateTest.php
More file actions
91 lines (71 loc) · 2.7 KB
/
PageTemplateTest.php
File metadata and controls
91 lines (71 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Tests\Entity;
use BookStack\Entities\Models\Page;
use Tests\TestCase;
class PageTemplateTest extends TestCase
{
public function test_active_templates_visible_on_page_view()
{
$page = $this->entities->page();
$this->asEditor();
$templateView = $this->get($page->getUrl());
$templateView->assertDontSee('Page Template');
$page->template = true;
$page->save();
$templateView = $this->get($page->getUrl());
$templateView->assertSee('Page Template');
}
public function test_manage_templates_permission_required_to_change_page_template_status()
{
$page = $this->entities->page();
$editor = $this->users->editor();
$this->actingAs($editor);
$pageUpdateData = [
'name' => $page->name,
'html' => $page->html,
'template' => 'true',
];
$this->put($page->getUrl(), $pageUpdateData);
$this->assertDatabaseHasEntityData('page', [
'id' => $page->id,
'template' => false,
]);
$this->permissions->grantUserRolePermissions($editor, ['templates-manage']);
$this->put($page->getUrl(), $pageUpdateData);
$this->assertDatabaseHasEntityData('page', [
'id' => $page->id,
'template' => true,
]);
}
public function test_templates_content_should_be_fetchable_only_if_page_marked_as_template()
{
$content = '<div>my_custom_template_content</div>';
$page = $this->entities->page();
$editor = $this->users->editor();
$this->actingAs($editor);
$templateFetch = $this->get('/templates/' . $page->id);
$templateFetch->assertStatus(404);
$page->html = $content;
$page->template = true;
$page->save();
$templateFetch = $this->get('/templates/' . $page->id);
$templateFetch->assertStatus(200);
$templateFetch->assertJson([
'html' => $content,
'markdown' => '',
]);
}
public function test_template_endpoint_returns_paginated_list_of_templates()
{
$editor = $this->users->editor();
$this->actingAs($editor);
$toBeTemplates = Page::query()->orderBy('name', 'asc')->take(12)->get();
$page = $toBeTemplates->first();
$emptyTemplatesFetch = $this->get('/templates');
$emptyTemplatesFetch->assertDontSee($page->name);
Page::query()->whereIn('id', $toBeTemplates->pluck('id')->toArray())->update(['template' => true]);
$templatesFetch = $this->get('/templates');
$templatesFetch->assertSee($page->name);
$templatesFetch->assertSee('pagination');
}
}