Bugzilla – Attachment 182293 Details for
Bug 39870
Add plugin hook for making arbitrary data available to notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39870: Unit tests
Bug-39870-Unit-tests.patch (text/plain), 4.28 KB, created by
David Nind
on 2025-05-12 14:39:49 UTC
(
hide
)
Description:
Bug 39870: Unit tests
Filename:
MIME Type:
Creator:
David Nind
Created:
2025-05-12 14:39:49 UTC
Size:
4.28 KB
patch
obsolete
>From d498ec2116dda50fd4eea97fea4ab7bb9d0f4799 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 9 May 2025 17:11:33 -0300 >Subject: [PATCH] Bug 39870: Unit tests > >Signed-off-by: David Nind <david@davidnind.com> >--- > .../Koha/Plugins/Notices_content_hook.t | 104 ++++++++++++++++++ > t/lib/plugins/Koha/Plugin/Test.pm | 10 ++ > 2 files changed, 114 insertions(+) > create mode 100755 t/db_dependent/Koha/Plugins/Notices_content_hook.t > >diff --git a/t/db_dependent/Koha/Plugins/Notices_content_hook.t b/t/db_dependent/Koha/Plugins/Notices_content_hook.t >new file mode 100755 >index 0000000000..879b1f203b >--- /dev/null >+++ b/t/db_dependent/Koha/Plugins/Notices_content_hook.t >@@ -0,0 +1,104 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::NoWarnings; >+use Test::More tests => 5; >+use Test::Warn; >+ >+use File::Basename; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use C4::Letters qw( GetPreparedLetter ); >+ >+BEGIN { >+ # Mock pluginsdir before loading Plugins module >+ my $path = dirname(__FILE__) . '/../../../lib/plugins'; >+ t::lib::Mocks::mock_config( 'pluginsdir', $path ); >+ >+ use_ok('Koha::Plugins'); >+ use_ok('Koha::Plugins::Handler'); >+ use_ok('Koha::Plugin::Test'); >+} >+ >+t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ >+my $schema = Koha::Database->schema; >+my $builder = t::lib::TestBuilder->new(); >+ >+subtest 'notices_content() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin(); >+ >+ my $dbh = C4::Context->dbh; >+ >+ # just to be sure >+ $dbh->do(q|DELETE FROM letter WHERE module='test'|); >+ >+ my $plugins = Koha::Plugins->new; >+ warning_is { $plugins->InstallPlugins; } undef; >+ >+ my $prepared_letter; >+ >+ my $sth = $dbh->prepare( >+ q{ >+ INSERT INTO letter (module, code, name, title, content) >+ VALUES ('test',?,'Test',?,?)} >+ ); >+ >+ $sth->execute( >+ "TEST_HOLD", >+ "[% hold.id %]", >+ "[% plugin_content.test.custom_attribute.message %]. " >+ . "We identified this is the '[% plugin_content.test.custom_attribute.module %]' module" >+ ); >+ >+ my $hold = $builder->build_object( { class => 'Koha::Holds' } ); >+ warning_like { >+ $prepared_letter = GetPreparedLetter( >+ ( >+ module => 'test', >+ letter_code => 'TEST_HOLD', >+ tables => { >+ reserves => $hold->unblessed, >+ } >+ ) >+ ) >+ } >+ qr/transform_prepared_letter called with letter content/, >+ 'GetPreparedLetter calls the transform_prepared_letter hook'; >+ >+ is( >+ $prepared_letter->{content}, >+ "notices_content() called. We identified this is the 'test' module" >+ . "\nThank you for using your local library!", >+ 'Patron object used correctly with scalar for content' >+ ); >+ is( >+ $prepared_letter->{title}, >+ $hold->id . "!", >+ 'Hold object used correctly with scalar for title' >+ ); >+ >+ $schema->storage->txn_rollback; >+ Koha::Plugins::Methods->delete; >+ >+}; >diff --git a/t/lib/plugins/Koha/Plugin/Test.pm b/t/lib/plugins/Koha/Plugin/Test.pm >index 77600be3d5..46f0732dc6 100644 >--- a/t/lib/plugins/Koha/Plugin/Test.pm >+++ b/t/lib/plugins/Koha/Plugin/Test.pm >@@ -156,6 +156,16 @@ sub before_send_messages { > Koha::Exception->throw("before_send_messages called"); > } > >+sub notices_content { >+ my ( $self, $params ) = @_; >+ return { >+ custom_attribute => { >+ module => $params->{module}, >+ message => 'notices_content() called', >+ }, >+ }; >+} >+ > sub before_biblio_action { > my ( $self, $params ) = @_; > >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39870
:
182265
|
182266
|
182293
|
182294
|
182418
|
182419