Skip to content

Commit

Permalink
Add some tests for newsletter features
Browse files Browse the repository at this point in the history
  • Loading branch information
denny committed Jun 9, 2019
1 parent 8e3eac5 commit 0bab94b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions t/controllers/controller_Newsletters.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ use warnings;
use Test::More;
use Test::WWW::Mechanize::Catalyst::WithContext;

use lib 't/support';
require 'login_helpers.pl'; ## no critic

my $t = Test::WWW::Mechanize::Catalyst::WithContext->new( catalyst_app => 'ShinyCMS' );

# Get the list of recent newsletters
$t->get_ok(
'/newsletters',
'Fetch list of newsletters'
Expand All @@ -26,5 +30,56 @@ $t->title_is(
'Newsletters - ShinySite',
'Loaded list of newsletters'
);
# View an individual newsletter
$t->follow_link_ok(
{ text => 'Donations and a word to teachers and librarians' },
'Click on link to view newsletter'
);
$t->content_contains(
"<h1>\n\tDonations and a word to teachers and librarians\n</h1>",
'Loaded newsletter'
);
# Try to fetch a non-existent newsletter
$t->get_ok(
'/newsletters/2012/01/does-not-exist',
'Try to view a non-existent newsletter'
);
$t->title_is(
'Newsletters - ShinySite',
'Redirected back to list of newsletters instead'
);
$t->text_contains(
'Specified newsletter not found',
'Got helpful error message about missing newsletter'
);
# Try to view mailing list subscriptions before logging in
$t->get_ok(
'/newsletters/lists',
'Try to view mailing list subscriptions, before logging in'
);
$t->title_is(
'Mailing Lists - ShinySite',
'Reached the lists page...'
);
$t->text_contains(
'You need to log in before you can edit your mailing list subscriptions',
'... and got a message telling us to log in'
);
# Log in
$t = login_test_user( 'admin', 'changeme' ) or die 'Failed to log in';
# Try to view mailing list subscriptions after logging in
$t->get_ok(
'/newsletters/lists',
'Try to view mailing list subscriptions, after logging in'
);
$t->title_is(
'Mailing Lists - ShinySite',
'Reached the lists page...'
);
$t->text_contains(
'Below is a list of all of our public mailing lists',
'Reached subscribe/unsubscribe page for mailing lists'
);


done_testing();

0 comments on commit 0bab94b

Please sign in to comment.