summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-08-10 21:41:53 +0200
committerdklawren <dklawren@users.noreply.github.com>2018-08-10 21:41:53 +0200
commitea5beeacb185309572836cc60989f95ea4705f9d (patch)
tree1f8f44b5d1dba73fb05214ba1e539c0918d42bb9 /Bugzilla
parent53e1adcc77b3e68c1d8659d418aa5639d9917e42 (diff)
downloadbugzilla-ea5beeacb185309572836cc60989f95ea4705f9d.tar.gz
bugzilla-ea5beeacb185309572836cc60989f95ea4705f9d.tar.xz
Bug 1482475 - Add extensive testing framework
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Config.pm37
-rw-r--r--Bugzilla/DB/Sqlite.pm2
-rw-r--r--Bugzilla/Test/MockDB.pm49
-rw-r--r--Bugzilla/Test/MockLocalconfig.pm18
-rw-r--r--Bugzilla/Test/MockParams.pm71
-rw-r--r--Bugzilla/Test/Util.pm2
6 files changed, 159 insertions, 20 deletions
diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm
index d050ff9e0..85779fa6b 100644
--- a/Bugzilla/Config.pm
+++ b/Bugzilla/Config.pm
@@ -251,28 +251,11 @@ sub write_params {
my ($param_data) = @_;
$param_data ||= Bugzilla->params;
- my $datadir = bz_locations()->{'datadir'};
- my $param_file = "$datadir/params";
-
local $Data::Dumper::Sortkeys = 1;
- my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX',
- DIR => $datadir );
-
my %params = %$param_data;
$params{urlbase} = Bugzilla->localconfig->{urlbase};
- print $fh (Data::Dumper->Dump([\%params], ['*param']))
- || die "Can't write param file: $!";
-
- close $fh;
-
- rename $tmpname, $param_file
- or die "Can't rename $tmpname to $param_file: $!";
-
- # It's not common to edit parameters and loading
- # Bugzilla::Install::Filesystem is slow.
- require Bugzilla::Install::Filesystem;
- Bugzilla::Install::Filesystem::fix_file_permissions($param_file);
+ __PACKAGE__->_write_file( Data::Dumper->Dump([\%params], ['*param']) );
# And now we have to reset the params cache so that Bugzilla will re-read
# them.
@@ -311,6 +294,24 @@ sub read_param_file {
return \%params;
}
+sub _write_file {
+ my ($class, $str) = @_;
+ my $datadir = bz_locations()->{'datadir'};
+ my $param_file = "$datadir/params";
+ my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX',
+ DIR => $datadir );
+ print $fh $str || die "Can't write param file: $!";
+ close $fh || die "Can't close param file: $!";
+
+ rename $tmpname, $param_file
+ or die "Can't rename $tmpname to $param_file: $!";
+
+ # It's not common to edit parameters and loading
+ # Bugzilla::Install::Filesystem is slow.
+ require Bugzilla::Install::Filesystem;
+ Bugzilla::Install::Filesystem::fix_file_permissions($param_file);
+}
+
1;
__END__
diff --git a/Bugzilla/DB/Sqlite.pm b/Bugzilla/DB/Sqlite.pm
index 3890d0795..81ee7d888 100644
--- a/Bugzilla/DB/Sqlite.pm
+++ b/Bugzilla/DB/Sqlite.pm
@@ -73,7 +73,7 @@ sub BUILDARGS {
my $db_name = $params->{db_name};
# Let people specify paths intead of data/ for the DB.
- if ($db_name and $db_name !~ m{[\\/]}) {
+ if ($db_name && $db_name ne ':memory:' && $db_name !~ m{[\\/]}) {
# When the DB is first created, there's a chance that the
# data directory doesn't exist at all, because the Install::Filesystem
# code happens after DB creation. So we create the directory ourselves
diff --git a/Bugzilla/Test/MockDB.pm b/Bugzilla/Test/MockDB.pm
new file mode 100644
index 000000000..d158a73de
--- /dev/null
+++ b/Bugzilla/Test/MockDB.pm
@@ -0,0 +1,49 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::Test::MockDB;
+use 5.10.1;
+use strict;
+use warnings;
+use Try::Tiny;
+use Capture::Tiny qw(capture_merged);
+
+use Bugzilla::Test::MockLocalconfig (
+ db_driver => 'sqlite',
+ db_name => ':memory:',
+);
+use Bugzilla;
+BEGIN { Bugzilla->extensions };
+use Bugzilla::Test::MockParams;
+
+sub import {
+ require Bugzilla::Install;
+ require Bugzilla::Install::DB;
+ require Bugzilla::Field;;
+
+ state $first_time = 0;
+
+ return undef if $first_time++;
+
+ return capture_merged {
+ Bugzilla->dbh->bz_setup_database();
+
+ # Populate the tables that hold the values for the <select> fields.
+ Bugzilla->dbh->bz_populate_enum_tables();
+
+ Bugzilla::Install::DB::update_fielddefs_definition();
+ Bugzilla::Field::populate_field_definitions();
+ Bugzilla::Install::init_workflow();
+ Bugzilla::Install::DB->update_table_definitions({});
+ Bugzilla::Install::update_system_groups();
+
+ Bugzilla->set_user(Bugzilla::User->super_user);
+
+ Bugzilla::Install::update_settings();
+ };
+}
+
+1;
diff --git a/Bugzilla/Test/MockLocalconfig.pm b/Bugzilla/Test/MockLocalconfig.pm
new file mode 100644
index 000000000..a32aea0d4
--- /dev/null
+++ b/Bugzilla/Test/MockLocalconfig.pm
@@ -0,0 +1,18 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::Test::MockLocalconfig;
+use 5.10.1;
+use strict;
+use warnings;
+
+sub import {
+ my ($class, %lc) = @_;
+ $ENV{LOCALCONFIG_ENV} = 'BMO';
+ $ENV{"BMO_$_"} = $lc{$_} for keys %lc;
+}
+
+1;
diff --git a/Bugzilla/Test/MockParams.pm b/Bugzilla/Test/MockParams.pm
new file mode 100644
index 000000000..2d064c616
--- /dev/null
+++ b/Bugzilla/Test/MockParams.pm
@@ -0,0 +1,71 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::Test::MockParams;
+use 5.10.1;
+use strict;
+use warnings;
+use Try::Tiny;
+use Capture::Tiny qw(capture_merged);
+use Test2::Tools::Mock qw(mock);
+
+use Bugzilla::Config;
+use Safe;
+
+our $Params;
+BEGIN {
+ our $Mock = mock 'Bugzilla::Config' => (
+ override => [
+ 'read_param_file' => sub {
+ my ($class) = @_;
+ return {} unless $Params;
+ my $s = Safe->new;
+ $s->reval($Params);
+ die "Error evaluating params: $@" if $@;
+ return { %{ $s->varglob('param') } };
+ },
+ '_write_file' => sub {
+ my ($class, $str) = @_;
+ $Params = $str;
+ },
+ ],
+ );
+}
+
+sub import {
+ my ($self, %answers) = @_;
+ state $first_time = 0;
+
+ require Bugzilla::Field;
+ require Bugzilla::Status;
+ require Bugzilla;
+ my $Bugzilla = mock 'Bugzilla' => (
+ override => [
+ installation_answers => sub { \%answers },
+ ],
+ );
+ my $BugzillaField = mock 'Bugzilla::Field' => (
+ override => [
+ get_legal_field_values => sub { [] },
+ ],
+ );
+ my $BugzillaStatus = mock 'Bugzilla::Status' => (
+ override => [
+ closed_bug_statuses => sub { die "no database" },
+ ],
+ );
+
+ if ($first_time++) {
+ capture_merged {
+ Bugzilla::Config::update_params();
+ };
+ }
+ else {
+ Bugzilla::Config::SetParam($_, $answers{$_}) for keys %answers;
+ }
+}
+
+1; \ No newline at end of file
diff --git a/Bugzilla/Test/Util.pm b/Bugzilla/Test/Util.pm
index 4c9981e52..02c842658 100644
--- a/Bugzilla/Test/Util.pm
+++ b/Bugzilla/Test/Util.pm
@@ -24,7 +24,7 @@ sub create_user {
cryptpassword => $password,
disabledtext => "",
disable_mail => 0,
- extern_id => 0,
+ extern_id => undef,
%extra,
});
}