diff options
Diffstat (limited to 'Bugzilla/Test')
-rw-r--r-- | Bugzilla/Test/MockDB.pm | 179 | ||||
-rw-r--r-- | Bugzilla/Test/MockLocalconfig.pm | 6 | ||||
-rw-r--r-- | Bugzilla/Test/MockParams.pm | 82 | ||||
-rw-r--r-- | Bugzilla/Test/Util.pm | 65 |
4 files changed, 166 insertions, 166 deletions
diff --git a/Bugzilla/Test/MockDB.pm b/Bugzilla/Test/MockDB.pm index fb7873ccf..db55b5d1e 100644 --- a/Bugzilla/Test/MockDB.pm +++ b/Bugzilla/Test/MockDB.pm @@ -11,110 +11,117 @@ use warnings; use Try::Tiny; use Capture::Tiny qw(capture_merged); -use Bugzilla::Test::MockLocalconfig ( - db_driver => 'sqlite', - db_name => ':memory:', -); +use Bugzilla::Test::MockLocalconfig (db_driver => 'sqlite', + db_name => ':memory:',); use Bugzilla; -BEGIN { Bugzilla->extensions }; -use Bugzilla::Test::MockParams ( - emailsuffix => '', - emailregexp => '.+', -); +BEGIN { Bugzilla->extensions } +use Bugzilla::Test::MockParams (emailsuffix => '', emailregexp => '.+',); sub import { - require Bugzilla::Install; - require Bugzilla::Install::DB; - require Bugzilla::Field;; + require Bugzilla::Install; + require Bugzilla::Install::DB; + require Bugzilla::Field; - state $first_time = 0; + state $first_time = 0; - return undef if $first_time++; + return undef if $first_time++; - return capture_merged { - Bugzilla->dbh->bz_setup_database(); + 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(); + # 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::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->set_user(Bugzilla::User->super_user); - Bugzilla::Install::update_settings(); + Bugzilla::Install::update_settings(); - my $dbh = Bugzilla->dbh; - if ( !$dbh->selectrow_array("SELECT 1 FROM priority WHERE value = 'P1'") ) { - $dbh->do("DELETE FROM priority"); - my $count = 100; - foreach my $priority (map { "P$_" } 1..5) { - $dbh->do( "INSERT INTO priority (value, sortkey) VALUES (?, ?)", undef, ( $priority, $count + 100 ) ); - } - } - my @flagtypes = ( - { - name => 'review', - desc => 'The patch has passed review by a module owner or peer.', - is_requestable => 1, - is_requesteeble => 1, - is_multiplicable => 1, - grant_group => '', - target_type => 'a', - cc_list => '', - inclusions => [''] - }, - { - name => 'feedback', - desc => 'A particular person\'s input is requested for a patch, ' . - 'but that input does not amount to an official review.', - is_requestable => 1, - is_requesteeble => 1, - is_multiplicable => 1, - grant_group => '', - target_type => 'a', - cc_list => '', - inclusions => [''] - } - ); + my $dbh = Bugzilla->dbh; + if (!$dbh->selectrow_array("SELECT 1 FROM priority WHERE value = 'P1'")) { + $dbh->do("DELETE FROM priority"); + my $count = 100; + foreach my $priority (map {"P$_"} 1 .. 5) { + $dbh->do("INSERT INTO priority (value, sortkey) VALUES (?, ?)", + undef, ($priority, $count + 100)); + } + } + my @flagtypes = ( + { + name => 'review', + desc => 'The patch has passed review by a module owner or peer.', + is_requestable => 1, + is_requesteeble => 1, + is_multiplicable => 1, + grant_group => '', + target_type => 'a', + cc_list => '', + inclusions => [''] + }, + { + name => 'feedback', + desc => 'A particular person\'s input is requested for a patch, ' + . 'but that input does not amount to an official review.', + is_requestable => 1, + is_requesteeble => 1, + is_multiplicable => 1, + grant_group => '', + target_type => 'a', + cc_list => '', + inclusions => [''] + } + ); - foreach my $flag (@flagtypes) { - next if Bugzilla::FlagType->new({ name => $flag->{name} }); - my $grant_group_id = $flag->{grant_group} - ? Bugzilla::Group->new({ name => $flag->{grant_group} })->id - : undef; - my $request_group_id = $flag->{request_group} - ? Bugzilla::Group->new({ name => $flag->{request_group} })->id - : undef; + foreach my $flag (@flagtypes) { + next if Bugzilla::FlagType->new({name => $flag->{name}}); + my $grant_group_id + = $flag->{grant_group} + ? Bugzilla::Group->new({name => $flag->{grant_group}})->id + : undef; + my $request_group_id + = $flag->{request_group} + ? Bugzilla::Group->new({name => $flag->{request_group}})->id + : undef; - $dbh->do('INSERT INTO flagtypes (name, description, cc_list, target_type, is_requestable, + $dbh->do( + 'INSERT INTO flagtypes (name, description, cc_list, target_type, is_requestable, is_requesteeble, is_multiplicable, grant_group_id, request_group_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', - undef, ($flag->{name}, $flag->{desc}, $flag->{cc_list}, $flag->{target_type}, - $flag->{is_requestable}, $flag->{is_requesteeble}, $flag->{is_multiplicable}, - $grant_group_id, $request_group_id)); + undef, + ( + $flag->{name}, $flag->{desc}, + $flag->{cc_list}, $flag->{target_type}, + $flag->{is_requestable}, $flag->{is_requesteeble}, + $flag->{is_multiplicable}, $grant_group_id, + $request_group_id + ) + ); - my $type_id = $dbh->bz_last_key('flagtypes', 'id'); + my $type_id = $dbh->bz_last_key('flagtypes', 'id'); - foreach my $inclusion (@{$flag->{inclusions}}) { - my ($product, $component) = split(':', $inclusion); - my ($prod_id, $comp_id); - if ($product) { - my $prod_obj = Bugzilla::Product->new({ name => $product }); - $prod_id = $prod_obj->id; - if ($component) { - $comp_id = Bugzilla::Component->new({ name => $component, product => $prod_obj})->id; - } - } - $dbh->do('INSERT INTO flaginclusions (type_id, product_id, component_id) - VALUES (?, ?, ?)', - undef, ($type_id, $prod_id, $comp_id)); - } + foreach my $inclusion (@{$flag->{inclusions}}) { + my ($product, $component) = split(':', $inclusion); + my ($prod_id, $comp_id); + if ($product) { + my $prod_obj = Bugzilla::Product->new({name => $product}); + $prod_id = $prod_obj->id; + if ($component) { + $comp_id + = Bugzilla::Component->new({name => $component, product => $prod_obj})->id; + } } - }; + $dbh->do( + 'INSERT INTO flaginclusions (type_id, product_id, component_id) + VALUES (?, ?, ?)', undef, ($type_id, $prod_id, $comp_id) + ); + } + } + }; } 1; diff --git a/Bugzilla/Test/MockLocalconfig.pm b/Bugzilla/Test/MockLocalconfig.pm index a32aea0d4..080fdeef8 100644 --- a/Bugzilla/Test/MockLocalconfig.pm +++ b/Bugzilla/Test/MockLocalconfig.pm @@ -10,9 +10,9 @@ use strict; use warnings; sub import { - my ($class, %lc) = @_; - $ENV{LOCALCONFIG_ENV} = 'BMO'; - $ENV{"BMO_$_"} = $lc{$_} for keys %lc; + 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 index 2d064c616..8738f78d4 100644 --- a/Bugzilla/Test/MockParams.pm +++ b/Bugzilla/Test/MockParams.pm @@ -16,56 +16,48 @@ 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; - }, - ], - ); + 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; + 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" }, - ], - ); + 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; - } + if ($first_time++) { + capture_merged { + Bugzilla::Config::update_params(); + }; + } + else { + Bugzilla::Config::SetParam($_, $answers{$_}) for keys %answers; + } } -1;
\ No newline at end of file +1; diff --git a/Bugzilla/Test/Util.pm b/Bugzilla/Test/Util.pm index 9fbc151f7..995cff0be 100644 --- a/Bugzilla/Test/Util.pm +++ b/Bugzilla/Test/Util.pm @@ -20,50 +20,51 @@ use Mojo::Message::Response; use Test2::Tools::Mock qw(mock); sub create_user { - my ($login, $password, %extra) = @_; - require Bugzilla; - return Bugzilla::User->create({ - login_name => $login, - cryptpassword => $password, - disabledtext => "", - disable_mail => 0, - extern_id => undef, - %extra, - }); + my ($login, $password, %extra) = @_; + require Bugzilla; + return Bugzilla::User->create({ + login_name => $login, + cryptpassword => $password, + disabledtext => "", + disable_mail => 0, + extern_id => undef, + %extra, + }); } sub issue_api_key { - my ($login, $given_api_key) = @_; - my $user = Bugzilla::User->check({ name => $login }); + my ($login, $given_api_key) = @_; + my $user = Bugzilla::User->check({name => $login}); - my $params = { - user_id => $user->id, - description => 'Bugzilla::Test::Util::issue_api_key', - api_key => $given_api_key, - }; + my $params = { + user_id => $user->id, + description => 'Bugzilla::Test::Util::issue_api_key', + api_key => $given_api_key, + }; - if ($given_api_key) { - return Bugzilla::User::APIKey->create_special($params); - } else { - return Bugzilla::User::APIKey->create($params); - } + if ($given_api_key) { + return Bugzilla::User::APIKey->create_special($params); + } + else { + return Bugzilla::User::APIKey->create($params); + } } sub _json_content_type { $_->headers->content_type('application/json') } sub mock_useragent_tx { - my ($body, $modify) = @_; - $modify //= \&_json_content_type; + my ($body, $modify) = @_; + $modify //= \&_json_content_type; - my $res = Mojo::Message::Response->new; - $res->code(200); - $res->body($body); - if ($modify) { - local $_ = $res; - $modify->($res); - } + my $res = Mojo::Message::Response->new; + $res->code(200); + $res->body($body); + if ($modify) { + local $_ = $res; + $modify->($res); + } - return mock({result => $res}); + return mock({result => $res}); } 1; |