diff --git a/.env.example.complete b/.env.example.complete index 683db703c..9a46b23a5 100644 --- a/.env.example.complete +++ b/.env.example.complete @@ -293,6 +293,10 @@ REVISION_LIMIT=50 # Set to -1 for unlimited recycle bin lifetime. RECYCLE_BIN_LIFETIME=30 +# File Upload Limit +# Maximum file size, in megabytes, that can be uploaded to the system. +FILE_UPLOAD_SIZE_LIMIT=50 + # Allow '); + $resp->assertSee('', false); } public function test_script_csp_nonce_changes_per_request() diff --git a/tests/Settings/CustomHeadContentTest.php b/tests/Settings/CustomHeadContentTest.php index 94ef4711d..36c8a4c0f 100644 --- a/tests/Settings/CustomHeadContentTest.php +++ b/tests/Settings/CustomHeadContentTest.php @@ -11,21 +11,21 @@ class CustomHeadContentTest extends TestCase { $this->setSettings(['app-custom-head' => '']); $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' => '']); $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' => '']); $resp = $this->get('/login'); - $resp->assertSee('
cat
'); + $resp->assertSee('
cat
', false); } public function test_nonce_application_handles_edge_cases() @@ -61,6 +61,6 @@ const b = `setSettings(['app-custom-head' => $content]); $resp = $this->get('/login'); - $resp->assertSee($expectedOutput); + $resp->assertSee($expectedOutput, false); } } diff --git a/tests/Settings/FooterLinksTest.php b/tests/Settings/FooterLinksTest.php index 55c3e107d..f1b5d4294 100644 --- a/tests/Settings/FooterLinksTest.php +++ b/tests/Settings/FooterLinksTest.php @@ -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() diff --git a/tests/SharedTestHelpers.php b/tests/SharedTestHelpers.php index 04952d223..cbf49bf71 100644 --- a/tests/SharedTestHelpers.php +++ b/tests/SharedTestHelpers.php @@ -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); diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 09882759c..37b1b15a1 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -34,7 +34,7 @@ class StatusTest extends TestCase { $mockStore = Mockery::mock(new ArrayStore())->makePartial(); Cache::swap($mockStore); - $mockStore->shouldReceive('get')->andReturn('cat'); + $mockStore->shouldReceive('pull')->andReturn('cat'); $resp = $this->get('/status'); $resp->assertStatus(500); diff --git a/tests/TestResponse.php b/tests/TestResponse.php index 79f173c9b..4e53aa020 100644 --- a/tests/TestResponse.php +++ b/tests/TestResponse.php @@ -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; @@ -53,6 +53,26 @@ class TestResponse extends BaseTestResponse return $this; } + /** + * Assert the response contains the given count of elements + * that match the given css selector. + * + * @return $this + */ + public function assertElementCount(string $selector, int $count) + { + $elements = $this->crawler()->filter($selector); + PHPUnit::assertTrue( + $elements->count() === $count, + 'Unable to ' . $count . ' element(s) matching the selector: ' . PHP_EOL . PHP_EOL . + "[{$selector}]" . PHP_EOL . PHP_EOL . + 'found ' . $elements->count() . ' within' . PHP_EOL . PHP_EOL . + "[{$this->getContent()}]." + ); + + return $this; + } + /** * Assert the response does not contain the specified element. * diff --git a/tests/ThemeTest.php b/tests/ThemeTest.php index 2cab765ae..9aa7873b0 100644 --- a/tests/ThemeTest.php +++ b/tests/ThemeTest.php @@ -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); diff --git a/tests/Uploads/AttachmentTest.php b/tests/Uploads/AttachmentTest.php index abd7ca616..5545edf13 100644 --- a/tests/Uploads/AttachmentTest.php +++ b/tests/Uploads/AttachmentTest.php @@ -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); diff --git a/tests/Uploads/AvatarTest.php b/tests/Uploads/AvatarTest.php index cf568d07c..d10b5cfc6 100644 --- a/tests/Uploads/AvatarTest.php +++ b/tests/Uploads/AvatarTest.php @@ -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')); } diff --git a/tests/Uploads/DrawioTest.php b/tests/Uploads/DrawioTest.php index 422de472a..1fc3d1049 100644 --- a/tests/Uploads/DrawioTest.php +++ b/tests/Uploads/DrawioTest.php @@ -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&proto=json&spin=1"'); + $resp->assertSee('drawio-url="https://embed.diagrams.net/?embed=1&proto=json&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); } } diff --git a/tests/User/UserManagementTest.php b/tests/User/UserManagementTest.php index ed2fb5f04..5a36b85df 100644 --- a/tests/User/UserManagementTest.php +++ b/tests/User/UserManagementTest.php @@ -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'); diff --git a/tests/User/UserProfileTest.php b/tests/User/UserProfileTest.php index 3942efa8e..c3888f8c5 100644 --- a/tests/User/UserProfileTest.php +++ b/tests/User/UserProfileTest.php @@ -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);