line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mojo::More; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26308
|
use Mojo::Base 'Test::Mojo'; |
|
1
|
|
|
|
|
11582
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
410542
|
use Mojolicious::Sessions; |
|
1
|
|
|
|
|
2023
|
|
|
1
|
|
|
|
|
14
|
|
6
|
1
|
|
|
1
|
|
42
|
use Mojo::Util qw(b64_decode b64_encode); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
52
|
|
7
|
1
|
|
|
1
|
|
5
|
use Mojo::JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
6
|
use Mojo::JSON::Pointer; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1118
|
use Mojolicious::Controller; |
|
1
|
|
|
|
|
147136
|
|
|
1
|
|
|
|
|
10
|
|
11
|
1
|
|
|
1
|
|
41
|
use Mojo::Message::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Test::Mojo::More - Test::Mojo and more. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.05 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = 0.050_000; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Test::More; |
29
|
|
|
|
|
|
|
use Test::Mojo::More; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $t = new Test::Mojo::More 'MyApp'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$t->post_ok('/account/login/', form => { |
34
|
|
|
|
|
|
|
login => 'false', |
35
|
|
|
|
|
|
|
pass => 123, |
36
|
|
|
|
|
|
|
}) |
37
|
|
|
|
|
|
|
->status_is(302) |
38
|
|
|
|
|
|
|
->flash_is( '/error/login' => 'Error login.' ) |
39
|
|
|
|
|
|
|
->cookie_hasnt( 'user_id' ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$t->post_ok('account/login/', form => { |
42
|
|
|
|
|
|
|
login => 'true', |
43
|
|
|
|
|
|
|
pass => 123, |
44
|
|
|
|
|
|
|
}) |
45
|
|
|
|
|
|
|
->status_is(302) |
46
|
|
|
|
|
|
|
->flash_hasnt( '/errror' ) |
47
|
|
|
|
|
|
|
->cookie_has( 'user_id' ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
done_testing; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
L is an extension for the L which allows |
55
|
|
|
|
|
|
|
you to test L and L applications. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
L inherits all attributed from L and inplements |
61
|
|
|
|
|
|
|
the following new ones. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 C |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
@a = $t->dom->find('.menu li a'); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Currect DOM from transaction. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 C |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$cookie = $t->cookie_hashref; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Current cookies from transaction. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 C |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$flases = $t->flash_hashref; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Current flashes from transaction. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
0
|
1
|
|
sub dom { return shift->tx->res->dom } |
87
|
0
|
|
|
0
|
1
|
|
sub cookie_hashref { return { map { $_->name => $_->value } @{ $_[0]->_controller->req->cookies } } } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
88
|
0
|
|
0
|
0
|
1
|
|
sub flash_hashref { return $_[0]->_session->{flash} || {} } |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 METHODS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
L inherits all method from L and inplements |
95
|
|
|
|
|
|
|
the following new ones. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 C |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$t = $t->flash_is( '/error', { message => 'error message' } ); |
100
|
|
|
|
|
|
|
$t = $t->flash_is( '/error/message', 'error message' ); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Check flash the given JSON Pointer with Mojo::JSON::Pointer. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub flash_is { |
107
|
0
|
|
|
0
|
1
|
|
my ($self, $key, $value, $desc) = @_; |
108
|
0
|
|
|
|
|
|
my ( $flash, $path ) = $self->_prepare_key($key); |
109
|
0
|
|
|
|
|
|
$flash = $self->_flash($flash); |
110
|
0
|
0
|
0
|
|
|
|
return $self->_test( |
111
|
|
|
|
|
|
|
'is_deeply', |
112
|
|
|
|
|
|
|
Mojo::JSON::Pointer->new->get( $flash, $path ? "/$path" : "" ), |
113
|
|
|
|
|
|
|
$value, |
114
|
|
|
|
|
|
|
$desc || "flash exact match for JSON Pointer \"$key\"", |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 C |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
$t = $t->flash_has( '/error' ); |
122
|
|
|
|
|
|
|
$t = $t->flash_has( '/error/message' ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Check if flash contains a value that can be identified using |
125
|
|
|
|
|
|
|
the given JSON Pointer with Mojo::JSON::Pointer. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub flash_has { |
130
|
0
|
|
|
0
|
1
|
|
my ($self, $key, $value, $desc) = @_; |
131
|
0
|
|
|
|
|
|
my ( $flash, $path ) = $self->_prepare_key($key); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$flash = $self->_flash($flash); |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
0
|
|
|
|
return $self->_test( |
136
|
|
|
|
|
|
|
'ok', |
137
|
|
|
|
|
|
|
!!Mojo::JSON::Pointer->new->get( $flash, $path ? "/$path" : "" ), |
138
|
|
|
|
|
|
|
$desc || "flash has value for JSON Pointer \"$key\"", |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 C |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$t = $t->flash_hasnt( '/error' ); |
146
|
|
|
|
|
|
|
$t = $t->flash_hasnt( '/error/message' ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Check if flash no contains a value that can be identified using |
149
|
|
|
|
|
|
|
the given JSON Pointer with Mojo::JSON::Pointer |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub flash_hasnt { |
154
|
0
|
|
|
0
|
1
|
|
my ($self, $key, $value, $desc) = @_; |
155
|
0
|
|
|
|
|
|
my ( $flash, $path ) = $self->_prepare_key($key); |
156
|
0
|
|
|
|
|
|
$flash = $self->_flash($flash); |
157
|
0
|
0
|
0
|
|
|
|
return $self->_test( |
158
|
|
|
|
|
|
|
'ok', |
159
|
|
|
|
|
|
|
!Mojo::JSON::Pointer->new->get( $flash, $path ? "/$path" : "" ), |
160
|
|
|
|
|
|
|
$desc || "flash has no value for JSON Pointer \"$key\"" |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 C |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$t = $t->cookie_has( 'error' ); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Check if cookie contains a cracker. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub cookie_has { |
175
|
0
|
|
|
0
|
1
|
|
my ($self, $cookie, $desc) = @_; |
176
|
0
|
|
0
|
|
|
|
return $self->_test( |
177
|
|
|
|
|
|
|
'ok', |
178
|
|
|
|
|
|
|
!!$self->_cookie( $cookie ), |
179
|
|
|
|
|
|
|
$desc || "has cookie \"$cookie\"", |
180
|
|
|
|
|
|
|
); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 C |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
$t = $t->cookie_hasnt( 'error' ); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Check if cookie no contains a cookie. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# Polly wants a cracker |
193
|
|
|
|
|
|
|
sub cookie_hasnt { |
194
|
0
|
|
|
0
|
1
|
|
my ($self, $cookie, $desc) = @_; |
195
|
0
|
|
0
|
|
|
|
return $self->_test( |
196
|
|
|
|
|
|
|
'ok', |
197
|
|
|
|
|
|
|
!$self->_cookie( $cookie ), |
198
|
|
|
|
|
|
|
$desc || "has no cookie \"$cookie\"", |
199
|
|
|
|
|
|
|
); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 C |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
$t = $t->cookie_like( 'error', 'fatal error' ); |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Check if cookie for similar match. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub cookie_like { |
212
|
0
|
|
|
0
|
1
|
|
my ($self, $cookie, $regex, $desc) = @_; |
213
|
0
|
|
0
|
|
|
|
return $self->_test( |
214
|
|
|
|
|
|
|
'like', |
215
|
|
|
|
|
|
|
$self->_cookie( $cookie ), |
216
|
|
|
|
|
|
|
$regex, |
217
|
|
|
|
|
|
|
$desc || "cookie \"$cookie\" is similar", |
218
|
|
|
|
|
|
|
); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _prepare_key { |
224
|
0
|
|
|
0
|
|
|
shift; |
225
|
0
|
0
|
|
|
|
|
return ( '', '' ) unless @_; |
226
|
0
|
|
|
|
|
|
my ( undef, $flash, $path ) = split '\/', +shift, 3; |
227
|
0
|
|
|
|
|
|
( $flash, $path ) |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub _session { |
231
|
|
|
|
|
|
|
shift->_controller->session |
232
|
0
|
|
|
0
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub _flash { |
235
|
0
|
0
|
|
0
|
|
|
return $_[0]->_controller->flash( $_[1] ) if @_ == 2; |
236
|
|
|
|
|
|
|
{} |
237
|
0
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub _cookie { |
240
|
0
|
|
|
0
|
|
|
return $_[0]->_controller->cookie( $_[1] ); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub _controller { |
244
|
0
|
|
|
0
|
|
|
my $self = shift; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# Build res cookies |
247
|
0
|
|
|
|
|
|
my $req = new Mojo::Message::Request; |
248
|
0
|
|
|
|
|
|
$req->cookies( join "; ", map{ $_->name ."=". $_->value } @{$self->tx->res->cookies} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# Make app && controller |
251
|
0
|
|
|
|
|
|
my $app = Mojolicious->new(); |
252
|
0
|
|
|
|
|
|
my $c = Mojolicious::Controller->new; |
253
|
0
|
|
|
|
|
|
$c->tx->req( $req ); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
# XXX copy secret |
256
|
0
|
|
0
|
|
|
|
my $secret = $app->can('secrets') || $app->can('secret'); |
257
|
0
|
|
0
|
|
|
|
$secret->( $app, [ @{ ( $self->app->can('secrets') || $self->app->can('secret') )->( $self->app ) } ] ); |
|
0
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
# Init |
260
|
0
|
|
|
|
|
|
$app->handler( $c ); |
261
|
0
|
|
|
|
|
|
$app->sessions->load( $c ); |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
$c; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 SEE ALSO |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
L, L |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 AUTHOR |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
coolmen, C<< >> |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Copyright 2013 coolmen. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
This program is distributed under the MIT (X11) License: |
280
|
|
|
|
|
|
|
L |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person |
283
|
|
|
|
|
|
|
obtaining a copy of this software and associated documentation |
284
|
|
|
|
|
|
|
files (the "Software"), to deal in the Software without |
285
|
|
|
|
|
|
|
restriction, including without limitation the rights to use, |
286
|
|
|
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or sell |
287
|
|
|
|
|
|
|
copies of the Software, and to permit persons to whom the |
288
|
|
|
|
|
|
|
Software is furnished to do so, subject to the following |
289
|
|
|
|
|
|
|
conditions: |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be |
292
|
|
|
|
|
|
|
included in all copies or substantial portions of the Software. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
295
|
|
|
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
296
|
|
|
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
297
|
|
|
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
298
|
|
|
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
299
|
|
|
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
300
|
|
|
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
301
|
|
|
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=cut |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
1; # End of Test::Mojo::More |
307
|
|
|
|
|
|
|
|