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

(-)a/Koha/Patron/Message/Attribute.pm (+50 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Attribute;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.a
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Patron::Message::Attribute - Koha Patron Message Attribute object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'MessageAttribute';
42
}
43
44
=head1 AUTHOR
45
46
Lari Taskula <lari.taskula@jns.fi>
47
48
=cut
49
50
1;
(-)a/Koha/Patron/Message/Attributes.pm (+55 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Attributes;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::Patron::Message::Attribute;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Patron::Message::Attributes - Koha Patron Message Attributes object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'MessageAttribute';
43
}
44
45
sub object_class {
46
    return 'Koha::Patron::Message::Attribute';
47
}
48
49
=head1 AUTHOR
50
51
Lari Taskula <lari.taskula@jns.fi>
52
53
=cut
54
55
1;
(-)a/Koha/Patron/Message/Preference.pm (+50 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Preference;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.a
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Patron::Message::Preference - Koha Patron Message Preference object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'BorrowerMessagePreference';
42
}
43
44
=head1 AUTHOR
45
46
Lari Taskula <lari.taskula@jns.fi>
47
48
=cut
49
50
1;
(-)a/Koha/Patron/Message/Preferences.pm (+55 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Preferences;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::Patron::Message::Preference;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Patron::Message::Preferences - Koha Patron Message Preferences object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'BorrowerMessagePreference';
43
}
44
45
sub object_class {
46
    return 'Koha::Patron::Message::Preference';
47
}
48
49
=head1 AUTHOR
50
51
Lari Taskula <lari.taskula@jns.fi>
52
53
=cut
54
55
1;
(-)a/Koha/Patron/Message/Transport.pm (+50 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Transport;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.a
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Patron::Message::Transport - Koha Patron Message Transport object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'MessageTransport';
42
}
43
44
=head1 AUTHOR
45
46
Lari Taskula <lari.taskula@jns.fi>
47
48
=cut
49
50
1;
(-)a/Koha/Patron/Message/Transport/Preference.pm (+51 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Transport::Preference;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.a
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Patron::Message::Transport::Preference - Koha Patron Message Transport
29
Preference object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'BorrowerMessageTransportPreference';
43
}
44
45
=head1 AUTHOR
46
47
Lari Taskula <lari.taskula@jns.fi>
48
49
=cut
50
51
1;
(-)a/Koha/Patron/Message/Transport/Preferences.pm (+56 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Transport::Preferences;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::Patron::Message::Transport::Preference;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Patron::Message::Transport::Preferences - Koha Patron Message Transport
30
Preferences object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'BorrowerMessageTransportPreference';
44
}
45
46
sub object_class {
47
    return 'Koha::Patron::Message::Transport::Preference';
48
}
49
50
=head1 AUTHOR
51
52
Lari Taskula <lari.taskula@jns.fi>
53
54
=cut
55
56
1;
(-)a/Koha/Patron/Message/Transport/Type.pm (+51 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Transport::Type;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.a
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Patron::Message::Transport::Type - Koha Patron Message Transport Type
29
object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'MessageTransportType';
43
}
44
45
=head1 AUTHOR
46
47
Lari Taskula <lari.taskula@jns.fi>
48
49
=cut
50
51
1;
(-)a/Koha/Patron/Message/Transport/Types.pm (+56 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Transport::Types;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::Patron::Message::Transport::Type;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Patron::Message::Transport::Types - Koha Patron Message Transport Types
30
object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'MessageTransportType';
44
}
45
46
sub object_class {
47
    return 'Koha::Patron::Message::Transport::Type';
48
}
49
50
=head1 AUTHOR
51
52
Lari Taskula <lari.taskula@jns.fi>
53
54
=cut
55
56
1;
(-)a/Koha/Patron/Message/Transports.pm (+55 lines)
Line 0 Link Here
1
package Koha::Patron::Message::Transports;
2
3
# Copyright Koha-Suomi Oy 2016
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::Patron::Message::Transport;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Patron::Message::Transports - Koha Patron Message Transports object class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'MessageTransport';
43
}
44
45
sub object_class {
46
    return 'Koha::Patron::Message::Transport';
47
}
48
49
=head1 AUTHOR
50
51
Lari Taskula <lari.taskula@jns.fi>
52
53
=cut
54
55
1;
(-)a/t/db_dependent/Koha/Patron/Message/Attributes.t (+74 lines)
Line 0 Link Here
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::Message::Attribute');
32
    use_ok('Koha::Patron::Message::Attributes');
33
};
34
35
subtest 'Test Koha::Patron::Message::Attributes' => sub {
36
    plan tests => 6;
37
38
    $schema->storage->txn_begin;
39
40
    Koha::Patron::Message::Attribute->new({
41
        message_name => 'Test_Attribute'
42
    })->store;
43
    Koha::Patron::Message::Attribute->new({
44
        message_name => 'Test_Attribute2',
45
        takes_days   => 1
46
    })->store;
47
48
    my $attribute  = Koha::Patron::Message::Attributes->find({
49
        message_name => 'Test_Attribute' });
50
    my $attribute2 = Koha::Patron::Message::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::Message::Attributes->find({
65
        message_name => 'Test_Attribute' }), undef,
66
       'Deleted the first message attribute.');
67
    is(Koha::Patron::Message::Attributes->find({
68
        message_name => 'Test_Attribute2' }), undef,
69
       'Deleted the second message attribute.');
70
71
    $schema->storage->txn_rollback;
72
};
73
74
1;
(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (+136 lines)
Line 0 Link Here
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 t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
use Koha::Notice::Templates;
28
use Koha::Patron::Categories;
29
use Koha::Patron::Message::Attributes;
30
use Koha::Patron::Message::Transport::Types;
31
use Koha::Patron::Message::Transports;
32
use Koha::Patrons;
33
34
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
36
37
subtest 'Test class imports' => sub {
38
    plan tests => 2;
39
40
    use_ok('Koha::Patron::Message::Preference');
41
    use_ok('Koha::Patron::Message::Preferences');
42
};
43
44
subtest 'Test Koha::Patron::Message::Preferences' => sub {
45
    plan tests => 2;
46
47
    $schema->storage->txn_begin;
48
49
    my $attribute = build_a_test_attribute();
50
51
    subtest 'Test for a patron' => sub {
52
        plan tests => 2;
53
54
        my $patron = build_a_test_patron();
55
        Koha::Patron::Message::Preference->new({
56
            borrowernumber       => $patron->borrowernumber,
57
            message_attribute_id => $attribute->message_attribute_id,
58
            wants_digest         => 0,
59
            days_in_advance      => undef,
60
        })->store;
61
62
        my $preference = Koha::Patron::Message::Preferences->find({
63
            borrowernumber       => $patron->borrowernumber,
64
            message_attribute_id => $attribute->message_attribute_id
65
        });
66
        ok($preference->borrower_message_preference_id > 0,
67
           'Added a new messaging preference for patron.');
68
69
        $preference->delete;
70
        is(Koha::Patron::Message::Preferences->search({
71
            borrowernumber       => $patron->borrowernumber,
72
            message_attribute_id => $attribute->message_attribute_id
73
        })->count, 0, 'Deleted the messaging preference.');
74
    };
75
76
    subtest 'Test for a category' => sub {
77
        my $category = build_a_test_category();
78
        Koha::Patron::Message::Preference->new({
79
            categorycode         => $category->categorycode,
80
            message_attribute_id => $attribute->message_attribute_id,
81
            wants_digest         => 0,
82
            days_in_advance      => undef,
83
        })->store;
84
85
        my $preference = Koha::Patron::Message::Preferences->find({
86
            categorycode         => $category->categorycode,
87
            message_attribute_id => $attribute->message_attribute_id
88
        });
89
        ok($preference->borrower_message_preference_id > 0,
90
           'Added a new messaging preference for category.');
91
92
        $preference->delete;
93
        is(Koha::Patron::Message::Preferences->search({
94
            categorycode         => $category->categorycode,
95
            message_attribute_id => $attribute->message_attribute_id
96
        })->count, 0, 'Deleted the messaging preference.');
97
    };
98
99
    $schema->storage->txn_rollback;
100
};
101
102
sub build_a_test_attribute {
103
    my ($params) = @_;
104
105
    $params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
106
                            ? 1 : 0;
107
108
    my $attribute = $builder->build({
109
        source => 'MessageAttribute',
110
        value => $params,
111
    });
112
113
    return Koha::Patron::Message::Attributes->find(
114
        $attribute->{message_attribute_id}
115
    );
116
}
117
118
sub build_a_test_category {
119
    my $categorycode   = $builder->build({
120
        source => 'Category' })->{categorycode};
121
122
    return Koha::Patron::Categories->find($categorycode);
123
}
124
125
sub build_a_test_patron {
126
    my $categorycode   = $builder->build({
127
        source => 'Category' })->{categorycode};
128
    my $branchcode     = $builder->build({
129
        source => 'Branch' })->{branchcode};
130
    my $borrowernumber = $builder->build({
131
        source => 'Borrower' })->{borrowernumber};
132
133
    return Koha::Patrons->find($borrowernumber);
134
}
135
136
1;
(-)a/t/db_dependent/Koha/Patron/Message/Transport/Preferences.t (+172 lines)
Line 0 Link Here
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 t::lib::Mocks;
25
use t::lib::TestBuilder;
26
27
use Koha::Notice::Templates;
28
use Koha::Patron::Categories;
29
use Koha::Patron::Message::Attributes;
30
use Koha::Patron::Message::Preferences;
31
use Koha::Patron::Message::Transport::Types;
32
use Koha::Patron::Message::Transports;
33
use Koha::Patrons;
34
35
my $schema  = Koha::Database->new->schema;
36
my $builder = t::lib::TestBuilder->new;
37
38
subtest 'Test class imports' => sub {
39
    plan tests => 2;
40
41
    use_ok('Koha::Patron::Message::Transport::Preference');
42
    use_ok('Koha::Patron::Message::Transport::Preferences');
43
};
44
45
subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub {
46
    plan tests => 2;
47
48
    $schema->storage->txn_begin;
49
50
    my $attribute = build_a_test_attribute();
51
    my $mtt       = build_a_test_transport_type();
52
    my $letter    = build_a_test_letter({
53
        mtt => $mtt->message_transport_type
54
    });
55
56
    subtest 'For a patron' => sub {
57
        my $patron    = build_a_test_patron();
58
        my $preference = Koha::Patron::Message::Preference->new({
59
            borrowernumber       => $patron->borrowernumber,
60
            message_attribute_id => $attribute->message_attribute_id,
61
            wants_digest         => 0,
62
            days_in_advance      => undef,
63
        })->store;
64
65
        my $pref_id = $preference->borrower_message_preference_id;
66
        my $transport_pref = Koha::Patron::Message::Transport::Preference->new({
67
            borrower_message_preference_id => $pref_id,
68
            message_transport_type => $mtt->message_transport_type,
69
        })->store;
70
        is(ref($transport_pref), 'Koha::Patron::Message::Transport::Preference',
71
           'Added a new messaging transport preference for patron.');
72
73
        $transport_pref->delete;
74
        is(Koha::Patron::Message::Transport::Preferences->search({
75
            borrower_message_preference_id => $pref_id,
76
            message_transport_type => $mtt->message_transport_type,
77
        })->count, 0, 'Deleted the messaging transport preference.');
78
    };
79
80
    subtest 'For a category' => sub {
81
        my $category   = build_a_test_category();
82
        my $preference = Koha::Patron::Message::Preference->new({
83
            categorycode         => $category->categorycode,
84
            message_attribute_id => $attribute->message_attribute_id,
85
            wants_digest         => 0,
86
            days_in_advance      => undef,
87
        })->store;
88
89
        my $pref_id = $preference->borrower_message_preference_id;
90
        my $transport_pref = Koha::Patron::Message::Transport::Preference->new({
91
            borrower_message_preference_id => $pref_id,
92
            message_transport_type => $mtt->message_transport_type,
93
        })->store;
94
        is(ref($transport_pref), 'Koha::Patron::Message::Transport::Preference',
95
           'Added a new messaging transport preference for category.');
96
97
        $transport_pref->delete;
98
        is(Koha::Patron::Message::Transport::Preferences->search({
99
            borrower_message_preference_id => $pref_id,
100
            message_transport_type => $mtt->message_transport_type,
101
        })->count, 0, 'Deleted the messaging transport preference.');
102
    };
103
104
    $schema->storage->txn_rollback;
105
};
106
107
sub build_a_test_attribute {
108
    my ($params) = @_;
109
110
    $params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
111
                            ? 1 : 0;
112
113
    my $attribute = $builder->build({
114
        source => 'MessageAttribute',
115
        value => $params,
116
    });
117
118
    return Koha::Patron::Message::Attributes->find(
119
        $attribute->{message_attribute_id}
120
    );
121
}
122
123
sub build_a_test_category {
124
    my $categorycode   = $builder->build({
125
        source => 'Category' })->{categorycode};
126
127
    return Koha::Patron::Categories->find($categorycode);
128
}
129
130
sub build_a_test_letter {
131
    my ($params) = @_;
132
133
    my $mtt = $params->{mtt} ? $params->{mtt} : 'email';
134
    my $branchcode     = $builder->build({
135
        source => 'Branch' })->{branchcode};
136
    my $letter = $builder->build({
137
        source => 'Letter',
138
        value => {
139
            branchcode => '',
140
            is_html => 0,
141
            message_transport_type => $mtt
142
        }
143
    });
144
145
    return Koha::Notice::Templates->find({
146
        module => $letter->{module},
147
        code   => $letter->{code},
148
        branchcode => $letter->{branchcode},
149
    });
150
}
151
152
sub build_a_test_patron {
153
    my $categorycode   = $builder->build({
154
        source => 'Category' })->{categorycode};
155
    my $branchcode     = $builder->build({
156
        source => 'Branch' })->{branchcode};
157
    my $borrowernumber = $builder->build({
158
        source => 'Borrower' })->{borrowernumber};
159
160
    return Koha::Patrons->find($borrowernumber);
161
}
162
163
sub build_a_test_transport_type {
164
    my $mtt = $builder->build({
165
        source => 'MessageTransportType' });
166
167
    return Koha::Patron::Message::Transport::Types->find(
168
        $mtt->{message_transport_type}
169
    );
170
}
171
172
1;
(-)a/t/db_dependent/Koha/Patron/Message/Transport/Types.t (+54 lines)
Line 0 Link Here
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::Message::Transport::Type');
32
    use_ok('Koha::Patron::Message::Transport::Types');
33
};
34
35
subtest 'Test Koha::Patron::Message::Transport::Types' => sub {
36
    plan tests => 2;
37
38
    $schema->storage->txn_begin;
39
40
    my $transport_type = Koha::Patron::Message::Transport::Type->new({
41
        message_transport_type => 'test'
42
    })->store;
43
44
    is($transport_type->message_transport_type, 'test',
45
       'Added a new message transport type.');
46
47
    $transport_type->delete;
48
    is(Koha::Patron::Message::Transport::Types->find('test'), undef,
49
       'Deleted the message transport type.');
50
51
    $schema->storage->txn_rollback;
52
};
53
54
1;
(-)a/t/db_dependent/Koha/Patron/Message/Transports.t (-1 / +119 lines)
Line 0 Link Here
0
- 
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 t::lib::TestBuilder;
25
26
use Koha::Notice::Templates;
27
use Koha::Patron::Message::Attributes;
28
use Koha::Patron::Message::Transport::Types;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
subtest 'Test class imports' => sub {
34
    plan tests => 2;
35
36
    use_ok('Koha::Patron::Message::Transport');
37
    use_ok('Koha::Patron::Message::Transports');
38
};
39
40
subtest 'Test Koha::Patron::Message::Transports' => sub {
41
    plan tests => 2;
42
43
    $schema->storage->txn_begin;
44
45
    my $attribute = build_a_test_attribute();
46
    my $mtt       = build_a_test_transport_type();
47
    my $letter    = build_a_test_letter({
48
        mtt => $mtt->message_transport_type
49
    });
50
51
    my $transport = Koha::Patron::Message::Transport->new({
52
        message_attribute_id   => $attribute->message_attribute_id,
53
        message_transport_type => $mtt->message_transport_type,
54
        is_digest              => 0,
55
        letter_module          => $letter->module,
56
        letter_code            => $letter->code,
57
    })->store;
58
59
    is($transport->message_attribute_id, $attribute->message_attribute_id,
60
       'Added a new messaging transport.');
61
62
    $transport->delete;
63
    is(Koha::Patron::Message::Transports->search({
64
        message_attribute_id => $attribute->message_attribute_id,
65
        message_transport_type => $mtt->message_transport_type,
66
        is_digest => 0
67
    })->count, 0, 'Deleted the messaging transport.');
68
69
    $schema->storage->txn_rollback;
70
};
71
72
sub build_a_test_attribute {
73
    my ($params) = @_;
74
75
    $params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
76
                            ? 1 : 0;
77
78
    my $attribute = $builder->build({
79
        source => 'MessageAttribute',
80
        value => $params,
81
    });
82
83
    return Koha::Patron::Message::Attributes->find(
84
        $attribute->{message_attribute_id}
85
    );
86
}
87
88
sub build_a_test_letter {
89
    my ($params) = @_;
90
91
    my $mtt = $params->{mtt} ? $params->{mtt} : 'email';
92
    my $branchcode     = $builder->build({
93
        source => 'Branch' })->{branchcode};
94
    my $letter = $builder->build({
95
        source => 'Letter',
96
        value => {
97
            branchcode => '',
98
            is_html => 0,
99
            message_transport_type => $mtt
100
        }
101
    });
102
103
    return Koha::Notice::Templates->find({
104
        module => $letter->{module},
105
        code   => $letter->{code},
106
        branchcode => $letter->{branchcode},
107
    });
108
}
109
110
sub build_a_test_transport_type {
111
    my $mtt = $builder->build({
112
        source => 'MessageTransportType' });
113
114
    return Koha::Patron::Message::Transport::Types->find(
115
        $mtt->{message_transport_type}
116
    );
117
}
118
119
1;

Return to bug 17499