Skip to content

Commit 8995c46

Browse files
author
Kaitlyn Parkhurst
committed
Testing layout.
1 parent f77829e commit 8995c46

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Web/cpanfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ requires 'Mojolicious::Plugin::RenderFile';
44
requires 'Mojo::Pg';
55
requires 'DateTime::Format::Pg';
66
requires 'BlogDB::DB';
7+
8+
test_requires "Test::Postgresql58";
9+
test_requires "Test::More";
10+
test_requires "Test::Deep";

Web/t/01_index.t

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env perl
2+
use Mojo::Base -strict;
3+
use Test::Mojo;
4+
use Test::More;
5+
use Test::Postgresql58;
6+
use DBI;
7+
8+
my $t = Test::Mojo->new('BlogDB::Web');
9+
10+
$t->get_ok( '/' );
11+
12+
our $pgsql = Test::Postgresql58->new()
13+
or BAILOUT( "PSQL Error: " . $Test::Postgresql58::errstr );
14+
15+
load_psql_file("/home/symkat/Code/BlogDB/DB/etc/schema.sql");
16+
17+
# Create an account.
18+
$t->post_ok( '/register', form => {
19+
username => 'fred',
20+
email => 'fred@blog.com',
21+
password => 'SuperSecure',
22+
confirm => 'SuperSecure',
23+
})->status_is( 200 );
24+
25+
# Login works and redirects the user.
26+
$t->post_ok( '/login', form => {
27+
username => 'fred',
28+
password => 'SuperSecure',
29+
confirm => 'SuperSecure',
30+
return => '/',
31+
})->status_is( 302 );
32+
33+
# Login without account throws an error
34+
$t->post_ok( '/login', form => {
35+
username => 'james',
36+
password => 'NoPassword',
37+
confirm => 'NoPassword',
38+
return => '/',
39+
})->status_is( 500 );
40+
41+
done_testing();
42+
43+
sub load_psql_file {
44+
my ( $file ) = @_;
45+
46+
open my $lf, "<", $file
47+
or die "Failed to open $file for reading: $!";
48+
my $content;
49+
while ( defined( my $line = <$lf> ) ) {
50+
next unless $line !~ /^\s*--/;
51+
$content .= $line;
52+
}
53+
close $lf;
54+
55+
my $dbh = DBI->connect( $pgsql->dsn );
56+
for my $command ( split( /;/, $content ) ) {
57+
next if $command =~ /^\s*$/;
58+
$dbh->do( $command )
59+
or BAIL_OUT( "PSQL Error($file): $command: " . $dbh->errstr);
60+
}
61+
undef $dbh;
62+
}

0 commit comments

Comments
 (0)