FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BookStackApp-BookStack/tests/Entity/PageTest.php at master · OneToolsCollection/BookStackApp-BookStack · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
OneToolsCollection
/
BookStackApp-BookStack
Public
forked from
BookStackApp/BookStack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
BookStackApp-BookStack
/
tests
/
Entity
/
PageTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
301 lines (242 loc) · 10.6 KB
Breadcrumbs
BookStackApp-BookStack
/
tests
/
Entity
/
PageTest.php
Copy path
File metadata and controls
301 lines (242 loc) · 10.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
namespace
Tests
\
Entity
;
use
BookStack
\
Entities
\
Models
\
Book
;
use
BookStack
\
Entities
\
Models
\
Page
;
use
BookStack
\
Uploads
\
Image
;
use
Carbon
\
Carbon
;
use
Tests
\
TestCase
;
class
PageTest
extends
TestCase
{
public
function
test_create
()
{
$
chapter
=
$
this
->
entities
->
chapter
();
$
page
= Page::
factory
()->
make
([
'
name
'
=>
'
My First Page
'
,
]);
$
resp
=
$
this
->
asEditor
()->
get
(
$
chapter
->
getUrl
());
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
a[href="
'
.
$
chapter
->
getUrl
(
'
/create-page
'
) .
'
"]
'
,
'
New Page
'
);
$
resp
=
$
this
->
get
(
$
chapter
->
getUrl
(
'
/create-page
'
));
/** @var Page $draftPage */
$
draftPage
= Page::
query
()
->
where
(
'
draft
'
,
'
=
'
,
true
)
->
orderBy
(
'
created_at
'
,
'
desc
'
)
->
first
();
$
resp
->
assertRedirect
(
$
draftPage
->
getUrl
());
$
resp
=
$
this
->
get
(
$
draftPage
->
getUrl
());
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
form[action="
'
.
$
draftPage
->
getUrl
() .
'
"][method="POST"]
'
,
'
Save Page
'
);
$
resp
=
$
this
->
post
(
$
draftPage
->
getUrl
(),
$
draftPage
->
only
(
'
name
'
,
'
html
'
));
$
draftPage
->
refresh
();
$
resp
->
assertRedirect
(
$
draftPage
->
getUrl
());
}
public
function
test_page_view_when_creator_is_deleted_but_owner_exists
()
{
$
page
=
$
this
->
entities
->
page
();
$
user
=
$
this
->
users
->
viewer
();
$
owner
=
$
this
->
users
->
editor
();
$
page
->
created_by
=
$
user
->
id
;
$
page
->
owned_by
=
$
owner
->
id
;
$
page
->
save
();
$
user
->
delete
();
$
resp
=
$
this
->
asAdmin
()->
get
(
$
page
->
getUrl
());
$
resp
->
assertStatus
(
200
);
$
resp
->
assertSeeText
(
'
Owned by
'
.
$
owner
->
name
);
}
public
function
test_page_show_includes_pointer_section_select_mode_button
()
{
$
page
=
$
this
->
entities
->
page
();
$
resp
=
$
this
->
asEditor
()->
get
(
$
page
->
getUrl
());
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
.content-wrap button.screen-reader-only
'
,
'
Enter section select mode
'
);
}
public
function
test_page_creation_with_markdown_content
()
{
$
this
->
setSettings
([
'
app-editor
'
=>
'
markdown
'
]);
$
book
=
$
this
->
entities
->
book
();
$
this
->
asEditor
()->
get
(
$
book
->
getUrl
(
'
/create-page
'
));
$
draft
= Page::
query
()->
where
(
'
book_id
'
,
'
=
'
,
$
book
->
id
)
->
where
(
'
draft
'
,
'
=
'
,
true
)->
first
();
$
details
= [
'
markdown
'
=>
'
# a title
'
,
'
html
'
=>
'
<h1>a title</h1>
'
,
'
name
'
=>
'
my page
'
,
];
$
resp
=
$
this
->
post
(
$
book
->
getUrl
(
"
/draft/
{
$
draft
->
id
}"
),
$
details
);
$
resp
->
assertRedirect
();
$
this
->
assertDatabaseHasEntityData
(
'
page
'
, [
'
markdown
'
=>
$
details
[
'
markdown
'
],
'
name
'
=>
$
details
[
'
name
'
],
'
id
'
=>
$
draft
->
id
,
'
draft
'
=>
false
,
]);
$
draft
->
refresh
();
$
resp
=
$
this
->
get
(
$
draft
->
getUrl
(
'
/edit
'
));
$
resp
->
assertSee
(
'
# a title
'
);
}
public
function
test_page_creation_allows_summary_to_be_set
()
{
$
book
=
$
this
->
entities
->
book
();
$
this
->
asEditor
()->
get
(
$
book
->
getUrl
(
'
/create-page
'
));
$
draft
= Page::
query
()->
where
(
'
book_id
'
,
'
=
'
,
$
book
->
id
)
->
where
(
'
draft
'
,
'
=
'
,
true
)->
first
();
$
details
= [
'
html
'
=>
'
<h1>a title</h1>
'
,
'
name
'
=>
'
My page with summary
'
,
'
summary
'
=>
'
Here is my changelog message for a new page!
'
,
];
$
resp
=
$
this
->
post
(
$
book
->
getUrl
(
"
/draft/
{
$
draft
->
id
}"
),
$
details
);
$
resp
->
assertRedirect
();
$
this
->
assertDatabaseHas
(
'
page_revisions
'
, [
'
page_id
'
=>
$
draft
->
id
,
'
summary
'
=>
'
Here is my changelog message for a new page!
'
,
]);
$
draft
->
refresh
();
$
resp
=
$
this
->
get
(
$
draft
->
getUrl
(
'
/revisions
'
));
$
resp
->
assertSee
(
'
Here is my changelog message for a new page!
'
);
}
public
function
test_page_delete
()
{
$
page
=
$
this
->
entities
->
page
();
$
this
->
assertNull
(
$
page
->
deleted_at
);
$
deleteViewReq
=
$
this
->
asEditor
()->
get
(
$
page
->
getUrl
(
'
/delete
'
));
$
deleteViewReq
->
assertSeeText
(
'
Are you sure you want to delete this page?
'
);
$
deleteReq
=
$
this
->
delete
(
$
page
->
getUrl
());
$
deleteReq
->
assertRedirect
(
$
page
->
getParent
()->
getUrl
());
$
this
->
assertActivityExists
(
'
page_delete
'
,
$
page
);
$
page
->
refresh
();
$
this
->
assertNotNull
(
$
page
->
deleted_at
);
$
this
->
assertTrue
(
$
page
->
deletions
()->
count
() ===
1
);
$
redirectReq
=
$
this
->
get
(
$
deleteReq
->
baseResponse
->
headers
->
get
(
'
location
'
));
$
this
->
assertNotificationContains
(
$
redirectReq
,
'
Page Successfully Deleted
'
);
}
public
function
test_page_full_delete_removes_all_revisions
()
{
$
page
=
$
this
->
entities
->
page
();
$
page
->
revisions
()->
create
([
'
html
'
=>
'
<p>ducks</p>
'
,
'
name
'
=>
'
my page revision
'
,
'
type
'
=>
'
draft
'
,
]);
$
page
->
revisions
()->
create
([
'
html
'
=>
'
<p>ducks</p>
'
,
'
name
'
=>
'
my page revision
'
,
'
type
'
=>
'
revision
'
,
]);
$
this
->
assertDatabaseHas
(
'
page_revisions
'
, [
'
page_id
'
=>
$
page
->
id
,
]);
$
this
->
asEditor
()->
delete
(
$
page
->
getUrl
());
$
this
->
asAdmin
()->
post
(
'
/settings/recycle-bin/empty
'
);
$
this
->
assertDatabaseMissing
(
'
page_revisions
'
, [
'
page_id
'
=>
$
page
->
id
,
]);
}
public
function
test_page_full_delete_nulls_related_images
()
{
$
page
=
$
this
->
entities
->
page
();
$
image
= Image::
factory
()->
create
([
'
type
'
=>
'
gallery
'
,
'
uploaded_to
'
=>
$
page
->
id
]);
$
this
->
asEditor
()->
delete
(
$
page
->
getUrl
());
$
this
->
asAdmin
()->
post
(
'
/settings/recycle-bin/empty
'
);
$
this
->
assertDatabaseMissing
(
'
images
'
, [
'
type
'
=>
'
gallery
'
,
'
uploaded_to
'
=>
$
page
->
id
,
]);
$
this
->
assertDatabaseHas
(
'
images
'
, [
'
id
'
=>
$
image
->
id
,
'
uploaded_to
'
=>
null
,
]);
}
public
function
test_page_within_chapter_deletion_returns_to_chapter
()
{
$
chapter
=
$
this
->
entities
->
chapter
();
$
page
=
$
chapter
->
pages
()->
first
();
$
this
->
asEditor
()->
delete
(
$
page
->
getUrl
())
->
assertRedirect
(
$
chapter
->
getUrl
());
}
public
function
test_recently_updated_pages_view
()
{
$
user
=
$
this
->
users
->
editor
();
$
content
=
$
this
->
entities
->
createChainBelongingToUser
(
$
user
);
$
resp
=
$
this
->
asAdmin
()->
get
(
'
/pages/recently-updated
'
);
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
.entity-list .page:nth-child(1)
'
,
$
content
[
'
page
'
]->
name
);
}
public
function
test_recently_updated_pages_view_shows_updated_by_details
()
{
$
user
=
$
this
->
users
->
editor
();
$
page
=
$
this
->
entities
->
page
();
$
this
->
actingAs
(
$
user
)->
put
(
$
page
->
getUrl
(), [
'
name
'
=>
'
Updated title
'
,
'
html
'
=>
'
<p>Updated content</p>
'
,
]);
$
resp
=
$
this
->
asAdmin
()->
get
(
'
/pages/recently-updated
'
);
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
.entity-list .page:nth-child(1) small
'
,
'
by
'
.
$
user
->
name
);
}
public
function
test_recently_updated_pages_view_shows_parent_chain
()
{
$
user
=
$
this
->
users
->
editor
();
$
page
=
$
this
->
entities
->
pageWithinChapter
();
$
this
->
actingAs
(
$
user
)->
put
(
$
page
->
getUrl
(), [
'
name
'
=>
'
Updated title
'
,
'
html
'
=>
'
<p>Updated content</p>
'
,
]);
$
resp
=
$
this
->
asAdmin
()->
get
(
'
/pages/recently-updated
'
);
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
.entity-list .page:nth-child(1)
'
,
$
page
->
chapter
->
getShortName
(
42
));
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
.entity-list .page:nth-child(1)
'
,
$
page
->
book
->
getShortName
(
42
));
}
public
function
test_recently_updated_pages_view_does_not_show_parent_if_not_visible
()
{
$
user
=
$
this
->
users
->
editor
();
$
page
=
$
this
->
entities
->
pageWithinChapter
();
$
this
->
actingAs
(
$
user
)->
put
(
$
page
->
getUrl
(), [
'
name
'
=>
'
Updated title
'
,
'
html
'
=>
'
<p>Updated content</p>
'
,
]);
$
this
->
permissions
->
setEntityPermissions
(
$
page
->
book
);
$
this
->
permissions
->
setEntityPermissions
(
$
page
, [
'
view
'
], [
$
user
->
roles
->
first
()]);
$
resp
=
$
this
->
get
(
'
/pages/recently-updated
'
);
$
resp
->
assertDontSee
(
$
page
->
book
->
getShortName
(
42
));
$
resp
->
assertDontSee
(
$
page
->
chapter
->
getShortName
(
42
));
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
.entity-list .page:nth-child(1)
'
,
'
Updated title
'
);
}
public
function
test_recently_updated_pages_on_home
()
{
/** @var Page $page */
$
page
= Page::
query
()->
orderBy
(
'
updated_at
'
,
'
asc
'
)->
first
();
Page::
query
()->
where
(
'
id
'
,
'
!=
'
,
$
page
->
id
)->
update
([
'
updated_at
'
=> Carbon::
now
()->
subSecond
(
1
),
]);
$
resp
=
$
this
->
asAdmin
()->
get
(
'
/
'
);
$
this
->
withHtml
(
$
resp
)->
assertElementNotContains
(
'
#recently-updated-pages
'
,
$
page
->
name
);
$
this
->
put
(
$
page
->
getUrl
(), [
'
name
'
=>
$
page
->
name
,
'
html
'
=>
$
page
->
html
,
]);
$
resp
=
$
this
->
get
(
'
/
'
);
$
this
->
withHtml
(
$
resp
)->
assertElementContains
(
'
#recently-updated-pages
'
,
$
page
->
name
);
}
public
function
test_page_edit_without_update_permissions_but_with_view_redirects_to_page
()
{
$
page
=
$
this
->
entities
->
page
();
$
resp
=
$
this
->
asViewer
()->
get
(
$
page
->
getUrl
(
'
/edit
'
));
$
resp
->
assertRedirect
(
$
page
->
getUrl
());
$
resp
->
assertSessionHas
(
'
error
'
,
'
You do not have permission to access the requested page.
'
);
}
public
function
test_page_html_content_remains_stable_through_re_edit_and_does_not_create_revision
()
{
$
page
=
$
this
->
entities
->
page
();
$
this
->
asEditor
()->
put
(
$
page
->
getUrl
(), [
'
name
'
=>
'
Stability Test
'
,
'
html
'
=>
'
<table border="1" style="border-collapse: collapse; width: 100%;" border="1"><tbody><tr><td>a</td></tr></tbody></table>
'
,
]);
$
initialRevisionCount
=
$
page
->
revisions
()->
count
();
$
page
->
refresh
();
// Get the page content from the edit view to ensure we're using the
// exact same content which would be loaded into the editor.
$
editView
=
$
this
->
get
(
$
page
->
getUrl
(
'
/edit
'
));
$
htmlContentEncoded
=
$
this
->
withHtml
(
$
editView
)->
getInnerHtml
(
'
textarea#html-editor
'
);
$
htmlContent
=
html_entity_decode
(
$
htmlContentEncoded
);
$
this
->
asEditor
()->
put
(
$
page
->
getUrl
(), [
'
name
'
=>
'
Stability Test
'
,
'
html
'
=>
$
htmlContent
,
]);
$
this
->
assertEquals
(
$
initialRevisionCount
,
$
page
->
revisions
()->
count
());
}
}
Back
|
FazBrowse Home
|
New Git URL