Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 12; |
23 |
|
23 |
|
24 |
use C4::Context; |
24 |
use C4::Context; |
25 |
use C4::Log; |
25 |
use C4::Log; |
Lines 38-43
my $builder = t::lib::TestBuilder->new;
Link Here
|
38 |
my $library = $builder->build( { source => 'Branch' } ); |
38 |
my $library = $builder->build( { source => 'Branch' } ); |
39 |
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); |
39 |
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); |
40 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
40 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
|
|
41 |
my $patron_3 = $builder->build( { source => 'Borrower' } ); |
41 |
my $nb_of_logaction = get_nb_of_logactions(); |
42 |
my $nb_of_logaction = get_nb_of_logactions(); |
42 |
my $nb_of_messages = Koha::Patron::Messages->search->count; |
43 |
my $nb_of_messages = Koha::Patron::Messages->search->count; |
43 |
|
44 |
|
Lines 66-91
my $new_message_2 = Koha::Patron::Message->new(
Link Here
|
66 |
message => 'my message 2', |
67 |
message => 'my message 2', |
67 |
} |
68 |
} |
68 |
)->store; |
69 |
)->store; |
69 |
is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog on, 1 new log should have been added when adding a new message' ); |
70 |
|
|
|
71 |
my $new_message_3 = Koha::Patron::Message->new( |
72 |
{ borrowernumber => $patron->{borrowernumber}, |
73 |
branchcode => $library->{branchcode}, |
74 |
message_type => 'B', |
75 |
message => 'my message 2', |
76 |
manager_id => $patron_3->{borrowernumber}, |
77 |
} |
78 |
)->store; |
79 |
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog on, 2 new log should have been added when adding a new message' ); |
70 |
|
80 |
|
71 |
like( $new_message_1->message_id, qr|^\d+$|, 'Adding a new message should have set the message_id'); |
81 |
like( $new_message_1->message_id, qr|^\d+$|, 'Adding a new message should have set the message_id'); |
72 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages should have been added' ); |
82 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 3, 'The 3 messages should have been added' ); |
73 |
|
83 |
|
74 |
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id ); |
84 |
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id ); |
75 |
is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' ); |
85 |
is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' ); |
76 |
is( $retrieved_message_1->manager_id, undef, 'Manager id should not be filled in when it is not defined in userenv' ); |
86 |
is( $retrieved_message_1->manager_id, undef, 'Manager id should not be filled in when it is not defined in userenv' ); |
77 |
my $retrieved_message_2 = Koha::Patron::Messages->find( $new_message_2->message_id ); |
87 |
my $retrieved_message_2 = Koha::Patron::Messages->find( $new_message_2->message_id ); |
78 |
is( $retrieved_message_2->manager_id, $patron_2->{borrowernumber}, 'Manager id should be filled in when it is defined in userenv' ); |
88 |
is( $retrieved_message_2->manager_id, $patron_2->{borrowernumber}, 'Manager id should be filled in when it is defined in userenv' ); |
|
|
89 |
my $retrieved_message_3 = Koha::Patron::Messages->find( $new_message_3->message_id ); |
90 |
is( $retrieved_message_3->manager_id, $patron_3->{borrowernumber}, 'Manager id should be overwrite-able even if defined in userenv' ); |
79 |
|
91 |
|
80 |
t::lib::Mocks::mock_preference('BorrowersLog', 0); |
92 |
t::lib::Mocks::mock_preference('BorrowersLog', 0); |
81 |
$retrieved_message_1->delete; |
93 |
$retrieved_message_1->delete; |
82 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message 1' ); |
94 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'Delete should have deleted the message 1' ); |
83 |
is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog off, no new log should have been added when deleting a new message' ); |
95 |
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog off, no new log should have been added when deleting a new message' ); |
84 |
|
96 |
|
85 |
t::lib::Mocks::mock_preference('BorrowersLog', 1); |
97 |
t::lib::Mocks::mock_preference('BorrowersLog', 1); |
86 |
$new_message_2->delete; |
98 |
$new_message_2->delete; |
87 |
is( Koha::Patron::Messages->search->count, $nb_of_messages, 'Delete should have deleted the message 2' ); |
99 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message 2' ); |
88 |
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' ); |
100 |
is( get_nb_of_logactions(), $nb_of_logaction + 3, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' ); |
89 |
|
101 |
|
90 |
$schema->storage->txn_rollback; |
102 |
$schema->storage->txn_rollback; |
91 |
|
103 |
|
92 |
- |
|
|