View | Details | Raw Unified | Return to bug 17558
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patron/Messages.t (-2 / +13 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 11;
23
23
24
use C4::Context;
24
use C4::Context;
25
use C4::Log;
25
use C4::Log;
26
use Koha::Patron::Message;
26
use Koha::Patron::Message;
27
use Koha::Patron::Messages;
27
use Koha::Patron::Messages;
28
use Koha::Patrons;
28
use Koha::Database;
29
use Koha::Database;
29
30
30
use t::lib::Mocks;
31
use t::lib::Mocks;
Lines 36-41 $schema->storage->txn_begin; Link Here
36
my $builder        = t::lib::TestBuilder->new;
37
my $builder        = t::lib::TestBuilder->new;
37
my $library        = $builder->build( { source => 'Branch' } );
38
my $library        = $builder->build( { source => 'Branch' } );
38
my $patron         = $builder->build( { source => 'Borrower', values => { branchcode => $library->{branchcode} } } );
39
my $patron         = $builder->build( { source => 'Borrower', values => { branchcode => $library->{branchcode} } } );
40
my $patron_2       = Koha::Patrons->search->next;
39
my $nb_of_logaction = get_nb_of_logactions();
41
my $nb_of_logaction = get_nb_of_logactions();
40
my $nb_of_messages = Koha::Patron::Messages->search->count;
42
my $nb_of_messages = Koha::Patron::Messages->search->count;
41
43
Lines 49-54 my $new_message_1 = Koha::Patron::Message->new( Link Here
49
)->store;
51
)->store;
50
is( get_nb_of_logactions(), $nb_of_logaction, 'With BorrowersLog off, no new log should have been added' );
52
is( get_nb_of_logactions(), $nb_of_logaction, 'With BorrowersLog off, no new log should have been added' );
51
53
54
my $context = new Test::MockModule('C4::Context');
55
$context->mock( 'userenv', sub {
56
    return {
57
        number => $patron_2->{borrowernumber},
58
    };
59
});
60
52
t::lib::Mocks::mock_preference('BorrowersLog', 1);
61
t::lib::Mocks::mock_preference('BorrowersLog', 1);
53
my $new_message_2  = Koha::Patron::Message->new(
62
my $new_message_2  = Koha::Patron::Message->new(
54
    {   borrowernumber => $patron->{borrowernumber},
63
    {   borrowernumber => $patron->{borrowernumber},
Lines 64-69 is( Koha::Patron::Messages->search->count, $nb_of_messages + 2, 'The 2 messages Link Here
64
73
65
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id );
74
my $retrieved_message_1 = Koha::Patron::Messages->find( $new_message_1->message_id );
66
is( $retrieved_message_1->message, $new_message_1->message, 'Find a message by id should return the correct message' );
75
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' );
77
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' );
67
79
68
t::lib::Mocks::mock_preference('BorrowersLog', 0);
80
t::lib::Mocks::mock_preference('BorrowersLog', 0);
69
$retrieved_message_1->delete;
81
$retrieved_message_1->delete;
70
- 

Return to bug 17558