]> BookStack Code Mirror - bookstack/blob - tests/TestCase.php
Applied StyleCI changes
[bookstack] / tests / TestCase.php
1 <?php
2
3 namespace Tests;
4
5 use BookStack\Entities\Models\Entity;
6 use Illuminate\Foundation\Testing\DatabaseTransactions;
7 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
8
9 abstract class TestCase extends BaseTestCase
10 {
11     use CreatesApplication;
12     use DatabaseTransactions;
13     use SharedTestHelpers;
14
15     /**
16      * The base URL to use while testing the application.
17      *
18      * @var string
19      */
20     protected $baseUrl = 'http://localhost';
21
22     /**
23      * Assert the session contains a specific entry.
24      *
25      * @param string $key
26      *
27      * @return $this
28      */
29     protected function assertSessionHas(string $key)
30     {
31         $this->assertTrue(session()->has($key), "Session does not contain a [{$key}] entry");
32
33         return $this;
34     }
35
36     /**
37      * Override of the get method so we can get visibility of custom TestResponse methods.
38      *
39      * @param string $uri
40      * @param array  $headers
41      *
42      * @return TestResponse
43      */
44     public function get($uri, array $headers = [])
45     {
46         return parent::get($uri, $headers);
47     }
48
49     /**
50      * Create the test response instance from the given response.
51      *
52      * @param \Illuminate\Http\Response $response
53      *
54      * @return TestResponse
55      */
56     protected function createTestResponse($response)
57     {
58         return TestResponse::fromBaseResponse($response);
59     }
60
61     /**
62      * Assert that an activity entry exists of the given key.
63      * Checks the activity belongs to the given entity if provided.
64      */
65     protected function assertActivityExists(string $type, ?Entity $entity = null, string $detail = '')
66     {
67         $detailsToCheck = ['type' => $type];
68
69         if ($entity) {
70             $detailsToCheck['entity_type'] = $entity->getMorphClass();
71             $detailsToCheck['entity_id'] = $entity->id;
72         }
73
74         if ($detail) {
75             $detailsToCheck['detail'] = $detail;
76         }
77
78         $this->assertDatabaseHas('activities', $detailsToCheck);
79     }
80 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.