]> BookStack Code Mirror - bookstack/blob - tests/Entity/EntityAccessTest.php
Merge branch 'development' of github.com:BookStackApp/BookStack into development
[bookstack] / tests / Entity / EntityAccessTest.php
1 <?php
2
3 namespace Tests\Entity;
4
5 use BookStack\Entities\Models\Entity;
6 use BookStack\Users\UserRepo;
7 use Tests\TestCase;
8
9 class EntityAccessTest extends TestCase
10 {
11     public function test_entities_viewable_after_creator_deletion()
12     {
13         // Create required assets and revisions
14         $creator = $this->users->editor();
15         $updater = $this->users->viewer();
16         $entities = $this->entities->createChainBelongingToUser($creator, $updater);
17         app()->make(UserRepo::class)->destroy($creator);
18         $this->entities->updatePage($entities['page'], ['html' => '<p>hello!</p>>']);
19
20         $this->checkEntitiesViewable($entities);
21     }
22
23     public function test_entities_viewable_after_updater_deletion()
24     {
25         // Create required assets and revisions
26         $creator = $this->users->viewer();
27         $updater = $this->users->editor();
28         $entities = $this->entities->createChainBelongingToUser($creator, $updater);
29         app()->make(UserRepo::class)->destroy($updater);
30         $this->entities->updatePage($entities['page'], ['html' => '<p>Hello there!</p>']);
31
32         $this->checkEntitiesViewable($entities);
33     }
34
35     /**
36      * @param array<string, Entity> $entities
37      */
38     private function checkEntitiesViewable(array $entities)
39     {
40         // Check pages and books are visible.
41         $this->asAdmin();
42         foreach ($entities as $entity) {
43             $this->get($entity->getUrl())
44                 ->assertStatus(200)
45                 ->assertSee($entity->name);
46         }
47
48         // Check revision listing shows no errors.
49         $this->get($entities['page']->getUrl('/revisions'))->assertStatus(200);
50     }
51 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.