Toolkit/TestConfig/Utilities.pm

filter: Statementstmt 55.9% 47 / 84 Branchbran 55.5% 10 / 18 Conditioncond 28.5% 4 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 3 totaltotal 50.0% 67 / 134 CC 3 SCAR 7.9
CC
3
Cov
53%
reinitialise_stores
4.3
combinations
2.0
BEGIN
1.0
CRAP 2.2
« Toolkit/Search/SII.pm ↑ Summary Toolkit/TestConfig.pm »
1 package Wiki::Toolkit::TestConfig::Utilities;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 ▶use Wiki::Toolkit::TestConfig;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use vars qw( $num_stores $num_combinations $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 $VERSION = '0.06';
9  
10 =head1 NAME
11  
12 Wiki::Toolkit::TestConfig::Utilities - Utilities for testing Wiki::Toolkit things (deprecated).
13  
14 =head1 DESCRIPTION
15  
16 Deprecated - use L<Wiki::Toolkit::TestLib> instead.
17  
18 =cut
19  
20 8 my %stores;
21  
22 8 foreach my $dbtype (qw( MySQL Pg SQLite )) {
23 24 ▶ if ($Wiki::Toolkit::TestConfig::config{$dbtype}->{dbname}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Wiki::Toolkit::TestConfig::config{$dbtype}{'dbname'}) { } 0 24 24
24 0 my %config = %{$Wiki::Toolkit::TestConfig::config{$dbtype}};
25 0 my $store_class = "Wiki::Toolkit::Store::$dbtype";
26 0 eval "require $store_class";
27 my $store = $store_class->new( dbname => $config{dbname},
28 dbuser => $config{dbuser},
29 dbpass => $config{dbpass},
30 0 dbhost => $config{dbhost} );
31 0 $stores{$dbtype} = $store;
32 } else {
33 24 $stores{$dbtype} = undef;
34 }
35 }
36  
37 8 $num_stores = scalar keys %stores;
38  
39 8 my %searches;
40  
41 # DBIxFTS only works with MySQL.
42 8 ▶if ( $Wiki::Toolkit::TestConfig::config{dbixfts} && $stores{MySQL} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Wiki::Toolkit::TestConfig::config{'dbixfts'} and $stores{'MySQL'}) { } 0 8 8
Condition33%1/3
$Wiki::Toolkit::TestConfig::config{"dbixfts"} and $stores{"MySQL"}
!ll&&!rl&&r
800
MC/DC0%0/2
$Wiki::Toolkit::TestConfig::config{"dbixfts"} and $stores{"MySQL"}
$Wiki::Toolkit::TestConfig::config{"dbixfts"} $stores{"MySQL"}
Truth table33%1/3
A and B
A= $Wiki::Toolkit::TestConfig::config{"dbixfts"}B= $stores{"MySQL"}
ABresult
0X0
100
111
43 0 require Wiki::Toolkit::Search::DBIxFTS;
44 0 my $dbh = $stores{MySQL}->dbh;
45 0 $searches{DBIxFTSMySQL} = Wiki::Toolkit::Search::DBIxFTS->new( dbh => $dbh );
46 } else {
47 8 $searches{DBIxFTSMySQL} = undef;
48 }
49  
50 # Test the MySQL SII backend, if we can.
51 8 ▶if ( $Wiki::Toolkit::TestConfig::config{search_invertedindex} && $stores{MySQL} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Wiki::Toolkit::TestConfig::config{'search_invertedindex'} and $stores{'MySQL'}) { } 0 8 8
Condition33%1/3
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} and $stores{"MySQL"}
!ll&&!rl&&r
800
MC/DC0%0/2
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} and $stores{"MySQL"}
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} $stores{"MySQL"}
Truth table33%1/3
A and B
A= $Wiki::Toolkit::TestConfig::config{"search_invertedindex"}B= $stores{"MySQL"}
ABresult
0X0
100
111
52 0 require Search::InvertedIndex::DB::Mysql;
53 0 require Wiki::Toolkit::Search::SII;
54 0 my %dbconfig = %{$Wiki::Toolkit::TestConfig::config{MySQL}};
55 my $indexdb = Search::InvertedIndex::DB::Mysql->new(
56 -db_name => $dbconfig{dbname},
57 -username => $dbconfig{dbuser},
58 -password => $dbconfig{dbpass},
59 0 ▶ -hostname => $dbconfig{dbhost} || "",
Condition0%0/2
$dbconfig{'dbhost'} || ''
l!l
00
MC/DC0%0/1
$dbconfig{'dbhost'} || ''
$dbconfig{'dbhost'}
Truth table0%0/2
A
A= $dbconfig{'dbhost'}
Aresult
11
00
60 -table_name => 'siindex',
61 -lock_mode => 'EX' );
62 0 $searches{SIIMySQL} = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb );
63 } else {
64 8 $searches{SIIMySQL} = undef;
65 }
66  
67 # Test the Pg SII backend, if we can.
68 8 eval { require Search::InvertedIndex::DB::Pg; };
69 8 ▶my $sii_pg = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 8 0 8
70 8 ▶if ( $Wiki::Toolkit::TestConfig::config{search_invertedindex} && $stores{Pg}
Branch: 1 branch
BranchTrueFalseTotal
if ($Wiki::Toolkit::TestConfig::config{'search_invertedindex'} and $stores{'Pg'} and $sii_pg) { } 0 8 8
Condition33%2/6
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} and $stores{"Pg"} and $sii_pg
!ll&&!rl&&r
800
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} and $stores{"Pg"}
!ll&&!rl&&r
800
MC/DC0%0/3
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} and $stores{"Pg"} and $sii_pg
$Wiki::Toolkit::TestConfig::config{"search_invertedindex"} $stores{"Pg"} $sii_pg
Truth table25%1/4
A and B and C
A= $Wiki::Toolkit::TestConfig::config{"search_invertedindex"}B= $stores{"Pg"}C= $sii_pg
ABCresult
0XX0
10X0
1100
1111
71 && $sii_pg ) {
72 0 require Search::InvertedIndex::DB::Pg;
73 0 require Wiki::Toolkit::Search::SII;
74 0 my %dbconfig = %{$Wiki::Toolkit::TestConfig::config{Pg}};
75 my $indexdb = Search::InvertedIndex::DB::Pg->new(
76 -db_name => $dbconfig{dbname},
77 -username => $dbconfig{dbuser},
78 -password => $dbconfig{dbpass},
79 -hostname => $dbconfig{dbhost},
80 0 -table_name => 'siindex',
81 -lock_mode => 'EX' );
82 0 $searches{SIIPg} = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb );
83 } else {
84 8 $searches{SIIPg} = undef;
85 }
86  
87 # Also test the default DB_File backend, if we have S::II installed at all.
88 8 ▶if ( $Wiki::Toolkit::TestConfig::config{search_invertedindex} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Wiki::Toolkit::TestConfig::config{'search_invertedindex'}) { } 0 8 8
89 0 require Search::InvertedIndex;
90 0 require Wiki::Toolkit::Search::SII;
91 0 my $indexdb = Search::InvertedIndex::DB::DB_File_SplitHash->new(
92 -map_name => 't/sii-db-file-test.db',
93 -lock_mode => 'EX' );
94 0 $searches{SII} = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb );
95 } else {
96 8 $searches{SII} = undef;
97 }
98  
99 8 my @combinations; # which searches work with which stores.
100 push @combinations, { store_name => "MySQL",
101 store => $stores{MySQL},
102 search_name => "DBIxFTSMySQL",
103 8 search => $searches{DBIxFTSMySQL} };
104 push @combinations, { store_name => "MySQL",
105 store => $stores{MySQL},
106 search_name => "SIIMySQL",
107 8 search => $searches{SIIMySQL} };
108 push @combinations, { store_name => "Pg",
109 store => $stores{Pg},
110 search_name => "SIIPg",
111 8 search => $searches{SIIPg} };
112  
113 # All stores are compatible with the default S::II search, and with no search.
114 8 foreach my $store_name ( keys %stores ) {
115 push @combinations, { store_name => $store_name,
116 store => $stores{$store_name},
117 search_name => "SII",
118 24 search => $searches{SII} };
119 push @combinations, { store_name => $store_name,
120 24 store => $stores{$store_name},
121 search_name => "undef",
122 search => undef };
123 }
124  
125 8 foreach my $comb ( @combinations ) {
126 # There must be a store configured for us to test, but a search is optional
127 72 ▶ $comb->{configured} = $comb->{store} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$comb->{'store'} ? : 0 72 72
128 }
129  
130 8 $num_combinations = scalar @combinations;
131  
132 1 ▶sub reinitialise_stores {
Subroutine reinitialise_stores: called CC=3 SCAR=14.5
Pod undocumented
133 1 my $class = shift;
134 1 my %stores = $class->stores;
135  
136 1 my ($store_name, $store);
137 1 ▶ while ( ($store_name, $store) = each %stores ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %stores) 3 1 4
138 3 ▶ next unless $store;
Branch: 1 branch
BranchTrueFalseTotal
unless $store 3 0 3
139  
140 0 my $dbname = $store->dbname;
141 0 my $dbuser = $store->dbuser;
142 0 my $dbpass = $store->dbpass;
143 0 my $dbhost = $store->dbhost;
144  
145 # Clear out the test database, then set up tables afresh.
146 0 my $setup_class = "Wiki::Toolkit::Setup::$store_name";
147 0 eval "require $setup_class";
148 {
149 0 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.2
150 0 &{"$setup_class\:\:cleardb"}($dbname, $dbuser, $dbpass, $dbhost);
151 0 &{"$setup_class\:\:setup"}($dbname, $dbuser, $dbpass, $dbhost);
152 }
153 }
154 }
155  
156 8 ▶sub stores {
Subroutine stores: called CC=1 SCAR=0.0
Pod undocumented
157 8 return %stores;
158 }
159  
160 0 ▶sub combinations {
Subroutine combinations: not called CC=1 SCAR=6.9
Pod undocumented
161 0 return @combinations;
162 }
163  
164 =head1 SEE ALSO
165  
166 L<Wiki::Toolkit::TestLib>, the replacement for this module.
167  
168 =head1 AUTHOR
169  
170 Kake Pugh (kake@earth.li).
171  
172 =head1 COPYRIGHT
173  
174 Copyright (C) 2003 Kake Pugh. All Rights Reserved.
175  
176 This module is free software; you can redistribute it and/or modify it
177 under the same terms as Perl itself.
178  
179 =cut
180  
181 8 1;
« Toolkit/Search/SII.pm ↑ Summary Toolkit/TestConfig.pm »