-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.t
131 lines (111 loc) · 4.88 KB
/
app.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use strictures 1;
use 5.010;
use Plack::Test;
use Plack::Util;
use Test::More;
use HTTP::Request;
use HTTP::Request::Common;
use JSON;
use FindBin qw($Bin);
use Data::Dumper::Concise;
# Monkey patch Auth::Digest during testing to let me in the door.
BEGIN {
if ( !$ENV{AUTHORZ_TESTING} ) {
require Test::More;
Test::More::plan(
skip_all => 'these tests are for author testing' );
}
use Plack::Middleware::Auth::Digest;
no warnings 'redefine';
*Plack::Middleware::Auth::Digest::call = sub {
my ( $self, $env ) = @_;
$env->{REMOTE_USER} = 'hunter';
return $self->app->($env);
};
}
my %framework_scripts = (
web_simple => '../app.psgi',
# dancer => 'dancer.pl',
# mojo => 'mojo.pl',
# tatsumaki => 'tatsumaki.psgi'
);
my $base_path = "$Bin/../app/";
my @app_files = map { $base_path . $framework_scripts{$_} } keys %framework_scripts;
if ( my $framework = $ARGV[0] ) {
my $app = "$Bin/../app/" . $framework_scripts{$framework};
@app_files = ($app);
}
foreach my $app_file (@app_files) {
my $app = Plack::Util::load_psgi $app_file;
test_psgi
app => $app,
client => sub {
my $client_cb = shift;
my $request = HTTP::Request->new( GET => '/public/feed/ironman' );
my $response = $client_cb->($request);
is $response->code, 200, 'feed status';
like $response->content, qr/(Articles|empty)/, 'feed content';
$request = HTTP::Request->new( GET => '/' );
$response = $client_cb->($request);
is $response->code, 200, 'home page status';
like $response->content, qr/Recent Articles/, 'home page content';
$request = HTTP::Request->new( GET => '/page' );
$response = $client_cb->($request);
is $response->code, 200, 'create page status';
like $response->content, qr/id="edit_area"/, 'create page content';
$request = POST '/page',
[ content => "h1. Perl Rocks", wiki_language => 'textile' ];
$response = $client_cb->($request);
like $response->code, qr/^(?:301|302)$/, 'post create page redirect';
$request = HTTP::Request->new( GET => '/calendar' );
$response = $client_cb->($request);
is $response->code, 200, 'calendar page status';
like $response->content, qr/Previous Month/, 'calendar page navigation content';
$request = HTTP::Request->new( GET => '/recent' );
$response = $client_cb->($request);
is $response->code, 200, 'recent page status';
like $response->content, qr/Perl Rocks/, 'recent page content';
# Let's get page id from the recent page
# so we can request a specific page then delete it.
my $content = $response->content;
my ($id) = $content =~ m!<a href="/page/(\w+)">Perl Rocks</a>!;
$request = HTTP::Request->new( GET => "/page/${id}" );
$response = $client_cb->($request);
is $response->code, 200, "page ${id} GET status";
like $response->content, qr/Perl Rocks/, "page ${id} content";
$request = HTTP::Request->new( GET => "/page/${id}/edit" );
$response = $client_cb->($request);
is $response->code, 200, 'edit page status';
$request = POST "/page/${id}/edit",
[
content => "h1. Perl Rolls",
wiki_language => 'textile',
commit_message => 'note the flexibility of Perl',
];
$response = $client_cb->($request);
like $response->code, qr/^(?:301|302)$/, 'post edit page redirect';
$request = HTTP::Request->new( GET => "/page/${id}" );
$response = $client_cb->($request);
is $response->code, 200, 'get edited page status';
like $response->content, qr/Perl Rolls/, 'edited page content';
$request = HTTP::Request->new( GET => "/search/Perl" );
$response = $client_cb->($request);
is $response->code, 200, 'search results';
like $response->content, qr/Perl Rolls/, 'search hit';
$request = HTTP::Request->new( GET => "/page/${id}/delete" );
$response = $client_cb->($request);
like $response->code, qr/^(?:301|302)$/, 'delete page redirect';
$request = HTTP::Request->new( GET => '/recent' );
$response = $client_cb->($request);
is $response->code, 200, 'recent page status';
unlike $response->content, qr/${id}/, "page ${id} not on recent page";
$request = POST '/preview',
[ content => '*Bom dia*', wiki_language => 'textile' ];
$response = $client_cb->($request);
is $response->code, 200, 'preview page status';
my $hashref = decode_json( $response->content );
is $hashref->{rendered_content}, '<p><strong>Bom dia</strong></p>',
'preview page content';
};
}
done_testing;