| 
									
										
										
										
											2021-09-18 04:29:16 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Tests\Entity; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use BookStack\Entities\Models\Entity; | 
					
						
							| 
									
										
										
										
											2023-05-18 00:56:55 +08:00
										 |  |  | use BookStack\Users\UserRepo; | 
					
						
							| 
									
										
										
										
											2021-09-18 04:29:16 +08:00
										 |  |  | use Tests\TestCase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EntityAccessTest extends TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function test_entities_viewable_after_creator_deletion() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Create required assets and revisions
 | 
					
						
							| 
									
										
										
										
											2023-01-21 19:08:34 +08:00
										 |  |  |         $creator = $this->users->editor(); | 
					
						
							|  |  |  |         $updater = $this->users->viewer(); | 
					
						
							| 
									
										
										
										
											2022-09-29 23:49:25 +08:00
										 |  |  |         $entities = $this->entities->createChainBelongingToUser($creator, $updater); | 
					
						
							| 
									
										
										
										
											2021-09-18 04:29:16 +08:00
										 |  |  |         app()->make(UserRepo::class)->destroy($creator); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $this->entities->updatePage($entities['page'], ['html' => '<p>hello!</p>>']); | 
					
						
							| 
									
										
										
										
											2021-09-18 04:29:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->checkEntitiesViewable($entities); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function test_entities_viewable_after_updater_deletion() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Create required assets and revisions
 | 
					
						
							| 
									
										
										
										
											2023-01-21 19:08:34 +08:00
										 |  |  |         $creator = $this->users->viewer(); | 
					
						
							|  |  |  |         $updater = $this->users->editor(); | 
					
						
							| 
									
										
										
										
											2022-09-29 23:49:25 +08:00
										 |  |  |         $entities = $this->entities->createChainBelongingToUser($creator, $updater); | 
					
						
							| 
									
										
										
										
											2021-09-18 04:29:16 +08:00
										 |  |  |         app()->make(UserRepo::class)->destroy($updater); | 
					
						
							| 
									
										
										
										
											2022-09-30 05:11:16 +08:00
										 |  |  |         $this->entities->updatePage($entities['page'], ['html' => '<p>Hello there!</p>']); | 
					
						
							| 
									
										
										
										
											2021-09-18 04:29:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->checkEntitiesViewable($entities); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param array<string, Entity> $entities | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function checkEntitiesViewable(array $entities) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Check pages and books are visible.
 | 
					
						
							|  |  |  |         $this->asAdmin(); | 
					
						
							|  |  |  |         foreach ($entities as $entity) { | 
					
						
							|  |  |  |             $this->get($entity->getUrl()) | 
					
						
							|  |  |  |                 ->assertStatus(200) | 
					
						
							|  |  |  |                 ->assertSee($entity->name); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Check revision listing shows no errors.
 | 
					
						
							|  |  |  |         $this->get($entities['page']->getUrl('/revisions'))->assertStatus(200); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |