Bug 24883: Add POD entry and remove unused variable
[koha.git] / t / db_dependent / AudioAlerts.t
blob4f43b3c59a9d62c70b815c4699c4105e63b0ebf0
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
20 use Test::More tests => 33;
22 BEGIN {
23 use_ok('Koha::AudioAlert');
24 use_ok('Koha::AudioAlerts');
27 my $schema = Koha::Database->new()->schema();
28 $schema->storage->txn_begin();
30 map { $_->delete() } Koha::AudioAlerts->search();
32 ## Check the basics
33 # Creating 3 audio alerts named a, b and c
34 my $a = Koha::AudioAlert->new( { selector => 'A', sound => 'test.wav' } )->store();
35 is( $a->precedence, 1, "First alert has a precedence of 1" );
37 my $b = Koha::AudioAlert->new( { selector => 'B', sound => 'sound.mp3' } )->store();
38 is( $b->precedence, 2, "Second alert has a precedence of 2" );
40 my $c = Koha::AudioAlert->new( { selector => 'C', sound => 'test.ogg' } )->store();
41 is( $c->precedence, 3, "Third alert has a precedence of 3" );
43 ## Check precedence getting methods
44 # Testing get_last_precedence and get_next_precedence
46 is( Koha::AudioAlerts->get_last_precedence(), 3, "Last prececence should be 3" );
47 is( Koha::AudioAlerts->get_next_precedence(), 4, "Next prececence should be 4" );
49 ## Check edge cases
50 # Testing edge cases for moving ( up from 1, down from the last precedence )
52 $a->move('up');
53 is( $a->precedence, 1, "First alert still has a precedence of 1" );
55 $c->move('down');
56 is( $c->precedence, 3, "Third alert still has a precedence of 3" );
58 ## Check moving
59 # Moving A down by one
60 $a->move('down');
61 $a = Koha::AudioAlerts->find( $a->id );
62 $b = Koha::AudioAlerts->find( $b->id );
63 $c = Koha::AudioAlerts->find( $c->id );
64 is( $a->precedence, 2, "Alert A has a precedence of 2" );
65 is( $b->precedence, 1, "Alert B has a precedence of 1" );
66 is( $c->precedence, 3, "Alert C has a precedence of 3" );
68 # Moving A up by one, should restore original order
69 $a->move('up');
70 $a = Koha::AudioAlerts->find( $a->id );
71 $b = Koha::AudioAlerts->find( $b->id );
72 $c = Koha::AudioAlerts->find( $c->id );
73 is( $a->precedence, 1, "Alert A has a precedence of 1" );
74 is( $b->precedence, 2, "Alert B has a precedence of 2" );
75 is( $c->precedence, 3, "Alert C has a precedence of 3" );
77 # Moving A to the bottom
78 $a->move('bottom');
79 $a = Koha::AudioAlerts->find( $a->id );
80 $b = Koha::AudioAlerts->find( $b->id );
81 $c = Koha::AudioAlerts->find( $c->id );
82 is( $a->precedence, 3, "Alert A has a precedence of 3" );
83 is( $b->precedence, 1, "Alert B has a precedence of 1" );
84 is( $c->precedence, 2, "Alert C has a precedence of 2" );
86 # Moving A to the top, should restore original order
87 $a->move('top');
88 $a = Koha::AudioAlerts->find( $a->id );
89 $b = Koha::AudioAlerts->find( $b->id );
90 $c = Koha::AudioAlerts->find( $c->id );
91 is( $a->precedence, 1, "Alert A has a precedence of 1" );
92 is( $b->precedence, 2, "Alert B has a precedence of 2" );
93 is( $c->precedence, 3, "Alert C has a precedence of 3" );
95 ## Test searching, should be ordered by precedence by default
96 # Test searching, default search should be ordered by precedence
97 $a->move('bottom');
98 # Changed precedence order from database insert order
99 # Insert order was a, b, c. Precedence order is now b, c, a.
100 ( $b, $c, $a ) = Koha::AudioAlerts->search();
102 is( $b->selector, 'B', 'First sound is indeed B' );
103 is( $b->precedence, 1, "Alert B has a precedence of 1" );
105 is( $c->selector, 'C', "Second sound is indeed C" );
106 is( $c->precedence, 2, "Alert C has a precedence of 2" );
108 is( $a->selector, 'A', 'Third sound is indeed A' );
109 is( $a->precedence, 3, "Alert A has a precedence of 3" );
111 ## Test fix precedences, should remove gaps in precedences
112 # Testing precedence fixing. Should remove gaps from precedence list.
113 $a->precedence( 0 )->store();
114 $b->precedence( 50 )->store();
115 $c->precedence( 100 )->store();
116 is( $a->precedence, 0, "Alert A has a precedence of 0" );
117 is( $b->precedence, 50, "Alert B has a precedence of 50" );
118 is( $c->precedence, 100, "Alert C has a precedence of 100" );
120 # Running fix_precedences()
121 Koha::AudioAlerts->fix_precedences();
122 $a = Koha::AudioAlerts->find( $a->id );
123 $b = Koha::AudioAlerts->find( $b->id );
124 $c = Koha::AudioAlerts->find( $c->id );
125 is( $a->precedence, 1, "Alert A has a precedence of 1" );
126 is( $b->precedence, 2, "Alert B has a precedence of 2" );
127 is( $c->precedence, 3, "Alert C has a precedence of 3" );
130 $schema->storage->txn_rollback();