Bug 17499: (follow-up) Rename to Koha::Patron::MessagePreference
[koha.git] / t / db_dependent / Koha / Patron / MessagePreference / Attributes.t
1 #!/usr/bin/perl
2
3 # Copyright 2017 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 => 2;
23
24 use Koha::Database;
25
26 my $schema  = Koha::Database->new->schema;
27
28 subtest 'Test class imports' => sub {
29     plan tests => 2;
30
31     use_ok('Koha::Patron::MessagePreference::Attribute');
32     use_ok('Koha::Patron::MessagePreference::Attributes');
33 };
34
35 subtest 'Test Koha::Patron::MessagePreference::Attributes' => sub {
36     plan tests => 6;
37
38     $schema->storage->txn_begin;
39
40     Koha::Patron::MessagePreference::Attribute->new({
41         message_name => 'Test_Attribute'
42     })->store;
43     Koha::Patron::MessagePreference::Attribute->new({
44         message_name => 'Test_Attribute2',
45         takes_days   => 1
46     })->store;
47
48     my $attribute  = Koha::Patron::MessagePreference::Attributes->find({
49         message_name => 'Test_Attribute' });
50     my $attribute2 = Koha::Patron::MessagePreference::Attributes->find({
51         message_name => 'Test_Attribute2' });
52
53     is($attribute->message_name, 'Test_Attribute',
54        'Added a new messaging attribute.');
55     is($attribute->takes_days, 0,
56        'For that messaging attribute, takes_days is disabled by default.');
57     is($attribute2->message_name, 'Test_Attribute2',
58        'Added another messaging attribute.');
59     is($attribute2->takes_days, 1,
60        'takes_days is enabled for that message attribute (as expected).');
61
62     $attribute->delete;
63     $attribute2->delete;
64     is(Koha::Patron::MessagePreference::Attributes->find({
65         message_name => 'Test_Attribute' }), undef,
66        'Deleted the first message attribute.');
67     is(Koha::Patron::MessagePreference::Attributes->find({
68         message_name => 'Test_Attribute2' }), undef,
69        'Deleted the second message attribute.');
70
71     $schema->storage->txn_rollback;
72 };
73
74 1;