Showing
4 changed files
with
42 additions
and
53 deletions
| ... | @@ -157,7 +157,7 @@ class PermissionService | ... | @@ -157,7 +157,7 @@ class PermissionService |
| 157 | */ | 157 | */ |
| 158 | public function buildJointPermissionsForEntity(Entity $entity) | 158 | public function buildJointPermissionsForEntity(Entity $entity) |
| 159 | { | 159 | { |
| 160 | - $roles = $this->role->with('jointPermissions')->get(); | 160 | + $roles = $this->role->get(); |
| 161 | $entities = collect([$entity]); | 161 | $entities = collect([$entity]); |
| 162 | 162 | ||
| 163 | if ($entity->isA('book')) { | 163 | if ($entity->isA('book')) { |
| ... | @@ -177,7 +177,7 @@ class PermissionService | ... | @@ -177,7 +177,7 @@ class PermissionService |
| 177 | */ | 177 | */ |
| 178 | public function buildJointPermissionsForEntities(Collection $entities) | 178 | public function buildJointPermissionsForEntities(Collection $entities) |
| 179 | { | 179 | { |
| 180 | - $roles = $this->role->with('jointPermissions')->get(); | 180 | + $roles = $this->role->get(); |
| 181 | $this->deleteManyJointPermissionsForEntities($entities); | 181 | $this->deleteManyJointPermissionsForEntities($entities); |
| 182 | $this->createManyJointPermissions($entities, $roles); | 182 | $this->createManyJointPermissions($entities, $roles); |
| 183 | } | 183 | } |
| ... | @@ -564,6 +564,7 @@ class PermissionService | ... | @@ -564,6 +564,7 @@ class PermissionService |
| 564 | }); | 564 | }); |
| 565 | }); | 565 | }); |
| 566 | }); | 566 | }); |
| 567 | + $this->clean(); | ||
| 567 | return $q; | 568 | return $q; |
| 568 | } | 569 | } |
| 569 | 570 | ... | ... |
tests/Entity/PageContentTest.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +class PageContentTest extends TestCase | ||
| 4 | +{ | ||
| 5 | + | ||
| 6 | + public function test_page_includes() | ||
| 7 | + { | ||
| 8 | + $page = \BookStack\Page::first(); | ||
| 9 | + $secondPage = \BookStack\Page::all()->get(2); | ||
| 10 | + | ||
| 11 | + $secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>"; | ||
| 12 | + $secondPage->save(); | ||
| 13 | + | ||
| 14 | + $this->asAdmin()->visit($page->getUrl()) | ||
| 15 | + ->dontSee('Hello, This is a test'); | ||
| 16 | + | ||
| 17 | + $originalHtml = $page->html; | ||
| 18 | + $page->html .= "{{@{$secondPage->id}}}"; | ||
| 19 | + $page->save(); | ||
| 20 | + | ||
| 21 | + $this->asAdmin()->visit($page->getUrl()) | ||
| 22 | + ->see('Hello, This is a test') | ||
| 23 | + ->see('This is a second block of content'); | ||
| 24 | + | ||
| 25 | + $page->html = $originalHtml . " Well {{@{$secondPage->id}#section2}}"; | ||
| 26 | + $page->save(); | ||
| 27 | + | ||
| 28 | + $this->asAdmin()->visit($page->getUrl()) | ||
| 29 | + ->dontSee('Hello, This is a test') | ||
| 30 | + ->see('Well This is a second block of content'); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | +} |
| ... | @@ -4,7 +4,7 @@ use BookStack\Tag; | ... | @@ -4,7 +4,7 @@ use BookStack\Tag; |
| 4 | use BookStack\Page; | 4 | use BookStack\Page; |
| 5 | use BookStack\Services\PermissionService; | 5 | use BookStack\Services\PermissionService; |
| 6 | 6 | ||
| 7 | -class TagTests extends \TestCase | 7 | +class TagTest extends \TestCase |
| 8 | { | 8 | { |
| 9 | 9 | ||
| 10 | protected $defaultTagCount = 20; | 10 | protected $defaultTagCount = 20; |
| ... | @@ -86,61 +86,16 @@ class TagTests extends \TestCase | ... | @@ -86,61 +86,16 @@ class TagTests extends \TestCase |
| 86 | $attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'color'])); | 86 | $attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'color'])); |
| 87 | $page = $this->getPageWithTags($attrs); | 87 | $page = $this->getPageWithTags($attrs); |
| 88 | 88 | ||
| 89 | - $this->asAdmin()->get('/ajax/tags/suggest?search=co')->seeJsonEquals(['color', 'country']); | 89 | + $this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->seeJsonEquals(['color', 'country']); |
| 90 | - $this->asEditor()->get('/ajax/tags/suggest?search=co')->seeJsonEquals(['color', 'country']); | 90 | + $this->asEditor()->get('/ajax/tags/suggest/names?search=co')->seeJsonEquals(['color', 'country']); |
| 91 | 91 | ||
| 92 | // Set restricted permission the page | 92 | // Set restricted permission the page |
| 93 | $page->restricted = true; | 93 | $page->restricted = true; |
| 94 | $page->save(); | 94 | $page->save(); |
| 95 | $permissionService->buildJointPermissionsForEntity($page); | 95 | $permissionService->buildJointPermissionsForEntity($page); |
| 96 | 96 | ||
| 97 | - $this->asAdmin()->get('/ajax/tags/suggest?search=co')->seeJsonEquals(['color', 'country']); | 97 | + $this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->seeJsonEquals(['color', 'country']); |
| 98 | - $this->asEditor()->get('/ajax/tags/suggest?search=co')->seeJsonEquals([]); | 98 | + $this->asEditor()->get('/ajax/tags/suggest/names?search=co')->seeJsonEquals([]); |
| 99 | - } | ||
| 100 | - | ||
| 101 | - public function test_entity_tag_updating() | ||
| 102 | - { | ||
| 103 | - $page = $this->getPageWithTags(); | ||
| 104 | - | ||
| 105 | - $testJsonData = [ | ||
| 106 | - ['name' => 'color', 'value' => 'red'], | ||
| 107 | - ['name' => 'color', 'value' => ' blue '], | ||
| 108 | - ['name' => 'city', 'value' => 'London '], | ||
| 109 | - ['name' => 'country', 'value' => ' England'], | ||
| 110 | - ]; | ||
| 111 | - $testResponseJsonData = [ | ||
| 112 | - ['name' => 'color', 'value' => 'red'], | ||
| 113 | - ['name' => 'color', 'value' => 'blue'], | ||
| 114 | - ['name' => 'city', 'value' => 'London'], | ||
| 115 | - ['name' => 'country', 'value' => 'England'], | ||
| 116 | - ]; | ||
| 117 | - | ||
| 118 | - // Do update request | ||
| 119 | - $this->asAdmin()->json("POST", "/ajax/tags/update/page/" . $page->id, ['tags' => $testJsonData]); | ||
| 120 | - $updateData = json_decode($this->response->getContent()); | ||
| 121 | - // Check data is correct | ||
| 122 | - $testDataCorrect = true; | ||
| 123 | - foreach ($updateData->tags as $data) { | ||
| 124 | - $testItem = ['name' => $data->name, 'value' => $data->value]; | ||
| 125 | - if (!in_array($testItem, $testResponseJsonData)) $testDataCorrect = false; | ||
| 126 | - } | ||
| 127 | - $testMessage = "Expected data was not found in the response.\nExpected Data: %s\nRecieved Data: %s"; | ||
| 128 | - $this->assertTrue($testDataCorrect, sprintf($testMessage, json_encode($testResponseJsonData), json_encode($updateData))); | ||
| 129 | - $this->assertTrue(isset($updateData->message), "No message returned in tag update response"); | ||
| 130 | - | ||
| 131 | - // Do get request | ||
| 132 | - $this->asAdmin()->get("/ajax/tags/get/page/" . $page->id); | ||
| 133 | - $getResponseData = json_decode($this->response->getContent()); | ||
| 134 | - // Check counts | ||
| 135 | - $this->assertTrue(count($getResponseData) === count($testJsonData), "The received tag count is incorrect"); | ||
| 136 | - // Check data is correct | ||
| 137 | - $testDataCorrect = true; | ||
| 138 | - foreach ($getResponseData as $data) { | ||
| 139 | - $testItem = ['name' => $data->name, 'value' => $data->value]; | ||
| 140 | - if (!in_array($testItem, $testResponseJsonData)) $testDataCorrect = false; | ||
| 141 | - } | ||
| 142 | - $testMessage = "Expected data was not found in the response.\nExpected Data: %s\nRecieved Data: %s"; | ||
| 143 | - $this->assertTrue($testDataCorrect, sprintf($testMessage, json_encode($testResponseJsonData), json_encode($getResponseData))); | ||
| 144 | } | 99 | } |
| 145 | 100 | ||
| 146 | } | 101 | } | ... | ... |
| ... | @@ -60,7 +60,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase | ... | @@ -60,7 +60,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase |
| 60 | */ | 60 | */ |
| 61 | public function asEditor() | 61 | public function asEditor() |
| 62 | { | 62 | { |
| 63 | - if($this->editor === null) { | 63 | + if ($this->editor === null) { |
| 64 | $this->editor = $this->getEditor(); | 64 | $this->editor = $this->getEditor(); |
| 65 | } | 65 | } |
| 66 | return $this->actingAs($this->editor); | 66 | return $this->actingAs($this->editor); | ... | ... |
-
Please register or sign in to post a comment