Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 1 | use Mojo::Base -strict; |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 2 | use Mojolicious::Lite; |
| 3 | use Test::More; |
| 4 | use Test::Mojo; |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 5 | use utf8; |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 6 | |
| 7 | my $t = Test::Mojo->new; |
| 8 | my $app = $t->app; |
| 9 | |
| 10 | # Add additional plugin path |
| 11 | push(@{$app->plugins->namespaces}, 'Kalamar::Plugin'); |
| 12 | |
| 13 | # Establish test route |
Akron | 254fe21 | 2019-10-24 14:33:28 +0200 | [diff] [blame] | 14 | $app->routes->get('/doc/:scope/:page')->to(cb => sub {}, scope => undef)->name('doc'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 15 | |
| 16 | # Load plugin to test |
Akron | 41a190a | 2019-10-16 18:01:02 +0200 | [diff] [blame] | 17 | $app->plugin('KalamarPages'); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 18 | |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 19 | my $languages = [qw/en de/]; |
| 20 | $app->plugin('Localize' => { |
| 21 | dict => { |
| 22 | Nav => { |
| 23 | _ => sub { $languages }, |
| 24 | -en => { |
| 25 | faq => 'F.A.Q.', |
| 26 | '#default-foundries' => 'Default Foundries', |
| 27 | }, |
| 28 | de => { |
| 29 | faq => 'Häufige Fragen', |
| 30 | '#default-foundries' => 'Standard Foundries' |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | }); |
| 35 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 36 | my $navi = [ |
| 37 | { |
| 38 | id => 'korap', |
| 39 | title => 'KorAP' |
| 40 | } |
| 41 | ]; |
| 42 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 43 | my $render = $app->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 44 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 45 | like($render, qr!KorAP!, 'Title matches'); |
| 46 | |
| 47 | $navi = [ |
| 48 | { |
| 49 | id => 'korap', |
| 50 | title => 'KorAP' |
| 51 | }, |
| 52 | { |
| 53 | id => 'krill', |
| 54 | title => 'Krill' |
| 55 | } |
| 56 | ]; |
| 57 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 58 | $render = $app->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 59 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 60 | like($render, qr!KorAP!, 'Title matches'); |
| 61 | like($render, qr!/doc/krill!, 'Path matches doc/krill'); |
| 62 | like($render, qr!Krill!, 'Title matches'); |
| 63 | |
| 64 | $navi = [ |
| 65 | { |
| 66 | id => 'korap', |
| 67 | title => 'KorAP', |
| 68 | items => [ |
| 69 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 70 | id => 'krill', |
| 71 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 72 | } |
| 73 | ] |
| 74 | }, |
| 75 | { |
| 76 | id => 'faq', |
| 77 | title => 'F.A.Q.' |
| 78 | } |
| 79 | ]; |
| 80 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 81 | $render = $app->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 82 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 83 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 84 | like($render, qr!/doc/faq!, 'Path matches doc/faq'); |
| 85 | |
| 86 | $navi = [ |
| 87 | { |
| 88 | id => 'korap', |
| 89 | title => 'KorAP', |
| 90 | items => [ |
| 91 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 92 | id => 'krill', |
| 93 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 94 | }, |
| 95 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 96 | id => 'koral', |
| 97 | title => 'Koral' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 98 | } |
| 99 | ] |
| 100 | }, |
| 101 | { |
| 102 | title => 'Query Languages', |
| 103 | id => 'ql', |
| 104 | items => [ |
| 105 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 106 | title => 'Cosmas II', |
| 107 | id => 'cosmas2' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 108 | }, |
| 109 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 110 | 'title' => 'Poliqarp+', |
| 111 | 'id' => 'poliqarp-plus', |
| 112 | items => [ |
| 113 | { |
| 114 | "title" => "Simple Segments", |
| 115 | "id" => "#segments" |
| 116 | }, |
| 117 | { |
| 118 | "title" => "Complex Segments", |
| 119 | "id" => "#complex" |
| 120 | } |
| 121 | ] |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 122 | } |
| 123 | ] |
| 124 | }, |
| 125 | { |
| 126 | id => 'faq', |
| 127 | title => 'F.A.Q.' |
| 128 | } |
| 129 | ]; |
| 130 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 131 | $render = $app->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 132 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 133 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 134 | like($render, qr!/doc/korap/koral!, 'Path matches korap/koral'); |
| 135 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 136 | like($render, qr!/doc/ql/cosmas2!, 'Path matches doc/ql/cosmas2'); |
| 137 | like($render, qr!/doc/ql/poliqarp-plus!, 'Path matches doc/ql/poliqarp-plus'); |
| 138 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 139 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 140 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 141 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 142 | like($render, qr!/doc/faq!, 'Path matches doc/faq'); |
| 143 | |
Akron | 5999212 | 2019-10-29 11:28:45 +0100 | [diff] [blame] | 144 | ok($app->navi->exists('doc')); |
| 145 | ok(!$app->navi->exists('xy')); |
| 146 | is($app->navigation('xy'), '');; |
| 147 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 148 | |
| 149 | my $c = $app->build_controller; |
| 150 | $c->stash(page => 'korap'); |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 151 | $render = $c->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 152 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 153 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 154 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 155 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 156 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 157 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 158 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 159 | like($render, qr!class="active".*?KorAP!, 'Active value for KorAP'); |
| 160 | |
| 161 | $c->stash(page => 'poliqarp-plus'); |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 162 | $render = $c->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 163 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 164 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 165 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 166 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 167 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 168 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 169 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 170 | like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+'); |
| 171 | |
| 172 | |
| 173 | $navi = [ |
| 174 | { |
| 175 | id => 'korap', |
| 176 | title => 'KorAP', |
| 177 | items => [ |
| 178 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 179 | id => 'krill', |
| 180 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 181 | }, |
| 182 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 183 | id => 'koral', |
| 184 | title => 'Koral' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 185 | } |
| 186 | ] |
| 187 | }, |
| 188 | { |
| 189 | title => 'Query Languages', |
| 190 | id => 'ql', |
| 191 | items => [ |
| 192 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 193 | title => 'Cosmas II', |
| 194 | id => 'cosmas2' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 195 | }, |
| 196 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 197 | 'title' => 'Poliqarp+', |
| 198 | 'id' => 'poliqarp-plus', |
| 199 | 'class' => 'folded', |
| 200 | items => [ |
| 201 | { |
| 202 | "title" => "Simple Segments", |
| 203 | "id" => "#segments" |
| 204 | }, |
| 205 | { |
| 206 | "title" => "Complex Segments", |
| 207 | "id" => "#complex" |
| 208 | } |
| 209 | ] |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 210 | } |
| 211 | ] |
| 212 | }, |
| 213 | { |
| 214 | id => 'faq', |
| 215 | title => 'F.A.Q.' |
| 216 | } |
| 217 | ]; |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 218 | $render = $c->navigation('doc', $navi); |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 219 | |
| 220 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 221 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 222 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 223 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 224 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 225 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 226 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 227 | like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+'); |
| 228 | |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 229 | |
| 230 | # Test for translations |
| 231 | $navi = [ |
| 232 | { |
| 233 | id => 'korap', |
| 234 | title => 'KorAP', |
| 235 | items => [ |
| 236 | { |
| 237 | id => 'krill', |
| 238 | title => 'Krill', |
| 239 | } |
| 240 | ] |
| 241 | }, |
| 242 | { |
| 243 | id => 'faq', |
| 244 | title => 'F.A.Q.' |
| 245 | } |
| 246 | ]; |
| 247 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 248 | $render = $app->navigation('doc', $navi); |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 249 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 250 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 251 | like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 252 | 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 253 | like($render, qr!<a href="/doc/faq(?:#[^"]+)?">F\.A\.Q\.</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 254 | 'Path matches FAQ'); |
| 255 | |
| 256 | # Change preferred language |
| 257 | $languages = [qw/de en/]; |
| 258 | |
Akron | d512ea6 | 2019-10-24 15:50:04 +0200 | [diff] [blame] | 259 | $render = $app->navigation('doc', $navi); |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 260 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 261 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 262 | like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 263 | 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 264 | like($render, qr!<a href="/doc/faq(?:#[^"]+)?">Häufige Fragen</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 265 | 'Path matches FAQ'); |
| 266 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 267 | done_testing; |
| 268 | |
| 269 | __END__ |
| 270 | |