-<?php
+<?php namespace Tests;
use Illuminate\Foundation\Testing\DatabaseTransactions;
+use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
-class TestCase extends Illuminate\Foundation\Testing\TestCase
+abstract class TestCase extends BaseTestCase
{
-
+ use CreatesApplication;
use DatabaseTransactions;
+ use SharedTestHelpers;
/**
* The base URL to use while testing the application.
- *
* @var string
*/
protected $baseUrl = 'http://localhost';
- private $admin;
/**
- * Creates the application.
- *
- * @return \Illuminate\Foundation\Application
+ * Assert a permission error has occurred.
+ * @param TestResponse $response
+ * @return TestCase
*/
- public function createApplication()
+ protected function assertPermissionError(TestResponse $response)
{
- $app = require __DIR__.'/../bootstrap/app.php';
-
- $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
+ $response->assertRedirect('/');
+ $this->assertSessionHas('error');
+ session()->remove('error');
+ return $this;
+ }
- return $app;
+ /**
+ * Assert the session contains a specific entry.
+ * @param string $key
+ * @return $this
+ */
+ protected function assertSessionHas(string $key)
+ {
+ $this->assertTrue(session()->has($key), "Session does not contain a [{$key}] entry");
+ return $this;
}
- public function asAdmin()
+ /**
+ * Override of the get method so we can get visibility of custom TestResponse methods.
+ * @param string $uri
+ * @param array $headers
+ * @return TestResponse
+ */
+ public function get($uri, array $headers = [])
{
- if($this->admin === null) {
- $this->admin = \BookStack\User::find(1);
- }
- return $this->actingAs($this->admin);
+ return parent::get($uri, $headers);
}
/**
- * Quickly sets an array of settings.
- * @param $settingsArray
+ * Create the test response instance from the given response.
+ *
+ * @param \Illuminate\Http\Response $response
+ * @return TestResponse
*/
- protected function setSettings($settingsArray)
+ protected function createTestResponse($response)
{
- $settings = app('BookStack\Services\SettingService');
- foreach ($settingsArray as $key => $value) {
- $settings->put($key, $value);
- }
+ return TestResponse::fromBaseResponse($response);
}
-}
+}
\ No newline at end of file