Bugzilla – Attachment 183221 Details for
Bug 34776
Patron messaging preferences are lost when an error occurs during new account creation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34776: Add unit tests for sub restore_form_values
0001-Bug-34776-Add-unit-tests-for-sub-restore_form_values.patch (text/plain), 3.85 KB, created by
Emmi Takkinen
on 2025-06-13 05:33:26 UTC
(
hide
)
Description:
Bug 34776: Add unit tests for sub restore_form_values
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2025-06-13 05:33:26 UTC
Size:
3.85 KB
patch
obsolete
>From 85fbc767e4b07393cdea7616e92d703d334b9d6d Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@koha-suomi.fi> >Date: Thu, 24 Apr 2025 13:46:27 +0300 >Subject: [PATCH] Bug 34776: Add unit tests for sub restore_form_values > >Test that input values don't change when send to the >sub restore_form_values. > >To test prove t/Form_MessagingPreferences.t > >Sponsored-by: Koha-Suomi Oy >--- > C4/Form/MessagingPreferences.pm | 2 +- > t/Form_MessagingPreferences.t | 63 ++++++++++++++++++++++++++++----- > 2 files changed, 56 insertions(+), 9 deletions(-) > >diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm >index 51540f1d78..36b0979099 100644 >--- a/C4/Form/MessagingPreferences.pm >+++ b/C4/Form/MessagingPreferences.pm >@@ -150,7 +150,7 @@ PREF: foreach my $option (@$messaging_options) { > > =head2 restore_form_values > >- C4::Form::MessagingPreferences::restore_form_values({ borrowernumber => 51 }, $template, $input); >+ C4::Form::MessagingPreferences::restore_form_values( $input, $template ); > > Restores patron message preferences if error occurs while creating a patron. > >diff --git a/t/Form_MessagingPreferences.t b/t/Form_MessagingPreferences.t >index fd1d5fee7b..0656ab9a14 100755 >--- a/t/Form_MessagingPreferences.t >+++ b/t/Form_MessagingPreferences.t >@@ -6,21 +6,68 @@ use Template; > > use Test::More tests => 1; > use Test::MockModule; >+ > #use Test::NoWarnings; >+use t::lib::TestBuilder; >+use t::lib::Mocks; > > use C4::Form::MessagingPreferences; > >-subtest 'restore_values' => sub { >- plan tests => 1; >- my $cgi = CGI->new; >- my $template_module = Test::MockModule->new( 'Template' ); >- my $vars = {}; >+my $builder = t::lib::TestBuilder->new; >+my $schema = Koha::Database->new->schema; >+ >+subtest 'restore_form_values' => sub { >+ >+ plan tests => 2; >+ >+ my $cgi = CGI->new; >+ my $template_module = Test::MockModule->new('Template'); >+ my $vars = {}; > $template_module->mock( 'param', sub { my ( $self, $key, $val ) = @_; $vars->{$key} = $val; } ); > my $template = Template->new( ENCODING => 'UTF-8' ); > >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ t::lib::Mocks::mock_preference( 'EnhancedMessagingPreferences', 1 ); >+ >+ C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $patron->id }, $template ); >+ my $set_form_values_vars = { %$vars }; >+ $vars = {}; >+ > C4::Form::MessagingPreferences::restore_form_values( $cgi, $template ); >- require Data::Dumper; warn Data::Dumper::Dumper( $vars ); #FIXME Remove debugging >- # TODO Add some checking on $vars->{messaging_preferences} here >+ my $restore_form_values_vars = { %$vars }; >+ >+ is_deeply( >+ $set_form_values_vars, $restore_form_values_vars, >+ "Default messaging preferences don't change when handled with restore_form_values." >+ ); >+ >+ C4::Members::Messaging::SetMessagingPreference( >+ { >+ borrowernumber => $patron->id, >+ message_transport_types => ['email'], >+ message_attribute_id => 2, >+ days_in_advance => 10, >+ wants_digest => 1 >+ } >+ ); >+ >+ C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $patron->id }, $template ); >+ $set_form_values_vars = { %$vars }; >+ $vars = {}; >+ >+ $cgi->param( -name => '2', -value => 'email' ); >+ $cgi->param( -name => '2-DAYS', -value => '10' ); >+ $cgi->param( -name => 'digest', -value => '2' ); >+ >+ C4::Form::MessagingPreferences::restore_form_values( $cgi, $template ); >+ $restore_form_values_vars = { %$vars }; >+ >+ is_deeply( >+ $set_form_values_vars, $restore_form_values_vars, >+ "Patrons messaging preferences don't change when handled with restore_form_values." >+ ); > >- ok(1); # FIXME Replace >+ $schema->storage->txn_rollback; > }; >-- >2.34.1 >
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 34776
:
178702
|
178896
|
180100
|
181389
|
181433
|
181434
|
183221
|
183222
|
183236
|
183237
|
183238
|
183239
|
183573
|
183574
|
183575
|
183576
|
183577
|
183578
|
183579
|
183580