blib/lib/App/Prove/Plugin/KohaBootstrap.pm

filter: Statementstmt 28.3% 19 / 67 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 31.7% 26 / 82 CC 6 SCAR 30.7
CC
6
Cov
26%
load
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 21.5
↑ Summary
1 package App::Prove::Plugin::KohaBootstrap;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Temp qw( tempfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 App::Prove::Plugin::KohaBootstrap - prove plugin to run Koha tests on a separate database
14  
15 =head1 VERSION
16  
17 Version 0.02
18  
19 =cut
20  
21 1 our $VERSION = '0.02';
22  
23  
24 =head1 SYNOPSIS
25  
26 prove -P KohaBootstrap=database,koha_test,marcflavour,MARC21
27  
28 =head1 SUBROUTINES/METHODS
29  
30 =head2 load
31  
32 Drop and recreate a database, and run the necessary installation steps to fill
33 the database
34  
35 =cut
36  
37 0 ▶sub load {
Subroutine load: not called CC=6 SCAR=37.4
Pod documented
38 0 my ($class, $p) = @_;
39  
40 0 my $app = $p->{app_prove};
41 0 my %args = @{ $p->{args} };
42  
43 0 ▶ unless (defined $args{database}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"database"}) 0 0 0
44 0 die "Test database is not defined";
45 }
46  
47 0 ▶ $args{marcflavour} //= 'MARC21';
Condition0%0/2
$args{"marcflavour"} //= "MARC21"
l!l
00
MC/DC0%0/1
$args{"marcflavour"} //= "MARC21"
$args{"marcflavour"}
Truth table0%0/2
A
A= $args{"marcflavour"}
Aresult
11
00
48  
49 0 my $xml = XML::LibXML->load_xml(location => $ENV{KOHA_CONF});
50 0 my $root = $xml->documentElement();
51 0 my ($databaseElement) = $root->findnodes('//config/database');
52 0 my $currentDatabase = $databaseElement->textContent();
53  
54 0 ▶ if ($currentDatabase eq $args{database}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($currentDatabase eq $args{"database"}) 0 0 0
55 0 die "Test database is the same as database in KOHA_CONF, abort!";
56 }
57  
58 0 $databaseElement->firstChild()->setData($args{database});
59  
60 0 my ($fh, $filename) = tempfile('koha-conf.XXXXXX', TMPDIR => 1, UNLINK => 1);
61 0 $xml->toFH($fh);
62 0 close $fh;
63  
64 0 $ENV{KOHA_CONF} = $filename;
65  
66 0 require C4::Context;
67 0 C4::Context->import;
68  
69 0 require C4::Installer;
70 0 C4::Installer->import;
71  
72 0 require C4::Languages;
73  
74 0 my $host = C4::Context->config('hostname');
75 0 my $port = C4::Context->config('port');
76 0 my $database = C4::Context->config('database');
77 0 my $user = C4::Context->config('user');
78 0 my $pass = C4::Context->config('pass');
79  
80 0 say "Create test database $database...";
81  
82 0 my $dbh = DBI->connect("dbi:mysql:;host=$host;port=$port", $user, $pass, {
83 RaiseError => 1,
84 PrintError => 0,
85 });
86  
87 0 $dbh->do("DROP DATABASE IF EXISTS $database");
88 0 $dbh->do("CREATE DATABASE $database");
89  
90 0 my $installer = C4::Installer->new();
91 0 $installer->load_db_schema();
92 0 $installer->set_marcflavour_syspref($args{marcflavour});
93 0 my (undef, $fwklist) = $installer->marc_framework_sql_list('en', $args{marcflavour});
94 0 my (undef, $list) = $installer->sample_data_sql_list('en');
95 0 my @frameworks;
96 0 foreach my $fwk (@$fwklist, @$list) {
97 0 foreach my $framework (@{ $fwk->{frameworks} }) {
98 0 push @frameworks, $framework->{fwkfile};
99 }
100 }
101 0 my $all_languages = C4::Languages::getAllLanguages();
102 0 $installer->load_sql_in_order('en', $all_languages, @frameworks);
103 0 require Koha::SearchEngine::Elasticsearch;
104 0 Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
105 0 $installer->set_version_syspref();
106  
107 0 return 1;
108 }
109  
110  
111 =head1 AUTHOR
112  
113 Julian Maurice, C<< <julian.maurice at biblibre.com> >>
114  
115 =head1 BUGS
116  
117 Please report any bugs or feature requests to C<bug-app-prove-plugin-kohabootstrap at rt.cpan.org>, or through
118 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Prove-Plugin-KohaBootstrap>. I will be notified, and then you'll
119 automatically be notified of progress on your bug as I make changes.
120  
121  
122  
123  
124 =head1 SUPPORT
125  
126 You can find documentation for this module with the perldoc command.
127  
128 perldoc App::Prove::Plugin::KohaBootstrap
129  
130  
131 You can also look for information at:
132  
133 =over 4
134  
135 =item * RT: CPAN's request tracker (report bugs here)
136  
137 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=App-Prove-Plugin-KohaBootstrap>
138  
139 =item * Search CPAN
140  
141 L<https://metacpan.org/release/App-Prove-Plugin-KohaBootstrap>
142  
143 =back
144  
145  
146 =head1 ACKNOWLEDGEMENTS
147  
148  
149 =head1 LICENSE AND COPYRIGHT
150  
151 This software is Copyright (c) 2023 by Julian Maurice.
152  
153 This is free software, licensed under:
154  
155 The Artistic License 2.0 (GPL Compatible)
156  
157  
158 =cut
159  
160 1 1;
↑ Summary