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

(-)a/Koha/AudioAlerts.pm (-1 / +1 lines)
Lines 71-77 Gets the last precedence value for audio alerts Link Here
71
sub get_last_precedence {
71
sub get_last_precedence {
72
    my ($self) = @_;
72
    my ($self) = @_;
73
73
74
    return $self->_resultset()->get_column('precedence')->max();
74
    return $self->_resultset()->get_column('precedence')->max() || 0;
75
}
75
}
76
76
77
=head3 move
77
=head3 move
(-)a/t/db_dependent/AudioAlerts.t (-1 / +133 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 33;
21
22
BEGIN {
23
    use_ok('Koha::AudioAlert');
24
    use_ok('Koha::AudioAlerts');
25
}
26
27
my $schema = Koha::Database->new()->schema();
28
$schema->storage->txn_begin();
29
30
my $dbh = C4::Context->dbh;
31
$dbh->{RaiseError} = 1;
32
33
map { $_->delete() } Koha::AudioAlerts->search();
34
35
# Check the basics
36
diag("Creating 3 audio alerts named a, b and c");
37
38
my $a = Koha::AudioAlert->new( { selector => 'A', sound => 'test.wav' } )->store();
39
is( $a->precedence, 1, "First alert has a precedence of 1" );
40
41
my $b = Koha::AudioAlert->new( { selector => 'B', sound => 'sound.mp3' } )->store();
42
is( $b->precedence, 2, "Second alert has a precedence of 2" );
43
44
my $c = Koha::AudioAlert->new( { selector => 'C', sound => 'test.ogg' } )->store();
45
is( $c->precedence, 3, "Third alert has a precedence of 3" );
46
47
# Check precedence getting methods
48
diag('Testing get_last_precedence and get_next_precedence');
49
is( Koha::AudioAlerts->get_last_precedence(), 3, "Last prececence should be 3" );
50
is( Koha::AudioAlerts->get_next_precedence(), 4, "Next prececence should be 4" );
51
52
# Check edge cases
53
diag('Testing edge cases for moving ( up from 1, down from the last precedence )');
54
55
$a->move('up');
56
is( $a->precedence, 1, "First alert still has a precedence of 1" );
57
58
$c->move('down');
59
is( $c->precedence, 3, "Third alert still has a precedence of 3" );
60
61
# Check moving
62
diag("Moving A down by one");
63
$a->move('down');
64
$a = Koha::AudioAlerts->find( $a->id );
65
$b = Koha::AudioAlerts->find( $b->id );
66
$c = Koha::AudioAlerts->find( $c->id );
67
is( $a->precedence, 2, "Alert A has a precedence of 2" );
68
is( $b->precedence, 1, "Alert B has a precedence of 1" );
69
is( $c->precedence, 3, "Alert C has a precedence of 3" );
70
71
diag("Moving A up by one, should restore original order");
72
$a->move('up');
73
$a = Koha::AudioAlerts->find( $a->id );
74
$b = Koha::AudioAlerts->find( $b->id );
75
$c = Koha::AudioAlerts->find( $c->id );
76
is( $a->precedence, 1, "Alert A has a precedence of 1" );
77
is( $b->precedence, 2, "Alert B has a precedence of 2" );
78
is( $c->precedence, 3, "Alert C has a precedence of 3" );
79
80
diag("Moving A to the bottom");
81
$a->move('bottom');
82
$a = Koha::AudioAlerts->find( $a->id );
83
$b = Koha::AudioAlerts->find( $b->id );
84
$c = Koha::AudioAlerts->find( $c->id );
85
is( $a->precedence, 3, "Alert A has a precedence of 3" );
86
is( $b->precedence, 1, "Alert B has a precedence of 1" );
87
is( $c->precedence, 2, "Alert C has a precedence of 2" );
88
89
diag("Moving A to the top, should restore original order");
90
$a->move('top');
91
$a = Koha::AudioAlerts->find( $a->id );
92
$b = Koha::AudioAlerts->find( $b->id );
93
$c = Koha::AudioAlerts->find( $c->id );
94
is( $a->precedence, 1, "Alert A has a precedence of 1" );
95
is( $b->precedence, 2, "Alert B has a precedence of 2" );
96
is( $c->precedence, 3, "Alert C has a precedence of 3" );
97
98
# Test searching, should be ordered by precedence by default
99
diag("Test searching, default search should be ordered by precedence");
100
$a->move('bottom');
101
diag("Changed precedence order from database insert order");
102
diag("Insert order was a, b, c. Precedence order is now b, c, a.");
103
( $b, $c, $a ) = Koha::AudioAlerts->search();
104
105
is( $b->selector,   'B', 'First sound is indeed B' );
106
is( $b->precedence, 1,   "Alert B has a precedence of 1" );
107
108
is( $c->selector,   'C', "Second sound is indeed C" );
109
is( $c->precedence, 2,   "Alert C has a precedence of 2" );
110
111
is( $a->selector,   'A', 'Third sound is indeed A' );
112
is( $a->precedence, 3,   "Alert A has a precedence of 3" );
113
114
# Test fix precedences, should remove gaps in precedences
115
diag("Testing precedence fixing. Should remove gaps from precedence list.");
116
$a->precedence( 0 )->store();
117
$b->precedence( 50 )->store();
118
$c->precedence( 100 )->store();
119
is( $a->precedence, 0, "Alert A has a precedence of 0" );
120
is( $b->precedence, 50, "Alert B has a precedence of 50" );
121
is( $c->precedence, 100, "Alert C has a precedence of 100" );
122
123
diag("Running fix_precedences()");
124
Koha::AudioAlerts->fix_precedences();
125
$a = Koha::AudioAlerts->find( $a->id );
126
$b = Koha::AudioAlerts->find( $b->id );
127
$c = Koha::AudioAlerts->find( $c->id );
128
is( $a->precedence, 1, "Alert A has a precedence of 1" );
129
is( $b->precedence, 2, "Alert B has a precedence of 2" );
130
is( $c->precedence, 3, "Alert C has a precedence of 3" );
131
132
133
$schema->storage->txn_rollback();

Return to bug 11431