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