]> BookStack Code Mirror - bookstack/blob - tests/Entity/EntityAccessTest.php
Removed old book sort permission test
[bookstack] / tests / Entity / EntityAccessTest.php
1 <?php
2
3 namespace Tests\Entity;
4
5 use BookStack\Auth\UserRepo;
6 use BookStack\Entities\Models\Entity;
7 use BookStack\Entities\Repos\PageRepo;
8 use Tests\TestCase;
9
10 class EntityAccessTest extends TestCase
11 {
12     public function test_entities_viewable_after_creator_deletion()
13     {
14         // Create required assets and revisions
15         $creator = $this->getEditor();
16         $updater = $this->getViewer();
17         $entities = $this->createEntityChainBelongingToUser($creator, $updater);
18         app()->make(UserRepo::class)->destroy($creator);
19         app()->make(PageRepo::class)->update($entities['page'], ['html' => '<p>hello!</p>>']);
20
21         $this->checkEntitiesViewable($entities);
22     }
23
24     public function test_entities_viewable_after_updater_deletion()
25     {
26         // Create required assets and revisions
27         $creator = $this->getViewer();
28         $updater = $this->getEditor();
29         $entities = $this->createEntityChainBelongingToUser($creator, $updater);
30         app()->make(UserRepo::class)->destroy($updater);
31         app()->make(PageRepo::class)->update($entities['page'], ['html' => '<p>Hello there!</p>']);
32
33         $this->checkEntitiesViewable($entities);
34     }
35
36     /**
37      * @param array<string, Entity> $entities
38      */
39     private function checkEntitiesViewable(array $entities)
40     {
41         // Check pages and books are visible.
42         $this->asAdmin();
43         foreach ($entities as $entity) {
44             $this->get($entity->getUrl())
45                 ->assertStatus(200)
46                 ->assertSee($entity->name);
47         }
48
49         // Check revision listing shows no errors.
50         $this->get($entities['page']->getUrl('/revisions'))->assertStatus(200);
51     }
52 }