3 namespace Tests\Entity;
5 use BookStack\Auth\UserRepo;
6 use BookStack\Entities\Models\Entity;
7 use BookStack\Entities\Repos\PageRepo;
10 class EntityAccessTest extends TestCase
12 public function test_entities_viewable_after_creator_deletion()
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>>']);
21 $this->checkEntitiesViewable($entities);
24 public function test_entities_viewable_after_updater_deletion()
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>']);
33 $this->checkEntitiesViewable($entities);
37 * @param array<string, Entity> $entities
39 private function checkEntitiesViewable(array $entities)
41 // Check pages and books are visible.
43 foreach ($entities as $entity) {
44 $this->get($entity->getUrl())
46 ->assertSee($entity->name);
49 // Check revision listing shows no errors.
50 $this->get($entities['page']->getUrl('/revisions'))->assertStatus(200);