ASP/Test/Base.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« ASP/ConfigLoader.pm ↑ Summary ASP/HTTPContext.pm »
1  
2 package Apache2::ASP::Test::Base;
3  
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use Apache2::ASP::ConfigLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use Apache2::ASP::Test::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Apache2::ASP::Test::Fixtures;
9 use Data::Properties::YAML;
10  
11  
12 #==============================================================================
13 sub new
14 {
15 my $class = shift;
16
17 my $config = Apache2::ASP::ConfigLoader->load();
18
19 # Our test fixtures:
20 my $data = Apache2::ASP::Test::Fixtures->new(
21 properties_file => $config->web->application_root . '/etc/test_fixtures.yaml'
22 ) if -f $config->web->application_root . '/etc/test_fixtures.yaml';
23
24 # Our diagnostic messages:
25 my $properties = Data::Properties::YAML->new(
26 properties_file => $config->web->application_root . '/etc/properties.yaml'
27 ) if -f $config->web->application_root . '/etc/properties.yaml';
28
29 my $s = bless {
30 # TBD:
31 ua => Apache2::ASP::Test::UserAgent->new( config => $config ),
32 config => $config,
33 data => $data,
34 properties => $properties,
35 }, $class;
36
37 return $s;
38 }# end new()
39  
40  
41 #==============================================================================
42 sub ua { $_[0]->{ua} }
43 sub config { $_[0]->{config} }
44 sub data { $_[0]->{data} } # Deprecated
45 sub test_fixtures { $_[0]->{data} }
46 sub diags { $_[0]->{properties} } # Deprecated
47 sub properties { $_[0]->{properties} }
48 sub session { $_[0]->{ua}->context->session }
49  
50 1;# return true:
51  
52 =head1 NAME
53  
54 Apache2::ASP::Test::Base - base class for all test helper objects.
55  
56 =head1 SYNOPSIS
57  
58 #!/usr/bin/perl -w
59
60 use strict;
61 use warnings 'all';
62 use Test::More 'no_plan';
63 use Apache2::ASP::Test::Base;
64
65 ok( my $t = Apache2::ASP::Test::Base->new() );
66
67 my $res = $t->ua->get("/index.asp");
68 ok( $res->is_success );
69 is( $res->header('location') => undef );
70  
71 =head1 DESCRIPTION
72  
73 The whole point of writing Apache2::ASP was to enable command-line testing
74 of entire websites - and to gather statistics via L<Devel::Cover> and L<Devel::NYTProf>.
75  
76 Somehow the test-driven-development world completely missed the point:
77  
78 B<YOU HAVE GOT TO TEST YOUR WEB PAGES SOMEHOW!!>
79  
80 Apache2::ASP and this class provide an excellent means of doing that.
81  
82 See the C</t> folder in this distribution for several examples of testing different
83 kinds of functionality with C<Apache2::ASP::Test::Base>.
84  
85 =head1 PUBLIC PROPERTIES
86  
87 =head2 ua
88  
89 Returns the current L<Apache2::ASP::Test::UserAgent> object.
90  
91 =head2 config
92  
93 Shortcut method to the current L<Apache2::ASP::Config> object.
94  
95 =head2 test_fixtures
96  
97 Shortcut method to the current L<Data::Properties::YAML> object
98 representing the test fixtures found in C</etc/test_fixtures.yaml>
99  
100 =head2 properties
101  
102 Shortcut method to the current L<Data::Properties::YAML> object
103 representing the properties found in C</etc/properties.yaml>
104  
105 =head2 session
106  
107 Shortcut method to the current L<Apache2::ASP::SessionStateManager> object.
108
109 =head1 BUGS
110
111 It's possible that some bugs have found their way into this release.
112
113 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
114
115 =head1 HOMEPAGE
116
117 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
118 of Apache2::ASP in action.
119
120 =head1 AUTHOR
121
122 John Drago L<mailto:jdrago_999@yahoo.com>
123
124 =head1 COPYRIGHT AND LICENSE
125
126 Copyright 2007 John Drago, All rights reserved.
127
128 This software is free software. It may be used and distributed under the
129 same terms as Perl itself.
130
131 =cut
132  
« ASP/ConfigLoader.pm ↑ Summary ASP/HTTPContext.pm »