Lines 1-20
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Test::More tests => 2; |
4 |
use Test::More tests => 3; |
|
|
5 |
use DateTime::Duration; |
5 |
|
6 |
|
6 |
use C4::Context; |
7 |
use C4::Context; |
7 |
use Koha::DateUtils; |
8 |
use Koha::DateUtils; |
8 |
use Koha::Virtualshelves; |
9 |
use Koha::Virtualshelves; |
9 |
use Koha::Virtualshelfshares; |
10 |
use Koha::Virtualshelfshares; |
|
|
11 |
use Koha::Virtualshelfcontents; |
10 |
|
12 |
|
11 |
use t::lib::TestBuilder; |
13 |
use t::lib::TestBuilder; |
12 |
|
14 |
|
13 |
my $dbh = C4::Context->dbh; |
15 |
my $dbh = C4::Context->dbh; |
14 |
$dbh->{AutoCommit} = 0; |
16 |
$dbh->{AutoCommit} = 0; |
15 |
|
17 |
|
16 |
$dbh->do(q|DELETE FROM virtualshelves|); |
|
|
17 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
18 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
|
|
19 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
20 |
$dbh->do(q|DELETE FROM virtualshelves|); |
18 |
|
21 |
|
19 |
my $builder = t::lib::TestBuilder->new; |
22 |
my $builder = t::lib::TestBuilder->new; |
20 |
|
23 |
|
Lines 147-149
subtest 'Sharing' => sub {
Link Here
|
147 |
$number_of_shelves_shared = Koha::Virtualshelfshares->search->count; |
150 |
$number_of_shelves_shared = Koha::Virtualshelfshares->search->count; |
148 |
is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' ); |
151 |
is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' ); |
149 |
}; |
152 |
}; |
|
|
153 |
|
154 |
subtest 'Shelf content' => sub { |
155 |
|
156 |
plan tests => 18; |
157 |
my $patron1 = $builder->build( { source => 'Borrower', } ); |
158 |
my $patron2 = $builder->build( { source => 'Borrower', } ); |
159 |
my $biblio1 = $builder->build( { source => 'Biblio', } ); |
160 |
my $biblio2 = $builder->build( { source => 'Biblio', } ); |
161 |
my $biblio3 = $builder->build( { source => 'Biblio', } ); |
162 |
my $biblio4 = $builder->build( { source => 'Biblio', } ); |
163 |
my $number_of_contents = Koha::Virtualshelfcontents->search->count; |
164 |
|
165 |
is( $number_of_contents, 0, 'No content should exist' ); |
166 |
|
167 |
my $dt_yesterday = dt_from_string->subtract_duration( DateTime::Duration->new( days => 1 ) ); |
168 |
my $shelf = Koha::Virtualshelf->new( |
169 |
{ shelfname => "my first shelf", |
170 |
owner => $patron1->{borrowernumber}, |
171 |
category => 1, |
172 |
lastmodified => $dt_yesterday, |
173 |
} |
174 |
)->store; |
175 |
|
176 |
$shelf = Koha::Virtualshelves->find( $shelf->shelfnumber ); |
177 |
is( output_pref( dt_from_string $shelf->lastmodified ), output_pref($dt_yesterday), 'The lastmodified has been set to yesterday, will be useful for another test later' ); |
178 |
my $content1 = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} ); |
179 |
is( ref($content1), 'Koha::Virtualshelfcontent', 'add_biblio to a shelf should return a Koha::Virtualshelfcontent object if inserted' ); |
180 |
$shelf = Koha::Virtualshelves->find( $shelf->shelfnumber ); |
181 |
is( output_pref( dt_from_string( $shelf->lastmodified ) ), output_pref(dt_from_string), 'Adding a biblio to a shelf should update the lastmodified for the shelf' ); |
182 |
my $content2 = $shelf->add_biblio( $biblio2->{biblionumber}, $patron1->{borrowernumber} ); |
183 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
184 |
is( $number_of_contents, 2, '2 biblio should have been inserted' ); |
185 |
|
186 |
my $content1_bis = $shelf->add_biblio( $biblio1->{biblionumber}, $patron1->{borrowernumber} ); |
187 |
is( $content1_bis, undef, 'add_biblio should return undef on duplicate' ); # Or an exception ? |
188 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
189 |
is( $number_of_contents, 2, 'The biblio should not have been duplicated' ); |
190 |
|
191 |
$shelf = Koha::Virtualshelves->find( $shelf->shelfnumber ); |
192 |
my $contents = $shelf->get_contents; |
193 |
is( $contents->count, 2, 'There are 2 biblios on this shelf' ); |
194 |
|
195 |
# Patron 2 will try to remove a content |
196 |
# allow_add = 0, allow_delete_own = 1, allow_delete_other = 0 => Default values |
197 |
my $number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } ); |
198 |
is( $number_of_deleted_biblios, 0, ); |
199 |
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio1->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } ); |
200 |
is( $number_of_deleted_biblios, 1, ); |
201 |
|
202 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
203 |
is( $number_of_contents, 1, 'To be sure the content has been deleted' ); |
204 |
|
205 |
# allow_delete_own = 0 |
206 |
$shelf->allow_delete_own(0); |
207 |
$shelf->store; |
208 |
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron1->{borrowernumber} } ); |
209 |
is( $number_of_deleted_biblios, 0, ); |
210 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
211 |
is( $number_of_contents, 1, 'The biblio should not have been deleted to the shelf by the patron, even if it is his own content (allow_delete_own=0)' ); |
212 |
|
213 |
# allow_add = 1, allow_delete_own = 1 |
214 |
$shelf->allow_add(1); |
215 |
$shelf->allow_delete_own(1); |
216 |
$shelf->store; |
217 |
|
218 |
my $content3 = $shelf->add_biblio( $biblio3->{biblionumber}, $patron2->{borrowernumber} ); |
219 |
my $content4 = $shelf->add_biblio( $biblio4->{biblionumber}, $patron2->{borrowernumber} ); |
220 |
|
221 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
222 |
is( $number_of_contents, 3, 'The biblio should have been added to the shelf by the patron 2' ); |
223 |
|
224 |
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio3->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } ); |
225 |
is( $number_of_deleted_biblios, 1, ); |
226 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
227 |
is( $number_of_contents, 2, 'The biblio should have been deleted to the shelf by the patron, it is his own content (allow_delete_own=1) ' ); |
228 |
|
229 |
# allow_add = 1, allow_delete_own = 1, allow_delete_other = 1 |
230 |
$shelf->allow_delete_other(1); |
231 |
$shelf->store; |
232 |
|
233 |
$number_of_deleted_biblios = $shelf->remove_biblios( { biblionumbers => [ $biblio2->{biblionumber} ], borrowernumber => $patron2->{borrowernumber} } ); |
234 |
is( $number_of_deleted_biblios, 1, ); |
235 |
$number_of_contents = Koha::Virtualshelfcontents->search->count; |
236 |
is( $number_of_contents, 1, 'The biblio should have been deleted to the shelf by the patron 2, even if it is not his own content (allow_delete_other=1)' ); |
237 |
}; |