Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 1 | use Mojo::Base -strict; |
| 2 | use lib '../lib', 'lib'; |
| 3 | use Test::More; |
| 4 | use Test::Mojo; |
| 5 | |
| 6 | my $t = Test::Mojo->new('Korap'); |
| 7 | |
| 8 | $t->app->routes->get('/searchtest')->to( |
| 9 | cb => sub { |
| 10 | my $c = shift; |
| 11 | $c->render(inline => <<'TEMPLATE'); |
| 12 | %= search query => 'baum', start_page => param('p'), no_cache => 1, begin |
| 13 | <h1><%= search->query %></h1> |
| 14 | <p id="api"><%= search->api %></p> |
| 15 | <p id="cutoff"><%= search->cutoff %></p> |
| 16 | <p id="ql"><%= search->query_language %></p> |
| 17 | <p id="no_cache"><%= search->no_cache %></p> |
| 18 | <p id="start_page"><%= search->start_page %></p> |
| 19 | <p id="total_results"><%= search->total_results %></p> |
| 20 | <p id="api_request"><%= search->api_request %></p> |
| 21 | %= search_results begin |
| 22 | <li><%= $_->{ID} %></li> |
| 23 | % end |
| 24 | % end |
| 25 | TEMPLATE |
| 26 | } |
| 27 | ); |
| 28 | |
| 29 | my $exttemplate = <<'EXTTEMPLATE'; |
| 30 | <h1><%= search->query %></h1> |
| 31 | <p id="api"><%= search->api %></p> |
| 32 | <p id="cutoff"><%= search->cutoff %></p> |
| 33 | <p id="ql"><%= search->query_language %></p> |
| 34 | <p id="no_cache"><%= search->no_cache %></p> |
| 35 | <p id="start_page"><%= search->start_page %></p> |
| 36 | <p id="total_results"><%= search->total_results %></p> |
| 37 | <p id="api_request"><%= search->api_request %></p> |
| 38 | %= search_results begin |
| 39 | <li><%= $_->{ID} %></li> |
| 40 | % end |
| 41 | EXTTEMPLATE |
| 42 | |
| 43 | |
| 44 | $t->app->routes->get('/searchasync')->to( |
| 45 | cb => sub { |
| 46 | my $c = shift; |
| 47 | $c->search( |
| 48 | query => 'baum', |
| 49 | start_page => $c->param('p'), |
| 50 | no_cache => 1, |
| 51 | cb => sub { |
| 52 | return $c->render(inline => $exttemplate); |
| 53 | } |
| 54 | ); |
| 55 | } |
| 56 | ); |
| 57 | |
| 58 | $t->get_ok('/searchasync') |
| 59 | ->status_is(200) |
| 60 | ->text_is('.notify-error', '') |
| 61 | ->text_is('h1', 'baum') |
| 62 | ->text_is('#api', 'http://10.0.10.13:7070/api/v0.1/') |
| 63 | ->text_is('#cutoff', '') |
| 64 | ->text_is('#ql', 'poliqarp') |
| 65 | ->text_is('#no_cache', 1) |
| 66 | ->text_is('#start_page', 1) |
| 67 | ->text_is('#total_results', 3) |
| 68 | ->text_is('li', 'p265-266'); |
| 69 | |
| 70 | |
| 71 | $t->get_ok('/searchtest') |
| 72 | ->status_is(200) |
| 73 | ->text_is('.notify-error', '') |
| 74 | ->text_is('h1', 'baum') |
| 75 | ->text_is('#api', 'http://10.0.10.13:7070/api/v0.1/') |
| 76 | ->text_is('#cutoff', '') |
| 77 | ->text_is('#ql', 'poliqarp') |
| 78 | ->text_is('#no_cache', 1) |
| 79 | ->text_is('#start_page', 1) |
| 80 | ->text_is('#total_results', 3) |
| 81 | ->text_is('li', 'p265-266'); |
| 82 | |
| 83 | |
| 84 | done_testing; |