Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2017-01-21 16:16:27 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
2d4034f3b7a0828a47859f0fc313dfb0b506e622
2d4034f3
1 parent
56d58ad8
Added transclusion tests and fixed other tests
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
53 deletions
app/Services/PermissionService.php
tests/Entity/PageContentTest.php
tests/Entity/TagTests.php → tests/Entity/TagTest.php
tests/TestCase.php
app/Services/PermissionService.php
View file @
2d4034f
...
...
@@ -157,7 +157,7 @@ class PermissionService
*/
public
function
buildJointPermissionsForEntity
(
Entity
$entity
)
{
$roles
=
$this
->
role
->
with
(
'jointPermissions'
)
->
get
();
$roles
=
$this
->
role
->
get
();
$entities
=
collect
([
$entity
]);
if
(
$entity
->
isA
(
'book'
))
{
...
...
@@ -177,7 +177,7 @@ class PermissionService
*/
public
function
buildJointPermissionsForEntities
(
Collection
$entities
)
{
$roles
=
$this
->
role
->
with
(
'jointPermissions'
)
->
get
();
$roles
=
$this
->
role
->
get
();
$this
->
deleteManyJointPermissionsForEntities
(
$entities
);
$this
->
createManyJointPermissions
(
$entities
,
$roles
);
}
...
...
@@ -564,6 +564,7 @@ class PermissionService
});
});
});
$this
->
clean
();
return
$q
;
}
...
...
tests/Entity/PageContentTest.php
0 → 100644
View file @
2d4034f
<?php
class
PageContentTest
extends
TestCase
{
public
function
test_page_includes
()
{
$page
=
\BookStack\Page
::
first
();
$secondPage
=
\BookStack\Page
::
all
()
->
get
(
2
);
$secondPage
->
html
=
"<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>"
;
$secondPage
->
save
();
$this
->
asAdmin
()
->
visit
(
$page
->
getUrl
())
->
dontSee
(
'Hello, This is a test'
);
$originalHtml
=
$page
->
html
;
$page
->
html
.=
"
{
{@{$secondPage->id}}
}
"
;
$page
->
save
();
$this
->
asAdmin
()
->
visit
(
$page
->
getUrl
())
->
see
(
'Hello, This is a test'
)
->
see
(
'This is a second block of content'
);
$page
->
html
=
$originalHtml
.
" Well
{
{@{$secondPage->id}#section2}
}
"
;
$page
->
save
();
$this
->
asAdmin
()
->
visit
(
$page
->
getUrl
())
->
dontSee
(
'Hello, This is a test'
)
->
see
(
'Well This is a second block of content'
);
}
}
tests/Entity/TagTest
s
.php
→
tests/Entity/TagTest.php
View file @
2d4034f
...
...
@@ -4,7 +4,7 @@ use BookStack\Tag;
use
BookStack\Page
;
use
BookStack\Services\PermissionService
;
class
TagTest
s
extends
\TestCase
class
TagTest
extends
\TestCase
{
protected
$defaultTagCount
=
20
;
...
...
@@ -86,61 +86,16 @@ class TagTests extends \TestCase
$attrs
=
$attrs
->
merge
(
factory
(
Tag
::
class
,
5
)
->
make
([
'name'
=>
'color'
]));
$page
=
$this
->
getPageWithTags
(
$attrs
);
$this
->
asAdmin
()
->
get
(
'/ajax/tags/suggest?search=co'
)
->
seeJsonEquals
([
'color'
,
'country'
]);
$this
->
asEditor
()
->
get
(
'/ajax/tags/suggest?search=co'
)
->
seeJsonEquals
([
'color'
,
'country'
]);
$this
->
asAdmin
()
->
get
(
'/ajax/tags/suggest
/names
?search=co'
)
->
seeJsonEquals
([
'color'
,
'country'
]);
$this
->
asEditor
()
->
get
(
'/ajax/tags/suggest
/names
?search=co'
)
->
seeJsonEquals
([
'color'
,
'country'
]);
// Set restricted permission the page
$page
->
restricted
=
true
;
$page
->
save
();
$permissionService
->
buildJointPermissionsForEntity
(
$page
);
$this
->
asAdmin
()
->
get
(
'/ajax/tags/suggest?search=co'
)
->
seeJsonEquals
([
'color'
,
'country'
]);
$this
->
asEditor
()
->
get
(
'/ajax/tags/suggest?search=co'
)
->
seeJsonEquals
([]);
}
public
function
test_entity_tag_updating
()
{
$page
=
$this
->
getPageWithTags
();
$testJsonData
=
[
[
'name'
=>
'color'
,
'value'
=>
'red'
],
[
'name'
=>
'color'
,
'value'
=>
' blue '
],
[
'name'
=>
'city'
,
'value'
=>
'London '
],
[
'name'
=>
'country'
,
'value'
=>
' England'
],
];
$testResponseJsonData
=
[
[
'name'
=>
'color'
,
'value'
=>
'red'
],
[
'name'
=>
'color'
,
'value'
=>
'blue'
],
[
'name'
=>
'city'
,
'value'
=>
'London'
],
[
'name'
=>
'country'
,
'value'
=>
'England'
],
];
// Do update request
$this
->
asAdmin
()
->
json
(
"POST"
,
"/ajax/tags/update/page/"
.
$page
->
id
,
[
'tags'
=>
$testJsonData
]);
$updateData
=
json_decode
(
$this
->
response
->
getContent
());
// Check data is correct
$testDataCorrect
=
true
;
foreach
(
$updateData
->
tags
as
$data
)
{
$testItem
=
[
'name'
=>
$data
->
name
,
'value'
=>
$data
->
value
];
if
(
!
in_array
(
$testItem
,
$testResponseJsonData
))
$testDataCorrect
=
false
;
}
$testMessage
=
"Expected data was not found in the response.
\n
Expected Data: %s
\n
Recieved Data: %s"
;
$this
->
assertTrue
(
$testDataCorrect
,
sprintf
(
$testMessage
,
json_encode
(
$testResponseJsonData
),
json_encode
(
$updateData
)));
$this
->
assertTrue
(
isset
(
$updateData
->
message
),
"No message returned in tag update response"
);
// Do get request
$this
->
asAdmin
()
->
get
(
"/ajax/tags/get/page/"
.
$page
->
id
);
$getResponseData
=
json_decode
(
$this
->
response
->
getContent
());
// Check counts
$this
->
assertTrue
(
count
(
$getResponseData
)
===
count
(
$testJsonData
),
"The received tag count is incorrect"
);
// Check data is correct
$testDataCorrect
=
true
;
foreach
(
$getResponseData
as
$data
)
{
$testItem
=
[
'name'
=>
$data
->
name
,
'value'
=>
$data
->
value
];
if
(
!
in_array
(
$testItem
,
$testResponseJsonData
))
$testDataCorrect
=
false
;
}
$testMessage
=
"Expected data was not found in the response.
\n
Expected Data: %s
\n
Recieved Data: %s"
;
$this
->
assertTrue
(
$testDataCorrect
,
sprintf
(
$testMessage
,
json_encode
(
$testResponseJsonData
),
json_encode
(
$getResponseData
)));
$this
->
asAdmin
()
->
get
(
'/ajax/tags/suggest/names?search=co'
)
->
seeJsonEquals
([
'color'
,
'country'
]);
$this
->
asEditor
()
->
get
(
'/ajax/tags/suggest/names?search=co'
)
->
seeJsonEquals
([]);
}
}
...
...
tests/TestCase.php
View file @
2d4034f
...
...
@@ -60,7 +60,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
*/
public
function
asEditor
()
{
if
(
$this
->
editor
===
null
)
{
if
(
$this
->
editor
===
null
)
{
$this
->
editor
=
$this
->
getEditor
();
}
return
$this
->
actingAs
(
$this
->
editor
);
...
...
Please
register
or
sign in
to post a comment