use strict; use warnings; use Test::Fatal; use Test::More; use lib 't/lib'; use Silki::Test::Email qw( clear_emails test_email ); use Silki::Test::RealSchema; use Silki::Schema::User; use Silki::Schema::Wiki; my $user1 = Silki::Schema::User->insert( display_name => 'Joe Smith', email_address => 'joe@example.com', password => 'foo', user => Silki::Schema::User->SystemUser(), ); my $user2 = Silki::Schema::User->insert( display_name => 'Bjork', email_address => 'bjork@example.com', password => 'foo', user => Silki::Schema::User->SystemUser(), ); my $wiki = Silki::Schema::Wiki->new( title => 'First Wiki' ); $user1->send_invitation_email( wiki => $wiki, sender => $user2, ); test_email( { From => q{"Bjork" }, To => q{"Joe Smith" }, Subject => qr{^\QYou have been invited to join the First Wiki wiki at \E.+}, }, qr{

\s+ \QYou have been invited to join the First Wiki wiki.\E \s+ \QSince you already have a user account at \E\S+?\Q, you can visit the wiki right now.\E \s+

.+?

\s+ \QSent by Bjork\E \s+

}xs, qr{\QYou have been invited to join the First Wiki wiki. Since you already have\E \s+ \Qa user account at \E\S+?\Q, you can visit the wiki right\E \s+ \Qnow (http://\E\S+?\Q/wiki/first-wiki).\E \s+ \QSent by Bjork\E }xs, ); clear_emails(); my $user3 = Silki::Schema::User->insert( display_name => 'Colin', email_address => 'colin@example.com', password => 'foo', requires_activation => 1, user => Silki::Schema::User->SystemUser(), ); $user3->send_activation_email( sender => Silki::Schema::User->SystemUser() ); test_email( { From => qr{\Q"System User" }, To => q{"Colin" }, Subject => qr{^\QActivate your user account on the \E\S+\Q server}, }, qr{

\s+ \QYou have created a user account on the \E\S+\Q server. You must activate your user account before you can log in.\E \s+

\s+ \Q\E }xs, qr{\QYou have created a user account on the \E\S+\Q server. You\E \s+ \Qmust activate your user account (http://\E\S+?\) \s+ \Qbefore you can log in.\E \s+$ }xs, ); clear_emails(); $user3->send_activation_email( wiki => $wiki, sender => $user2, ); test_email( { From => q{"Bjork" }, To => q{"Colin" }, Subject => qr{^\QYou have been invited to join the First Wiki wiki at \E.+}, }, qr{

\s+ \QYou have been invited to join the First Wiki wiki.\E \s+ \QOnce you activate your user account, you will be a member of the wiki.\E \s+

.+?

\s+ \QSent by Bjork\E \s+

}xs, qr{\QYou have been invited to join the First Wiki wiki. Once you activate your\E \s+ \Quser account (http://\E\S+?\), \s+ \Qyou will be a member of the wiki.\E \s+ \QSent by Bjork\E }xs, ); like( exception { $user3->send_invitation_email( sender => $user2, ); }, qr/\QCannot send an invitation email without a wiki./, 'cannot send an invitation email without a wiki' ); done_testing();