Lines 1-7
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
4 |
# |
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. |
9 |
# |
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. |
14 |
# |
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>. |
17 |
|
3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
4 |
use Test::More tests => 7; |
19 |
use Test::More tests => 7; |
|
|
20 |
use Test::Exception; |
21 |
|
5 |
use DateTime::Duration; |
22 |
use DateTime::Duration; |
6 |
|
23 |
|
7 |
use C4::Context; |
24 |
use C4::Context; |
Lines 762-767
subtest 'cannot_be_transferred' => sub {
Link Here
|
762 |
|
779 |
|
763 |
$schema->storage->txn_rollback; |
780 |
$schema->storage->txn_rollback; |
764 |
|
781 |
|
|
|
782 |
subtest 'filter_by_public() tests' => sub { |
783 |
|
784 |
plan tests => 4; |
785 |
|
786 |
$schema->storage->txn_begin; |
787 |
|
788 |
my $list_1 = $builder->build_object( |
789 |
{ |
790 |
class => 'Koha::Virtualshelves', |
791 |
value => { public => 0 } |
792 |
} |
793 |
); |
794 |
my $list_2 = $builder->build_object( |
795 |
{ |
796 |
class => 'Koha::Virtualshelves', |
797 |
value => { public => 1 } |
798 |
} |
799 |
); |
800 |
my $list_3 = $builder->build_object( |
801 |
{ |
802 |
class => 'Koha::Virtualshelves', |
803 |
value => { public => 1 } |
804 |
} |
805 |
); |
806 |
|
807 |
my $lists = Koha::Virtualshelves->search( { shelfnumber => [ $list_1->id, $list_2->id, $list_3->id ] } ); |
808 |
|
809 |
is( $lists->count, 3, 'Our three lists are returned' ); |
810 |
$lists = $lists->filter_by_public; |
811 |
|
812 |
is( $lists->count, 2, 'Our two public lists are returned' ); |
813 |
|
814 |
while ( my $list = $lists->next ) { |
815 |
ok( $list->public, 'Only public lists in the resultset' ); |
816 |
} |
817 |
|
818 |
$schema->storage->txn_rollback; |
819 |
}; |
820 |
|
821 |
subtest 'filter_by_readable() tests' => sub { |
822 |
|
823 |
plan tests => 6; |
824 |
|
825 |
$schema->storage->txn_begin; |
826 |
|
827 |
my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); |
828 |
my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } ); |
829 |
|
830 |
my $list_1 = $builder->build_object( |
831 |
{ |
832 |
class => 'Koha::Virtualshelves', |
833 |
value => { |
834 |
public => 0, |
835 |
owner => $patron_1->id, |
836 |
} |
837 |
} |
838 |
); |
839 |
my $list_2 = $builder->build_object( |
840 |
{ |
841 |
class => 'Koha::Virtualshelves', |
842 |
value => { |
843 |
public => 1, |
844 |
owner => $patron_1->id, |
845 |
} |
846 |
} |
847 |
); |
848 |
my $list_3 = $builder->build_object( |
849 |
{ |
850 |
class => 'Koha::Virtualshelves', |
851 |
value => { |
852 |
public => 0, |
853 |
owner => $patron_2->id, |
854 |
} |
855 |
} |
856 |
); |
857 |
my $list_4 = $builder->build_object( |
858 |
{ |
859 |
class => 'Koha::Virtualshelves', |
860 |
value => { |
861 |
public => 1, |
862 |
owner => $patron_2->id, |
863 |
} |
864 |
} |
865 |
); |
866 |
|
867 |
my $lists = |
868 |
Koha::Virtualshelves->search( { shelfnumber => [ $list_1->id, $list_2->id, $list_3->id, $list_4->id ] } ); |
869 |
|
870 |
is( $lists->count, 4, 'Our four lists are returned' ); |
871 |
|
872 |
throws_ok { $lists->filter_by_readable; } |
873 |
'Koha::Exceptions::MissingParameter', |
874 |
'Exception thrown on missing'; |
875 |
|
876 |
$lists = $lists->filter_by_readable( { patron_id => $patron_1->id } ); |
877 |
|
878 |
is( $lists->count, 3, 'Three lists are returned' ); |
879 |
|
880 |
while ( my $list = $lists->next ) { |
881 |
ok( $list->owner == $patron_1->id || $list->public, 'Only public or self lists in the resultset' ); |
882 |
} |
883 |
|
884 |
$schema->storage->txn_rollback; |
885 |
}; |
886 |
|
765 |
sub teardown { |
887 |
sub teardown { |
766 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
888 |
$dbh->do(q|DELETE FROM virtualshelfshares|); |
767 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
889 |
$dbh->do(q|DELETE FROM virtualshelfcontents|); |
768 |
- |
|
|