@@ -152,38 +152,38 @@ the following modules can be used:
152
152
=back
153
153
154
154
Taking the previous test, assuming it actually creates and uses
155
- cookies for sessions:
155
+ cookies for sessions (see L<cookie|Dancer2::Manual/"Setting and Updating
156
+ Cookies"> and perhaps L<Dancer2::Session::Cookie> for more information on how
157
+ to do that):
156
158
157
159
# ... all the use statements
158
160
use HTTP::Cookies;
159
161
160
162
my $jar = HTTP::Cookies->new;
161
163
my $test = Plack::Test->create( MyApp->to_app );
162
164
163
- subtest 'A empty request' => sub {
164
- my $res = $test->request( GET '/' );
165
- ok( $res->is_success, 'Successful request' );
166
- is( $res->content '{}', 'Empty response back' );
165
+ subtest 'Request with invalid user' => sub {
166
+ my $req = GET '/sawyer_x';
167
+ $jar->add_cookie_header($req);
168
+ my $res = $test->request($req);
169
+ ok !$res->is_success, 'Request failed';
167
170
$jar->extract_cookies($res);
168
- ok( $jar->as_string, 'We have cookies!' );
171
+
172
+ ok !$jar->as_string, 'All cookies deleted';
169
173
};
170
174
171
175
subtest 'Request with user' => sub {
172
- my $req = GET '/?user=sawyer_x ';
176
+ my $req = GET '/jason ';
173
177
$jar->add_cookie_header($req);
174
178
my $res = $test->request($req);
175
- ok( $res->is_success, 'Successful request' );
176
- is( $res->content '{"user":"sawyer_x"}', 'Empty response back' );
179
+ ok $res->is_success, 'Successful request';
177
180
$jar->extract_cookies($res);
178
181
179
- ok( ! $jar->as_string, 'All cookies deleted' ) ;
182
+ ok ! $jar->as_string, 'All cookies deleted';
180
183
};
181
184
182
185
done_testing();
183
186
184
- Here a cookie jar is created, all requests and responses, existing
185
- cookies, as well as cookies that were deleted by the response, are checked.
186
-
187
187
If you don't want to use an entire user agent for this test, you can use
188
188
L<HTTP::Cookies> to store cookies and then retrieve them:
189
189
0 commit comments