diff --git a/composer.json b/composer.json index a54977321..6d4bb734d 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "nunomaduro/collision": "^5.10", "nunomaduro/larastan": "^1.0", "phpunit/phpunit": "^9.5", - "symfony/dom-crawler": "^5.3" + "ssddanbrown/asserthtml": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 040bce4a1..9cd171488 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "23657e068ced89802ea578718478da3a", + "content-hash": "4ab21f732b2380ed1c3dd1a4eca2ef1a", "packages": [ { "name": "aws/aws-crt-php", @@ -10728,6 +10728,62 @@ }, "time": "2021-12-10T11:20:11+00:00" }, + { + "name": "ssddanbrown/asserthtml", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/ssddanbrown/htmlassert.git", + "reference": "f7d4352bb3d69347097b2841fd71934182821928" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ssddanbrown/htmlassert/zipball/f7d4352bb3d69347097b2841fd71934182821928", + "reference": "f7d4352bb3d69347097b2841fd71934182821928", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "php": ">=7.4", + "phpunit/phpunit": "^9.0", + "symfony/css-selector": "^5.0|^6.0", + "symfony/dom-crawler": "^5.0|^6.0" + }, + "require-dev": { + "vimeo/psalm": "^4.10" + }, + "type": "library", + "autoload": { + "psr-4": { + "Ssddanbrown\\AssertHtml\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dan Brown", + "email": "ssddanbrown@googlemail.com", + "role": "Developer" + } + ], + "description": "HTML Content Assertions for PHPUnit", + "homepage": "https://github.com/ssddanbrown/asserthtml", + "support": { + "issues": "https://github.com/ssddanbrown/htmlassert/issues", + "source": "https://github.com/ssddanbrown/htmlassert/tree/v1.0.1" + }, + "funding": [ + { + "url": "https://github.com/ssddanbrown", + "type": "github" + } + ], + "time": "2022-04-09T13:31:13+00:00" + }, { "name": "symfony/dom-crawler", "version": "v5.4.9", diff --git a/tests/Actions/AuditLogTest.php b/tests/Actions/AuditLogTest.php index 92289cd4f..d699724f5 100644 --- a/tests/Actions/AuditLogTest.php +++ b/tests/Actions/AuditLogTest.php @@ -56,7 +56,7 @@ class AuditLogTest extends TestCase $resp->assertSeeText($page->name); $resp->assertSeeText('page_create'); $resp->assertSeeText($activity->created_at->toDateTimeString()); - $resp->assertElementContains('.table-user-item', $admin->name); + $this->withHtml($resp)->assertElementContains('.table-user-item', $admin->name); } public function test_shows_name_for_deleted_items() diff --git a/tests/Actions/WebhookManagementTest.php b/tests/Actions/WebhookManagementTest.php index 1fbf9b7a9..f106f303a 100644 --- a/tests/Actions/WebhookManagementTest.php +++ b/tests/Actions/WebhookManagementTest.php @@ -17,8 +17,8 @@ class WebhookManagementTest extends TestCase $resp = $this->asAdmin()->get('/settings/webhooks'); $resp->assertOk(); - $resp->assertElementContains('a[href$="/settings/webhooks/create"]', 'Create New Webhook'); - $resp->assertElementExists('a[href="' . $webhook->getUrl() . '"]', $webhook->name); + $this->withHtml($resp)->assertElementContains('a[href$="/settings/webhooks/create"]', 'Create New Webhook'); + $this->withHtml($resp)->assertElementContains('a[href="' . $webhook->getUrl() . '"]', $webhook->name); $resp->assertSee($webhook->endpoint); $resp->assertSee('All system events'); $resp->assertSee('Active'); @@ -29,7 +29,7 @@ class WebhookManagementTest extends TestCase $resp = $this->asAdmin()->get('/settings/webhooks/create'); $resp->assertOk(); $resp->assertSee('Create New Webhook'); - $resp->assertElementContains('form[action$="/settings/webhooks/create"] button', 'Save Webhook'); + $this->withHtml($resp)->assertElementContains('form[action$="/settings/webhooks/create"] button', 'Save Webhook'); } public function test_store() @@ -70,9 +70,9 @@ class WebhookManagementTest extends TestCase $resp = $this->asAdmin()->get('/settings/webhooks/' . $webhook->id); $resp->assertOk(); $resp->assertSee('Edit Webhook'); - $resp->assertElementContains('form[action="' . $webhook->getUrl() . '"] button', 'Save Webhook'); - $resp->assertElementContains('a[href="' . $webhook->getUrl('/delete') . '"]', 'Delete Webhook'); - $resp->assertElementExists('input[type="checkbox"][value="all"][name="events[]"]'); + $this->withHtml($resp)->assertElementContains('form[action="' . $webhook->getUrl() . '"] button', 'Save Webhook'); + $this->withHtml($resp)->assertElementContains('a[href="' . $webhook->getUrl('/delete') . '"]', 'Delete Webhook'); + $this->withHtml($resp)->assertElementExists('input[type="checkbox"][value="all"][name="events[]"]'); } public function test_update() @@ -114,7 +114,7 @@ class WebhookManagementTest extends TestCase $resp->assertOk(); $resp->assertSee('Delete Webhook'); $resp->assertSee('This will fully delete this webhook, with the name \'Webhook to delete\', from the system.'); - $resp->assertElementContains('form[action$="/settings/webhooks/' . $webhook->id . '"]', 'Delete'); + $this->withHtml($resp)->assertElementContains('form[action$="/settings/webhooks/' . $webhook->id . '"]', 'Delete'); } public function test_destroy() diff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.php index 0ab6d0e8c..106b71875 100644 --- a/tests/Auth/AuthTest.php +++ b/tests/Auth/AuthTest.php @@ -10,8 +10,8 @@ use BookStack\Notifications\ConfirmEmail; use BookStack\Notifications\ResetPassword; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Notification; +use Illuminate\Testing\TestResponse; use Tests\TestCase; -use Tests\TestResponse; class AuthTest extends TestCase { @@ -37,8 +37,8 @@ class AuthTest extends TestCase { // Ensure registration form is showing $this->setSettings(['registration-enabled' => 'true']); - $this->get('/login') - ->assertElementContains('a[href="' . url('/register') . '"]', 'Sign up'); + $resp = $this->get('/login'); + $this->withHtml($resp)->assertElementContains('a[href="' . url('/register') . '"]', 'Sign up'); } public function test_normal_registration() @@ -51,9 +51,9 @@ class AuthTest extends TestCase $user = User::factory()->make(); // Test form and ensure user is created - $this->get('/register') - ->assertSee('Sign Up') - ->assertElementContains('form[action="' . url('/register') . '"]', 'Create Account'); + $resp = $this->get('/register') + ->assertSee('Sign Up'); + $this->withHtml($resp)->assertElementContains('form[action="' . url('/register') . '"]', 'Create Account'); $resp = $this->post('/register', $user->only('password', 'name', 'email')); $resp->assertRedirect('/'); @@ -128,7 +128,7 @@ class AuthTest extends TestCase $resp->assertRedirect('/register/confirm/awaiting'); $resp = $this->get('/register/confirm/awaiting'); - $resp->assertElementContains('form[action="' . url('/register/confirm/resend') . '"]', 'Resend'); + $this->withHtml($resp)->assertElementContains('form[action="' . url('/register/confirm/resend') . '"]', 'Resend'); $this->get('/books')->assertRedirect('/login'); $this->post('/register/confirm/resend', $user->only('email')); @@ -203,7 +203,7 @@ class AuthTest extends TestCase $this->assertFalse(setting('registration-role')); $resp = $this->asAdmin()->get('/settings/registration'); - $resp->assertElementContains('select[name="setting-registration-role"] option[value="0"][selected]', '-- None --'); + $this->withHtml($resp)->assertElementContains('select[name="setting-registration-role"] option[value="0"][selected]', '-- None --'); } public function test_logout() @@ -229,11 +229,11 @@ class AuthTest extends TestCase { Notification::fake(); - $this->get('/login') - ->assertElementContains('a[href="' . url('/password/email') . '"]', 'Forgot Password?'); + $resp = $this->get('/login'); + $this->withHtml($resp)->assertElementContains('a[href="' . url('/password/email') . '"]', 'Forgot Password?'); - $this->get('/password/email') - ->assertElementContains('form[action="' . url('/password/email') . '"]', 'Send Reset Link'); + $resp = $this->get('/password/email'); + $this->withHtml($resp)->assertElementContains('form[action="' . url('/password/email') . '"]', 'Send Reset Link'); $resp = $this->post('/password/email', [ 'email' => 'admin@admin.com', @@ -294,8 +294,8 @@ class AuthTest extends TestCase public function test_reset_password_page_shows_sign_links() { $this->setSettings(['registration-enabled' => 'true']); - $this->get('/password/email') - ->assertElementContains('a', 'Log in') + $resp = $this->get('/password/email'); + $this->withHtml($resp)->assertElementContains('a', 'Log in') ->assertElementContains('a', 'Sign up'); } diff --git a/tests/Auth/LdapTest.php b/tests/Auth/LdapTest.php index 96e10e4da..978420f86 100644 --- a/tests/Auth/LdapTest.php +++ b/tests/Auth/LdapTest.php @@ -6,9 +6,9 @@ use BookStack\Auth\Access\Ldap; use BookStack\Auth\Access\LdapService; use BookStack\Auth\Role; use BookStack\Auth\User; +use Illuminate\Testing\TestResponse; use Mockery\MockInterface; use Tests\TestCase; -use Tests\TestResponse; class LdapTest extends TestCase { @@ -106,7 +106,7 @@ class LdapTest extends TestCase $resp->assertSee($this->mockUser->name); $resp = $this->followingRedirects()->mockUserLogin($this->mockUser->email); - $resp->assertElementExists('#home-default'); + $this->withHtml($resp)->assertElementExists('#home-default'); $resp->assertSee($this->mockUser->name); $this->assertDatabaseHas('users', [ 'email' => $this->mockUser->email, @@ -251,7 +251,8 @@ class LdapTest extends TestCase public function test_registration_disabled() { - $this->followingRedirects()->get('/register')->assertElementContains('#content', 'Log In'); + $resp = $this->followingRedirects()->get('/register'); + $this->withHtml($resp)->assertElementContains('#content', 'Log In'); } public function test_non_admins_cannot_change_auth_id() diff --git a/tests/Auth/LoginAutoInitiateTest.php b/tests/Auth/LoginAutoInitiateTest.php index 86e1f93e2..2d0384435 100644 --- a/tests/Auth/LoginAutoInitiateTest.php +++ b/tests/Auth/LoginAutoInitiateTest.php @@ -25,8 +25,8 @@ class LoginAutoInitiateTest extends TestCase $req = $this->get('/login'); $req->assertSeeText('Attempting Login'); - $req->assertElementExists('form[action$="/oidc/login"][method=POST][id="login-form"] button'); - $req->assertElementExists('button[form="login-form"]'); + $this->withHtml($req)->assertElementExists('form[action$="/oidc/login"][method=POST][id="login-form"] button'); + $this->withHtml($req)->assertElementExists('button[form="login-form"]'); } public function test_with_saml2() @@ -37,8 +37,8 @@ class LoginAutoInitiateTest extends TestCase $req = $this->get('/login'); $req->assertSeeText('Attempting Login'); - $req->assertElementExists('form[action$="/saml2/login"][method=POST][id="login-form"] button'); - $req->assertElementExists('button[form="login-form"]'); + $this->withHtml($req)->assertElementExists('form[action$="/saml2/login"][method=POST][id="login-form"] button'); + $this->withHtml($req)->assertElementExists('button[form="login-form"]'); } public function test_it_does_not_run_if_social_provider_is_active() diff --git a/tests/Auth/MfaConfigurationTest.php b/tests/Auth/MfaConfigurationTest.php index fab94817c..3416263f3 100644 --- a/tests/Auth/MfaConfigurationTest.php +++ b/tests/Auth/MfaConfigurationTest.php @@ -18,15 +18,15 @@ class MfaConfigurationTest extends TestCase // Setup page state $resp = $this->actingAs($editor)->get('/mfa/setup'); - $resp->assertElementContains('a[href$="/mfa/totp/generate"]', 'Setup'); + $this->withHtml($resp)->assertElementContains('a[href$="/mfa/totp/generate"]', 'Setup'); // Generate page access $resp = $this->get('/mfa/totp/generate'); $resp->assertSee('Mobile App Setup'); $resp->assertSee('Verify Setup'); - $resp->assertElementExists('form[action$="/mfa/totp/confirm"] button'); + $this->withHtml($resp)->assertElementExists('form[action$="/mfa/totp/confirm"] button'); $this->assertSessionHas('mfa-setup-totp-secret'); - $svg = $resp->getElementHtml('#main-content .card svg'); + $svg = $this->withHtml($resp)->getOuterHtml('#main-content .card svg'); // Validation error, code should remain the same $resp = $this->post('/mfa/totp/confirm', [ @@ -35,7 +35,7 @@ class MfaConfigurationTest extends TestCase $resp->assertRedirect('/mfa/totp/generate'); $resp = $this->followRedirects($resp); $resp->assertSee('The provided code is not valid or has expired.'); - $revisitSvg = $resp->getElementHtml('#main-content .card svg'); + $revisitSvg = $this->withHtml($resp)->getOuterHtml('#main-content .card svg'); $this->assertTrue($svg === $revisitSvg); $secret = decrypt(session()->get('mfa-setup-totp-secret')); @@ -52,7 +52,7 @@ class MfaConfigurationTest extends TestCase // Confirmation of setup $resp = $this->followRedirects($resp); $resp->assertSee('Multi-factor method successfully configured'); - $resp->assertElementContains('a[href$="/mfa/totp/generate"]', 'Reconfigure'); + $this->withHtml($resp)->assertElementContains('a[href$="/mfa/totp/generate"]', 'Reconfigure'); $this->assertDatabaseHas('mfa_values', [ 'user_id' => $editor->id, @@ -71,12 +71,12 @@ class MfaConfigurationTest extends TestCase // Setup page state $resp = $this->actingAs($editor)->get('/mfa/setup'); - $resp->assertElementContains('a[href$="/mfa/backup_codes/generate"]', 'Setup'); + $this->withHtml($resp)->assertElementContains('a[href$="/mfa/backup_codes/generate"]', 'Setup'); // Generate page access $resp = $this->get('/mfa/backup_codes/generate'); $resp->assertSee('Backup Codes'); - $resp->assertElementContains('form[action$="/mfa/backup_codes/confirm"]', 'Confirm and Enable'); + $this->withHtml($resp)->assertElementContains('form[action$="/mfa/backup_codes/confirm"]', 'Confirm and Enable'); $this->assertSessionHas('mfa-setup-backup-codes'); $codes = decrypt(session()->get('mfa-setup-backup-codes')); // Check code format @@ -92,7 +92,7 @@ class MfaConfigurationTest extends TestCase // Confirmation of setup $resp = $this->followRedirects($resp); $resp->assertSee('Multi-factor method successfully configured'); - $resp->assertElementContains('a[href$="/mfa/backup_codes/generate"]', 'Reconfigure'); + $this->withHtml($resp)->assertElementContains('a[href$="/mfa/backup_codes/generate"]', 'Reconfigure'); $this->assertDatabaseHas('mfa_values', [ 'user_id' => $editor->id, @@ -129,10 +129,10 @@ class MfaConfigurationTest extends TestCase { $admin = $this->getAdmin(); $resp = $this->actingAs($admin)->get($admin->getEditUrl()); - $resp->assertElementExists('a[href$="/mfa/setup"]'); + $this->withHtml($resp)->assertElementExists('a[href$="/mfa/setup"]'); $resp = $this->actingAs($admin)->get($this->getEditor()->getEditUrl()); - $resp->assertElementNotExists('a[href$="/mfa/setup"]'); + $this->withHtml($resp)->assertElementNotExists('a[href$="/mfa/setup"]'); } public function test_mfa_indicator_shows_in_user_list() @@ -141,11 +141,11 @@ class MfaConfigurationTest extends TestCase User::query()->where('id', '!=', $admin->id)->delete(); $resp = $this->actingAs($admin)->get('/settings/users'); - $resp->assertElementNotExists('[title="MFA Configured"] svg'); + $this->withHtml($resp)->assertElementNotExists('[title="MFA Configured"] svg'); MfaValue::upsertWithValue($admin, MfaValue::METHOD_TOTP, 'test'); $resp = $this->actingAs($admin)->get('/settings/users'); - $resp->assertElementExists('[title="MFA Configured"] svg'); + $this->withHtml($resp)->assertElementExists('[title="MFA Configured"] svg'); } public function test_remove_mfa_method() @@ -155,7 +155,7 @@ class MfaConfigurationTest extends TestCase MfaValue::upsertWithValue($admin, MfaValue::METHOD_TOTP, 'test'); $this->assertEquals(1, $admin->mfaValues()->count()); $resp = $this->actingAs($admin)->get('/mfa/setup'); - $resp->assertElementExists('form[action$="/mfa/totp/remove"]'); + $this->withHtml($resp)->assertElementExists('form[action$="/mfa/totp/remove"]'); $resp = $this->delete('/mfa/totp/remove'); $resp->assertRedirect('/mfa/setup'); diff --git a/tests/Auth/MfaVerificationTest.php b/tests/Auth/MfaVerificationTest.php index 7286a1de8..ba4c9b983 100644 --- a/tests/Auth/MfaVerificationTest.php +++ b/tests/Auth/MfaVerificationTest.php @@ -23,7 +23,7 @@ class MfaVerificationTest extends TestCase $resp = $this->get('/mfa/verify'); $resp->assertSee('Verify Access'); $resp->assertSee('Enter the code, generated using your mobile app, below:'); - $resp->assertElementExists('form[action$="/mfa/totp/verify"] input[name="code"][autofocus]'); + $this->withHtml($resp)->assertElementExists('form[action$="/mfa/totp/verify"] input[name="code"][autofocus]'); $google2fa = new Google2FA(); $resp = $this->post('/mfa/totp/verify', [ @@ -66,7 +66,7 @@ class MfaVerificationTest extends TestCase $resp->assertSee('Verify Access'); $resp->assertSee('Backup Code'); $resp->assertSee('Enter one of your remaining backup codes below:'); - $resp->assertElementExists('form[action$="/mfa/backup_codes/verify"] input[name="code"]'); + $this->withHtml($resp)->assertElementExists('form[action$="/mfa/backup_codes/verify"] input[name="code"]'); $resp = $this->post('/mfa/backup_codes/verify', [ 'code' => $codes[1], @@ -154,13 +154,13 @@ class MfaVerificationTest extends TestCase ]); // Totp shown by default - $mfaView->assertElementExists('form[action$="/mfa/totp/verify"] input[name="code"]'); - $mfaView->assertElementContains('a[href$="/mfa/verify?method=backup_codes"]', 'Verify using a backup code'); + $this->withHtml($mfaView)->assertElementExists('form[action$="/mfa/totp/verify"] input[name="code"]'); + $this->withHtml($mfaView)->assertElementContains('a[href$="/mfa/verify?method=backup_codes"]', 'Verify using a backup code'); // Ensure can view backup_codes view $resp = $this->get('/mfa/verify?method=backup_codes'); - $resp->assertElementExists('form[action$="/mfa/backup_codes/verify"] input[name="code"]'); - $resp->assertElementContains('a[href$="/mfa/verify?method=totp"]', 'Verify using a mobile app'); + $this->withHtml($resp)->assertElementExists('form[action$="/mfa/backup_codes/verify"] input[name="code"]'); + $this->withHtml($resp)->assertElementContains('a[href$="/mfa/verify?method=totp"]', 'Verify using a mobile app'); } public function test_mfa_required_with_no_methods_leads_to_setup() @@ -184,7 +184,7 @@ class MfaVerificationTest extends TestCase ]); $resp->assertSeeText('No Methods Configured'); - $resp->assertElementContains('a[href$="/mfa/setup"]', 'Configure'); + $this->withHtml($resp)->assertElementContains('a[href$="/mfa/setup"]', 'Configure'); $this->get('/mfa/backup_codes/generate'); $resp = $this->post('/mfa/backup_codes/confirm'); diff --git a/tests/Auth/OidcTest.php b/tests/Auth/OidcTest.php index 9aebb4d04..aa2c99a36 100644 --- a/tests/Auth/OidcTest.php +++ b/tests/Auth/OidcTest.php @@ -6,9 +6,9 @@ use BookStack\Actions\ActivityType; use BookStack\Auth\User; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; +use Illuminate\Testing\TestResponse; use Tests\Helpers\OidcJwtHelper; use Tests\TestCase; -use Tests\TestResponse; class OidcTest extends TestCase { @@ -52,7 +52,7 @@ class OidcTest extends TestCase { $req = $this->get('/login'); $req->assertSeeText('SingleSignOn-Testing'); - $req->assertElementExists('form[action$="/oidc/login"][method=POST] button'); + $this->withHtml($req)->assertElementExists('form[action$="/oidc/login"][method=POST] button'); } public function test_oidc_routes_are_only_active_if_oidc_enabled() diff --git a/tests/Auth/Saml2Test.php b/tests/Auth/Saml2Test.php index cb217585c..885adf9e0 100644 --- a/tests/Auth/Saml2Test.php +++ b/tests/Auth/Saml2Test.php @@ -56,7 +56,7 @@ class Saml2Test extends TestCase { $req = $this->get('/login'); $req->assertSeeText('SingleSignOn-Testing'); - $req->assertElementExists('form[action$="/saml2/login"][method=POST] button'); + $this->withHtml($req)->assertElementExists('form[action$="/saml2/login"][method=POST] button'); } public function test_login() @@ -157,7 +157,7 @@ class Saml2Test extends TestCase ]); $resp = $this->actingAs($this->getEditor())->get('/'); - $resp->assertElementContains('form[action$="/saml2/logout"] button', 'Logout'); + $this->withHtml($resp)->assertElementContains('form[action$="/saml2/logout"] button', 'Logout'); } public function test_logout_sls_flow() diff --git a/tests/Auth/SocialAuthTest.php b/tests/Auth/SocialAuthTest.php index 90d7e37aa..67da771a5 100644 --- a/tests/Auth/SocialAuthTest.php +++ b/tests/Auth/SocialAuthTest.php @@ -61,7 +61,7 @@ class SocialAuthTest extends TestCase // Test login routes $resp = $this->get('/login'); - $resp->assertElementExists('a#social-login-google[href$="/login/service/google"]'); + $this->withHtml($resp)->assertElementExists('a#social-login-google[href$="/login/service/google"]'); $resp = $this->followingRedirects()->get('/login/service/google'); $resp->assertSee('login-form'); @@ -71,7 +71,7 @@ class SocialAuthTest extends TestCase $resp->assertSee(trans('errors.social_account_not_used', ['socialAccount' => 'Google'])); $resp = $this->get('/login'); - $resp->assertElementExists('a#social-login-github[href$="/login/service/github"]'); + $this->withHtml($resp)->assertElementExists('a#social-login-github[href$="/login/service/github"]'); $resp = $this->followingRedirects()->get('/login/service/github'); $resp->assertSee('login-form'); @@ -101,7 +101,7 @@ class SocialAuthTest extends TestCase ]); $resp = $this->actingAs($editor)->get($editor->getEditUrl()); - $resp->assertElementContains('form[action$="/login/service/github/detach"]', 'Disconnect Account'); + $this->withHtml($resp)->assertElementContains('form[action$="/login/service/github/detach"]', 'Disconnect Account'); $resp = $this->post('/login/service/github/detach'); $resp->assertRedirect($editor->getEditUrl()); diff --git a/tests/DebugViewTest.php b/tests/DebugViewTest.php index 63d6472b9..ec66de10a 100644 --- a/tests/DebugViewTest.php +++ b/tests/DebugViewTest.php @@ -3,6 +3,7 @@ namespace Tests; use BookStack\Auth\Access\SocialAuthService; +use Illuminate\Testing\TestResponse; class DebugViewTest extends TestCase { @@ -25,8 +26,8 @@ class DebugViewTest extends TestCase // BookStack version $resp->assertSeeText('BookStack Version: ' . trim(file_get_contents(base_path('version')))); // Dynamic help links - $resp->assertElementExists('a[href*="q=' . urlencode('BookStack An error occurred during testing') . '"]'); - $resp->assertElementExists('a[href*="?q=is%3Aissue+' . urlencode('An error occurred during testing') . '"]'); + $this->withHtml($resp)->assertElementExists('a[href*="q=' . urlencode('BookStack An error occurred during testing') . '"]'); + $this->withHtml($resp)->assertElementExists('a[href*="?q=is%3Aissue+' . urlencode('An error occurred during testing') . '"]'); } public function test_debug_view_only_shows_when_debug_mode_is_enabled() diff --git a/tests/Entity/BookShelfTest.php b/tests/Entity/BookShelfTest.php index fcbc17ea9..5a7107ff0 100644 --- a/tests/Entity/BookShelfTest.php +++ b/tests/Entity/BookShelfTest.php @@ -18,21 +18,21 @@ class BookShelfTest extends TestCase { $viewer = $this->getViewer(); $resp = $this->actingAs($viewer)->get('/'); - $resp->assertElementContains('header', 'Shelves'); + $this->withHtml($resp)->assertElementContains('header', 'Shelves'); $viewer->roles()->delete(); $this->giveUserPermissions($viewer); $resp = $this->actingAs($viewer)->get('/'); - $resp->assertElementNotContains('header', 'Shelves'); + $this->withHtml($resp)->assertElementNotContains('header', 'Shelves'); $this->giveUserPermissions($viewer, ['bookshelf-view-all']); $resp = $this->actingAs($viewer)->get('/'); - $resp->assertElementContains('header', 'Shelves'); + $this->withHtml($resp)->assertElementContains('header', 'Shelves'); $viewer->roles()->delete(); $this->giveUserPermissions($viewer, ['bookshelf-view-own']); $resp = $this->actingAs($viewer)->get('/'); - $resp->assertElementContains('header', 'Shelves'); + $this->withHtml($resp)->assertElementContains('header', 'Shelves'); } public function test_shelves_shows_in_header_if_have_any_shelve_view_permission() @@ -43,18 +43,18 @@ class BookShelfTest extends TestCase $userRole = $user->roles()->first(); $resp = $this->actingAs($user)->get('/'); - $resp->assertElementNotContains('header', 'Shelves'); + $this->withHtml($resp)->assertElementNotContains('header', 'Shelves'); $this->setEntityRestrictions($shelf, ['view'], [$userRole]); $resp = $this->get('/'); - $resp->assertElementContains('header', 'Shelves'); + $this->withHtml($resp)->assertElementContains('header', 'Shelves'); } public function test_shelves_page_contains_create_link() { $resp = $this->asEditor()->get('/shelves'); - $resp->assertElementContains('a', 'New Shelf'); + $this->withHtml($resp)->assertElementContains('a', 'New Shelf'); } public function test_book_not_visible_in_shelf_list_view_if_user_cant_view_shelf() @@ -100,8 +100,8 @@ class BookShelfTest extends TestCase $shelfPage = $this->get($shelf->getUrl()); $shelfPage->assertSee($shelfInfo['name']); $shelfPage->assertSee($shelfInfo['description']); - $shelfPage->assertElementContains('.tag-item', 'Test Category'); - $shelfPage->assertElementContains('.tag-item', 'Test Tag Value'); + $this->withHtml($shelfPage)->assertElementContains('.tag-item', 'Test Category'); + $this->withHtml($shelfPage)->assertElementContains('.tag-item', 'Test Tag Value'); $this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id, 'book_id' => $booksToInclude[0]->id]); $this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id, 'book_id' => $booksToInclude[1]->id]); @@ -148,10 +148,10 @@ class BookShelfTest extends TestCase $resp->assertSee($shelf->getUrl('/edit')); $resp->assertSee($shelf->getUrl('/permissions')); $resp->assertSee($shelf->getUrl('/delete')); - $resp->assertElementContains('a', 'New Book'); - $resp->assertElementContains('a', 'Edit'); - $resp->assertElementContains('a', 'Permissions'); - $resp->assertElementContains('a', 'Delete'); + $this->withHtml($resp)->assertElementContains('a', 'New Book'); + $this->withHtml($resp)->assertElementContains('a', 'Edit'); + $this->withHtml($resp)->assertElementContains('a', 'Permissions'); + $this->withHtml($resp)->assertElementContains('a', 'Delete'); $resp = $this->asEditor()->get($shelf->getUrl()); $resp->assertDontSee($shelf->getUrl('/permissions')); @@ -161,8 +161,8 @@ class BookShelfTest extends TestCase { $shelf = Bookshelf::query()->first(); $resp = $this->asAdmin()->get($shelf->getUrl()); - $resp->assertElementExists('form[action$="change-sort/shelf_books"]'); - $resp->assertElementContains('form[action$="change-sort/shelf_books"] [aria-haspopup="true"]', 'Default'); + $this->withHtml($resp)->assertElementExists('form[action$="change-sort/shelf_books"]'); + $this->withHtml($resp)->assertElementContains('form[action$="change-sort/shelf_books"] [aria-haspopup="true"]', 'Default'); } public function test_shelf_view_sort_takes_action() @@ -182,20 +182,20 @@ class BookShelfTest extends TestCase $shelf->refresh(); $resp = $this->asEditor()->get($shelf->getUrl()); - $resp->assertElementContains('.book-content a.grid-card', $books[0]->name, 1); - $resp->assertElementNotContains('.book-content a.grid-card', $books[0]->name, 3); + $this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(1)', $books[0]->name); + $this->withHtml($resp)->assertElementNotContains('.book-content a.grid-card:nth-child(3)', $books[0]->name); setting()->putUser($this->getEditor(), 'shelf_books_sort_order', 'desc'); $resp = $this->asEditor()->get($shelf->getUrl()); - $resp->assertElementNotContains('.book-content a.grid-card', $books[0]->name, 1); - $resp->assertElementContains('.book-content a.grid-card', $books[0]->name, 3); + $this->withHtml($resp)->assertElementNotContains('.book-content a.grid-card:nth-child(1)', $books[0]->name); + $this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(3)', $books[0]->name); setting()->putUser($this->getEditor(), 'shelf_books_sort_order', 'desc'); setting()->putUser($this->getEditor(), 'shelf_books_sort', 'name'); $resp = $this->asEditor()->get($shelf->getUrl()); - $resp->assertElementContains('.book-content a.grid-card', 'hdgfgdfg', 1); - $resp->assertElementContains('.book-content a.grid-card', 'bsfsdfsdfsd', 2); - $resp->assertElementContains('.book-content a.grid-card', 'adsfsdfsdfsd', 3); + $this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(1)', 'hdgfgdfg'); + $this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(2)', 'bsfsdfsdfsd'); + $this->withHtml($resp)->assertElementContains('.book-content a.grid-card:nth-child(3)', 'adsfsdfsdfsd'); } public function test_shelf_edit() @@ -229,8 +229,8 @@ class BookShelfTest extends TestCase $shelfPage = $this->get($shelf->getUrl()); $shelfPage->assertSee($shelfInfo['name']); $shelfPage->assertSee($shelfInfo['description']); - $shelfPage->assertElementContains('.tag-item', 'Test Category'); - $shelfPage->assertElementContains('.tag-item', 'Test Tag Value'); + $this->withHtml($shelfPage)->assertElementContains('.tag-item', 'Test Category'); + $this->withHtml($shelfPage)->assertElementContains('.tag-item', 'Test Tag Value'); $this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id, 'book_id' => $booksToInclude[0]->id]); $this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id, 'book_id' => $booksToInclude[1]->id]); @@ -282,7 +282,7 @@ class BookShelfTest extends TestCase $this->assertTrue($shelf->deletions()->count() === 1); $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location')); - $redirectReq->assertNotificationContains('Bookshelf Successfully Deleted'); + $this->assertNotificationContains($redirectReq, 'Bookshelf Successfully Deleted'); } public function test_shelf_copy_permissions() @@ -323,22 +323,22 @@ class BookShelfTest extends TestCase $this->asAdmin(); $bookVisit = $this->get($shelfBook->getUrl()); - $bookVisit->assertElementNotContains('.breadcrumbs', 'Shelves'); - $bookVisit->assertElementNotContains('.breadcrumbs', $shelf->getShortName()); + $this->withHtml($bookVisit)->assertElementNotContains('.breadcrumbs', 'Shelves'); + $this->withHtml($bookVisit)->assertElementNotContains('.breadcrumbs', $shelf->getShortName()); $this->get($shelf->getUrl()); $bookVisit = $this->get($shelfBook->getUrl()); - $bookVisit->assertElementContains('.breadcrumbs', 'Shelves'); - $bookVisit->assertElementContains('.breadcrumbs', $shelf->getShortName()); + $this->withHtml($bookVisit)->assertElementContains('.breadcrumbs', 'Shelves'); + $this->withHtml($bookVisit)->assertElementContains('.breadcrumbs', $shelf->getShortName()); $pageVisit = $this->get($shelfPage->getUrl()); - $pageVisit->assertElementContains('.breadcrumbs', 'Shelves'); - $pageVisit->assertElementContains('.breadcrumbs', $shelf->getShortName()); + $this->withHtml($pageVisit)->assertElementContains('.breadcrumbs', 'Shelves'); + $this->withHtml($pageVisit)->assertElementContains('.breadcrumbs', $shelf->getShortName()); $this->get('/books'); $pageVisit = $this->get($shelfPage->getUrl()); - $pageVisit->assertElementNotContains('.breadcrumbs', 'Shelves'); - $pageVisit->assertElementNotContains('.breadcrumbs', $shelf->getShortName()); + $this->withHtml($pageVisit)->assertElementNotContains('.breadcrumbs', 'Shelves'); + $this->withHtml($pageVisit)->assertElementNotContains('.breadcrumbs', $shelf->getShortName()); } public function test_bookshelves_show_on_book() @@ -361,7 +361,7 @@ class BookShelfTest extends TestCase $newBook = Book::query()->orderBy('id', 'desc')->first(); $resp = $this->asEditor()->get($newBook->getUrl()); - $resp->assertElementContains('.tri-layout-left-contents', $shelfInfo['name']); + $this->withHtml($resp)->assertElementContains('.tri-layout-left-contents', $shelfInfo['name']); // Remove shelf $this->delete($shelf->getUrl()); @@ -375,6 +375,6 @@ class BookShelfTest extends TestCase /** @var Bookshelf $shelf */ $shelf = Bookshelf::query()->first(); $resp = $this->asEditor()->get($shelf->getUrl('/create-book')); - $resp->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel'); + $this->withHtml($resp)->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel'); } } diff --git a/tests/Entity/BookTest.php b/tests/Entity/BookTest.php index 6b3c6aa38..2e6f8e9de 100644 --- a/tests/Entity/BookTest.php +++ b/tests/Entity/BookTest.php @@ -19,10 +19,10 @@ class BookTest extends TestCase ]); $resp = $this->asEditor()->get('/books'); - $resp->assertElementContains('a[href="' . url('/create-book') . '"]', 'Create New Book'); + $this->withHtml($resp)->assertElementContains('a[href="' . url('/create-book') . '"]', 'Create New Book'); $resp = $this->get('/create-book'); - $resp->assertElementContains('form[action="' . url('/books') . '"][method="POST"]', 'Save Book'); + $this->withHtml($resp)->assertElementContains('form[action="' . url('/books') . '"][method="POST"]', 'Save Book'); $resp = $this->post('/books', $book->only('name', 'description')); $resp->assertRedirect('/books/my-first-book'); @@ -91,7 +91,7 @@ class BookTest extends TestCase $resp = $this->get($book->getUrl('/edit')); $resp->assertSee($book->name); $resp->assertSee($book->description); - $resp->assertElementContains('form[action="' . $book->getUrl() . '"]', 'Save Book'); + $this->withHtml($resp)->assertElementContains('form[action="' . $book->getUrl() . '"]', 'Save Book'); $resp = $this->put($book->getUrl(), ['name' => $newName, 'description' => $newDesc]); $resp->assertRedirect($book->getUrl() . '-updated'); @@ -155,13 +155,13 @@ class BookTest extends TestCase $this->assertTrue($book->deletions()->count() === 1); $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location')); - $redirectReq->assertNotificationContains('Book Successfully Deleted'); + $this->assertNotificationContains($redirectReq, 'Book Successfully Deleted'); } public function test_cancel_on_create_page_leads_back_to_books_listing() { $resp = $this->asEditor()->get('/create-book'); - $resp->assertElementContains('form a[href="' . url('/books') . '"]', 'Cancel'); + $this->withHtml($resp)->assertElementContains('form a[href="' . url('/books') . '"]', 'Cancel'); } public function test_cancel_on_edit_book_page_leads_back_to_book() @@ -169,7 +169,7 @@ class BookTest extends TestCase /** @var Book $book */ $book = Book::query()->first(); $resp = $this->asEditor()->get($book->getUrl('/edit')); - $resp->assertElementContains('form a[href="' . $book->getUrl() . '"]', 'Cancel'); + $this->withHtml($resp)->assertElementContains('form a[href="' . $book->getUrl() . '"]', 'Cancel'); } public function test_next_previous_navigation_controls_show_within_book_content() @@ -178,28 +178,28 @@ class BookTest extends TestCase $chapter = $book->chapters->first(); $resp = $this->asEditor()->get($chapter->getUrl()); - $resp->assertElementContains('#sibling-navigation', 'Next'); - $resp->assertElementContains('#sibling-navigation', substr($chapter->pages[0]->name, 0, 20)); + $this->withHtml($resp)->assertElementContains('#sibling-navigation', 'Next'); + $this->withHtml($resp)->assertElementContains('#sibling-navigation', substr($chapter->pages[0]->name, 0, 20)); $resp = $this->get($chapter->pages[0]->getUrl()); - $resp->assertElementContains('#sibling-navigation', substr($chapter->pages[1]->name, 0, 20)); - $resp->assertElementContains('#sibling-navigation', 'Previous'); - $resp->assertElementContains('#sibling-navigation', substr($chapter->name, 0, 20)); + $this->withHtml($resp)->assertElementContains('#sibling-navigation', substr($chapter->pages[1]->name, 0, 20)); + $this->withHtml($resp)->assertElementContains('#sibling-navigation', 'Previous'); + $this->withHtml($resp)->assertElementContains('#sibling-navigation', substr($chapter->name, 0, 20)); } public function test_recently_viewed_books_updates_as_expected() { $books = Book::all()->take(2); - $this->asAdmin()->get('/books') - ->assertElementNotContains('#recents', $books[0]->name) + $resp = $this->asAdmin()->get('/books'); + $this->withHtml($resp)->assertElementNotContains('#recents', $books[0]->name) ->assertElementNotContains('#recents', $books[1]->name); $this->get($books[0]->getUrl()); $this->get($books[1]->getUrl()); - $this->get('/books') - ->assertElementContains('#recents', $books[0]->name) + $resp = $this->get('/books'); + $this->withHtml($resp)->assertElementContains('#recents', $books[0]->name) ->assertElementContains('#recents', $books[1]->name); } @@ -207,16 +207,16 @@ class BookTest extends TestCase { $books = Book::all()->take(2); - $this->asAdmin()->get('/books') - ->assertElementNotContains('#popular', $books[0]->name) + $resp = $this->asAdmin()->get('/books'); + $this->withHtml($resp)->assertElementNotContains('#popular', $books[0]->name) ->assertElementNotContains('#popular', $books[1]->name); $this->get($books[0]->getUrl()); $this->get($books[1]->getUrl()); $this->get($books[0]->getUrl()); - $this->get('/books') - ->assertElementContains('#popular .book:nth-child(1)', $books[0]->name) + $resp = $this->get('/books'); + $this->withHtml($resp)->assertElementContains('#popular .book:nth-child(1)', $books[0]->name) ->assertElementContains('#popular .book:nth-child(2)', $books[1]->name); } @@ -227,16 +227,16 @@ class BookTest extends TestCase setting()->putUser($editor, 'books_view_type', 'list'); $resp = $this->actingAs($editor)->get('/books'); - $resp->assertElementContains('form[action$="/settings/users/' . $editor->id . '/switch-books-view"]', 'Grid View'); - $resp->assertElementExists('input[name="view_type"][value="grid"]'); + $this->withHtml($resp)->assertElementContains('form[action$="/settings/users/' . $editor->id . '/switch-books-view"]', 'Grid View'); + $this->withHtml($resp)->assertElementExists('input[name="view_type"][value="grid"]'); $resp = $this->patch("/settings/users/{$editor->id}/switch-books-view", ['view_type' => 'grid']); $resp->assertRedirect(); $this->assertEquals('grid', setting()->getUser($editor, 'books_view_type')); $resp = $this->actingAs($editor)->get('/books'); - $resp->assertElementContains('form[action$="/settings/users/' . $editor->id . '/switch-books-view"]', 'List View'); - $resp->assertElementExists('input[name="view_type"][value="list"]'); + $this->withHtml($resp)->assertElementContains('form[action$="/settings/users/' . $editor->id . '/switch-books-view"]', 'List View'); + $this->withHtml($resp)->assertElementExists('input[name="view_type"][value="list"]'); $resp = $this->patch("/settings/users/{$editor->id}/switch-books-view", ['view_type' => 'list']); $resp->assertRedirect(); @@ -273,7 +273,7 @@ class BookTest extends TestCase $book = Book::query()->first(); $resp = $this->asEditor()->get($book->getUrl()); - $resp->assertElementContains("a[href=\"{$book->getUrl('/copy')}\"]", 'Copy'); + $this->withHtml($resp)->assertElementContains("a[href=\"{$book->getUrl('/copy')}\"]", 'Copy'); } public function test_copy_view() @@ -284,7 +284,7 @@ class BookTest extends TestCase $resp->assertOk(); $resp->assertSee('Copy Book'); - $resp->assertElementExists("input[name=\"name\"][value=\"{$book->name}\"]"); + $this->withHtml($resp)->assertElementExists("input[name=\"name\"][value=\"{$book->name}\"]"); } public function test_copy() diff --git a/tests/Entity/ChapterTest.php b/tests/Entity/ChapterTest.php index f099ca2bb..5a761b94f 100644 --- a/tests/Entity/ChapterTest.php +++ b/tests/Entity/ChapterTest.php @@ -19,10 +19,10 @@ class ChapterTest extends TestCase ]); $resp = $this->asEditor()->get($book->getUrl()); - $resp->assertElementContains('a[href="' . $book->getUrl('/create-chapter') . '"]', 'New Chapter'); + $this->withHtml($resp)->assertElementContains('a[href="' . $book->getUrl('/create-chapter') . '"]', 'New Chapter'); $resp = $this->get($book->getUrl('/create-chapter')); - $resp->assertElementContains('form[action="' . $book->getUrl('/create-chapter') . '"][method="POST"]', 'Save Chapter'); + $this->withHtml($resp)->assertElementContains('form[action="' . $book->getUrl('/create-chapter') . '"][method="POST"]', 'Save Chapter'); $resp = $this->post($book->getUrl('/create-chapter'), $chapter->only('name', 'description')); $resp->assertRedirect($book->getUrl('/chapter/my-first-chapter')); @@ -53,7 +53,7 @@ class ChapterTest extends TestCase $this->assertTrue($chapter->deletions()->count() === 1); $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location')); - $redirectReq->assertNotificationContains('Chapter Successfully Deleted'); + $this->assertNotificationContains($redirectReq, 'Chapter Successfully Deleted'); } public function test_show_view_has_copy_button() @@ -62,7 +62,7 @@ class ChapterTest extends TestCase $chapter = Chapter::query()->first(); $resp = $this->asEditor()->get($chapter->getUrl()); - $resp->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy'); + $this->withHtml($resp)->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy'); } public function test_copy_view() @@ -73,8 +73,8 @@ class ChapterTest extends TestCase $resp = $this->asEditor()->get($chapter->getUrl('/copy')); $resp->assertOk(); $resp->assertSee('Copy Chapter'); - $resp->assertElementExists("input[name=\"name\"][value=\"{$chapter->name}\"]"); - $resp->assertElementExists('input[name="entity_selection"]'); + $this->withHtml($resp)->assertElementExists("input[name=\"name\"][value=\"{$chapter->name}\"]"); + $this->withHtml($resp)->assertElementExists('input[name="entity_selection"]'); } public function test_copy() diff --git a/tests/Entity/CommentSettingTest.php b/tests/Entity/CommentSettingTest.php index 23607f5a7..0e3199979 100644 --- a/tests/Entity/CommentSettingTest.php +++ b/tests/Entity/CommentSettingTest.php @@ -20,8 +20,8 @@ class CommentSettingTest extends TestCase $this->setSettings(['app-disable-comments' => 'true']); $this->asAdmin(); - $this->asAdmin()->get($this->page->getUrl()) - ->assertElementNotExists('.comments-list'); + $resp = $this->asAdmin()->get($this->page->getUrl()); + $this->withHtml($resp)->assertElementNotExists('.comments-list'); } public function test_comment_enable() @@ -29,7 +29,7 @@ class CommentSettingTest extends TestCase $this->setSettings(['app-disable-comments' => 'false']); $this->asAdmin(); - $this->asAdmin()->get($this->page->getUrl()) - ->assertElementExists('.comments-list'); + $resp = $this->asAdmin()->get($this->page->getUrl()); + $this->withHtml($resp)->assertElementExists('.comments-list'); } } diff --git a/tests/Entity/ConvertTest.php b/tests/Entity/ConvertTest.php index 9791f77e4..58f694f60 100644 --- a/tests/Entity/ConvertTest.php +++ b/tests/Entity/ConvertTest.php @@ -20,7 +20,7 @@ class ConvertTest extends TestCase $resp = $this->asEditor()->get($chapter->getUrl('/edit')); $resp->assertSee('Convert to Book'); $resp->assertSee('Convert Chapter'); - $resp->assertElementExists('form[action$="/convert-to-book"] button'); + $this->withHtml($resp)->assertElementExists('form[action$="/convert-to-book"] button'); } public function test_convert_chapter_to_book() @@ -77,7 +77,7 @@ class ConvertTest extends TestCase $resp->assertSee('Convert to Shelf'); $resp->assertSee('Convert Book'); $resp->assertSee('Note that permissions on shelves do not auto-cascade to content'); - $resp->assertElementExists('form[action$="/convert-to-shelf"] button'); + $this->withHtml($resp)->assertElementExists('form[action$="/convert-to-shelf"] button'); } public function test_book_convert_to_shelf() diff --git a/tests/Entity/EntitySearchTest.php b/tests/Entity/EntitySearchTest.php index a23a2fd26..3a9b9f31b 100644 --- a/tests/Entity/EntitySearchTest.php +++ b/tests/Entity/EntitySearchTest.php @@ -237,12 +237,12 @@ class EntitySearchTest extends TestCase $searchUrl = '/ajax/search/entities?permission=update&term=' . urlencode($page->name); $resp = $this->asEditor()->get($searchUrl); - $resp->assertElementContains($baseSelector, $page->name); - $resp->assertElementNotContains($baseSelector, "You don't have the required permissions to select this item"); + $this->withHtml($resp)->assertElementContains($baseSelector, $page->name); + $this->withHtml($resp)->assertElementNotContains($baseSelector, "You don't have the required permissions to select this item"); $resp = $this->actingAs($this->getViewer())->get($searchUrl); - $resp->assertElementContains($baseSelector, $page->name); - $resp->assertElementContains($baseSelector, "You don't have the required permissions to select this item"); + $this->withHtml($resp)->assertElementContains($baseSelector, $page->name); + $this->withHtml($resp)->assertElementContains($baseSelector, "You don't have the required permissions to select this item"); } public function test_sibling_search_for_pages() @@ -338,16 +338,16 @@ class EntitySearchTest extends TestCase $this->newPage(['name' => 'Test page B', 'html' => '

cat biscuit

']); $search = $this->asEditor()->get('/search?term=cat+dog+biscuit'); - $search->assertElementContains('.entity-list > .page', 'Test page A', 1); - $search->assertElementContains('.entity-list > .page', 'Test page B', 2); + $this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(1)', 'Test page A'); + $this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(2)', 'Test page B'); for ($i = 0; $i < 2; $i++) { $this->newPage(['name' => 'Test page ' . $i, 'html' => '

dog

']); } $search = $this->asEditor()->get('/search?term=cat+dog+biscuit'); - $search->assertElementContains('.entity-list > .page', 'Test page B', 1); - $search->assertElementContains('.entity-list > .page', 'Test page A', 2); + $this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(1)', 'Test page B'); + $this->withHtml($search)->assertElementContains('.entity-list > .page:nth-child(2)', 'Test page A'); } public function test_terms_in_headers_have_an_adjusted_index_score() @@ -413,9 +413,9 @@ class EntitySearchTest extends TestCase // Content $search->assertSee('A superimportant page about meowieable animals', false); // Tag name - $search->assertElementContains('.tag-name.highlight', 'SuperImportant'); + $this->withHtml($search)->assertElementContains('.tag-name.highlight', 'SuperImportant'); // Tag value - $search->assertElementContains('.tag-value.highlight', 'MeowieCat'); + $this->withHtml($search)->assertElementContains('.tag-value.highlight', 'MeowieCat'); } public function test_match_highlighting_works_with_multibyte_content() @@ -452,7 +452,7 @@ class EntitySearchTest extends TestCase public function test_searches_with_user_filters_adds_them_into_advanced_search_form() { $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:me} {created_by:dan}')); - $resp->assertElementExists('form input[type="hidden"][name="filters[updated_by]"][value="me"]'); - $resp->assertElementExists('form input[type="hidden"][name="filters[created_by]"][value="dan"]'); + $this->withHtml($resp)->assertElementExists('form input[type="hidden"][name="filters[updated_by]"][value="me"]'); + $this->withHtml($resp)->assertElementExists('form input[type="hidden"][name="filters[created_by]"][value="dan"]'); } } diff --git a/tests/Entity/ExportTest.php b/tests/Entity/ExportTest.php index 826b69be5..0d13d208e 100644 --- a/tests/Entity/ExportTest.php +++ b/tests/Entity/ExportTest.php @@ -454,7 +454,7 @@ class ExportTest extends TestCase foreach ($entities as $entity) { $resp = $this->asEditor()->get($entity->getUrl('/export/html')); - $resp->assertElementExists('head meta[http-equiv="Content-Security-Policy"][content*="script-src "]'); + $this->withHtml($resp)->assertElementExists('head meta[http-equiv="Content-Security-Policy"][content*="script-src "]'); } } @@ -463,6 +463,6 @@ class ExportTest extends TestCase $page = Page::query()->first(); $resp = $this->asEditor()->get($page->getUrl('/export/html')); - $resp->assertElementExists('body.export.export-format-html.export-engine-none'); + $this->withHtml($resp)->assertElementExists('body.export.export-format-html.export-engine-none'); } } diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index c18ae18f7..d433c8b88 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -149,8 +149,8 @@ class PageContentTest extends TestCase $pageView = $this->get($page->getUrl()); $pageView->assertStatus(200); - $pageView->assertElementNotContains('.page-content', ''); + $this->withHtml($pageView)->assertElementNotContains('.page-content', ''); } } @@ -185,13 +185,14 @@ class PageContentTest extends TestCase $pageView = $this->get($page->getUrl()); $pageView->assertStatus(200); - $pageView->assertElementNotContains('.page-content', ''); - $pageView->assertElementNotContains('.page-content', 'src='); - $pageView->assertElementNotContains('.page-content', 'javascript:'); - $pageView->assertElementNotContains('.page-content', 'data:'); - $pageView->assertElementNotContains('.page-content', 'base64'); + $html = $this->withHtml($pageView); + $html->assertElementNotContains('.page-content', ''); + $html->assertElementNotContains('.page-content', 'src='); + $html->assertElementNotContains('.page-content', 'javascript:'); + $html->assertElementNotContains('.page-content', 'data:'); + $html->assertElementNotContains('.page-content', 'base64'); } } @@ -213,8 +214,8 @@ class PageContentTest extends TestCase $pageView = $this->get($page->getUrl()); $pageView->assertStatus(200); - $pageView->assertElementNotContains('.page-content', 'assertElementNotContains('.page-content', 'href=javascript:'); + $this->withHtml($pageView)->assertElementNotContains('.page-content', 'withHtml($pageView)->assertElementNotContains('.page-content', 'href=javascript:'); } } @@ -237,11 +238,11 @@ class PageContentTest extends TestCase $pageView = $this->get($page->getUrl()); $pageView->assertStatus(200); - $pageView->assertElementNotContains('.page-content', '