blob: 072d6f55aa2a5670fd439512fe6b01364461bc26 [file] [log] [blame]
Akron88c26b12020-09-07 12:44:18 +02001package 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->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
23package main;
24use Mojo::Base -strict;
25use Test::More;
26use Test::Mojo;
27use Mojo::File qw/path/;
28
29
30#####################
31# Start Fake server #
32#####################
33my $mount_point = '/realapi/';
34$ENV{KALAMAR_API} = $mount_point;
35
36my $t = Test::Mojo->new('Kalamar' => {
37 Kalamar => {
38 plugins => ['Test']
39 }
40});
41
42# Mount fake backend
43# Get the fixture path
44my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server');
45my $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
Akron3b3a4342021-05-31 11:14:48 +020071$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*&_format=json')
Akron88c26b12020-09-07 12:44:18 +020072 ->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
88done_testing;