blob: 9620504b4025dbd216d714b7765dfceb4e567b4a [file] [log] [blame]
Akronf7ec4442019-10-27 20:01:05 +01001package Kalamar::Plugin::Test;
2use Mojo::Base 'Mojolicious::Plugin';
3
4
5sub 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
22package main;
23use Mojo::Base -strict;
24use Test::More;
25use Test::Mojo;
26use Mojo::ByteStream 'b';
27
28my $t = Test::Mojo->new('Kalamar' => {
29 Kalamar => {
30 plugins => ['Test']
31 }
32});
33
34my $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
51done_testing;
52__END__