1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00

Merge branch 'laravel_upgrade'

This commit is contained in:
Dan Brown
2021-11-04 22:42:35 +00:00
308 changed files with 3347 additions and 2831 deletions

View File

@@ -325,6 +325,6 @@ class AttachmentsApiTest extends TestCase
*/
protected function getTestFile(string $fileName): UploadedFile
{
return new UploadedFile(base_path('tests/test-data/test-file.txt'), $fileName, 'text/plain', 55, null, true);
return new UploadedFile(base_path('tests/test-data/test-file.txt'), $fileName, 'text/plain', null, true);
}
}

View File

@@ -17,7 +17,7 @@ class AuditLogTest extends TestCase
/** @var ActivityService */
protected $activityService;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->activityService = app(ActivityService::class);

View File

@@ -44,7 +44,7 @@ class AuthTest extends TestCase
{
// Set settings and get user instance
$this->setSettings(['registration-enabled' => 'true']);
$user = factory(User::class)->make();
$user = User::factory()->make();
// Test form and ensure user is created
$this->get('/register')
@@ -102,7 +102,7 @@ class AuthTest extends TestCase
// Set settings and get user instance
$this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true']);
$user = factory(User::class)->make();
$user = User::factory()->make();
// Go through registration process
$resp = $this->post('/register', $user->only('name', 'email', 'password'));
@@ -140,7 +140,7 @@ class AuthTest extends TestCase
public function test_restricted_registration()
{
$this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true', 'registration-restrict' => 'example.com']);
$user = factory(User::class)->make();
$user = User::factory()->make();
// Go through registration process
$this->post('/register', $user->only('name', 'email', 'password'))
@@ -166,7 +166,7 @@ class AuthTest extends TestCase
public function test_restricted_registration_with_confirmation_disabled()
{
$this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'false', 'registration-restrict' => 'example.com']);
$user = factory(User::class)->make();
$user = User::factory()->make();
// Go through registration process
$this->post('/register', $user->only('name', 'email', 'password'))

View File

@@ -20,7 +20,7 @@ class LdapTest extends TestCase
protected $mockUser;
protected $resourceId = 'resource-test';
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
if (!defined('LDAP_OPT_REFERRALS')) {
@@ -42,7 +42,7 @@ class LdapTest extends TestCase
]);
$this->mockLdap = \Mockery::mock(Ldap::class);
$this->app[Ldap::class] = $this->mockLdap;
$this->mockUser = factory(User::class)->make();
$this->mockUser = User::factory()->make();
}
protected function runFailedAuthLogin()
@@ -264,9 +264,9 @@ class LdapTest extends TestCase
public function test_login_maps_roles_and_retains_existing_roles()
{
$roleToReceive = factory(Role::class)->create(['display_name' => 'LdapTester']);
$roleToReceive2 = factory(Role::class)->create(['display_name' => 'LdapTester Second']);
$existingRole = factory(Role::class)->create(['display_name' => 'ldaptester-existing']);
$roleToReceive = Role::factory()->create(['display_name' => 'LdapTester']);
$roleToReceive2 = Role::factory()->create(['display_name' => 'LdapTester Second']);
$existingRole = Role::factory()->create(['display_name' => 'ldaptester-existing']);
$this->mockUser->forceFill(['external_auth_id' => $this->mockUser->name])->save();
$this->mockUser->attachRole($existingRole);
@@ -310,8 +310,8 @@ class LdapTest extends TestCase
public function test_login_maps_roles_and_removes_old_roles_if_set()
{
$roleToReceive = factory(Role::class)->create(['display_name' => 'LdapTester']);
$existingRole = factory(Role::class)->create(['display_name' => 'ldaptester-existing']);
$roleToReceive = Role::factory()->create(['display_name' => 'LdapTester']);
$existingRole = Role::factory()->create(['display_name' => 'ldaptester-existing']);
$this->mockUser->forceFill(['external_auth_id' => $this->mockUser->name])->save();
$this->mockUser->attachRole($existingRole);
@@ -350,15 +350,15 @@ class LdapTest extends TestCase
public function test_external_auth_id_visible_in_roles_page_when_ldap_active()
{
$role = factory(Role::class)->create(['display_name' => 'ldaptester', 'external_auth_id' => 'ex-auth-a, test-second-param']);
$role = Role::factory()->create(['display_name' => 'ldaptester', 'external_auth_id' => 'ex-auth-a, test-second-param']);
$this->asAdmin()->get('/settings/roles/' . $role->id)
->assertSee('ex-auth-a');
}
public function test_login_maps_roles_using_external_auth_ids_if_set()
{
$roleToReceive = factory(Role::class)->create(['display_name' => 'ldaptester', 'external_auth_id' => 'test-second-param, ex-auth-a']);
$roleToNotReceive = factory(Role::class)->create(['display_name' => 'ex-auth-a', 'external_auth_id' => 'test-second-param']);
$roleToReceive = Role::factory()->create(['display_name' => 'ldaptester', 'external_auth_id' => 'test-second-param, ex-auth-a']);
$roleToNotReceive = Role::factory()->create(['display_name' => 'ex-auth-a', 'external_auth_id' => 'test-second-param']);
app('config')->set([
'services.ldap.user_to_groups' => true,
@@ -395,8 +395,8 @@ class LdapTest extends TestCase
public function test_login_group_mapping_does_not_conflict_with_default_role()
{
$roleToReceive = factory(Role::class)->create(['display_name' => 'LdapTester']);
$roleToReceive2 = factory(Role::class)->create(['display_name' => 'LdapTester Second']);
$roleToReceive = Role::factory()->create(['display_name' => 'LdapTester']);
$roleToReceive2 = Role::factory()->create(['display_name' => 'LdapTester Second']);
$this->mockUser->forceFill(['external_auth_id' => $this->mockUser->name])->save();
setting()->put('registration-role', $roleToReceive->id);
@@ -641,8 +641,8 @@ class LdapTest extends TestCase
public function test_login_with_email_confirmation_required_maps_groups_but_shows_confirmation_screen()
{
$roleToReceive = factory(Role::class)->create(['display_name' => 'LdapTester']);
$user = factory(User::class)->make();
$roleToReceive = Role::factory()->create(['display_name' => 'LdapTester']);
$user = User::factory()->make();
setting()->put('registration-confirmation', 'true');
app('config')->set([

View File

@@ -39,7 +39,7 @@ class MfaConfigurationTest extends TestCase
$this->assertTrue($svg === $revisitSvg);
$secret = decrypt(session()->get('mfa-setup-totp-secret'));
$resp->assertSee(htmlentities("?secret={$secret}&issuer=BookStack&algorithm=SHA1&digits=6&period=30"));
$resp->assertSee("?secret={$secret}&issuer=BookStack&algorithm=SHA1&digits=6&period=30");
// Successful confirmation
$google2fa = new Google2FA();
@@ -180,7 +180,7 @@ class MfaConfigurationTest extends TestCase
$resp = $this->get('/mfa/totp/generate');
$resp->assertSeeText('Mobile App Setup');
$resp->assertDontSee('otpauth://totp/BookStack:guest%40example.com');
$resp->assertSee('otpauth://totp/BookStack:admin%40admin.com');
$resp->assertDontSee('otpauth://totp/BookStack:guest%40example.com', false);
$resp->assertSee('otpauth://totp/BookStack:admin%40admin.com', false);
}
}

View File

@@ -16,7 +16,7 @@ class OidcTest extends TestCase
protected $keyFilePath;
protected $keyFile;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
// Set default config for OpenID Connect
@@ -41,7 +41,7 @@ class OidcTest extends TestCase
]);
}
public function tearDown(): void
protected function tearDown(): void
{
parent::tearDown();
if (file_exists($this->keyFilePath)) {

View File

@@ -8,7 +8,7 @@ use Tests\TestCase;
class Saml2Test extends TestCase
{
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
// Set default config for SAML2
@@ -49,7 +49,7 @@ class Saml2Test extends TestCase
$req = $this->get('/saml2/metadata');
$req->assertSee('https://example.com/super-cats');
$req->assertSee('md:ContactPerson');
$req->assertSee('<md:GivenName>Barry Scott</md:GivenName>');
$req->assertSee('<md:GivenName>Barry Scott</md:GivenName>', false);
}
public function test_login_option_shows_on_login_page()
@@ -119,7 +119,7 @@ class Saml2Test extends TestCase
'saml2.remove_from_groups' => false,
]);
$memberRole = factory(Role::class)->create(['external_auth_id' => 'member']);
$memberRole = Role::factory()->create(['external_auth_id' => 'member']);
$adminRole = Role::getSystemRole('admin');
$this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
@@ -141,7 +141,7 @@ class Saml2Test extends TestCase
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);
$user = User::query()->where('external_auth_id', '=', 'user')->first();
$randomRole = factory(Role::class)->create(['external_auth_id' => 'random']);
$randomRole = Role::factory()->create(['external_auth_id' => 'random']);
$user->attachRole($randomRole);
$this->assertContains($randomRole->id, $user->roles()->pluck('id'));
@@ -295,7 +295,7 @@ class Saml2Test extends TestCase
'saml2.remove_from_groups' => false,
]);
$memberRole = factory(Role::class)->create(['external_auth_id' => 'member']);
$memberRole = Role::factory()->create(['external_auth_id' => 'member']);
$adminRole = Role::getSystemRole('admin');
$acsPost = $this->followingRedirects()->post('/saml2/acs', ['SAMLResponse' => $this->acsPostData]);

View File

@@ -15,7 +15,7 @@ class SocialAuthTest extends TestCase
{
public function test_social_registration()
{
$user = factory(User::class)->make();
$user = User::factory()->make();
$this->setSettings(['registration-enabled' => 'true']);
config(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
@@ -118,7 +118,7 @@ class SocialAuthTest extends TestCase
'APP_URL' => 'http://localhost',
]);
$user = factory(User::class)->make();
$user = User::factory()->make();
$mockSocialite = $this->mock(Factory::class);
$mockSocialDriver = Mockery::mock(Provider::class);
$mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
@@ -156,7 +156,7 @@ class SocialAuthTest extends TestCase
'APP_URL' => 'http://localhost', 'services.google.auto_register' => true, 'services.google.auto_confirm' => true,
]);
$user = factory(User::class)->make();
$user = User::factory()->make();
$mockSocialite = $this->mock(Factory::class);
$mockSocialDriver = Mockery::mock(Provider::class);
$mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
@@ -188,7 +188,7 @@ class SocialAuthTest extends TestCase
public function test_social_registration_with_no_name_uses_email_as_name()
{
$user = factory(User::class)->make(['email' => 'nonameuser@example.com']);
$user = User::factory()->make(['email' => 'nonameuser@example.com']);
$this->setSettings(['registration-enabled' => 'true']);
config(['GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);

View File

@@ -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();
@@ -290,7 +290,7 @@ class BookShelfTest extends TestCase
$shelf = Bookshelf::first();
$resp = $this->asAdmin()->get($shelf->getUrl('/permissions'));
$resp->assertSeeText('Copy Permissions');
$resp->assertSee("action=\"{$shelf->getUrl('/copy-permissions')}\"");
$resp->assertSee("action=\"{$shelf->getUrl('/copy-permissions')}\"", false);
$child = $shelf->books()->first();
$editorRole = $this->getEditor()->roles()->first();

View File

@@ -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',
]);
@@ -187,7 +187,7 @@ class BookTest extends TestCase
'name' => 'информация',
]);
$this->assertEquals('informatsiya', $book->slug);
$this->assertEquals('informaciya', $book->slug);
$book = $this->newBook([
'name' => '¿Qué?',

View File

@@ -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',
]);

View File

@@ -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();

View File

@@ -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();
@@ -88,7 +88,7 @@ class CommentTest extends TestCase
]);
$pageView = $this->get($page->getUrl());
$pageView->assertSee('<h1>My Title</h1>');
$pageView->assertSee('<h1>My Title</h1>', false);
}
public function test_html_cannot_be_injected_via_comment_content()
@@ -102,7 +102,7 @@ class CommentTest extends TestCase
]);
$pageView = $this->get($page->getUrl());
$pageView->assertDontSee($script);
$pageView->assertDontSee($script, false);
$pageView->assertSee('sometextinthecomment');
$comment = $page->comments()->first();
@@ -111,7 +111,7 @@ class CommentTest extends TestCase
]);
$pageView = $this->get($page->getUrl());
$pageView->assertDontSee($script);
$pageView->assertDontSee($script, false);
$pageView->assertSee('sometextinthecommentupdated');
}
}

View File

@@ -139,7 +139,7 @@ class ExportTest extends TestCase
$this->setSettings(['app-custom-head' => $customHeadContent]);
$resp = $this->asEditor()->get($page->getUrl('/export/html'));
$resp->assertSee($customHeadContent);
$resp->assertSee($customHeadContent, false);
}
public function test_page_html_export_does_not_break_with_only_comments_in_custom_head()
@@ -151,7 +151,7 @@ class ExportTest extends TestCase
$resp = $this->asEditor()->get($page->getUrl('/export/html'));
$resp->assertStatus(200);
$resp->assertSee($customHeadContent);
$resp->assertSee($customHeadContent, false);
}
public function test_page_html_export_use_absolute_dates()
@@ -188,7 +188,7 @@ class ExportTest extends TestCase
Storage::disk('local')->delete('uploads/images/gallery/svg_test.svg');
$resp->assertStatus(200);
$resp->assertSee('<img src="data:image/svg+xml;base64');
$resp->assertSee('<img src="data:image/svg+xml;base64', false);
}
public function test_page_image_containment_works_on_multiple_images_within_a_single_line()
@@ -224,9 +224,9 @@ class ExportTest extends TestCase
$storageDisk->delete('uploads/images/gallery/svg_test.svg');
$storageDisk->delete('uploads/svg_test.svg');
$resp->assertDontSee('http://localhost/uploads/images/gallery/svg_test.svg');
$resp->assertDontSee('http://localhost/uploads/images/gallery/svg_test.svg', false);
$resp->assertSee('http://localhost/uploads/svg_test.svg');
$resp->assertSee('src="/uploads/svg_test.svg"');
$resp->assertSee('src="/uploads/svg_test.svg"', false);
}
public function test_page_export_contained_html_does_not_allow_upward_traversal_with_local()
@@ -333,7 +333,7 @@ class ExportTest extends TestCase
$page->save();
$resp = $this->asEditor()->get($page->getUrl('/export/markdown'));
$resp->assertSee("# Dogcat\n\n<p class=\"callout info\">Some callout text</p>\n\nAnother line");
$resp->assertSee("# Dogcat\n\n<p class=\"callout info\">Some callout text</p>\n\nAnother line", false);
}
public function test_page_markdown_export_handles_bookstacks_wysiwyg_codeblock_format()
@@ -345,7 +345,7 @@ class ExportTest extends TestCase
$page->save();
$resp = $this->asEditor()->get($page->getUrl('/export/markdown'));
$resp->assertSee("# Dogcat\n\n```JavaScript\nvar a = 'cat';\n```\n\nAnother line");
$resp->assertSee("# Dogcat\n\n```JavaScript\nvar a = 'cat';\n```\n\nAnother line", false);
}
public function test_chapter_markdown_export()

View File

@@ -74,7 +74,7 @@ class PageContentTest extends TestCase
$this->asEditor();
$pageResp = $this->get($page->getUrl());
$pageResp->assertSee($content);
$pageResp->assertSee($content, false);
}
public function test_page_includes_rendered_on_book_export()
@@ -106,7 +106,7 @@ class PageContentTest extends TestCase
$pageView = $this->get($page->getUrl());
$pageView->assertStatus(200);
$pageView->assertDontSee($script);
$pageView->assertDontSee($script, false);
$pageView->assertSee('abc123abc123');
}
@@ -260,8 +260,8 @@ class PageContentTest extends TestCase
$pageView = $this->get($page->getUrl());
$pageView->assertStatus(200);
$pageView->assertDontSee($script);
$pageView->assertSee('<p>Hello</p>');
$pageView->assertDontSee($script, false);
$pageView->assertSee('<p>Hello</p>', false);
}
public function test_more_complex_inline_on_attributes_escaping_scenarios()
@@ -301,7 +301,7 @@ class PageContentTest extends TestCase
$page->save();
$pageView = $this->get($page->getUrl());
$pageView->assertSee($script);
$pageView->assertSee($script, false);
$pageView->assertDontSee('abc123abc123');
}
@@ -338,8 +338,8 @@ class PageContentTest extends TestCase
$page->save();
$pageView = $this->get($page->getUrl());
$pageView->assertSee($script);
$pageView->assertDontSee('<p>Hello</p>');
$pageView->assertSee($script, false);
$pageView->assertDontSee('<p>Hello</p>', false);
}
public function test_duplicate_ids_does_not_break_page_render()
@@ -545,7 +545,7 @@ class PageContentTest extends TestCase
$pageView = $this->get($page->getUrl());
$pageView->assertStatus(200);
$pageView->assertSee($content);
$pageView->assertSee($content, false);
}
public function test_base64_images_get_extracted_from_page_content()

View File

@@ -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();

View File

@@ -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();

View File

@@ -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',
]);

View File

@@ -12,7 +12,7 @@ class SortTest extends TestCase
{
protected $book;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->book = Book::first();

View File

@@ -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);

View File

@@ -167,7 +167,7 @@ class HomepageTest extends TestCase
public function test_new_users_dont_have_any_recently_viewed()
{
$user = factory(User::class)->create();
$user = User::factory()->create();
$viewRole = Role::getRole('Viewer');
$user->attachRole($viewRole);

View File

@@ -9,7 +9,7 @@ class LanguageTest extends TestCase
/**
* LanguageTest constructor.
*/
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->langs = array_diff(scandir(resource_path('lang')), ['..', '.']);

View File

@@ -23,7 +23,7 @@ class EntityPermissionsTest extends TestCase
*/
protected $viewer;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->user = $this->getEditor();

View File

@@ -19,7 +19,7 @@ class RolesTest extends TestCase
{
protected $user;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->user = $this->getViewer();
@@ -173,11 +173,11 @@ class RolesTest extends TestCase
public function test_manage_users_permission_shows_link_in_header_if_does_not_have_settings_manage_permision()
{
$usersLink = 'href="' . url('/settings/users') . '"';
$this->actingAs($this->user)->get('/')->assertDontSee($usersLink);
$this->actingAs($this->user)->get('/')->assertDontSee($usersLink, false);
$this->giveUserPermissions($this->user, ['users-manage']);
$this->actingAs($this->user)->get('/')->assertSee($usersLink);
$this->actingAs($this->user)->get('/')->assertSee($usersLink, false);
$this->giveUserPermissions($this->user, ['settings-manage', 'users-manage']);
$this->actingAs($this->user)->get('/')->assertDontSee($usersLink);
$this->actingAs($this->user)->get('/')->assertDontSee($usersLink, false);
}
public function test_user_cannot_change_email_unless_they_have_manage_users_permission()
@@ -769,7 +769,7 @@ class RolesTest extends TestCase
$this->giveUserPermissions($this->user, ['image-update-all']);
/** @var Page $page */
$page = Page::query()->first();
$image = factory(Image::class)->create([
$image = Image::factory()->create([
'uploaded_to' => $page->id,
'created_by' => $this->user->id,
'updated_by' => $this->user->id,
@@ -789,7 +789,7 @@ class RolesTest extends TestCase
$admin = $this->getAdmin();
/** @var Page $page */
$page = Page::query()->first();
$image = factory(Image::class)->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
$image = Image::factory()->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
@@ -825,14 +825,14 @@ class RolesTest extends TestCase
{
$admin = $this->getAdmin();
// Book links
$book = factory(Book::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
$book = Book::factory()->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
$this->regenEntityPermissions($book);
$this->actingAs($this->getViewer())->get($book->getUrl())
->assertDontSee('Create a new page')
->assertDontSee('Add a chapter');
// Chapter links
$chapter = factory(Chapter::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
$chapter = Chapter::factory()->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
$this->regenEntityPermissions($chapter);
$this->actingAs($this->getViewer())->get($chapter->getUrl())
->assertDontSee('Create a new page')
@@ -926,14 +926,14 @@ class RolesTest extends TestCase
private function addComment(Page $page): TestResponse
{
$comment = factory(Comment::class)->make();
$comment = Comment::factory()->make();
return $this->postJson("/comment/$page->id", $comment->only('text', 'html'));
}
private function updateComment(Comment $comment): TestResponse
{
$commentData = factory(Comment::class)->make();
$commentData = Comment::factory()->make();
return $this->putJson("/comment/{$comment->id}", $commentData->only('text', 'html'));
}

View File

@@ -76,7 +76,7 @@ class SecurityHeaderTest extends TestCase
$nonce = app()->make(CspService::class)->getNonce();
$this->assertStringContainsString('nonce-' . $nonce, $scriptHeader);
$resp->assertSee('<script nonce="' . $nonce . '">console.log("cat");</script>');
$resp->assertSee('<script nonce="' . $nonce . '">console.log("cat");</script>', false);
}
public function test_script_csp_nonce_changes_per_request()

View File

@@ -11,21 +11,21 @@ class CustomHeadContentTest extends TestCase
{
$this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']);
$resp = $this->get('/login');
$resp->assertSee('console.log("cat")');
$resp->assertSee('console.log("cat")', false);
}
public function test_configured_content_does_not_show_on_settings_page()
{
$this->setSettings(['app-custom-head' => '<script>console.log("cat");</script>']);
$resp = $this->asAdmin()->get('/settings');
$resp->assertDontSee('console.log("cat")');
$resp->assertDontSee('console.log("cat")', false);
}
public function test_divs_in_js_preserved_in_configured_content()
{
$this->setSettings(['app-custom-head' => '<script><div id="hello">cat</div></script>']);
$resp = $this->get('/login');
$resp->assertSee('<div id="hello">cat</div>');
$resp->assertSee('<div id="hello">cat</div>', false);
}
public function test_nonce_application_handles_edge_cases()
@@ -61,6 +61,6 @@ const b = `<script`;
$this->setSettings(['app-custom-head' => $content]);
$resp = $this->get('/login');
$resp->assertSee($expectedOutput);
$resp->assertSee($expectedOutput, false);
}
}

View File

@@ -31,10 +31,10 @@ class FooterLinksTest extends TestCase
]]);
$resp = $this->asAdmin()->get('/settings');
$resp->assertSee('value="My custom link"');
$resp->assertSee('value="Another Link"');
$resp->assertSee('value="https://example.com/link-a"');
$resp->assertSee('value="https://example.com/link-b"');
$resp->assertSee('value="My custom link"', false);
$resp->assertSee('value="Another Link"', false);
$resp->assertSee('value="https://example.com/link-a"', false);
$resp->assertSee('value="https://example.com/link-b"', false);
}
public function test_footer_links_show_on_pages()

View File

@@ -22,10 +22,10 @@ use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use Illuminate\Foundation\Testing\Assert as PHPUnit;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Env;
use Illuminate\Support\Facades\Log;
use Illuminate\Testing\Assert as PHPUnit;
use Mockery;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
@@ -127,7 +127,7 @@ trait SharedTestHelpers
/**
* Create and return a new test chapter.
*/
public function newChapter(array $input = ['name' => 'test chapter', 'description' => 'My new test chapter'], Book $book): Chapter
public function newChapter(array $input, Book $book): Chapter
{
return app(ChapterRepo::class)->create($input, $book);
}
@@ -210,7 +210,7 @@ trait SharedTestHelpers
protected function createNewRole(array $permissions = []): Role
{
$permissionRepo = app(PermissionsRepo::class);
$roleData = factory(Role::class)->make()->toArray();
$roleData = Role::factory()->make()->toArray();
$roleData['permissions'] = array_flip($permissions);
return $permissionRepo->saveNewRole($roleData);
@@ -228,9 +228,9 @@ trait SharedTestHelpers
}
$userAttrs = ['created_by' => $creatorUser->id, 'owned_by' => $creatorUser->id, 'updated_by' => $updaterUser->id];
$book = factory(Book::class)->create($userAttrs);
$chapter = factory(Chapter::class)->create(array_merge(['book_id' => $book->id], $userAttrs));
$page = factory(Page::class)->create(array_merge(['book_id' => $book->id, 'chapter_id' => $chapter->id], $userAttrs));
$book = Book::factory()->create($userAttrs);
$chapter = Chapter::factory()->create(array_merge(['book_id' => $book->id], $userAttrs));
$page = Page::factory()->create(array_merge(['book_id' => $book->id, 'chapter_id' => $chapter->id], $userAttrs));
$restrictionService = $this->app[PermissionService::class];
$restrictionService->buildJointPermissionsForEntity($book);

View File

@@ -2,7 +2,7 @@
namespace Tests;
use Illuminate\Foundation\Testing\TestResponse as BaseTestResponse;
use Illuminate\Testing\TestResponse as BaseTestResponse;
use PHPUnit\Framework\Assert as PHPUnit;
use Symfony\Component\DomCrawler\Crawler;

View File

@@ -150,7 +150,7 @@ class ThemeTest extends TestCase
Theme::listen(ThemeEvents::AUTH_REGISTER, $callback);
$this->setSettings(['registration-enabled' => 'true']);
$user = factory(User::class)->make();
$user = User::factory()->make();
$this->post('/register', ['email' => $user->email, 'name' => $user->name, 'password' => 'password']);
$this->assertCount(2, $args);

View File

@@ -17,13 +17,13 @@ class AttachmentTest extends TestCase
*/
protected function getTestFile(string $fileName): UploadedFile
{
return new UploadedFile(base_path('tests/test-data/test-file.txt'), $fileName, 'text/plain', 55, null, true);
return new UploadedFile(base_path('tests/test-data/test-file.txt'), $fileName, 'text/plain', null, true);
}
/**
* Uploads a file with the given name.
*/
protected function uploadFile(string $name, int $uploadedTo = 0): \Illuminate\Foundation\Testing\TestResponse
protected function uploadFile(string $name, int $uploadedTo = 0): \Illuminate\Testing\TestResponse
{
$file = $this->getTestFile($name);

View File

@@ -42,7 +42,7 @@ class AvatarTest extends TestCase
config()->set([
'services.disable_services' => false,
]);
$user = factory(User::class)->make();
$user = User::factory()->make();
$this->assertImageFetchFrom('https://www.gravatar.com/avatar/' . md5(strtolower($user->email)) . '?s=500&d=identicon');
$user = $this->createUserRequest($user);
@@ -60,7 +60,7 @@ class AvatarTest extends TestCase
'services.avatar_url' => 'https://example.com/${email}/${hash}/${size}',
]);
$user = factory(User::class)->make();
$user = User::factory()->make();
$url = 'https://example.com/' . urlencode(strtolower($user->email)) . '/' . md5(strtolower($user->email)) . '/500';
$this->assertImageFetchFrom($url);
@@ -74,7 +74,7 @@ class AvatarTest extends TestCase
'services.disable_services' => true,
]);
$user = factory(User::class)->make();
$user = User::factory()->make();
$http = $this->mock(HttpFetcher::class);
$http->shouldNotReceive('fetch');
@@ -93,7 +93,7 @@ class AvatarTest extends TestCase
$logger = $this->withTestLogger();
$user = factory(User::class)->make();
$user = User::factory()->make();
$this->createUserRequest($user);
$this->assertTrue($logger->hasError('Failed to save user avatar image'));
}

View File

@@ -61,7 +61,7 @@ class DrawioTest extends TestCase
$editor = $this->getEditor();
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
$resp->assertSee('drawio-url="http://cats.com?dog=tree"');
$resp->assertSee('drawio-url="http://cats.com?dog=tree"', false);
}
public function test_drawio_url_can_be_disabled()
@@ -71,10 +71,10 @@ class DrawioTest extends TestCase
$editor = $this->getEditor();
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
$resp->assertSee('drawio-url="https://embed.diagrams.net/?embed=1&amp;proto=json&amp;spin=1"');
$resp->assertSee('drawio-url="https://embed.diagrams.net/?embed=1&amp;proto=json&amp;spin=1"', false);
config()->set('services.drawio', false);
$resp = $this->actingAs($editor)->get($page->getUrl('/edit'));
$resp->assertDontSee('drawio-url');
$resp->assertDontSee('drawio-url', false);
}
}

View File

@@ -15,7 +15,7 @@ class UserManagementTest extends TestCase
public function test_user_creation()
{
/** @var User $user */
$user = factory(User::class)->make();
$user = User::factory()->make();
$adminRole = Role::getRole('admin');
$resp = $this->asAdmin()->get('/settings/users');

View File

@@ -14,7 +14,7 @@ class UserProfileTest extends TestCase
*/
protected $user;
public function setUp(): void
protected function setUp(): void
{
parent::setUp();
$this->user = User::all()->last();
@@ -42,7 +42,7 @@ class UserProfileTest extends TestCase
public function test_profile_page_shows_created_content_counts()
{
$newUser = factory(User::class)->create();
$newUser = User::factory()->create();
$this->asAdmin()->get('/user/' . $newUser->slug)
->assertSee($newUser->name)
@@ -61,7 +61,7 @@ class UserProfileTest extends TestCase
public function test_profile_page_shows_recent_activity()
{
$newUser = factory(User::class)->create();
$newUser = User::factory()->create();
$this->actingAs($newUser);
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);
@@ -75,7 +75,7 @@ class UserProfileTest extends TestCase
public function test_user_activity_has_link_leading_to_profile()
{
$newUser = factory(User::class)->create();
$newUser = User::factory()->create();
$this->actingAs($newUser);
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
Activity::addForEntity($entities['book'], ActivityType::BOOK_UPDATE);