Akron | 88c26b1 | 2020-09-07 12:44:18 +0200 | [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->res->headers->header('X-Robots' => 'noindex'); |
| 17 | $c->content_with(settings => '<p id="abc">My Settings</p>'); |
| 18 | return $c->render('settings'); |
| 19 | } |
| 20 | ); |
| 21 | }; |
| 22 | |
| 23 | package main; |
| 24 | use Mojo::Base -strict; |
| 25 | use Test::More; |
| 26 | use Test::Mojo; |
| 27 | use Mojo::File qw/path/; |
| 28 | |
| 29 | |
| 30 | ##################### |
| 31 | # Start Fake server # |
| 32 | ##################### |
| 33 | my $mount_point = '/realapi/'; |
| 34 | $ENV{KALAMAR_API} = $mount_point; |
| 35 | |
| 36 | my $t = Test::Mojo->new('Kalamar' => { |
| 37 | Kalamar => { |
| 38 | plugins => ['Test'] |
| 39 | } |
| 40 | }); |
| 41 | |
| 42 | # Mount fake backend |
| 43 | # Get the fixture path |
| 44 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
| 45 | my $fake_backend = $t->app->plugin( |
| 46 | Mount => { |
| 47 | $mount_point => |
| 48 | $fixtures_path->child('mock.pl') |
| 49 | } |
| 50 | ); |
| 51 | # Configure fake backend |
| 52 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 53 | |
| 54 | # Test robots meta tag |
| 55 | |
| 56 | $t->get_ok('/') |
| 57 | ->attr_is('meta[name=robots]', 'content', 'index,follow') |
| 58 | ->header_isnt('X-Robots', 'noindex') |
| 59 | ; |
| 60 | |
| 61 | $t->get_ok('/doc/ql/poliqarp-plus') |
| 62 | ->attr_is('meta[name=robots]', 'content', 'index,follow') |
| 63 | ->header_isnt('X-Robots', 'noindex') |
| 64 | ; |
| 65 | |
| 66 | $t->get_ok('/corpus') |
| 67 | ->status_is(200) |
| 68 | ->header_is('X-Robots', 'noindex') |
| 69 | ; |
| 70 | |
| 71 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*&format=json') |
| 72 | ->status_is(200) |
| 73 | ->header_is('X-Robots', 'noindex') |
| 74 | ; |
| 75 | |
| 76 | $t->get_ok('/settings') |
| 77 | ->attr_is('meta[name=robots]', 'content', 'noindex') |
| 78 | ->header_is('X-Robots', 'noindex') |
| 79 | ; |
| 80 | |
| 81 | $t->get_ok('/?q=baum') |
| 82 | ->status_is(200) |
| 83 | ->text_is('#total-results', 51) |
| 84 | ->attr_is('meta[name=robots]', 'content', 'noindex') |
| 85 | ->header_is('X-Robots', 'noindex') |
| 86 | ; |
| 87 | |
| 88 | done_testing; |