]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1482475 - Add extensive testing framework
authorDylan William Hardison <dylan@hardison.net>
Fri, 10 Aug 2018 19:41:53 +0000 (15:41 -0400)
committerdklawren <dklawren@users.noreply.github.com>
Fri, 10 Aug 2018 19:41:53 +0000 (15:41 -0400)
20 files changed:
.circleci/config.yml
Bugzilla.pm
Bugzilla/Config.pm
Bugzilla/DB/Sqlite.pm
Bugzilla/Test/MockDB.pm [new file with mode: 0644]
Bugzilla/Test/MockLocalconfig.pm [new file with mode: 0644]
Bugzilla/Test/MockParams.pm [new file with mode: 0644]
Bugzilla/Test/Util.pm
Makefile.PL
conf/log4perl-t.conf [new file with mode: 0644]
extensions/BMO/t/bounty_attachment.t
extensions/BMO/t/bug_format_comment.t [deleted file]
extensions/PhabBugz/lib/Feed.pm
extensions/PhabBugz/t/basic.t [moved from t/phabbugz.t with 100% similarity]
extensions/PhabBugz/t/feed-daemon-guts.t [new file with mode: 0644]
extensions/Push/t/ReviewBoard.t
extensions/RequestNagger/Extension.pm
t/mock-db.t [new file with mode: 0644]
t/mock-params.t [new file with mode: 0644]
t/sqlite-memory.t [new file with mode: 0644]

index a9a0876091b71fcbe522a438786b6f19ef7fb374..d8c30f71707ff5054de3f9b3ef2d4c70e286b0af 100644 (file)
@@ -190,7 +190,7 @@ jobs:
           name: run sanity tests
           command: |
             [[ -f build_info/only_version_changed.txt ]] && exit 0
-            /app/scripts/entrypoint.pl prove -qf $(circleci tests glob 't/*.t' | circleci tests split) | tee artifacts/$CIRCLE_JOB.txt
+            /app/scripts/entrypoint.pl prove -qf $(circleci tests glob 't/*.t' 'extensions/*/t/*.t' | circleci tests split) | tee artifacts/$CIRCLE_JOB.txt
       - store_artifacts:
           path: /app/artifacts
       - *store_log
index b0387d179e71ae165cd30af71f721d589c1d1012..5e48d21f4a7c9a0f1f984dd4c4cdf487d9b6ac9c 100644 (file)
@@ -85,6 +85,9 @@ sub init_page {
     # request cache are very annoying (see bug 1347335)
     # and this is not an expensive operation.
     clear_request_cache();
+    if ($0 =~ /\.t/) {
+        return;
+    }
     if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) {
         init_console();
     }
index d050ff9e0901cc2369b1ce12bb3374da22c48f5d..85779fa6b476244a001988f5252c6f8f145ffe1c 100644 (file)
@@ -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__
index 3890d0795778ed76aab759d93c22c46b041874a6..81ee7d88844dcdd5d7aa147df9bd518b6223b2b6 100644 (file)
@@ -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 (file)
index 0000000..d158a73
--- /dev/null
@@ -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 (file)
index 0000000..a32aea0
--- /dev/null
@@ -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 (file)
index 0000000..2d064c6
--- /dev/null
@@ -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
index 4c9981e52eed05b4cedbb214f515e642e93e8737..02c8426582d942c9b38a67495c604078934840e4 100644 (file)
@@ -24,7 +24,7 @@ sub create_user {
         cryptpassword => $password,
         disabledtext  => "",
         disable_mail  => 0,
-        extern_id     => 0,
+        extern_id     => undef,
         %extra,
     });
 }
index d9245c36f90b497a9b33325e9c031785d5d5f3c2..4cf8755c6e56b7bcd9ac5c9bf7e698945738b135 100755 (executable)
@@ -93,6 +93,7 @@ my %test_requires = (
     'Test::Selenium::Firefox'         => 0,
     'Test::Perl::Critic::Progressive' => 0,
     'Perl::Critic::Freenode'          => 0,
+    'Capture::Tiny'                   => 0,
 );
 my %recommends = ( Safe => '2.30' );
 
diff --git a/conf/log4perl-t.conf b/conf/log4perl-t.conf
new file mode 100644 (file)
index 0000000..33100d7
--- /dev/null
@@ -0,0 +1,4 @@
+log4perl.rootLogger = DEBUG, Screen
+log4perl.appender.Screen = Log::Log4perl::Appender::Screen
+log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
+log4perl.appender.Screen.layout.ConversionPattern = # [%6p] {%c} %m{chomp}%n
index bd79b0dfe283e33b68a43485f5d8098f5d6a53a1..6e596eebae06b9b309c10fe048c632ecaa64f157 100644 (file)
@@ -7,15 +7,13 @@
 # defined by the Mozilla Public License, v. 2.0.
 use strict;
 use warnings;
-use lib qw( . lib );
+use lib qw( . lib local/lib/perl5 );
 
 use Test::More;
 use Bugzilla;
-use Bugzilla::Extension;
-
-my $class = Bugzilla::Extension->load('extensions/BMO/Extension.pm',
-                                      'extensions/BMO/Config.pm');
+BEGIN { Bugzilla->extensions }
 
+my $class = 'Bugzilla::Extension::BMO';
 my $parse  = $class->can('parse_bounty_attachment_description');
 my $format = $class->can('format_bounty_attachment_description');
 
diff --git a/extensions/BMO/t/bug_format_comment.t b/extensions/BMO/t/bug_format_comment.t
deleted file mode 100644 (file)
index 532b8fb..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/perl -T
-# 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.
-use strict;
-use warnings;
-use lib qw( . lib );
-
-use Test::More;
-use Bugzilla;
-use Bugzilla::Extension;
-
-my $class = Bugzilla::Extension->load('extensions/BMO/Extension.pm',
-                                      'extensions/BMO/Config.pm');
-ok( $class->can('bug_format_comment'), 'the function exists');
-
-my $bmo = $class->new;
-ok($bmo, "got a new bmo extension");
-
-my $text = <<'END_OF_LINKS';
-# crash stats, a fake one
-bp-deadbeef-deaf-beef-beed-cafefeed1337
-
-# CVE/CAN security things
-CVE-2014-0160
-CVE-2014-0001
-CVE-2014-13579
-CVE-2014-999999999
-
-# svn
-r2424
-
-# bzr commit
-Committing to: bzr+ssh://dlawrence%40mozilla.com@bzr.mozilla.org/bmo/4.2
-modified extensions/Review/Extension.pm
-Committed revision 9257.
-
-# git with scp-style address
-To gitolite3@git.mozilla.org:bugzilla/bugzilla.git
-   36f56bd..eab44b1  nouri -> nouri
-
-# git with uri (with login)
-To ssh://gitolite3@git.mozilla.org/bugzilla/bugzilla.git
-   36f56bd..eab44b1  withuri -> withuri
-
-# git with uri (without login)
-To ssh://git.mozilla.org/bugzilla/bugzilla.git
-   36f56bd..eab44b1  nologin -> nologin
-END_OF_LINKS
-
-my @regexes;
-
-$bmo->bug_format_comment({ regexes => \@regexes });
-
-ok(@regexes > 0, "got some regexes to play with");
-
-foreach my $re (@regexes) {
-    my ($match, $replace) = @$re{qw(match replace)};
-    if (ref($replace) eq 'CODE') {
-        $text =~ s/$match/$replace->({matches => [ $1, $2, $3, $4,
-                                                   $5, $6, $7, $8,
-                                                   $9, $10]})/egx;
-    }
-    else {
-        $text =~ s/$match/$replace/egx;
-    }
-}
-
-my @links = (
-    '<a href="https://crash-stats.mozilla.com/report/index/deadbeef-deaf-beef-beed-cafefeed1337">bp-deadbeef-deaf-beef-beed-cafefeed1337</a>',
-    '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0160">CVE-2014-0160</a>',
-    '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0001">CVE-2014-0001</a>',
-    '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-13579">CVE-2014-13579</a>',
-    '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-999999999">CVE-2014-999999999</a>',
-    '<a href="https://viewvc.svn.mozilla.org/vc?view=rev&amp;revision=2424">r2424</a>',
-    '<a href="https://git.mozilla.org/?p=bugzilla/bugzilla.git;a=commitdiff;h=eab44b1">36f56bd..eab44b1  withuri -> withuri</a>',
-    '<a href="https://git.mozilla.org/?p=bugzilla/bugzilla.git;a=commitdiff;h=eab44b1">36f56bd..eab44b1  nouri -> nouri</a>',
-    '<a href="https://git.mozilla.org/?p=bugzilla/bugzilla.git;a=commitdiff;h=eab44b1">36f56bd..eab44b1  nologin -> nologin</a>',
-    'https://bzr.mozilla.org/bmo/4.2/revision/9257',
-);
-
-foreach my $link (@links) {
-    ok(index($text, $link) > -1, "check for $link");
-}
-
-
-done_testing;
index 8e7290988086c787faeb62d98c515b2cdf234c76..1cc73d1347cf9199b6a92a44641c97699eceb217 100644 (file)
@@ -380,7 +380,7 @@ sub process_revision_change {
 
     # Pre setup before making changes
     my $old_user = set_phab_user();
-    my $bug = Bugzilla::Bug->new({ id => $revision->bug_id, cache => 1 });
+    my $bug = $revision->bug;
 
     # Check to make sure bug id is valid and author can see it
     if ($bug->{error}
@@ -714,7 +714,7 @@ sub process_new_user {
         # that are connected to revisions
         f11 => 'attachments.filename',
         o11 => 'regexp',
-        v11 => '^phabricator-D[[:digit:]]+-url[[.period.]]txt$',
+        v11 => '^phabricator-D[[:digit:]]+-url.txt$',
     };
 
     my $search = Bugzilla::Search->new( fields => [ 'bug_id' ],
similarity index 100%
rename from t/phabbugz.t
rename to extensions/PhabBugz/t/basic.t
diff --git a/extensions/PhabBugz/t/feed-daemon-guts.t b/extensions/PhabBugz/t/feed-daemon-guts.t
new file mode 100644 (file)
index 0000000..376af18
--- /dev/null
@@ -0,0 +1,160 @@
+#!/usr/bin/perl
+# 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.
+use strict;
+use warnings;
+use 5.10.1;
+use lib qw( . lib local/lib/perl5 );
+BEGIN { $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf' }
+use Bugzilla::Test::MockDB;
+use Bugzilla::Test::MockParams;
+use Bugzilla::Test::Util qw(create_user);
+use Test::More;
+use Test2::Tools::Mock;
+use Try::Tiny;
+use JSON::MaybeXS;
+use Bugzilla::Constants;
+use URI;
+use File::Basename;
+use Digest::SHA qw(sha1_hex);
+
+use ok 'Bugzilla::Extension::PhabBugz::Feed';
+use ok 'Bugzilla::Extension::PhabBugz::Constants', 'PHAB_AUTOMATION_USER';
+use ok 'Bugzilla::Config', 'SetParam';
+can_ok('Bugzilla::Extension::PhabBugz::Feed', qw( group_query feed_query user_query ));
+
+Bugzilla->error_mode(ERROR_MODE_TEST);
+
+my $phab_bot = create_user(PHAB_AUTOMATION_USER, '*');
+
+my $UserAgent = mock 'LWP::UserAgent' => ();
+
+{
+    SetParam('phabricator_enabled', 0);
+    my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+    my $Feed = mock 'Bugzilla::Extension::PhabBugz::Feed' => (
+        override => [
+            get_last_id => sub { die "get_last_id" },
+        ],
+    );
+
+    foreach my $method (qw( feed_query user_query group_query )) {
+        try {
+            $feed->$method;
+            pass "disabling the phabricator sync: $method";
+        }
+        catch {
+            fail "disabling the phabricator sync: $method";
+        }
+    }
+}
+
+my @bad_response = (
+    ['http error', mock({ is_error => 1, message => 'some http error' }) ],
+    ['invalid json', mock({ is_error => 0, content => '<xml>foo</xml>' })],
+    ['json containing error code', mock({ is_error => 0, content => encode_json({error_code => 1234 }) })],
+);
+
+SetParam(phabricator_enabled => 1);
+SetParam(phabricator_api_key => 'FAKE-API-KEY');
+SetParam(phabricator_base_uri => 'http://fake.fabricator.tld/');
+
+foreach my $bad_response (@bad_response) {
+    my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+    $UserAgent->override(
+        post => sub {
+            my ( $self, $url, $params ) = @_;
+            return $bad_response->[1];
+        }
+    );
+
+    foreach my $method (qw( feed_query user_query group_query )) {
+        try {
+            # This is a hack to get reasonable exception objects.
+            local $Bugzilla::Template::is_processing = 1;
+            $feed->$method;
+            fail "$method - $bad_response->[0]";
+        }
+        catch {
+            is( $_->type, 'bugzilla.code.phabricator_api_error', "$method - $bad_response->[0]" );
+        };
+    }
+    $UserAgent->reset('post');
+}
+
+my $feed      = Bugzilla::Extension::PhabBugz::Feed->new;
+my $json      = JSON::MaybeXS->new( canonical => 1, pretty => 1 );
+my $dylan     = create_user( 'dylan@mozilla.com', '*', realname => 'Dylan Hardison :dylan' );
+my $evildylan = create_user( 'dylan@gmail.com', '*', realname => 'Evil Dylan :dylan' );
+my $myk       = create_user( 'myk@mozilla.com', '*', realname => 'Myk Melez :myk' );
+
+my $phab_bot_phid = next_phid('PHID-USER');
+
+done_testing;
+
+sub user_search {
+    my (%conf) = @_;
+
+    return {
+        error_info => undef,
+        error_code => undef,
+        result     => {
+            cursor => {
+                after  => $conf{after},
+                order  => undef,
+                limit  => 100,
+                before => undef
+            },
+            query => {
+                queryKey => undef
+            },
+            maps => {},
+            data => [
+                map {
+                    +{
+                        attachments => {
+                            $_->{bmo_id}
+                            ? ( "external-accounts" => {
+                                    "external-accounts" => [
+                                        {
+                                            type => 'bmo',
+                                            id   => $_->{bmo_id},
+                                        }
+                                    ]
+                                }
+                              )
+                            : (),
+                        },
+                        fields => {
+                            roles        => [ "verified", "approved", "activated" ],
+                            realName     => $_->{realname},
+                            dateModified => time,
+                            policy       => {
+                                view => "public",
+                                edit => "no-one"
+                            },
+                            dateCreated => time,
+                            username    => $_->{username},
+                        },
+                        phid => next_phid("PHID-USER"),
+                        type => "USER",
+                        id   => $_->{phab_id},
+                      },
+                } @{ $conf{users} },
+            ]
+        }
+    };
+
+}
+
+sub next_phid {
+    my ($prefix) = @_;
+    state $number = 'a' x 20;
+    return $prefix . '-' .  ($number++);
+}
+
+
index 3eb54760c4f6e009c0f1608ee61cb693c0cb8d63..c752e34ef61a4889c762cef86662d932f7ed207d 100644 (file)
@@ -7,14 +7,13 @@
 # defined by the Mozilla Public License, v. 2.0.
 use strict;
 use warnings;
-use lib qw( . lib );
+use lib qw( . lib local/lib/perl5 );
 
 use Test::More;
 use Bugzilla;
 use Bugzilla::Extension;
 use Bugzilla::Attachment;
 use Scalar::Util 'blessed';
-use YAML;
 
 BEGIN {
     eval {
index 65f5e6b84fd2cc5dcd8945fc633a2244b5ca9bef..e0f97c9f7440b13db1e385b83d717f0dc22349b6 100644 (file)
@@ -355,7 +355,7 @@ sub db_schema_abstract_schema {
             },
         ],
         INDEXES => [
-            nag_watch_idx => {
+            nag_setting_idx => {
                 FIELDS => [ 'user_id', 'setting_name' ],
                 TYPE => 'UNIQUE',
             },
diff --git a/t/mock-db.t b/t/mock-db.t
new file mode 100644 (file)
index 0000000..6cf84f3
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+# 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.
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw( . lib local/lib/perl5 );
+use Test::More;
+use Try::Tiny;
+
+use ok 'Bugzilla::Test::MockDB';
+use ok 'Bugzilla::Test::Util', qw(create_user);
+
+try {
+    Bugzilla::Test::MockDB->import();
+    pass('made fake in-memory db');
+}
+catch {
+    diag $_;
+    fail('made fake in-memory db');
+};
+
+try {
+    create_user('bob@pants.gov', '*');
+    ok( Bugzilla::User->new({name => 'bob@pants.gov'})->id, 'create a user' );
+}
+catch {
+    fail('create a user');
+};
+
+done_testing;
diff --git a/t/mock-params.t b/t/mock-params.t
new file mode 100644 (file)
index 0000000..7c23181
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+# 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.
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw( . lib local/lib/perl5 );
+use Test::More;
+use Test2::Tools::Mock qw(mock);
+use Bugzilla::Test::MockParams (
+    phabricator_auth_callback_url => 'http://pants.gov/',
+);
+
+is(Bugzilla->params->{phabricator_auth_callback_url}, 'http://pants.gov/', 'import default params');
+
+Bugzilla::Test::MockParams->import(phabricator_api_key => 'FAKE-KEY');
+
+is(Bugzilla->params->{phabricator_api_key}, 'FAKE-KEY', 'set key');
+
+
+done_testing;
diff --git a/t/sqlite-memory.t b/t/sqlite-memory.t
new file mode 100644 (file)
index 0000000..66f8e5d
--- /dev/null
@@ -0,0 +1,89 @@
+# 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.
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw( . lib local/lib/perl5 );
+use Test::More;
+use Test2::Tools::Mock;
+use Try::Tiny;
+use Capture::Tiny qw(capture_merged);
+use Bugzilla::Test::MockParams;
+
+BEGIN {
+    $ENV{LOCALCONFIG_ENV} = 'BMO';
+    $ENV{BMO_db_driver} = 'sqlite';
+    $ENV{BMO_db_name} = ':memory:';
+};
+use Bugzilla;
+BEGIN { Bugzilla->extensions };
+
+
+isa_ok(Bugzilla->dbh, 'Bugzilla::DB::Sqlite');
+
+use ok 'Bugzilla::Install';
+use ok 'Bugzilla::Install::DB';
+
+my $lives_ok = sub {
+    my ($desc, $code) = @_;
+    my $output;
+    try {
+        $output = capture_merged { $code->() };
+        pass($desc);
+    } catch {
+        diag $_;
+        fail($desc);
+    } finally {
+        diag "OUTPUT: $output" if $output;
+    };
+};
+
+my $output = '';
+$lives_ok->('bz_setup_database' => sub {
+     Bugzilla->dbh->bz_setup_database
+});
+
+$lives_ok->('bz_populate_enum_tables' => sub {
+    # Populate the tables that hold the values for the <select> fields.
+    Bugzilla->dbh->bz_populate_enum_tables();
+});
+
+$lives_ok->('update_fielddefs_definition' => sub {
+    Bugzilla::Install::DB::update_fielddefs_definition();
+});
+
+$lives_ok->('populate_field_definitions' => sub {
+    Bugzilla::Field::populate_field_definitions();
+});
+
+$lives_ok->('init_workflow' => sub {
+    Bugzilla::Install::init_workflow();
+});
+
+$lives_ok->('update_table_definitions' => sub {
+    Bugzilla::Install::DB->update_table_definitions({});
+});
+
+$lives_ok->('update_system_groups' => sub {
+    Bugzilla::Install::update_system_groups();
+});
+
+# "Log In" as the fake superuser who can do everything.
+Bugzilla->set_user(Bugzilla::User->super_user);
+
+$lives_ok->('update_settings' => sub {
+    Bugzilla::Install::update_settings();
+});
+
+SKIP: {
+    skip 'default product cannot be created without default assignee', 1;
+    $lives_ok->('create_default_product' => sub {
+        Bugzilla::Install::create_default_product();
+    });
+}
+
+done_testing;