4 use Test::More tests => 1;
8 use Koha::Virtualshelf;
9 use Koha::Virtualshelves;
11 use t::lib::TestBuilder;
13 my $dbh = C4::Context->dbh;
14 $dbh->{AutoCommit} = 0;
16 $dbh->do(q|DELETE FROM virtualshelves|);
18 my $builder = t::lib::TestBuilder->new;
20 subtest 'CRUD' => sub {
22 my $patron = $builder->build({
26 my $number_of_shelves = Koha::Virtualshelves->search->count;
28 is( $number_of_shelves, 0, 'No shelves should exist' );
30 my $shelf = Koha::Virtualshelf->new({
31 shelfname => "my first shelf",
32 owner => $patron->{borrowernumber},
37 is( ref( $shelf ), 'Koha::Virtualshelf', 'The constructor should return a valid object' );
39 $number_of_shelves = Koha::Virtualshelves->search->count;
40 is( $number_of_shelves, 1, '1 shelf should have been inserted' );
41 is( $shelf->allow_add, 0, 'The default value for allow_add should be 1' );
42 is( $shelf->allow_delete_own, 1, 'The default value for allow_delete_own should be 0' );
43 is( $shelf->allow_delete_other, 0, 'The default value for allow_delete_other should be 0' );
44 is( output_pref($shelf->created_on), output_pref(dt_from_string), 'The creation time should have been set to today' );
46 my $retrieved_shelf = Koha::Virtualshelves->find( $shelf->shelfnumber );
48 is( $retrieved_shelf->shelfname, $shelf->shelfname, 'Find should correctly return the shelfname' );
50 # Insert with the same name
52 $shelf = Koha::Virtualshelf->new({
53 shelfname => "my first shelf",
54 owner => $patron->{borrowernumber},
59 is( ref($@), 'Koha::Exception::DuplicateObject' );
60 $number_of_shelves = Koha::Virtualshelves->search->count;
61 is( $number_of_shelves, 1, 'To be sure the number of shelves is still 1' );
63 my $another_patron = $builder->build({
67 $shelf = Koha::Virtualshelf->new({
68 shelfname => "my first shelf",
69 owner => $another_patron->{borrowernumber},
73 $number_of_shelves = Koha::Virtualshelves->search->count;
74 is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');