4 use Test
::More tests
=> 74;
5 use List
::Util
qw( shuffle );
13 use_ok
('C4::ShelfBrowser');
15 my $dbh = C4
::Context
->dbh;
16 $dbh->{AutoCommit
} = 0;
17 $dbh->{RaiseError
} = 1;
19 $dbh->do(q
|DELETE FROM reserves
|);
20 $dbh->do(q
|DELETE FROM issues
|);
21 $dbh->do(q
|DELETE FROM items
|);
25 # 100.100 150.100 200.100 210.100 300.000 320.000 400.100 410.100 500.100 510.100 520.100 600.000 610.000 700.100 710.100 720.100 730.100 740.100 750.100
48 my $record = MARC
::Record
->new();
49 $record->append_fields(
50 MARC
::Field
->new('100', ' ', ' ', a
=> 'Donald E. Knuth.'),
51 MARC
::Field
->new('245', ' ', ' ', a
=> 'The art of computer programming'),
53 my ( $biblionumber, undef, undef ) = C4
::Biblio
::AddBiblio
($record, '');
55 for my $callnumber ( shuffle
@callnumbers ) {
56 my ( $biblionumber, undef, $itemnumber ) = C4
::Items
::AddItem
({
58 holdingbranch
=> 'CPL',
59 itemcallnumber
=> $callnumber,
61 $cn->{$callnumber} = {
62 biblionumber
=> $biblionumber,
63 itemnumber
=> $itemnumber,
64 itemcallnumber
=> $callnumber,
70 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'500.100'}{itemnumber
} );
72 # < 320.000 400.100 410.100 500.100 510.100 520.100 600.000 >
74 # Clicking on previous, we want a link to 150.100
75 is
( $nearby->{prev_item
}{itemcallnumber
}, '150.100', "Simple case: previous link 1/2" );
76 is
( $nearby->{prev_item
}{itemnumber
}, $cn->{'150.100'}{itemnumber
}, "Simple case: previous link 2/2" );
77 # Clicking on next, we want a link to 730.100
78 is
( $nearby->{next_item
}{itemcallnumber
}, '720.100', "Simple case: next link 1/2" );
79 is
( $nearby->{next_item
}{itemnumber
}, $cn->{'720.100'}{itemnumber
}, "Simple case: next link 2/2" );
81 is
( $nearby->{items
}[0]{itemcallnumber
}, '320.000', "Simple case: item 1");
82 is
( $nearby->{items
}[1]{itemcallnumber
}, '400.100', "Simple case: item 2");
83 is
( $nearby->{items
}[2]{itemcallnumber
}, '410.100', "Simple case: item 3");
84 is
( $nearby->{items
}[3]{itemcallnumber
}, '500.100', "Simple case: item 4");
85 is
( $nearby->{items
}[4]{itemcallnumber
}, '510.100', "Simple case: item 5");
86 is
( $nearby->{items
}[5]{itemcallnumber
}, '520.100', "Simple case: item 6");
87 is
( $nearby->{items
}[6]{itemcallnumber
}, '600.000', "Simple case: item 7");
89 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'500.100'}{itemnumber
}, 2, 3 );
91 # < 400.100 410.100 500.100 510.100 520.100 >
93 # Clicking on previous, we want a link to 320.000
94 is
( $nearby->{prev_item
}{itemcallnumber
}, '320.000', "Test gap: previous link 1/2" );
95 is
( $nearby->{prev_item
}{itemnumber
}, $cn->{'320.000'}{itemnumber
}, "Test gap: previous link 2/2" );
96 # Clicking on next, we want a link to 600.000
97 is
( $nearby->{next_item
}{itemcallnumber
}, '600.000', "Test gap: next link 1/2" );
98 is
( $nearby->{next_item
}{itemnumber
}, $cn->{'600.000'}{itemnumber
}, "Test gap: next link 2/2" );
100 is
( scalar( @
{$nearby->{items
}} ), 5, "Test gap: got 5 items" );
101 is
( $nearby->{items
}[0]{itemcallnumber
}, '400.100', "Test gap: item 1");
102 is
( $nearby->{items
}[1]{itemcallnumber
}, '410.100', "Test gap: item 2");
103 is
( $nearby->{items
}[2]{itemcallnumber
}, '500.100', "Test gap: item 3");
104 is
( $nearby->{items
}[3]{itemcallnumber
}, '510.100', "Test gap: item 4");
105 is
( $nearby->{items
}[4]{itemcallnumber
}, '520.100', "Test gap: item 5");
107 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'300.000'}{itemnumber
} );
109 # < 150.100 200.100 210.100 300.000 320.000 400.100 410.100 >
111 # Clicking on previous, we want a link to 100.100
112 is
( $nearby->{prev_item
}{itemcallnumber
}, '100.100', "Test start shelf: previous link 1/2" );
113 is
( $nearby->{prev_item
}{itemnumber
}, $cn->{'100.100'}{itemnumber
}, "Test start shelf: previous link 2/2" );
114 # Clicking on next, we want a link to 600.000
115 is
( $nearby->{next_item
}{itemcallnumber
}, '600.000', "Test start shelf: next link 1/2" );
116 is
( $nearby->{next_item
}{itemnumber
}, $cn->{'600.000'}{itemnumber
}, "Test start shelf: next link 2/2" );
118 is
( $nearby->{items
}[0]{itemcallnumber
}, '150.100', "Test start shelf: item 1");
119 is
( $nearby->{items
}[1]{itemcallnumber
}, '200.100', "Test start shelf: item 2");
120 is
( $nearby->{items
}[2]{itemcallnumber
}, '210.100', "Test start shelf: item 3");
121 is
( $nearby->{items
}[3]{itemcallnumber
}, '300.000', "Test start shelf: item 4");
122 is
( $nearby->{items
}[4]{itemcallnumber
}, '320.000', "Test start shelf: item 5");
123 is
( $nearby->{items
}[5]{itemcallnumber
}, '400.100', "Test start shelf: item 6");
124 is
( $nearby->{items
}[6]{itemcallnumber
}, '410.100', "Test start shelf: item 7");
128 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'100.100'}{itemnumber
} );
130 # 100.100 150.100 200.100 210.100 >
132 # There is no previous link
133 is
( $nearby->{prev_item
}, undef, "Test first item on a shelf: no previous link" );
134 # Clicking on next, we want a link to 410.100
135 is
( $nearby->{next_item
}{itemcallnumber
}, '410.100', "Test first item on a shelf: next link 1/2" );
136 is
( $nearby->{next_item
}{itemnumber
}, $cn->{'410.100'}{itemnumber
}, "Test first item on a shelf: next link 2/2" );
138 is
( scalar( @
{$nearby->{items
}} ), 4, "Test first item on a shelf: There are 4 items displayed" );
139 is
( $nearby->{items
}[0]{itemcallnumber
}, '100.100', "Test first item on a shelf: item 1");
140 is
( $nearby->{items
}[1]{itemcallnumber
}, '150.100', "Test first item on a shelf: item 2");
141 is
( $nearby->{items
}[2]{itemcallnumber
}, '200.100', "Test first item on a shelf: item 3");
142 is
( $nearby->{items
}[3]{itemcallnumber
}, '210.100', "Test first item on a shelf: item 4");
145 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'150.100'}{itemnumber
} );
147 # 100.100 150.100 200.100 210.100 300.000 >
149 # There is no previous link
150 is
( $nearby->{prev_item
}, undef, "Test second item on a shelf: no previous link" );
151 # Clicking on next, we want a link to 500.100
152 is
( $nearby->{next_item
}{itemcallnumber
}, '500.100', "Test second item on a shelf: next link 1/2" );
153 is
( $nearby->{next_item
}{itemnumber
}, $cn->{'500.100'}{itemnumber
}, "Test second item on a shelf: next link 2/2" );
155 is
( scalar( @
{$nearby->{items
}} ), 5, "Test second item on a shelf: got 5 items" );
156 is
( $nearby->{items
}[0]{itemcallnumber
}, '100.100', "Test second item on a shelf: item 1");
157 is
( $nearby->{items
}[1]{itemcallnumber
}, '150.100', "Test second item on a shelf: item 2");
158 is
( $nearby->{items
}[2]{itemcallnumber
}, '200.100', "Test second item on a shelf: item 3");
159 is
( $nearby->{items
}[3]{itemcallnumber
}, '210.100', "Test second item on a shelf: item 4");
160 is
( $nearby->{items
}[4]{itemcallnumber
}, '300.000', "Test second item on a shelf: item 5");
163 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'710.100'}{itemnumber
} );
165 # < 600.000 610.000 700.100 710.100 720.100 730.100 740.100 >
166 # 12 13 14 [15] 16 17 18
167 # Clicking on previous, we want a link to 410.100
168 is
( $nearby->{prev_item
}{itemcallnumber
}, '410.100', "Test end shelf: previous link 1/2" );
169 is
( $nearby->{prev_item
}{itemnumber
}, $cn->{'410.100'}{itemnumber
}, "Test end shelf: previous link 2/2" );
170 # Clicking on next, we want a link to 730.100
171 is
( $nearby->{next_item
}{itemcallnumber
}, '750.100', "Test end shelf: next link is a link to the last item 1/2" );
172 is
( $nearby->{next_item
}{itemnumber
}, $cn->{'750.100'}{itemnumber
}, "Test end shelf: next link is a link to the last item 2/2" );
174 is
( $nearby->{items
}[0]{itemcallnumber
}, '600.000', "Test end shelf: item 1");
175 is
( $nearby->{items
}[1]{itemcallnumber
}, '610.000', "Test end shelf: item 2");
176 is
( $nearby->{items
}[2]{itemcallnumber
}, '700.100', "Test end shelf: item 3");
177 is
( $nearby->{items
}[3]{itemcallnumber
}, '710.100', "Test end shelf: item 4");
178 is
( $nearby->{items
}[4]{itemcallnumber
}, '720.100', "Test end shelf: item 5");
179 is
( $nearby->{items
}[5]{itemcallnumber
}, '730.100', "Test end shelf: item 6");
180 is
( $nearby->{items
}[6]{itemcallnumber
}, '740.100', "Test end shelf: item 7");
183 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'740.100'}{itemnumber
} );
185 # < 710.100 720.100 730.100 740.100 750.100
187 # Clicking on previous, we want a link to
188 is
( $nearby->{prev_item
}{itemcallnumber
}, '520.100', "Test end of the shelf: previous link 1/2" );
189 is
( $nearby->{prev_item
}{itemnumber
}, $cn->{'520.100'}{itemnumber
}, "Test end of the shelf: previous link 2/2" );
191 is
( $nearby->{next_item
}, undef, "Test end of the shelf: no next link" );
193 is
( scalar( @
{$nearby->{items
}} ), 5, "Test end of the shelf: got 5 items" );
194 is
( $nearby->{items
}[0]{itemcallnumber
}, '710.100', "Test end of the shelf: item 1");
195 is
( $nearby->{items
}[1]{itemcallnumber
}, '720.100', "Test end of the shelf: item 2");
196 is
( $nearby->{items
}[2]{itemcallnumber
}, '730.100', "Test end of the shelf: item 3");
197 is
( $nearby->{items
}[3]{itemcallnumber
}, '740.100', "Test end of the shelf: item 4");
198 is
( $nearby->{items
}[4]{itemcallnumber
}, '750.100', "Test end of the shelf: item 5");
200 $nearby = C4
::ShelfBrowser
::GetNearbyItems
( $cn->{'750.100'}{itemnumber
} );
202 # < 720.100 730.100 740.100 750.100
204 # Clicking on previous, we want a link to
205 is
( $nearby->{prev_item
}{itemcallnumber
}, '600.000', "Test last item of the shelf: previous link 1/2" );
206 is
( $nearby->{prev_item
}{itemnumber
}, $cn->{'600.000'}{itemnumber
}, "Test last item of the shelf: previous link 2/2" );
208 is
( $nearby->{next_item
}, undef, "Test end of the shelf: no next link" );
210 is
( scalar( @
{$nearby->{items
}} ), 4, "Test last item of the shelf: got 4 items" );