| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use Test::WWW::Mechanize::PSGI; |
| 5 |
|
| 6 |
use [d2% appname %2d]; |
| 7 |
my $mech = Test::WWW::Mechanize::PSGI->new( |
| 8 |
app => [d2% appname %2d]->to_app, |
| 9 |
); |
| 10 |
|
| 11 |
subtest 'Landing page' => sub { |
| 12 |
$mech->get_ok('/', 'Got landing page'); |
| 13 |
$mech->title_is('Danceyland Blog', '...for our blog'); |
| 14 |
$mech->content_contains('Test Blog Post','...and it has a test post'); |
| 15 |
}; |
| 16 |
|
| 17 |
subtest 'Login' => sub { |
| 18 |
$mech->get_ok('/login', 'Visit login page to make some changes'); |
| 19 |
$mech->submit_form_ok({ |
| 20 |
fields => { |
| 21 |
username => 'admin', |
| 22 |
password => 'test', |
| 23 |
}}, '...so we give it a user'); |
| 24 |
}; |
| 25 |
|
| 26 |
subtest 'Create' => sub { |
| 27 |
$mech->get_ok('/create', 'Write a new blog post'); |
| 28 |
$mech->submit_form_ok({ |
| 29 |
fields => { |
| 30 |
title => 'Another Test Post', |
| 31 |
summary => 'Writing a blog post can be done by tests too', |
| 32 |
content => 'You can create blog entries programmatically with Perl!', |
| 33 |
}}, '...then write another post'); |
| 34 |
$mech->base_like( qr</entry/\d+$>, '...and get redirected to the new entry' ); |
| 35 |
}; |
| 36 |
|
| 37 |
my $entry_id; |
| 38 |
subtest 'Update' => sub { |
| 39 |
($entry_id) = $mech->uri =~ m</(\d+)$>; |
| 40 |
$mech->get_ok("/update/$entry_id", 'Navigating to the update page for this post'); |
| 41 |
$mech->submit_form_ok({ |
| 42 |
fields => { |
| 43 |
title => 'Yet ANOTHER Test Post', |
| 44 |
}}, '...then update yet another post'); |
| 45 |
$mech->base_like( qr</entry/${entry_id}$>, '...and get redirected to the entry page' ); |
| 46 |
$mech->has_tag('h1','Yet ANOTHER Test Post', '...and it has the updated title'); |
| 47 |
}; |
| 48 |
|
| 49 |
subtest 'Delete' => sub { |
| 50 |
$mech->get_ok("/delete/$entry_id", "Go delete page for new entry"); |
| 51 |
$mech->submit_form_ok({ |
| 52 |
fields => { |
| 53 |
delete_it => 'yes', |
| 54 |
}}, '...then delete it!'); |
| 55 |
$mech->get_ok("/entry/$entry_id", '...then try to navigate to the entry'); |
| 56 |
$mech->content_contains('Invalid entry','...and see the post is no longer there'); |
| 57 |
}; |
| 58 |
|
| 59 |
done_testing; |