3 use BookStack\Entities\Entity;
4 use Illuminate\Foundation\Testing\DatabaseTransactions;
5 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
7 abstract class TestCase extends BaseTestCase
9 use CreatesApplication;
10 use DatabaseTransactions;
11 use SharedTestHelpers;
14 * The base URL to use while testing the application.
17 protected $baseUrl = 'http://localhost';
20 * Assert a permission error has occurred.
21 * @param TestResponse $response
24 protected function assertPermissionError(TestResponse $response)
26 $response->assertRedirect('/');
27 $this->assertSessionHas('error');
28 session()->remove('error');
33 * Assert the session contains a specific entry.
37 protected function assertSessionHas(string $key)
39 $this->assertTrue(session()->has($key), "Session does not contain a [{$key}] entry");
44 * Override of the get method so we can get visibility of custom TestResponse methods.
46 * @param array $headers
47 * @return TestResponse
49 public function get($uri, array $headers = [])
51 return parent::get($uri, $headers);
55 * Create the test response instance from the given response.
57 * @param \Illuminate\Http\Response $response
58 * @return TestResponse
60 protected function createTestResponse($response)
62 return TestResponse::fromBaseResponse($response);
66 * Assert that an activity entry exists of the given key.
67 * Checks the activity belongs to the given entity if provided.
69 protected function assertActivityExists(string $key, Entity $entity = null)
71 $detailsToCheck = ['key' => $key];
74 $detailsToCheck['entity_type'] = $entity->getMorphClass();
75 $detailsToCheck['entity_id'] = $entity->id;
78 $this->assertDatabaseHas('activities', $detailsToCheck);