Lines 19-26
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 4; |
22 |
use Test::More tests => 9; |
23 |
|
23 |
|
|
|
24 |
use C4::Context; |
25 |
use C4::Log; |
24 |
use Koha::Patron::Message; |
26 |
use Koha::Patron::Message; |
25 |
use Koha::Patron::Messages; |
27 |
use Koha::Patron::Messages; |
26 |
use Koha::Database; |
28 |
use Koha::Database; |
Lines 33-39
$schema->storage->txn_begin;
Link Here
|
33 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $library = $builder->build( { source => 'Branch' } ); |
36 |
my $library = $builder->build( { source => 'Branch' } ); |
35 |
my $patron = $builder->build( { source => 'Borrower', values => { branchcode => $library->{branchcode} } } ); |
37 |
my $patron = $builder->build( { source => 'Borrower', values => { branchcode => $library->{branchcode} } } ); |
|
|
38 |
my $nb_of_logaction = get_nb_of_logactions(); |
36 |
my $nb_of_messages = Koha::Patron::Messages->search->count; |
39 |
my $nb_of_messages = Koha::Patron::Messages->search->count; |
|
|
40 |
|
41 |
C4::Context->set_preference('BorrowersLog', 0); |
37 |
my $new_message_1 = Koha::Patron::Message->new( |
42 |
my $new_message_1 = Koha::Patron::Message->new( |
38 |
{ borrowernumber => $patron->{borrowernumber}, |
43 |
{ borrowernumber => $patron->{borrowernumber}, |
39 |
branchcode => $library->{branchcode}, |
44 |
branchcode => $library->{branchcode}, |
Lines 41-46
my $new_message_1 = Koha::Patron::Message->new(
Link Here
|
41 |
message => 'my message 1', |
46 |
message => 'my message 1', |
42 |
} |
47 |
} |
43 |
)->store; |
48 |
)->store; |
|
|
49 |
is( get_nb_of_logactions(), $nb_of_logaction, 'With BorrowersLog off, no new log should have been added' ); |
50 |
|
51 |
C4::Context->set_preference('BorrowersLog', 1); |
44 |
my $new_message_2 = Koha::Patron::Message->new( |
52 |
my $new_message_2 = Koha::Patron::Message->new( |
45 |
{ borrowernumber => $patron->{borrowernumber}, |
53 |
{ borrowernumber => $patron->{borrowernumber}, |
46 |
branchcode => $library->{branchcode}, |
54 |
branchcode => $library->{branchcode}, |
Lines 48-53
my $new_message_2 = Koha::Patron::Message->new(
Link Here
|
48 |
message => 'my message 2', |
56 |
message => 'my message 2', |
49 |
} |
57 |
} |
50 |
)->store; |
58 |
)->store; |
|
|
59 |
is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog on, 1 new log should have been added when adding a new message' ); |
51 |
|
60 |
|
52 |
like( $new_message_1->message_id, qr|^\d+$|, 'Adding a new message should have set the message_id'); |
61 |
like( $new_message_1->message_id, qr|^\d+$|, 'Adding a new message should have set the message_id'); |
53 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages should have been added' ); |
62 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages should have been added' ); |
Lines 55-63
is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages
Link Here
|
55 |
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id ); |
64 |
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id ); |
56 |
is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' ); |
65 |
is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' ); |
57 |
|
66 |
|
|
|
67 |
C4::Context->set_preference('BorrowersLog', 0); |
58 |
$retrieved_message_1->delete; |
68 |
$retrieved_message_1->delete; |
59 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message' ); |
69 |
is( Koha::Patron::Messages->search->count, $nb_of_messages + 1, 'Delete should have deleted the message 1' ); |
|
|
70 |
is( get_nb_of_logactions(), $nb_of_logaction + 1, 'With BorrowersLog off, no new log should have been added when deleting a new message' ); |
71 |
|
72 |
C4::Context->set_preference('BorrowersLog', 1); |
73 |
$new_message_2->delete; |
74 |
is( Koha::Patron::Messages->search->count, $nb_of_messages, 'Delete should have deleted the message 2' ); |
75 |
is( get_nb_of_logactions(), $nb_of_logaction + 2, 'With BorrowersLog on, 1 new log should have been added when deleting a new message' ); |
60 |
|
76 |
|
61 |
$schema->storage->txn_rollback; |
77 |
$schema->storage->txn_rollback; |
62 |
|
78 |
|
|
|
79 |
sub get_nb_of_logactions { |
80 |
return scalar( @{ C4::Log::GetLogs( undef, undef, undef, ['MEMBERS'] ) } ); |
81 |
} |
82 |
|
63 |
1; |
83 |
1; |
64 |
- |
|
|