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 | |
| 43 | my $render = $app->doc_navi($navi); |
| 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 | |
| 58 | $render = $app->doc_navi($navi); |
| 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 | |
| 81 | $render = $app->doc_navi($navi); |
| 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 | |
| 131 | $render = $app->doc_navi($navi); |
| 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 | |
| 144 | |
| 145 | my $c = $app->build_controller; |
| 146 | $c->stash(page => 'korap'); |
| 147 | $render = $c->doc_navi($navi); |
| 148 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 149 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 150 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 151 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 152 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 153 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 154 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 155 | like($render, qr!class="active".*?KorAP!, 'Active value for KorAP'); |
| 156 | |
| 157 | $c->stash(page => 'poliqarp-plus'); |
| 158 | $render = $c->doc_navi($navi); |
| 159 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 160 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 161 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 162 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 163 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 164 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 165 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 166 | like($render, qr!class="active".*?Poliqarp\+!, 'Active value for Poliqarp+'); |
| 167 | |
| 168 | |
| 169 | $navi = [ |
| 170 | { |
| 171 | id => 'korap', |
| 172 | title => 'KorAP', |
| 173 | items => [ |
| 174 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 175 | id => 'krill', |
| 176 | title => 'Krill', |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 177 | }, |
| 178 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 179 | id => 'koral', |
| 180 | title => 'Koral' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 181 | } |
| 182 | ] |
| 183 | }, |
| 184 | { |
| 185 | title => 'Query Languages', |
| 186 | id => 'ql', |
| 187 | items => [ |
| 188 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 189 | title => 'Cosmas II', |
| 190 | id => 'cosmas2' |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 191 | }, |
| 192 | { |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 193 | 'title' => 'Poliqarp+', |
| 194 | 'id' => 'poliqarp-plus', |
| 195 | 'class' => 'folded', |
| 196 | items => [ |
| 197 | { |
| 198 | "title" => "Simple Segments", |
| 199 | "id" => "#segments" |
| 200 | }, |
| 201 | { |
| 202 | "title" => "Complex Segments", |
| 203 | "id" => "#complex" |
| 204 | } |
| 205 | ] |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 206 | } |
| 207 | ] |
| 208 | }, |
| 209 | { |
| 210 | id => 'faq', |
| 211 | title => 'F.A.Q.' |
| 212 | } |
| 213 | ]; |
| 214 | $render = $c->doc_navi($navi); |
| 215 | |
| 216 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 217 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
| 218 | like($render, qr!/doc/ql!, 'Path matches doc/ql'); |
| 219 | like($render, qr!/doc/ql/poliqarp-plus#segments!, |
| 220 | 'Path matches doc/ql/poliqarp-plus#segments'); |
| 221 | like($render, qr!/doc/ql/poliqarp-plus#complex!, |
| 222 | 'Path matches doc/ql/poliqarp-plus#complex'); |
| 223 | like($render, qr!class="folded active".*?Poliqarp\+!, 'Active and folded value for Poliqarp+'); |
| 224 | |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 225 | |
| 226 | # Test for translations |
| 227 | $navi = [ |
| 228 | { |
| 229 | id => 'korap', |
| 230 | title => 'KorAP', |
| 231 | items => [ |
| 232 | { |
| 233 | id => 'krill', |
| 234 | title => 'Krill', |
| 235 | } |
| 236 | ] |
| 237 | }, |
| 238 | { |
| 239 | id => 'faq', |
| 240 | title => 'F.A.Q.' |
| 241 | } |
| 242 | ]; |
| 243 | |
| 244 | $render = $app->doc_navi($navi); |
| 245 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 246 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 247 | like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 248 | 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 249 | like($render, qr!<a href="/doc/faq(?:#[^"]+)?">F\.A\.Q\.</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 250 | 'Path matches FAQ'); |
| 251 | |
| 252 | # Change preferred language |
| 253 | $languages = [qw/de en/]; |
| 254 | |
| 255 | $render = $app->doc_navi($navi); |
| 256 | like($render, qr!/doc/korap!, 'Path matches doc/korap'); |
| 257 | like($render, qr!/doc/korap/krill!, 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 258 | like($render, qr!<a href="/doc/korap/krill(?:#[^"]+)?">Krill</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 259 | 'Path matches korap/krill'); |
Akron | 2dd8754 | 2017-11-17 11:21:01 +0100 | [diff] [blame] | 260 | like($render, qr!<a href="/doc/faq(?:#[^"]+)?">Häufige Fragen</a>!, |
Akron | 0dc1090 | 2017-09-01 18:00:16 +0200 | [diff] [blame] | 261 | 'Path matches FAQ'); |
| 262 | |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 263 | done_testing; |
| 264 | |
| 265 | __END__ |
| 266 | |