Bug 9302: Add error messages, correct number of unit tests in subtest 'Test Koha...
authorKyle M Hall <kyle@bywatetsolutions.com>
Thu, 19 Apr 2018 19:02:31 +0000 (15:02 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 20 Apr 2018 16:34:41 +0000 (13:34 -0300)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/en/modules/members/merge-patrons.tt
t/db_dependent/Koha/Patrons.t

index f016436..a8cd953 100644 (file)
             <h3>Merge patron records</h3>
 
             [% IF action == 'show' %]
-                <p>Select patron to keep. Data from the other patrons will be transferred to this patron record and the remaining patron records will be deleted.</p>
-                <form type="post" action="merge-patrons.pl">
-                    <table id="patron-merge-table" class="datatable">
-                        <thead>
-                            <tr>
-                                <th>&nbsp;</th>
-                                <th>Card</th>
-                                <th>Name</th>
-                                <th>Date of birth</th>
-                                <th>Category</th>
-                                <th>Library</th>
-                                <th>Expires on</th>
-                            </tr>
-                        </thead>
-
-                        <tbody>
-                            [% FOREACH p IN patrons %]
+                [% IF patrons.count > 1 %]
+                    <p>Select patron to keep. Data from the other patrons will be transferred to this patron record and the remaining patron records will be deleted.</p>
+                    <form type="post" action="merge-patrons.pl">
+                        <table id="patron-merge-table" class="datatable">
+                            <thead>
                                 <tr>
-                                    <td><input class='keeper' type='radio' name='keeper' value='[% p.id %]' /></td>
-                                    <td>[% p.cardnumber | html %]</td>
-                                    <td>[% INCLUDE 'patron-title.inc' patron = p %]</td>
-                                    <td>[% p.dateofbirth | $KohaDates %]</td>
-                                    <td>[% Categories.GetName( p.categorycode ) %] ([% p.categorycode %])</td>
-                                    <td>[% Branches.GetName( p.branchcode ) %]</td>
-                                    <td>[% p.dateexpiry | $KohaDates %]</td>
-                            [% END %]
-                        </tbody>
-                    </table>
-
-                    [% FOREACH p IN patrons %]
-                        <input type="hidden" name="id" value="[% p.id %]" />
-                    [% END %]
+                                    <th>&nbsp;</th>
+                                    <th>Card</th>
+                                    <th>Name</th>
+                                    <th>Date of birth</th>
+                                    <th>Category</th>
+                                    <th>Library</th>
+                                    <th>Expires on</th>
+                                </tr>
+                            </thead>
+
+                            <tbody>
+                                [% FOREACH p IN patrons %]
+                                    <tr>
+                                        <td><input class='keeper' type='radio' name='keeper' value='[% p.id %]' /></td>
+                                        <td>[% p.cardnumber | html %]</td>
+                                        <td>[% INCLUDE 'patron-title.inc' patron = p %]</td>
+                                        <td>[% p.dateofbirth | $KohaDates %]</td>
+                                        <td>[% Categories.GetName( p.categorycode ) %] ([% p.categorycode %])</td>
+                                        <td>[% Branches.GetName( p.branchcode ) %]</td>
+                                        <td>[% p.dateexpiry | $KohaDates %]</td>
+                                [% END %]
+                            </tbody>
+                        </table>
+
+                        [% FOREACH p IN patrons %]
+                            <input type="hidden" name="id" value="[% p.id %]" />
+                        [% END %]
 
-                    <p/>
+                        <p/>
 
-                    <input type="hidden" name="action" value="merge" />
-                    <input id="merge-patrons" type="submit" value="Merge patrons" />
+                        <input type="hidden" name="action" value="merge" />
+                        <input id="merge-patrons" type="submit" value="Merge patrons" />
+                    [% ELSE %]
+                        <div class="dialog alert">Error: Two or more patrons need to be selected for merging</div>
+                    [% END %]
                 </form>
             [% ELSIF action == 'merge' %]
                 <h4>Results</h4>
-
                 [% IF error %]
                     <div class="dialog alert">Merge failed! The following error was reported: [% error %].</div>
+                [% ELSIF !results.merged.keys.size %]
+                    <div class="dialog alert">No valid patrons to merge were found.</div>
                 [% ELSE %]
                     <p>
                         Patron records merged into <a href="moremember.pl?borrowernumber=[% keeper.id %]">[% INCLUDE 'patron-title.inc' patron = keeper %]</a>
index 8eb80e6..04352c9 100644 (file)
@@ -1337,7 +1337,7 @@ subtest 'Log cardnumber change' => sub {
 $schema->storage->txn_rollback;
 
 subtest 'Test Koha::Patrons::merge' => sub {
-    plan tests => 98;
+    plan tests => 110;
 
     my $schema = Koha::Database->new()->schema();