Bug 14206: Adds delete function for non email templates
authorIndranil Das Gupta <indradg@gmail.com>
Thu, 21 May 2015 22:19:10 +0000 (03:49 +0530)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Thu, 11 Jun 2015 13:14:22 +0000 (10:14 -0300)
C4::Letters::getletter() is called in tools/letter.pl by the function
delete_confirm() to display the selected notice for deletion. Due to
current implementation of getletter(), a notice that does not use
the 'email' template (but uses any/all of the other templates - sms,
print or phone) can't be deleted from the staff client.

This patch adds deletion capability for notices that do not use email
template, but uses any/all of the other templates i.e. sms, print or
phone. This also adds 2 tests to t/db_dependent/Letters.t for testing
both conditions - a) when message_transport_type is specified b) when
it is not.

Test plan
=========

1/ Go to Tools -> Notices & Slips. Add a new notice only for print,
   leave 'Library' and 'Koha module' options as default selections.
   Enter 'KOHA_14206' and 'Koha Test 14206' against Code and Name
   respectively, and 'Test' and 'Test Message' for subject and body.
   Leave the Email, Phone and SMS tabs blank. Save the notice.
2/ On the notices listing page the new notice will be listed. Try to
   delete it. It will load the 'Delete notice' dialog form, but the
   table will not show any data under <th>s - 'Library', 'Module',
   'Code' or 'Name'.
3/ Click the "Yes, delete" button. The page will be submitted and the
   Notices listing reloaded. The print-only KOHA_14206 notice should
   continue to exist. This is *wrong*.
4/ Apply this patch
5/ Reload the listings page and click on the 'Delete' link for Notice
   KOHA_14206. This time, it should show the data under 'Module',
   'Code' or 'Name' at least.
6/ Click on 'Yes, delete'. The page should submit and the listing page
   reload. This time KOHA_14206 will be gone.
7/ Run prove -v t/db_dependent/Letters.t
   All tests should PASS without any error.

Followed test plan. Works as expected.
Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Jonathan Druart <jonathan.druart@koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Letters.pm
t/db_dependent/Letters.t

index c7751ca..db9f987 100644 (file)
@@ -207,8 +207,7 @@ sub GetLettersAvailableForALibrary {
 our %letter;
 sub getletter {
     my ( $module, $code, $branchcode, $message_transport_type ) = @_;
-    $message_transport_type ||= 'email';
-
+    $message_transport_type //= '%';
 
     if ( C4::Context->preference('IndependentBranches')
             and $branchcode
@@ -226,7 +225,8 @@ sub getletter {
     my $sth = $dbh->prepare(q{
         SELECT *
         FROM letter
-        WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') AND message_transport_type = ?
+        WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '')
+        AND message_transport_type LIKE ?
         ORDER BY branchcode DESC LIMIT 1
     });
     $sth->execute( $module, $code, $branchcode, $message_transport_type );
@@ -237,6 +237,7 @@ sub getletter {
     return { %$line };
 }
 
+
 =head2 DelLetter
 
     DelLetter(
index 8599c3f..ac22824 100644 (file)
@@ -18,7 +18,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 58;
+use Test::More tests => 60;
 use Test::MockModule;
 use Test::Warn;
 
@@ -177,6 +177,12 @@ is( $letter->{title}, $title, 'GetLetters gets the title correctly' );
 is( $letter->{content}, $content, 'GetLetters gets the content correctly' );
 is( $letter->{message_transport_type}, 'email', 'GetLetters gets the message type correctly' );
 
+# Regression test for Bug 14206
+$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('FFL','my module','my code','my name',1,?,?,'print')|, undef, $title, $content );
+my $letter14206_a = C4::Letters::getletter('my module', 'my code', 'FFL' );
+is( $letter14206_a->{message_transport_type}, 'print', 'Bug 14206 - message_transport_type not passed, correct mtt detected' );
+my $letter14206_b = C4::Letters::getletter('my module', 'my code', 'FFL', 'print');
+is( $letter14206_b->{message_transport_type}, 'print', 'Bug 14206 - message_transport_type passed, correct mtt detected'  );
 
 # addalert
 my $type = 'my type';