Skip to content

Commit 1db96a2

Browse files
committed
New blog tests
1 parent 3522388 commit 1db96a2

6 files changed

Lines changed: 235 additions & 0 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env perl
2+
use Mojo::Base '-signatures';
3+
use BlogDB::Web::Test;
4+
5+
my $t = Test::Mojo::BlogDB->new('BlogDB::Web');
6+
7+
# Post a new blog as a logged in user, ensure that it exists,
8+
# make sure that the submitter id matches.
9+
$t->create_user->post_ok( '/blog/new',
10+
form => {
11+
url => 'https://modfoss.com/',
12+
})->code_block( sub {
13+
my ( $t ) = @_;
14+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
15+
ok $t->_sg, "Created blog entry.";
16+
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
17+
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
18+
});
19+
20+
# Post a new blog as an anonymous user, ensure that it exists,
21+
# and an edit token has been created for it.
22+
Test::Mojo::BlogDB->new('BlogDB::Web')->post_ok( '/blog/new',
23+
form => {
24+
url => 'https://symkat.com/',
25+
})->code_block( sub {
26+
my ( $t ) = @_;
27+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://symkat.com/'}));
28+
ok $t->_sg, "Created blog entry.";
29+
is $t->_sg->submitter_id, undef, 'No submitter id for anonymous submitted blog.';
30+
ok $t->_sg->edit_token, 'Edit token for a anonymous-submitted blog exists.';
31+
});
32+
33+
done_testing;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env perl
2+
# Test that a new blog submitted by a logged in user can be edited by that same user.
3+
use Mojo::Base '-signatures';
4+
use BlogDB::Web::Test;
5+
6+
my $t = Test::Mojo::BlogDB->new('BlogDB::Web');
7+
8+
# Post a new blog as a logged in user, ensure that it exists, make sure that the submitter id matches.
9+
$t->create_user->post_ok( '/blog/new',
10+
form => {
11+
url => 'https://modfoss.com/',
12+
})->code_block( sub {
13+
my ( $t ) = @_;
14+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
15+
ok $t->_sg, "Created blog entry.";
16+
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
17+
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
18+
});
19+
20+
my $blog_id = $t->_sg->id;
21+
22+
$t->post_ok( "/blog/new/$blog_id", form => {
23+
title => 'modFoss',
24+
url => 'https://modfoss.com/',
25+
rss_url => 'https://modfoss.com/feed',
26+
tagline => 'Articles on technical matters.',
27+
about => 'A technical blog.'
28+
})->code_block( sub {
29+
my ( $t ) = @_;
30+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
31+
ok $t->_sg, "Found blog entry";
32+
is $t->_sg->title, 'modFoss', 'Title updated.';
33+
is $t->_sg->url, 'https://modfoss.com/', 'URL updated.';
34+
is $t->_sg->rss_url , 'https://modfoss.com/feed', 'RSS URL updated.';
35+
is $t->_sg->tagline , 'Articles on technical matters.', 'Tagline updated.';
36+
is $t->_sg->about , 'A technical blog.', 'About updated.';
37+
})->stash_has( { authorization => [ 'submitter' ] } );
38+
39+
done_testing;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env perl
2+
#
3+
# Post a new blog without any user account, and then edit the blog.
4+
# Make sure the edit_token functionality is being used.
5+
use Mojo::Base '-signatures';
6+
use BlogDB::Web::Test;
7+
8+
my $t = Test::Mojo::BlogDB->new('BlogDB::Web');
9+
10+
$t->post_ok( '/blog/new',
11+
form => {
12+
url => 'https://modfoss.com/',
13+
})->code_block( sub {
14+
my ( $t ) = @_;
15+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
16+
ok $t->_sg, "Created blog entry.";
17+
ok $t->_sg->edit_token, 'Edit token exists';
18+
});
19+
20+
my $blog_id = $t->_sg->id;
21+
22+
$t->post_ok( "/blog/new/$blog_id", form => {
23+
title => 'modFoss',
24+
url => 'https://modfoss.com/',
25+
rss_url => 'https://modfoss.com/feed',
26+
tagline => 'Articles on technical matters.',
27+
about => 'A technical blog.'
28+
})->code_block( sub {
29+
my ( $t ) = @_;
30+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
31+
ok $t->_sg, "Found blog entry";
32+
is $t->_sg->title, 'modFoss', 'Title updated.';
33+
is $t->_sg->url, 'https://modfoss.com/', 'URL updated.';
34+
is $t->_sg->rss_url , 'https://modfoss.com/feed', 'RSS URL updated.';
35+
is $t->_sg->tagline , 'Articles on technical matters.', 'Tagline updated.';
36+
is $t->_sg->about , 'A technical blog.', 'About updated.';
37+
})->stash_has( { authorization => [ 'token' ] } );
38+
39+
done_testing;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env perl
2+
use Mojo::Base '-signatures';
3+
use BlogDB::Web::Test;
4+
5+
my $t = Test::Mojo::BlogDB->new('BlogDB::Web');
6+
7+
# Post a new blog as a logged in user, ensure that it exists, make sure that the submitter id matches.
8+
$t->create_user->post_ok( '/blog/new',
9+
form => {
10+
url => 'https://modfoss.com/',
11+
})->code_block( sub {
12+
my ( $t ) = @_;
13+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
14+
ok $t->_sg, "Created blog entry.";
15+
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
16+
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
17+
});
18+
19+
my $blog_id = $t->_sg->id;
20+
21+
# New Session.
22+
$t = Test::Mojo::BlogDB->new('BlogDB::Web');
23+
24+
$t->create_user({ can_manage_blogs => 1 })->post_ok( "/blog/new/$blog_id", form => {
25+
title => 'modFoss',
26+
url => 'https://modfoss.com/',
27+
rss_url => 'https://modfoss.com/feed',
28+
tagline => 'Articles on technical matters.',
29+
about => 'A technical blog.'
30+
})->code_block( sub {
31+
my ( $t ) = @_;
32+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
33+
ok $t->_sg, "Found blog entry";
34+
is $t->_sg->title, 'modFoss', 'Title updated.';
35+
is $t->_sg->url, 'https://modfoss.com/', 'URL updated.';
36+
is $t->_sg->rss_url , 'https://modfoss.com/feed', 'RSS URL updated.';
37+
is $t->_sg->tagline , 'Articles on technical matters.', 'Tagline updated.';
38+
is $t->_sg->about , 'A technical blog.', 'About updated.';
39+
})->stash_has( { authorization => [ 'setting:can_manage_blogs' ] } );
40+
41+
done_testing;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env perl
2+
# Test that a new blog submitted by an anonymous user cannot be edited by a
3+
# different anonymous user.
4+
use Mojo::Base '-signatures';
5+
use BlogDB::Web::Test;
6+
7+
my $t = Test::Mojo::BlogDB->new('BlogDB::Web');
8+
9+
# Post a new blog entry.
10+
$t->post_ok( '/blog/new',
11+
form => {
12+
url => 'https://modfoss.com/',
13+
})->code_block( sub {
14+
my ( $t ) = @_;
15+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
16+
ok $t->_sg, "Created blog entry.";
17+
});
18+
19+
my $blog_id = $t->_sg->id;
20+
21+
# New Session.
22+
$t = Test::Mojo::BlogDB->new('BlogDB::Web');
23+
24+
$t->post_ok( "/blog/new/$blog_id", form => {
25+
title => 'modFoss',
26+
url => 'https://modfoss.com/',
27+
rss_url => 'https://modfoss.com/feed',
28+
tagline => 'Articles on technical matters.',
29+
about => 'A technical blog.'
30+
})->code_block( sub {
31+
my ( $t ) = @_;
32+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
33+
ok $t->_sg, "Found blog entry";
34+
is $t->_sg->title, undef, 'Title still the same';
35+
is $t->_sg->url, 'https://modfoss.com/', 'URL the same.';
36+
is $t->_sg->rss_url , undef, 'RSS URL still the same.';
37+
is $t->_sg->tagline , undef, 'Tagline still the same.';
38+
is $t->_sg->about , undef, 'About still the same.';
39+
})->stash_has( { errors => [ 'Not Authorized.' ] } );
40+
41+
done_testing;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env perl
2+
# Test that a new blog submitted by a logged in user cannot be edited by another user.
3+
use Mojo::Base '-signatures';
4+
use BlogDB::Web::Test;
5+
6+
my $t = Test::Mojo::BlogDB->new('BlogDB::Web');
7+
8+
# Post a new blog as a logged in user, ensure that it exists, make sure that the submitter id matches.
9+
$t->create_user->post_ok( '/blog/new',
10+
form => {
11+
url => 'https://modfoss.com/',
12+
})->code_block( sub {
13+
my ( $t ) = @_;
14+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
15+
ok $t->_sg, "Created blog entry.";
16+
is $t->_sg->submitter_id, $t->stash->{person}->id, 'Owned by the current user.';
17+
is $t->_sg->edit_token, undef, 'No edit token for a user-submitted blog.';
18+
});
19+
20+
my $blog_id = $t->_sg->id;
21+
22+
# New Session.
23+
$t = Test::Mojo::BlogDB->new('BlogDB::Web');
24+
25+
$t->create_user->post_ok( "/blog/new/$blog_id", form => {
26+
title => 'modFoss',
27+
url => 'https://modfoss.com/',
28+
rss_url => 'https://modfoss.com/feed',
29+
tagline => 'Articles on technical matters.',
30+
about => 'A technical blog.'
31+
})->code_block( sub {
32+
my ( $t ) = @_;
33+
$t->_ss($t->app->db->resultset('PendingBlog')->find( { url => 'https://modfoss.com/'}));
34+
ok $t->_sg, "Found blog entry";
35+
is $t->_sg->title, undef, 'Title still the same';
36+
is $t->_sg->url, 'https://modfoss.com/', 'URL the same.';
37+
is $t->_sg->rss_url , undef, 'RSS URL still the same.';
38+
is $t->_sg->tagline , undef, 'Tagline still the same.';
39+
is $t->_sg->about , undef, 'About still the same.';
40+
})->stash_has( { errors => [ 'Not Authorized.' ] } );
41+
42+
done_testing;

0 commit comments

Comments
 (0)