bug 6281: add test case for sorting LC call numbers correctly
[koha.git] / t / ClassSortRoutine_LCC.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!  
4 # Add more tests here!!!
5
6 use strict;
7 use warnings;
8
9 use Test::More tests => 10;
10
11 BEGIN {
12         use_ok('C4::ClassSortRoutine::LCC');
13 }
14
15 #Obvious cases
16 is(C4::ClassSortRoutine::LCC::get_class_sort_key(), "", "No arguments returns an empty string");
17 is(C4::ClassSortRoutine::LCC::get_class_sort_key('a','b'), "A_B", "Arguments 'a','b' return 'A_B'");
18
19 #spaces in arguements
20 is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','b'), "B_", "Arguments ' ','b' return 'B_'");
21 is(C4::ClassSortRoutine::LCC::get_class_sort_key('a',' '), "A_", "Arguments 'a',' ' return 'A_'");
22 is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','    '), "", "Arguments ' ','    ' return ''");
23
24 #'funky cases' based on regex in code
25 is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','b'), "_B", "Arguments '.','b' return '_B'");
26 is(C4::ClassSortRoutine::LCC::get_class_sort_key('....','........'), "_______", "Arguments '....','........' return '_______'");
27 is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','.'), "__", "Arguments '.','.' return '__'");
28
29 # list of example call numbers -- these
30 # are intentionally in the _reverse_ of
31 # the correct sort order
32 my @call_numbers = (
33     'SB410.9 .P26 1993',
34     'SB410.A26 I75 2000',
35     'QC995 .E29 1997',
36     'QC145.45 .H4 D65 1998',
37     'QC145 .A57 V.12 1980',
38     'QC100 .U57 NO. 555 1986',
39 );
40
41 my @sorted_call_numbers = map { $_->{call_number} }
42                           sort { $a->{sortkey} cmp $b->{sortkey} }
43                           map { { call_number => $_, sortkey => C4::ClassSortRoutine::LCC::get_class_sort_key($_, '') } }
44                           @call_numbers;
45 is_deeply(\@sorted_call_numbers, [ reverse @call_numbers ], 'LC call numbers sorted in correct order');