OpenInteract2/Manage/Website/TestDB.pm

filter: Statementstmt 23.5% 16 / 68 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 3 totaltotal 19.4% 21 / 108 CC 14 SCAR 49.9
CC
14
Cov
17%
run_task
210.0
get_brief_description
2.0
BEGIN
1.0
CRAP 147.3
« OpenInteract2/TT2/Context.pm ↑ Summary OpenInteract2/Auth/User.pm »
1 package OpenInteract2::Manage::Website::TestDB;
2  
3 # $Id: TestDB.pm,v 1.13 2005/03/17 14:58:04 sjn Exp $
4  
5 87 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 87 ▶use base qw( OpenInteract2::Manage::Website );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 87 ▶use OpenInteract2::Constants qw( :log );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 87 ▶use OpenInteract2::Context qw( CTX );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 87 $OpenInteract2::Manage::Website::TestDB::VERSION = sprintf("%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/);
11  
12 87 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
13 87 return 'test_db';
14 }
15  
16 0 ▶sub get_brief_description {
Subroutine get_brief_description: not called CC=1 SCAR=6.9
Pod undocumented
17 0 return 'Test all configured database connections in a website';
18 }
19  
20 # get_parameters() is inherited from parent
21  
22 0 ▶sub run_task {
Subroutine run_task: not called CC=14 SCAR=53.5
Pod undocumented
23 0 my ( $self ) = @_;
24 0 my $datasource_config = CTX->lookup_datasource_config;
25 0 my ( $error_msg );
26  
27 0 my $action = 'check database connection';
28  
29 # Perform initial sanity checks
30  
31 0 ▶ unless ( ref $datasource_config ne 'HASH' and
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $datasource_config ne "HASH" and scalar keys %{$datasource_config;}) 0 0 0
Condition0%0/2
ref $datasource_config ne "HASH" and scalar keys %{$datasource_config;}
!ll
00
MC/DC0%0/1
ref $datasource_config ne "HASH" and scalar keys %{$datasource_config;}
ref $datasource_config ne "HASH"
Truth table0%0/2
A
A= ref $datasource_config ne "HASH"
Aresult
00
11
32 0 scalar keys %{ $datasource_config } ) {
33 0 $self->_ok( $action,
34 'No DBI datasources; no connection attempted.' );
35 }
36  
37 0 my $dbi_ds = 0;
38 0 my @status = ();
39 0 my $default_dbi = CTX->lookup_default_datasource_name;
40  
41 DATASOURCE:
42 0 ▶ while ( my ( $name, $ds_conf ) = each %{ $datasource_config } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$datasource_config;}) 0 0 0
43 0 ▶ next unless ( $ds_conf->{type} eq 'DBI' );
Branch: 1 branch
BranchTrueFalseTotal
unless $ds_conf->{"type"} eq "DBI" 0 0 0
44 0 ▶ my %s = (
Branch: 1 branch
BranchTrueFalseTotal
$default_dbi eq $name ? : 0 0 0
45 name => $name,
46 is_default => ( $default_dbi eq $name ) ? 'yes' : 'no'
47 );
48 0 $dbi_ds++;
49  
50 0 my $this_action = "$action '$name'";
51 0 ▶ unless ( $ds_conf->{dsn} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ds_conf->{"dsn"}) 0 0 0
52 0 my $msg = "You must define at least 'dsn' in the " .
53 "datasource configuration";
54 0 $self->_fail( $this_action, $msg, %s );
55 0 next DATASOURCE;
56 }
57 0 my $db = eval { CTX->datasource( $name ) };
58 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
59 0 $self->_fail( $this_action, "$@", %s );
60 0 next DATASOURCE;
61 }
62 0 ▶ unless ( $db and UNIVERSAL::isa( $db, 'DBI::db' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db and UNIVERSAL::isa($db, "DBI::db")) 0 0 0
Condition0%0/3
$db and UNIVERSAL::isa($db, "DBI::db")
!ll&&!rl&&r
000
MC/DC0%0/2
$db and UNIVERSAL::isa($db, "DBI::db")
$db UNIVERSAL::isa($db, "DBI::db")
Truth table0%0/3
A and B
A= $dbB= UNIVERSAL::isa($db, "DBI::db")
ABresult
0X0
100
111
63 0 my $msg = 'Connect failed (no error, but no database ' .
64 'handle returned)';
65 0 $self->_fail( $this_action, $msg, %s );
66 0 next DATASOURCE;
67 }
68 0 my $test_table = 'oi_test_create';
69 0 eval {
70 0 $db->do( "CREATE TABLE $test_table " .
71 "( oi_id int not null, primary key( oi_id ) )" ) };
72 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
73 0 my $msg = "Connected to database, but cannot create table: $@";
74 0 $self->_fail( $this_action, $msg, %s );
75 0 next DATASOURCE;
76 }
77 0 eval { $db->do( "DROP TABLE $test_table" ) };
78 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
79 0 my $msg = "Connected to database and created table " .
80 "ok, but DROP failed with '$@'. Please remove " .
81 "table '$test_table' by hand.";
82 0 $self->_ok( $this_action, $msg, %s );
83 0 eval { $db->disconnect };
84 0 next DATASOURCE;
85 }
86 0 eval { $db->disconnect };
87 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
88 0 my $msg = "Connected to database, created table, " .
89 "dropped table, but could not disconnect " .
90 "from database: $@";
91 0 $self->_ok( $this_action, $msg, %s );
92 }
93 }
94 0 ▶ unless ( $dbi_ds ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbi_ds) 0 0 0
95 0 $self->_ok( $action,
96 'No DBI datasources defined; no tests run' );
97 }
98 }
99  
100 87 OpenInteract2::Manage->register_factory_type( get_name() => __PACKAGE__ );
101  
102 87 1;
103  
104 __END__
« OpenInteract2/TT2/Context.pm ↑ Summary OpenInteract2/Auth/User.pm »