]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1482145 - Some changes required for unit tests to be written
authorDylan William Hardison <dylan@hardison.net>
Mon, 20 Aug 2018 21:27:57 +0000 (17:27 -0400)
committerGitHub <noreply@github.com>
Mon, 20 Aug 2018 21:27:57 +0000 (17:27 -0400)
Bugzilla/Test/MockDB.pm
extensions/ComponentWatching/Extension.pm
extensions/MyDashboard/Extension.pm
t/mock-db.t

index d158a73debb786713c532d2d398fd08890eb7ae5..fb7873ccf70a68b6b225850657097ef507dd639a 100644 (file)
@@ -17,7 +17,10 @@ use Bugzilla::Test::MockLocalconfig (
 );
 use Bugzilla;
 BEGIN { Bugzilla->extensions };
-use Bugzilla::Test::MockParams;
+use Bugzilla::Test::MockParams (
+    emailsuffix => '',
+    emailregexp => '.+',
+);
 
 sub import {
     require Bugzilla::Install;
@@ -43,6 +46,74 @@ sub import {
         Bugzilla->set_user(Bugzilla::User->super_user);
 
         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       => ['']
+            }
+        );
+
+        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,
+                                            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));
+
+            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));
+            }
+        }
     };
 }
 
index 674e0da7bce3c4198d717b2ac8cffb87d2c6d98e..25155f90bac75d47f7b31a2c86ceffabff09d79b 100644 (file)
@@ -411,7 +411,7 @@ sub bugmail_recipients {
                INNER JOIN components ON components.product_id = component_watch.product_id
          WHERE component_prefix IS NOT NULL
                AND (component_watch.product_id = ? OR component_watch.product_id = ?)
-               AND components.name LIKE CONCAT(component_prefix, '%')
+               AND components.name LIKE @{[$dbh->sql_string_concat('component_prefix', q{'%'})]}
                AND (components.id = ? OR components.id = ?)
     ");
     $sth->execute(
index 5278cfaa44ce73e56c2c9940af0f05ad8085606d..fc3a689bf3993a08fd9a217f122a2a096d272632 100644 (file)
@@ -106,7 +106,7 @@ sub _component_watcher_ids {
                   WHERE product_id = ?
                     AND (component_id = ?
                          OR component_id IS NULL
-                         OR ? LIKE CONCAT(component_prefix, '%'))";
+                         OR ? LIKE @{[$dbh->sql_string_concat('component_prefix', q{'%'})]})";
 
     $self->{watcher_ids} ||= $dbh->selectcol_arrayref($query, undef,
         $self->product_id, $self->id, $self->name);
index 6cf84f316edb2b33eb10f72ca0c5aa2f400022f6..54ceef10061147fb87210e3bfa91f97c6d7cf01d 100644 (file)
@@ -32,4 +32,14 @@ catch {
     fail('create a user');
 };
 
+try {
+    my $rob = create_user('rob@pants.gov', '*');
+    Bugzilla::User->check({id => $rob->id});
+    pass('rob@pants.gov checks out');
+}
+catch {
+    diag $_;
+    fail('rob@pants.gov fails');
+};
+
 done_testing;