mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-01-03 23:42:28 +03:00
Laravel 8 shift squash & merge (#3029)
* Temporarily moved back config path * Apply Laravel coding style * Shift exception handler * Shift HTTP kernel and middleware * Shift service providers * Convert options array to fluent methods * Shift to class based routes * Shift console routes * Ignore temporary framework files * Shift to class based factories * Namespace seeders * Shift PSR-4 autoloading * Shift config files * Default config files * Shift Laravel dependencies * Shift return type of base TestCase methods * Shift cleanup * Applied stylci style changes * Reverted config files location * Applied manual changes to Laravel 8 shift Co-authored-by: Shift <shift@laravelshift.com>
This commit is contained in:
@@ -37,7 +37,7 @@ class BookShelfTest extends TestCase
|
||||
|
||||
public function test_shelves_shows_in_header_if_have_any_shelve_view_permission()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$user = User::factory()->create();
|
||||
$this->giveUserPermissions($user, ['image-create-all']);
|
||||
$shelf = Bookshelf::first();
|
||||
$userRole = $user->roles()->first();
|
||||
|
||||
@@ -9,7 +9,7 @@ class BookTest extends TestCase
|
||||
{
|
||||
public function test_create()
|
||||
{
|
||||
$book = factory(Book::class)->make([
|
||||
$book = Book::factory()->make([
|
||||
'name' => 'My First Book',
|
||||
]);
|
||||
|
||||
@@ -29,7 +29,7 @@ class BookTest extends TestCase
|
||||
|
||||
public function test_create_uses_different_slugs_when_name_reused()
|
||||
{
|
||||
$book = factory(Book::class)->make([
|
||||
$book = Book::factory()->make([
|
||||
'name' => 'My First Book',
|
||||
]);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class ChapterTest extends TestCase
|
||||
/** @var Book $book */
|
||||
$book = Book::query()->first();
|
||||
|
||||
$chapter = factory(Chapter::class)->make([
|
||||
$chapter = Chapter::factory()->make([
|
||||
'name' => 'My First Chapter',
|
||||
]);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class CommentSettingTest extends TestCase
|
||||
{
|
||||
protected $page;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->page = Page::query()->first();
|
||||
|
||||
@@ -13,7 +13,7 @@ class CommentTest extends TestCase
|
||||
$this->asAdmin();
|
||||
$page = Page::first();
|
||||
|
||||
$comment = factory(Comment::class)->make(['parent_id' => 2]);
|
||||
$comment = Comment::factory()->make(['parent_id' => 2]);
|
||||
$resp = $this->postJson("/comment/$page->id", $comment->getAttributes());
|
||||
|
||||
$resp->assertStatus(200);
|
||||
@@ -36,7 +36,7 @@ class CommentTest extends TestCase
|
||||
$this->asAdmin();
|
||||
$page = Page::first();
|
||||
|
||||
$comment = factory(Comment::class)->make();
|
||||
$comment = Comment::factory()->make();
|
||||
$this->postJson("/comment/$page->id", $comment->getAttributes());
|
||||
|
||||
$comment = $page->comments()->first();
|
||||
@@ -60,7 +60,7 @@ class CommentTest extends TestCase
|
||||
$this->asAdmin();
|
||||
$page = Page::first();
|
||||
|
||||
$comment = factory(Comment::class)->make();
|
||||
$comment = Comment::factory()->make();
|
||||
$this->postJson("/comment/$page->id", $comment->getAttributes());
|
||||
|
||||
$comment = $page->comments()->first();
|
||||
|
||||
@@ -20,7 +20,7 @@ class PageDraftTest extends TestCase
|
||||
*/
|
||||
protected $pageRepo;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->page = Page::query()->first();
|
||||
|
||||
@@ -11,7 +11,7 @@ class PageEditorTest extends TestCase
|
||||
/** @var Page */
|
||||
protected $page;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->page = Page::query()->first();
|
||||
|
||||
@@ -14,7 +14,7 @@ class PageTest extends TestCase
|
||||
{
|
||||
/** @var Chapter $chapter */
|
||||
$chapter = Chapter::query()->first();
|
||||
$page = factory(Page::class)->make([
|
||||
$page = Page::factory()->make([
|
||||
'name' => 'My First Page',
|
||||
]);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class SortTest extends TestCase
|
||||
{
|
||||
protected $book;
|
||||
|
||||
public function setUp(): void
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->book = Book::first();
|
||||
|
||||
@@ -19,7 +19,7 @@ class TagTest extends TestCase
|
||||
$entity = $class::first();
|
||||
|
||||
if (is_null($tags)) {
|
||||
$tags = factory(Tag::class, $this->defaultTagCount)->make();
|
||||
$tags = Tag::factory()->count($this->defaultTagCount)->make();
|
||||
}
|
||||
|
||||
$entity->tags()->saveMany($tags);
|
||||
@@ -31,63 +31,63 @@ class TagTest extends TestCase
|
||||
{
|
||||
// Create some tags with similar names to test with
|
||||
$attrs = collect();
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'country']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'color']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'city']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'county']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'planet']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'plans']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'country']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'color']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'city']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'county']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'planet']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'plans']));
|
||||
$page = $this->getEntityWithTags(Page::class, $attrs->all());
|
||||
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=dog')->assertExactJson([]);
|
||||
$this->get('/ajax/tags/suggest/names?search=co')->assertExactJson(['color', 'country', 'county']);
|
||||
$this->get('/ajax/tags/suggest/names?search=cou')->assertExactJson(['country', 'county']);
|
||||
$this->get('/ajax/tags/suggest/names?search=pla')->assertExactJson(['planet', 'plans']);
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=dog')->assertSimilarJson([]);
|
||||
$this->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson(['color', 'country', 'county']);
|
||||
$this->get('/ajax/tags/suggest/names?search=cou')->assertSimilarJson(['country', 'county']);
|
||||
$this->get('/ajax/tags/suggest/names?search=pla')->assertSimilarJson(['planet', 'plans']);
|
||||
}
|
||||
|
||||
public function test_tag_value_suggestions()
|
||||
{
|
||||
// Create some tags with similar values to test with
|
||||
$attrs = collect();
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'country', 'value' => 'cats']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'color', 'value' => 'cattery']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'city', 'value' => 'castle']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'county', 'value' => 'dog']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'planet', 'value' => 'catapult']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'plans', 'value' => 'dodgy']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'country', 'value' => 'cats']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'color', 'value' => 'cattery']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'city', 'value' => 'castle']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'county', 'value' => 'dog']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'planet', 'value' => 'catapult']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'plans', 'value' => 'dodgy']));
|
||||
$page = $this->getEntityWithTags(Page::class, $attrs->all());
|
||||
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/values?search=ora')->assertExactJson([]);
|
||||
$this->get('/ajax/tags/suggest/values?search=cat')->assertExactJson(['cats', 'cattery', 'catapult']);
|
||||
$this->get('/ajax/tags/suggest/values?search=do')->assertExactJson(['dog', 'dodgy']);
|
||||
$this->get('/ajax/tags/suggest/values?search=cas')->assertExactJson(['castle']);
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/values?search=ora')->assertSimilarJson([]);
|
||||
$this->get('/ajax/tags/suggest/values?search=cat')->assertSimilarJson(['cats', 'cattery', 'catapult']);
|
||||
$this->get('/ajax/tags/suggest/values?search=do')->assertSimilarJson(['dog', 'dodgy']);
|
||||
$this->get('/ajax/tags/suggest/values?search=cas')->assertSimilarJson(['castle']);
|
||||
}
|
||||
|
||||
public function test_entity_permissions_effect_tag_suggestions()
|
||||
{
|
||||
// Create some tags with similar names to test with and save to a page
|
||||
$attrs = collect();
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'country']));
|
||||
$attrs = $attrs->merge(factory(Tag::class, 5)->make(['name' => 'color']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'country']));
|
||||
$attrs = $attrs->merge(Tag::factory()->count(5)->make(['name' => 'color']));
|
||||
$page = $this->getEntityWithTags(Page::class, $attrs->all());
|
||||
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->assertExactJson(['color', 'country']);
|
||||
$this->asEditor()->get('/ajax/tags/suggest/names?search=co')->assertExactJson(['color', 'country']);
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson(['color', 'country']);
|
||||
$this->asEditor()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson(['color', 'country']);
|
||||
|
||||
// Set restricted permission the page
|
||||
$page->restricted = true;
|
||||
$page->save();
|
||||
$page->rebuildPermissions();
|
||||
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->assertExactJson(['color', 'country']);
|
||||
$this->asEditor()->get('/ajax/tags/suggest/names?search=co')->assertExactJson([]);
|
||||
$this->asAdmin()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson(['color', 'country']);
|
||||
$this->asEditor()->get('/ajax/tags/suggest/names?search=co')->assertSimilarJson([]);
|
||||
}
|
||||
|
||||
public function test_tags_shown_on_search_listing()
|
||||
{
|
||||
$tags = [
|
||||
factory(Tag::class)->make(['name' => 'category', 'value' => 'buckets']),
|
||||
factory(Tag::class)->make(['name' => 'color', 'value' => 'red']),
|
||||
Tag::factory()->make(['name' => 'category', 'value' => 'buckets']),
|
||||
Tag::factory()->make(['name' => 'color', 'value' => 'red']),
|
||||
];
|
||||
|
||||
$page = $this->getEntityWithTags(Page::class, $tags);
|
||||
|
||||
Reference in New Issue
Block a user