]> BookStack Code Mirror - bookstack/blob - tests/TestCase.php
Added Popular books list with relevant tests
[bookstack] / tests / TestCase.php
1 <?php
2
3 use Illuminate\Foundation\Testing\DatabaseTransactions;
4
5 class TestCase extends Illuminate\Foundation\Testing\TestCase
6 {
7
8     use DatabaseTransactions;
9
10     /**
11      * The base URL to use while testing the application.
12      *
13      * @var string
14      */
15     protected $baseUrl = 'http://localhost';
16     private $admin;
17
18     /**
19      * Creates the application.
20      *
21      * @return \Illuminate\Foundation\Application
22      */
23     public function createApplication()
24     {
25         $app = require __DIR__.'/../bootstrap/app.php';
26
27         $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
28
29         return $app;
30     }
31
32     public function asAdmin()
33     {
34         if($this->admin === null) {
35             $this->admin = \BookStack\User::find(1);
36         }
37         return $this->actingAs($this->admin);
38     }
39
40     /**
41      * Quickly sets an array of settings.
42      * @param $settingsArray
43      */
44     protected function setSettings($settingsArray)
45     {
46         $settings = app('BookStack\Services\SettingService');
47         foreach ($settingsArray as $key => $value) {
48             $settings->put($key, $value);
49         }
50     }
51
52     /**
53      * Assert that a given string is seen inside an element.
54      *
55      * @param  bool|string|null $element
56      * @param  integer          $position
57      * @param  string           $text
58      * @param  bool             $negate
59      * @return $this
60      */
61     protected function seeInNthElement($element, $position, $text, $negate = false)
62     {
63         $method = $negate ? 'assertNotRegExp' : 'assertRegExp';
64
65         $rawPattern = preg_quote($text, '/');
66
67         $escapedPattern = preg_quote(e($text), '/');
68
69         $content = $this->crawler->filter($element)->eq($position)->html();
70
71         $pattern = $rawPattern == $escapedPattern
72             ? $rawPattern : "({$rawPattern}|{$escapedPattern})";
73
74         $this->$method("/$pattern/i", $content);
75
76         return $this;
77     }
78 }