Skip to content

Commit b2f73a4

Browse files
committed
Testing helpers
1 parent ca4bed7 commit b2f73a4

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

‎Web/lib/Test/Mojo/BlogDB.pm‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use strict;
3333
use parent 'Test::Mojo';
3434
use Data::Dumper;
3535
use Test::Deep;
36+
use Test::More;
3637

3738
sub new {
3839
my $class = shift;
@@ -75,6 +76,7 @@ sub dump_stash {
7576
next if $key eq 'action';
7677
next if $key eq 'cb';
7778
next if $key eq 'template';
79+
next if $key eq 'person';
7880
next if $key =~ m|^mojo\.|;
7981

8082
$ds->{$key} = $t->stash->{$key};
@@ -93,4 +95,51 @@ sub stash_has {
9395
return $t;
9496
}
9597

98+
sub create_user {
99+
my ( $t, $settings ) = @_;
100+
101+
my $user = join( '', map({ ('a'..'z','A'..'Z')[int rand 52] } ( 0 .. 8)) );
102+
$t->post_ok( '/register', form => {
103+
username => $user,
104+
email => "$user\@blogdb.com",
105+
password => $user,
106+
confirm => $user,
107+
})
108+
->get_ok( '/')
109+
->code_block( sub {
110+
is(shift->stash->{person}->username, $user, "Created test user $user");
111+
})
112+
->code_block( sub {
113+
# Now we're just gonna add whatever settings from $settings.
114+
my $t = shift;
115+
foreach my $key ( keys %{$settings || {}}) {
116+
$t->stash->{person}->setting( $key, $settings->{$key});
117+
}
118+
});
119+
120+
return $t;
121+
}
122+
123+
sub create_tag {
124+
my ( $t, $tag, $is_adult ) = @_;
125+
126+
$t->post_ok( '/tags/suggest', form => {
127+
tag => $tag,
128+
($is_adult ? ( is_adult => 1 ) : ( ) ),
129+
});
130+
131+
return $t;
132+
}
133+
134+
# Storage stack for a run, convenience for stashing stuff.
135+
sub _ss {
136+
my ( $t, $data_stack ) = @_;
137+
$t->{data_stack} = $data_stack;
138+
return $t;
139+
}
140+
141+
sub _sg {
142+
return shift->{data_stack};
143+
}
144+
96145
1;

0 commit comments

Comments
 (0)