summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Test/MockParams.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla/Test/MockParams.pm')
-rw-r--r--Bugzilla/Test/MockParams.pm71
1 files changed, 71 insertions, 0 deletions
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