Bug 24016: Add a failing test for overwrite-able manager_id in Koha::Patron::Message

To test:
1. prove t/db_dependent/Koha/Patron/Messages.t
2. Observe failure

t/db_dependent/Koha/Patron/Messages.t .. 2/12
   Failed test 'Manager id should be overwrite-able even if defined in userenv'
   at t/db_dependent/Koha/Patron/Messages.t line 90.
          got: '1100'
     expected: '1101'
 Looks like you failed 1 test of 12.
t/db_dependent/Koha/Patron/Messages.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/12 subtests

Sponsored-by: Koha-Suomi Oy
Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
(cherry picked from commit c74820c227)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 3d73723a9f)

Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
This commit is contained in:
Lari Taskula 2019-11-12 12:24:30 +00:00 committed by Hayley Mapley
parent ab03647466
commit c3ad074be4
1 changed files with 19 additions and 7 deletions

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 11;
use Test::More tests => 12;
use C4::Context;
use C4::Log;
@ -38,6 +38,7 @@ my $builder = t::lib::TestBuilder->new;
my $library = $builder->build( { source => 'Branch' } );
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } );
my $patron_2 = $builder->build( { source => 'Borrower' } );
my $patron_3 = $builder->build( { source => 'Borrower' } );
my $nb_of_logaction = get_nb_of_logactions();
my $nb_of_messages = Koha::Patron::Messages->search->count;
@ -66,26 +67,37 @@ my $new_message_2 = Koha::Patron::Message->new(
message => 'my message 2',
}
)->store;
is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog on, 1 new log should have been added when adding a new message' );
my $new_message_3 = Koha::Patron::Message->new(
{ borrowernumber => $patron->{borrowernumber},
branchcode => $library->{branchcode},
message_type => 'B',
message => 'my message 2',
manager_id => $patron_3->{borrowernumber},
}
)->store;
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog on, 2 new log should have been added when adding a new message' );
like( $new_message_1->message_id, qr|^\d+$|, 'Adding a new message should have set the message_id');
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages should have been added' );
is( Koha::Patron::Messages->search->count, $nb_of_messages + 3, 'The 3 messages should have been added' );
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id );
is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' );
is( $retrieved_message_1->manager_id, undef, 'Manager id should not be filled in when it is not defined in userenv' );
my $retrieved_message_2 = Koha::Patron::Messages->find( $new_message_2->message_id );
is( $retrieved_message_2->manager_id, $patron_2->{borrowernumber}, 'Manager id should be filled in when it is defined in userenv' );
my $retrieved_message_3 = Koha::Patron::Messages->find( $new_message_3->message_id );
is( $retrieved_message_3->manager_id, $patron_3->{borrowernumber}, 'Manager id should be overwrite-able even if defined in userenv' );
t::lib::Mocks::mock_preference('BorrowersLog', 0);
$retrieved_message_1->delete;
is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message 1' );
is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog off, no new log should have been added when deleting a new message' );
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'Delete should have deleted the message 1' );
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog off, no new log should have been added when deleting a new message' );
t::lib::Mocks::mock_preference('BorrowersLog', 1);
$new_message_2->delete;
is( Koha::Patron::Messages->search->count, $nb_of_messages, 'Delete should have deleted the message 2' );
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' );
is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message 2' );
is( get_nb_of_logactions(), $nb_of_logaction + 3, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' );
$schema->storage->txn_rollback;