mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-28 23:24:06 +08:00
Upgraded to Laravel 5.4
This commit is contained in:
parent
492e2f173e
commit
6669998c10
@ -3,9 +3,9 @@
|
|||||||
namespace BookStack\Exceptions;
|
namespace BookStack\Exceptions;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Validation\ValidationException;
|
use Illuminate\Auth\AuthenticationException;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||||
use PhpSpec\Exception\Example\ErrorException;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Illuminate\Auth\Access\AuthorizationException;
|
use Illuminate\Auth\Access\AuthorizationException;
|
||||||
|
@ -4,7 +4,7 @@ namespace BookStack\Http\Controllers;
|
|||||||
|
|
||||||
use BookStack\Ownable;
|
use BookStack\Ownable;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
use Illuminate\Http\Exception\HttpResponseException;
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller as BaseController;
|
use Illuminate\Routing\Controller as BaseController;
|
||||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||||
|
@ -6,17 +6,18 @@
|
|||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.6.4",
|
"php": ">=5.6.4",
|
||||||
"laravel/framework": "^5.3.4",
|
"laravel/framework": "5.4.*",
|
||||||
"ext-tidy": "*",
|
"ext-tidy": "*",
|
||||||
"intervention/image": "^2.3",
|
"intervention/image": "^2.3",
|
||||||
"laravel/socialite": "^2.0",
|
"laravel/socialite": "^3.0",
|
||||||
"barryvdh/laravel-ide-helper": "^2.1",
|
"barryvdh/laravel-ide-helper": "^2.2.3",
|
||||||
"barryvdh/laravel-debugbar": "^2.2.3",
|
"barryvdh/laravel-debugbar": "^2.3.2",
|
||||||
"league/flysystem-aws-s3-v3": "^1.0",
|
"league/flysystem-aws-s3-v3": "^1.0",
|
||||||
"barryvdh/laravel-dompdf": "^0.7",
|
"barryvdh/laravel-dompdf": "^0.7",
|
||||||
"predis/predis": "^1.1",
|
"predis/predis": "^1.1",
|
||||||
"gathercontent/htmldiff": "^0.2.1",
|
"gathercontent/htmldiff": "^0.2.1",
|
||||||
"barryvdh/laravel-snappy": "^0.3.1"
|
"barryvdh/laravel-snappy": "^0.3.1",
|
||||||
|
"laravel/browser-kit-testing": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fzaninotto/faker": "~1.4",
|
"fzaninotto/faker": "~1.4",
|
||||||
@ -35,7 +36,8 @@
|
|||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"tests/TestCase.php"
|
"tests/TestCase.php",
|
||||||
|
"tests/BrowserKitTest.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
1510
composer.lock
generated
1510
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
|
|
||||||
class ActivityTrackingTest extends TestCase
|
class ActivityTrackingTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_recently_viewed_books()
|
public function test_recently_viewed_books()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class AttachmentTest extends TestCase
|
class AttachmentTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get a test file that can be uploaded
|
* Get a test file that can be uploaded
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use BookStack\Notifications\ConfirmEmail;
|
use BookStack\Notifications\ConfirmEmail;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
|
||||||
class AuthTest extends TestCase
|
class AuthTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_auth_working()
|
public function test_auth_working()
|
||||||
@ -220,6 +220,9 @@ class AuthTest extends TestCase
|
|||||||
|
|
||||||
public function test_reset_password_flow()
|
public function test_reset_password_flow()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
$this->visit('/login')->click('Forgot Password?')
|
$this->visit('/login')->click('Forgot Password?')
|
||||||
->seePageIs('/password/email')
|
->seePageIs('/password/email')
|
||||||
->type('admin@admin.com', 'email')
|
->type('admin@admin.com', 'email')
|
||||||
@ -230,8 +233,13 @@ class AuthTest extends TestCase
|
|||||||
'email' => 'admin@admin.com'
|
'email' => 'admin@admin.com'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$user = \BookStack\User::where('email', '=', 'admin@admin.com')->first();
|
||||||
|
|
||||||
|
Notification::assertSentTo($user, \BookStack\Notifications\ResetPassword::class);
|
||||||
|
$n = Notification::sent($user, \BookStack\Notifications\ResetPassword::class);
|
||||||
|
|
||||||
$reset = DB::table('password_resets')->where('email', '=', 'admin@admin.com')->first();
|
$reset = DB::table('password_resets')->where('email', '=', 'admin@admin.com')->first();
|
||||||
$this->visit('/password/reset/' . $reset->token)
|
$this->visit('/password/reset/' . $n->first()->token)
|
||||||
->see('Reset Password')
|
->see('Reset Password')
|
||||||
->submitForm('Reset Password', [
|
->submitForm('Reset Password', [
|
||||||
'email' => 'admin@admin.com',
|
'email' => 'admin@admin.com',
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use BookStack\Services\LdapService;
|
|
||||||
use BookStack\User;
|
use BookStack\User;
|
||||||
|
|
||||||
class LdapTest extends \TestCase
|
class LdapTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $mockLdap;
|
protected $mockLdap;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SocialAuthTest extends TestCase
|
class SocialAuthTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_social_registration()
|
public function test_social_registration()
|
||||||
|
234
tests/BrowserKitTest.php
Normal file
234
tests/BrowserKitTest.php
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
abstract class BrowserKitTest extends \Laravel\BrowserKitTesting\TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base URL to use while testing the application.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $baseUrl = 'http://localhost';
|
||||||
|
|
||||||
|
// Local user instances
|
||||||
|
private $admin;
|
||||||
|
private $editor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the application.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Foundation\Application
|
||||||
|
*/
|
||||||
|
public function createApplication()
|
||||||
|
{
|
||||||
|
$app = require __DIR__.'/../bootstrap/app.php';
|
||||||
|
|
||||||
|
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
||||||
|
|
||||||
|
return $app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current user context to be an admin.
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function asAdmin()
|
||||||
|
{
|
||||||
|
return $this->actingAs($this->getAdmin());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current admin user.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getAdmin() {
|
||||||
|
if($this->admin === null) {
|
||||||
|
$adminRole = \BookStack\Role::getRole('admin');
|
||||||
|
$this->admin = $adminRole->users->first();
|
||||||
|
}
|
||||||
|
return $this->admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current editor context to be an editor.
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function asEditor()
|
||||||
|
{
|
||||||
|
if ($this->editor === null) {
|
||||||
|
$this->editor = $this->getEditor();
|
||||||
|
}
|
||||||
|
return $this->actingAs($this->editor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user that's not a system user such as the guest user.
|
||||||
|
*/
|
||||||
|
public function getNormalUser()
|
||||||
|
{
|
||||||
|
return \BookStack\User::where('system_name', '=', null)->get()->last();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quickly sets an array of settings.
|
||||||
|
* @param $settingsArray
|
||||||
|
*/
|
||||||
|
protected function setSettings($settingsArray)
|
||||||
|
{
|
||||||
|
$settings = app('BookStack\Services\SettingService');
|
||||||
|
foreach ($settingsArray as $key => $value) {
|
||||||
|
$settings->put($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a group of entities that belong to a specific user.
|
||||||
|
* @param $creatorUser
|
||||||
|
* @param $updaterUser
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function createEntityChainBelongingToUser($creatorUser, $updaterUser = false)
|
||||||
|
{
|
||||||
|
if ($updaterUser === false) $updaterUser = $creatorUser;
|
||||||
|
$book = factory(BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
|
||||||
|
$chapter = factory(BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
|
||||||
|
$page = factory(BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]);
|
||||||
|
$book->chapters()->saveMany([$chapter]);
|
||||||
|
$chapter->pages()->saveMany([$page]);
|
||||||
|
$restrictionService = $this->app[\BookStack\Services\PermissionService::class];
|
||||||
|
$restrictionService->buildJointPermissionsForEntity($book);
|
||||||
|
return [
|
||||||
|
'book' => $book,
|
||||||
|
'chapter' => $chapter,
|
||||||
|
'page' => $page
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick way to create a new user
|
||||||
|
* @param array $attributes
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getEditor($attributes = [])
|
||||||
|
{
|
||||||
|
$user = factory(\BookStack\User::class)->create($attributes);
|
||||||
|
$role = \BookStack\Role::getRole('editor');
|
||||||
|
$user->attachRole($role);;
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick way to create a new user without any permissions
|
||||||
|
* @param array $attributes
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getNewBlankUser($attributes = [])
|
||||||
|
{
|
||||||
|
$user = factory(\BookStack\User::class)->create($attributes);
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the current page matches a given URI.
|
||||||
|
*
|
||||||
|
* @param string $uri
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function seePageUrlIs($uri)
|
||||||
|
{
|
||||||
|
$this->assertEquals(
|
||||||
|
$uri, $this->currentUri, "Did not land on expected page [{$uri}].\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do a forced visit that does not error out on exception.
|
||||||
|
* @param string $uri
|
||||||
|
* @param array $parameters
|
||||||
|
* @param array $cookies
|
||||||
|
* @param array $files
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function forceVisit($uri, $parameters = [], $cookies = [], $files = [])
|
||||||
|
{
|
||||||
|
$method = 'GET';
|
||||||
|
$uri = $this->prepareUrlForRequest($uri);
|
||||||
|
$this->call($method, $uri, $parameters, $cookies, $files);
|
||||||
|
$this->clearInputs()->followRedirects();
|
||||||
|
$this->currentUri = $this->app->make('request')->fullUrl();
|
||||||
|
$this->crawler = new Crawler($this->response->getContent(), $uri);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Click the text within the selected element.
|
||||||
|
* @param $parentElement
|
||||||
|
* @param $linkText
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function clickInElement($parentElement, $linkText)
|
||||||
|
{
|
||||||
|
$elem = $this->crawler->filter($parentElement);
|
||||||
|
$link = $elem->selectLink($linkText);
|
||||||
|
$this->visit($link->link()->getUri());
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the page contains the given element.
|
||||||
|
* @param string $selector
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function pageHasElement($selector)
|
||||||
|
{
|
||||||
|
$elements = $this->crawler->filter($selector);
|
||||||
|
$this->assertTrue(count($elements) > 0, "The page does not contain an element matching " . $selector);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the page contains the given element.
|
||||||
|
* @param string $selector
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function pageNotHasElement($selector)
|
||||||
|
{
|
||||||
|
$elements = $this->crawler->filter($selector);
|
||||||
|
$this->assertFalse(count($elements) > 0, "The page contains " . count($elements) . " elements matching " . $selector);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
class EntitySearchTest extends BrowserKitTest
|
||||||
|
|
||||||
class EntitySearchTest extends TestCase
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_page_search()
|
public function test_page_search()
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
class EntityTest extends BrowserKitTest
|
||||||
|
|
||||||
class EntityTest extends TestCase
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_entity_creation()
|
public function test_entity_creation()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
class MarkdownTest extends BrowserKitTest
|
||||||
class MarkdownTest extends TestCase
|
|
||||||
{
|
{
|
||||||
protected $page;
|
protected $page;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class PageContentTest extends TestCase
|
class PageContentTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_page_includes()
|
public function test_page_includes()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
class PageDraftTest extends TestCase
|
class PageDraftTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
protected $page;
|
protected $page;
|
||||||
protected $entityRepo;
|
protected $entityRepo;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class SortTest extends TestCase
|
class SortTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
protected $book;
|
protected $book;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<?php namespace Entity;
|
<?php
|
||||||
|
|
||||||
use BookStack\Tag;
|
use BookStack\Tag;
|
||||||
use BookStack\Page;
|
use BookStack\Page;
|
||||||
use BookStack\Services\PermissionService;
|
use BookStack\Services\PermissionService;
|
||||||
|
|
||||||
class TagTest extends \TestCase
|
class TagTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $defaultTagCount = 20;
|
protected $defaultTagCount = 20;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ImageTest extends TestCase
|
class ImageTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class RestrictionsTest extends TestCase
|
class RestrictionsTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $viewer;
|
protected $viewer;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class RolesTest extends TestCase
|
class RolesTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class PublicActionTest extends TestCase
|
class PublicActionTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
|
|
||||||
public function test_app_not_public()
|
public function test_app_not_public()
|
||||||
|
@ -9,15 +9,11 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
use DatabaseTransactions;
|
use DatabaseTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base URL to use while testing the application.
|
* The base URL of the application.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $baseUrl = 'http://localhost';
|
public $baseUrl = 'http://localhost';
|
||||||
|
|
||||||
// Local user instances
|
|
||||||
private $admin;
|
|
||||||
private $editor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the application.
|
* Creates the application.
|
||||||
@ -28,207 +24,8 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
{
|
{
|
||||||
$app = require __DIR__.'/../bootstrap/app.php';
|
$app = require __DIR__.'/../bootstrap/app.php';
|
||||||
|
|
||||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
$app->make(Kernel::class)->bootstrap();
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the current user context to be an admin.
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function asAdmin()
|
|
||||||
{
|
|
||||||
return $this->actingAs($this->getAdmin());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current admin user.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getAdmin() {
|
|
||||||
if($this->admin === null) {
|
|
||||||
$adminRole = \BookStack\Role::getRole('admin');
|
|
||||||
$this->admin = $adminRole->users->first();
|
|
||||||
}
|
|
||||||
return $this->admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the current editor context to be an editor.
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function asEditor()
|
|
||||||
{
|
|
||||||
if ($this->editor === null) {
|
|
||||||
$this->editor = $this->getEditor();
|
|
||||||
}
|
|
||||||
return $this->actingAs($this->editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a user that's not a system user such as the guest user.
|
|
||||||
*/
|
|
||||||
public function getNormalUser()
|
|
||||||
{
|
|
||||||
return \BookStack\User::where('system_name', '=', null)->get()->last();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quickly sets an array of settings.
|
|
||||||
* @param $settingsArray
|
|
||||||
*/
|
|
||||||
protected function setSettings($settingsArray)
|
|
||||||
{
|
|
||||||
$settings = app('BookStack\Services\SettingService');
|
|
||||||
foreach ($settingsArray as $key => $value) {
|
|
||||||
$settings->put($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a group of entities that belong to a specific user.
|
|
||||||
* @param $creatorUser
|
|
||||||
* @param $updaterUser
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function createEntityChainBelongingToUser($creatorUser, $updaterUser = false)
|
|
||||||
{
|
|
||||||
if ($updaterUser === false) $updaterUser = $creatorUser;
|
|
||||||
$book = factory(BookStack\Book::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
|
|
||||||
$chapter = factory(BookStack\Chapter::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id]);
|
|
||||||
$page = factory(BookStack\Page::class)->create(['created_by' => $creatorUser->id, 'updated_by' => $updaterUser->id, 'book_id' => $book->id]);
|
|
||||||
$book->chapters()->saveMany([$chapter]);
|
|
||||||
$chapter->pages()->saveMany([$page]);
|
|
||||||
$restrictionService = $this->app[\BookStack\Services\PermissionService::class];
|
|
||||||
$restrictionService->buildJointPermissionsForEntity($book);
|
|
||||||
return [
|
|
||||||
'book' => $book,
|
|
||||||
'chapter' => $chapter,
|
|
||||||
'page' => $page
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quick way to create a new user
|
|
||||||
* @param array $attributes
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function getEditor($attributes = [])
|
|
||||||
{
|
|
||||||
$user = factory(\BookStack\User::class)->create($attributes);
|
|
||||||
$role = \BookStack\Role::getRole('editor');
|
|
||||||
$user->attachRole($role);;
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Quick way to create a new user without any permissions
|
|
||||||
* @param array $attributes
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
protected function getNewBlankUser($attributes = [])
|
|
||||||
{
|
|
||||||
$user = factory(\BookStack\User::class)->create($attributes);
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assert that the current page matches a given URI.
|
|
||||||
*
|
|
||||||
* @param string $uri
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
protected function seePageUrlIs($uri)
|
|
||||||
{
|
|
||||||
$this->assertEquals(
|
|
||||||
$uri, $this->currentUri, "Did not land on expected page [{$uri}].\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Do a forced visit that does not error out on exception.
|
|
||||||
* @param string $uri
|
|
||||||
* @param array $parameters
|
|
||||||
* @param array $cookies
|
|
||||||
* @param array $files
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
protected function forceVisit($uri, $parameters = [], $cookies = [], $files = [])
|
|
||||||
{
|
|
||||||
$method = 'GET';
|
|
||||||
$uri = $this->prepareUrlForRequest($uri);
|
|
||||||
$this->call($method, $uri, $parameters, $cookies, $files);
|
|
||||||
$this->clearInputs()->followRedirects();
|
|
||||||
$this->currentUri = $this->app->make('request')->fullUrl();
|
|
||||||
$this->crawler = new Crawler($this->response->getContent(), $uri);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Click the text within the selected element.
|
|
||||||
* @param $parentElement
|
|
||||||
* @param $linkText
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
protected function clickInElement($parentElement, $linkText)
|
|
||||||
{
|
|
||||||
$elem = $this->crawler->filter($parentElement);
|
|
||||||
$link = $elem->selectLink($linkText);
|
|
||||||
$this->visit($link->link()->getUri());
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the page contains the given element.
|
|
||||||
* @param string $selector
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function pageHasElement($selector)
|
|
||||||
{
|
|
||||||
$elements = $this->crawler->filter($selector);
|
|
||||||
$this->assertTrue(count($elements) > 0, "The page does not contain an element matching " . $selector);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the page contains the given element.
|
|
||||||
* @param string $selector
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function pageNotHasElement($selector)
|
|
||||||
{
|
|
||||||
$elements = $this->crawler->filter($selector);
|
|
||||||
$this->assertFalse(count($elements) > 0, "The page contains " . count($elements) . " elements matching " . $selector);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class UserProfileTest extends TestCase
|
class UserProfileTest extends BrowserKitTest
|
||||||
{
|
{
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user