From c55a9c711c810bab753eab6b42dfbad102e879e2 Mon Sep 17 00:00:00 2001 From: "Emma C. Hughes" <84008144+emmachughes@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:10:06 +0100 Subject: [PATCH] hub: fix unsetting flags on tools (#2877) * hub: fix unsetting flags on tools * Run php-cs-fixer --------- Co-authored-by: emmachughes --- .../Http/Requests/UpdateLtiToolRequest.php | 4 ++ .../hub/database/factories/LtiToolFactory.php | 12 ++++- .../views/admin/lti-tools/index.blade.php | 8 +-- sourcecode/hub/tests/Browser/AdminTest.php | 53 ++++++++++++++++++- .../tests/Browser/Components/LtiToolCard.php | 33 ++++++++++++ 5 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 sourcecode/hub/tests/Browser/Components/LtiToolCard.php diff --git a/sourcecode/hub/app/Http/Requests/UpdateLtiToolRequest.php b/sourcecode/hub/app/Http/Requests/UpdateLtiToolRequest.php index a20744c8a..dc44aea9f 100644 --- a/sourcecode/hub/app/Http/Requests/UpdateLtiToolRequest.php +++ b/sourcecode/hub/app/Http/Requests/UpdateLtiToolRequest.php @@ -21,6 +21,10 @@ public function prepareForValidation(): void if (!$parameters->get('slug')) { $parameters->remove('slug'); } + + $parameters->set('send_name', $parameters->getBoolean('send_name', false)); + $parameters->set('send_email', $parameters->getBoolean('send_email', false)); + $parameters->set('proxy_launch', $parameters->getBoolean('proxy_launch', false)); } /** diff --git a/sourcecode/hub/database/factories/LtiToolFactory.php b/sourcecode/hub/database/factories/LtiToolFactory.php index a279b9724..8ba421f49 100644 --- a/sourcecode/hub/database/factories/LtiToolFactory.php +++ b/sourcecode/hub/database/factories/LtiToolFactory.php @@ -38,7 +38,17 @@ public function launchUrl(string $launchUrl): self return $this->state(['creator_launch_url' => $launchUrl]); } - public function proxyLaunch(bool $proxyLaunch): self + public function sendName(bool $sendName = true): self + { + return $this->state(['send_name' => $sendName]); + } + + public function sendEmail(bool $sendEmail = true): self + { + return $this->state(['send_email' => $sendEmail]); + } + + public function proxyLaunch(bool $proxyLaunch = true): self { return $this->state(['proxy_launch' => $proxyLaunch]); } diff --git a/sourcecode/hub/resources/views/admin/lti-tools/index.blade.php b/sourcecode/hub/resources/views/admin/lti-tools/index.blade.php index 91cb85954..f977881ae 100644 --- a/sourcecode/hub/resources/views/admin/lti-tools/index.blade.php +++ b/sourcecode/hub/resources/views/admin/lti-tools/index.blade.php @@ -5,7 +5,7 @@
@foreach ($tools as $tool) -
+
{{ $tool->name }}
@@ -41,15 +41,15 @@ {{ trans('messages.send-full-name-to-lti-tool', ['site' => config('app.name')]) }} - {{ $tool->send_name ? trans('messages.yes') : trans('messages.no') }} + {{ $tool->send_name ? trans('messages.yes') : trans('messages.no') }} {{ trans('messages.send-email-to-lti-tool', ['site' => config('app.name')]) }} - {{ $tool->send_email ? trans('messages.yes') : trans('messages.no') }} + {{ $tool->send_email ? trans('messages.yes') : trans('messages.no') }} {{ trans('messages.proxy-launch-to-lti-tool', ['site' => config('app.name')]) }} - {{ $tool->proxy_launch ? trans('messages.yes') : trans('messages.no') }} + {{ $tool->proxy_launch ? trans('messages.yes') : trans('messages.no') }} diff --git a/sourcecode/hub/tests/Browser/AdminTest.php b/sourcecode/hub/tests/Browser/AdminTest.php index 52ea330ec..48de9edc9 100644 --- a/sourcecode/hub/tests/Browser/AdminTest.php +++ b/sourcecode/hub/tests/Browser/AdminTest.php @@ -10,6 +10,7 @@ use Laravel\Dusk\Browser; use Tests\Browser\Components\LtiPlatformAddedAlert; use Tests\Browser\Components\LtiPlatformCard; +use Tests\Browser\Components\LtiToolCard; use Tests\DuskTestCase; final class AdminTest extends DuskTestCase @@ -193,7 +194,7 @@ public function testCreatesToolsWithSlug(): void ); } - public function testCanEditUrlSlug(): void + public function testCanEditUrlSlugForTool(): void { LtiTool::factory()->withName('Hammer')->slug('the-old-slug')->create(); $user = User::factory()->name('Ben Hammerhead')->admin()->create(); @@ -215,4 +216,54 @@ public function testCanEditUrlSlug(): void ->assertPresent('.lti-launch') ); } + + public function testCanEditFlagsForTool(): void + { + $user = User::factory()->name('Flagg Stang')->admin()->create(); + LtiTool::factory() + ->withName('The Tool') + ->sendName() + ->sendEmail() + ->proxyLaunch() + ->create(); + + $this->browse( + fn (Browser $browser) => + $browser + ->loginAs($user->email) + ->assertAuthenticated() + ->visit('/') + ->press('Flagg Stang') + ->clickLink('Admin home') + ->clickLink('Manage LTI tools') + ->with( + new LtiToolCard(), + fn (Browser $card) => + $card + ->assertSeeIn('@proxy-launch', 'Yes') + ->assertSeeIn('@send-email', 'Yes') + ->assertSeeIn('@send-name', 'Yes') + ) + ->clickLink('Edit') + ->assertChecked('proxy_launch') + ->uncheck('proxy_launch') + ->assertChecked('send_name') + ->uncheck('send_name') + ->assertChecked('send_email') + ->uncheck('send_email') + ->press('Update') + ->assertSee('LTI tool updated.') + ->press('Flagg Stang') + ->clickLink('Admin home') + ->clickLink('Manage LTI tools') + ->with( + new LtiToolCard(), + fn (Browser $card) => + $card + ->assertSeeIn('@proxy-launch', 'No') + ->assertSeeIn('@send-email', 'No') + ->assertSeeIn('@send-name', 'No') + ) + ); + } } diff --git a/sourcecode/hub/tests/Browser/Components/LtiToolCard.php b/sourcecode/hub/tests/Browser/Components/LtiToolCard.php new file mode 100644 index 000000000..3388b79ab --- /dev/null +++ b/sourcecode/hub/tests/Browser/Components/LtiToolCard.php @@ -0,0 +1,33 @@ +assertVisible($this->selector()); + } + + /** + * @return array + */ + public function elements(): array + { + return [ + '@proxy-launch' => '.lti-tool-card-proxy-launch', + '@send-email' => '.lti-tool-card-send-email', + '@send-name' => '.lti-tool-card-send-name', + ]; + } +}