|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2016 Koha-Suomi Oy |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 15; |
| 23 |
|
| 24 |
use t::lib::Mocks; |
| 25 |
use t::lib::TestBuilder; |
| 26 |
|
| 27 |
use Koha::Patrons; |
| 28 |
|
| 29 |
use_ok("Koha::Patron::Message::Attribute"); |
| 30 |
use_ok("Koha::Patron::Message::Attributes"); |
| 31 |
use_ok("Koha::Patron::Message::Preference"); |
| 32 |
use_ok("Koha::Patron::Message::Preferences"); |
| 33 |
use_ok("Koha::Patron::Message::Transport"); |
| 34 |
use_ok("Koha::Patron::Message::Transport::Preference"); |
| 35 |
use_ok("Koha::Patron::Message::Transport::Preferences"); |
| 36 |
use_ok("Koha::Patron::Message::Transport::Type"); |
| 37 |
use_ok("Koha::Patron::Message::Transport::Types"); |
| 38 |
use_ok("Koha::Patron::Message::Transports"); |
| 39 |
|
| 40 |
my $schema = Koha::Database->new->schema; |
| 41 |
$schema->storage->txn_begin; |
| 42 |
|
| 43 |
my $builder = t::lib::TestBuilder->new; |
| 44 |
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); |
| 45 |
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); |
| 46 |
|
| 47 |
my $patron = $builder->build({ source => 'Borrower', |
| 48 |
value => { |
| 49 |
branchcode => $branchcode, |
| 50 |
categorycode => $categorycode, |
| 51 |
} |
| 52 |
}); |
| 53 |
|
| 54 |
my $attribute; |
| 55 |
my $preference; |
| 56 |
my $transport_preference; |
| 57 |
my $transport_type; |
| 58 |
|
| 59 |
subtest 'Add a test messaging transport type' => sub { |
| 60 |
plan tests => 2; |
| 61 |
|
| 62 |
ok($transport_type = Koha::Patron::Message::Transport::Type->new({ |
| 63 |
message_transport_type => "test" |
| 64 |
})->store, "Added a new messaging transport type."); |
| 65 |
is(Koha::Patron::Message::Transport::Types->find({ |
| 66 |
message_transport_type => "test" })->message_transport_type, |
| 67 |
"test" , "Found test messaging transport type from database."); |
| 68 |
}; |
| 69 |
|
| 70 |
subtest 'Add a test messaging attribute' => sub { |
| 71 |
plan tests => 2; |
| 72 |
|
| 73 |
ok($attribute = Koha::Patron::Message::Attribute->new({ |
| 74 |
message_name => "Test_Attribute" |
| 75 |
})->store, "Added a new messaging attribute."); |
| 76 |
is(Koha::Patron::Message::Attributes->find({ |
| 77 |
message_name => "Test_Attribute"})->message_name, |
| 78 |
"Test_Attribute", "Found test attribute from database."); |
| 79 |
}; |
| 80 |
|
| 81 |
subtest 'Add a test messaging transport' => sub { |
| 82 |
plan tests => 2; |
| 83 |
|
| 84 |
ok(Koha::Patron::Message::Transport->new({ |
| 85 |
message_attribute_id => $attribute->message_attribute_id, |
| 86 |
message_transport_type => $transport_type->message_transport_type, |
| 87 |
is_digest => 0, |
| 88 |
letter_module => "circulation", |
| 89 |
letter_code => "CHECKIN", |
| 90 |
})->store, "Added a new messaging transport type."); |
| 91 |
is(Koha::Patron::Message::Transports->find({ |
| 92 |
message_transport_type => "test" })->message_attribute_id, |
| 93 |
$attribute->message_attribute_id , "Found test messaging transport from database."); |
| 94 |
}; |
| 95 |
|
| 96 |
subtest 'Add a messaging preference to patron' => sub { |
| 97 |
plan tests => 2; |
| 98 |
|
| 99 |
ok($preference = Koha::Patron::Message::Preference->new({ |
| 100 |
borrowernumber => $patron->{'borrowernumber'}, |
| 101 |
message_attribute_id => $attribute->message_attribute_id, |
| 102 |
wants_digest => 0, |
| 103 |
days_in_advance => 1, |
| 104 |
})->store, "Added a new messaging preference for patron."); |
| 105 |
is(Koha::Patron::Message::Preferences->find({ |
| 106 |
borrowernumber => $patron->{'borrowernumber'} })->message_attribute_id, |
| 107 |
$preference->message_attribute_id, "Found test messaging preference from database."); |
| 108 |
}; |
| 109 |
|
| 110 |
subtest 'Add a messaging transport preference to patron' => sub { |
| 111 |
plan tests => 2; |
| 112 |
|
| 113 |
ok($transport_preference = Koha::Patron::Message::Transport::Preference->new({ |
| 114 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
| 115 |
message_transport_type => $transport_type->message_transport_type, |
| 116 |
})->store, "Added a new messaging transport preference for patron."); |
| 117 |
is(Koha::Patron::Message::Transport::Preferences->find({ |
| 118 |
message_transport_type => $transport_type->message_transport_type |
| 119 |
})->borrower_message_preference_id, $transport_preference->borrower_message_preference_id, |
| 120 |
"Found test messaging transport preference from database."); |
| 121 |
}; |
| 122 |
|
| 123 |
$schema->storage->txn_rollback; |
| 124 |
|
| 125 |
1; |