Akron | f7ec444 | 2019-10-27 20:01:05 +0100 | [diff] [blame] | 1 | package Kalamar::Plugin::Test; |
| 2 | use Mojo::Base 'Mojolicious::Plugin'; |
| 3 | |
| 4 | |
| 5 | sub register { |
| 6 | my ($plugin, $app, $param) = @_; |
| 7 | |
| 8 | # Add entry to settings navigation |
| 9 | $app->navi->add(settings => ( |
| 10 | 'OAuth Token Management', 'oauth' |
| 11 | )); |
| 12 | |
| 13 | $app->routes->get('/settings/oauth')->to( |
| 14 | cb => sub { |
| 15 | my $c = shift; |
| 16 | $c->content_with(settings => '<p id="abc">My Settings</p>'); |
| 17 | return $c->render('settings'); |
| 18 | } |
| 19 | ); |
| 20 | }; |
| 21 | |
| 22 | package main; |
| 23 | use Mojo::Base -strict; |
| 24 | use Test::More; |
| 25 | use Test::Mojo; |
| 26 | use Mojo::ByteStream 'b'; |
| 27 | |
| 28 | my $t = Test::Mojo->new('Kalamar' => { |
| 29 | Kalamar => { |
| 30 | plugins => ['Test'] |
| 31 | } |
| 32 | }); |
| 33 | |
| 34 | my $app = $t->app; |
| 35 | |
| 36 | $app->routes->get('/settings')->to(cb => sub { shift->render('settings') })->name('settings_start'); |
| 37 | $app->routes->get('/settings/:scope/:page')->to(scope => undef, page => undef)->name('settings'); |
| 38 | |
| 39 | |
| 40 | $t->get_ok('/settings') |
| 41 | ->text_is('a[href~/settings/oauth]','OAuth Token Management') |
| 42 | ->text_is('h2#page-top', 'Settings') |
| 43 | ; |
| 44 | |
| 45 | $t->get_ok('/settings/oauth') |
| 46 | ->text_is('a[href~/settings/oauth]','OAuth Token Management') |
| 47 | ->text_is('h2#page-top', 'Settings') |
| 48 | ->text_is('#abc', 'My Settings') |
| 49 | ; |
| 50 | |
| 51 | done_testing; |
| 52 | __END__ |