]> BookStack Code Mirror - bookstack/blobdiff - tests/TestCase.php
Update settings.php
[bookstack] / tests / TestCase.php
index d52e991e31cd88103e74e145a7478871bccbf380..1f1d5ece7288e88575b49975848812bac5915173 100644 (file)
@@ -1,54 +1,67 @@
 <?php namespace Tests;
 
-use BookStack\Book;
-use BookStack\Chapter;
-use BookStack\Repos\EntityRepo;
-use BookStack\Role;
+use BookStack\Entities\Entity;
+use Illuminate\Foundation\Testing\DatabaseTransactions;
 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
 
 abstract class TestCase extends BaseTestCase
 {
     use CreatesApplication;
+    use DatabaseTransactions;
+    use SharedTestHelpers;
 
-    protected $admin;
+    /**
+     * The base URL to use while testing the application.
+     * @var string
+     */
+    protected $baseUrl = 'http://localhost';
 
     /**
-     * Set the current user context to be an admin.
+     * Assert the session contains a specific entry.
+     * @param string $key
      * @return $this
      */
-    public function asAdmin()
+    protected function assertSessionHas(string $key)
     {
-        return $this->actingAs($this->getAdmin());
+        $this->assertTrue(session()->has($key), "Session does not contain a [{$key}] entry");
+        return $this;
     }
 
     /**
-     * Get the current admin user.
-     * @return mixed
+     * Override of the get method so we can get visibility of custom TestResponse methods.
+     * @param  string  $uri
+     * @param  array  $headers
+     * @return TestResponse
      */
-    public function getAdmin() {
-        if($this->admin === null) {
-            $adminRole = Role::getSystemRole('admin');
-            $this->admin = $adminRole->users->first();
-        }
-        return $this->admin;
+    public function get($uri, array $headers = [])
+    {
+        return parent::get($uri, $headers);
     }
 
     /**
-     * Create and return a new book.
-     * @param array $input
-     * @return Book
+     * Create the test response instance from the given response.
+     *
+     * @param  \Illuminate\Http\Response $response
+     * @return TestResponse
      */
-    public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) {
-        return $this->app[EntityRepo::class]->createFromInput('book', $input, false);
+    protected function createTestResponse($response)
+    {
+        return TestResponse::fromBaseResponse($response);
     }
 
     /**
-     * Create and return a new test chapter
-     * @param array $input
-     * @param Book $book
-     * @return Chapter
+     * Assert that an activity entry exists of the given key.
+     * Checks the activity belongs to the given entity if provided.
      */
-    public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) {
-        return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book);
+    protected function assertActivityExists(string $key, Entity $entity = null)
+    {
+        $detailsToCheck = ['key' => $key];
+
+        if ($entity) {
+            $detailsToCheck['entity_type'] = $entity->getMorphClass();
+            $detailsToCheck['entity_id'] = $entity->id;
+        }
+
+        $this->assertDatabaseHas('activities', $detailsToCheck);
     }
 }
\ No newline at end of file