X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/f1c2866fbc24ec6e951071c4886cfa8beee62e29..refs/pull/325/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index 3a0967c8e..d64aef3db 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,78 +1,56 @@ -make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); - - return $app; + return $this->actingAs($this->getAdmin()); } - public function asAdmin() - { + /** + * Get the current admin user. + * @return mixed + */ + public function getAdmin() { if($this->admin === null) { - $this->admin = \BookStack\User::find(1); + $adminRole = Role::getSystemRole('admin'); + $this->admin = $adminRole->users->first(); } - return $this->actingAs($this->admin); + return $this->admin; } /** - * Quickly sets an array of settings. - * @param $settingsArray + * Create and return a new book. + * @param array $input + * @return Book */ - protected function setSettings($settingsArray) - { - $settings = app('BookStack\Services\SettingService'); - foreach ($settingsArray as $key => $value) { - $settings->put($key, $value); - } + public function newBook($input = ['name' => 'test book', 'description' => 'My new test book']) { + return $this->app[EntityRepo::class]->createFromInput('book', $input, false); } /** - * Assert that a given string is seen inside an element. - * - * @param bool|string|null $element - * @param integer $position - * @param string $text - * @param bool $negate - * @return $this + * Create and return a new test chapter + * @param array $input + * @param Book $book + * @return Chapter */ - protected function seeInNthElement($element, $position, $text, $negate = false) - { - $method = $negate ? 'assertNotRegExp' : 'assertRegExp'; - - $rawPattern = preg_quote($text, '/'); - - $escapedPattern = preg_quote(e($text), '/'); - - $content = $this->crawler->filter($element)->eq($position)->html(); - - $pattern = $rawPattern == $escapedPattern - ? $rawPattern : "({$rawPattern}|{$escapedPattern})"; - - $this->$method("/$pattern/i", $content); - - return $this; + public function newChapter($input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book) { + return $this->app[EntityRepo::class]->createFromInput('chapter', $input, $book); } -} +} \ No newline at end of file