|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 39; |
22 |
use Test::More tests => 40; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
Lines 1792-1794
subtest 'anonymize' => sub {
Link Here
|
| 1792 |
is( $patron2->firstname, undef, 'First name patron2 cleared' ); |
1792 |
is( $patron2->firstname, undef, 'First name patron2 cleared' ); |
| 1793 |
}; |
1793 |
}; |
| 1794 |
$schema->storage->txn_rollback; |
1794 |
$schema->storage->txn_rollback; |
| 1795 |
- |
1795 |
|
|
|
1796 |
subtest 'libraries_where_can_edit_items + can_edit_item' => sub { |
| 1797 |
plan tests => 2; |
| 1798 |
|
| 1799 |
$schema->storage->txn_begin; |
| 1800 |
my $dbh = $schema->storage->dbh; |
| 1801 |
|
| 1802 |
$dbh->do("DELETE FROM library_groups"); |
| 1803 |
|
| 1804 |
# group1 |
| 1805 |
# library_1A |
| 1806 |
# library_1B |
| 1807 |
# group2 |
| 1808 |
# library_2A |
| 1809 |
my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_limit_item_editing => 1 } )->store; |
| 1810 |
my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_limit_item_editing => 1 } )->store; |
| 1811 |
my $library_1A = $builder->build( { source => 'Branch' } ); |
| 1812 |
my $library_1B = $builder->build( { source => 'Branch' } ); |
| 1813 |
my $library_2A = $builder->build( { source => 'Branch' } ); |
| 1814 |
$library_1A = Koha::Libraries->find( $library_1A->{branchcode} ); |
| 1815 |
$library_1B = Koha::Libraries->find( $library_1B->{branchcode} ); |
| 1816 |
$library_2A = Koha::Libraries->find( $library_2A->{branchcode} ); |
| 1817 |
Koha::Library::Group->new( { branchcode => $library_1A->branchcode, parent_id => $group_1->id } )->store; |
| 1818 |
Koha::Library::Group->new( { branchcode => $library_1B->branchcode, parent_id => $group_1->id } )->store; |
| 1819 |
Koha::Library::Group->new( { branchcode => $library_2A->branchcode, parent_id => $group_2->id } )->store; |
| 1820 |
|
| 1821 |
my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 9, ?)|); # 9 for editcatalogue |
| 1822 |
# 2 patrons from library_1A (group1) |
| 1823 |
# patron_1A_1 see patron's infos from outside its group |
| 1824 |
# Setting flags => undef to not be considered as superlibrarian |
| 1825 |
my $patron_1A_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }}); |
| 1826 |
$patron_1A_1 = Koha::Patrons->find( $patron_1A_1->{borrowernumber} ); |
| 1827 |
$sth->execute( $patron_1A_1->borrowernumber, 'edit_items' ); |
| 1828 |
$sth->execute( $patron_1A_1->borrowernumber, 'edit_any_item' ); |
| 1829 |
# patron_1A_2 can only see patron's info from its group |
| 1830 |
my $patron_1A_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }}); |
| 1831 |
$patron_1A_2 = Koha::Patrons->find( $patron_1A_2->{borrowernumber} ); |
| 1832 |
$sth->execute( $patron_1A_2->borrowernumber, 'edit_items' ); |
| 1833 |
# 1 patron from library_1B (group1) |
| 1834 |
my $patron_1B = $builder->build({ source => 'Borrower', value => { branchcode => $library_1B->branchcode, flags => undef, }}); |
| 1835 |
$patron_1B = Koha::Patrons->find( $patron_1B->{borrowernumber} ); |
| 1836 |
# 1 patron from library_2A (group2) can only see patron's info from its group |
| 1837 |
my $patron_2A = $builder->build({ source => 'Borrower', value => { branchcode => $library_2A->branchcode, flags => undef, }}); |
| 1838 |
$patron_2A = Koha::Patrons->find( $patron_2A->{borrowernumber} ); |
| 1839 |
$sth->execute( $patron_2A->borrowernumber, 'edit_items' ); |
| 1840 |
|
| 1841 |
subtest 'libraries_where_can_edit_items' => sub { |
| 1842 |
plan tests => 3; |
| 1843 |
|
| 1844 |
my @branchcodes; |
| 1845 |
|
| 1846 |
@branchcodes = $patron_1A_1->libraries_where_can_edit_items; |
| 1847 |
is_deeply( \@branchcodes, [], "patron_1A_1 has edit_any_item => No restrictions" ); |
| 1848 |
|
| 1849 |
@branchcodes = $patron_1A_2->libraries_where_can_edit_items; |
| 1850 |
is_deeply( \@branchcodes, [ sort ( $library_1A->branchcode, $library_1B->branchcode ) ], "patron_1A_2 doesn't have edit_any_item => Can only edit items from its group" ); |
| 1851 |
|
| 1852 |
@branchcodes = $patron_2A->libraries_where_can_edit_items; |
| 1853 |
is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" ); |
| 1854 |
}; |
| 1855 |
|
| 1856 |
subtest 'can_edit_item' => sub { |
| 1857 |
plan tests => 6; |
| 1858 |
|
| 1859 |
t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 }); |
| 1860 |
is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" ); |
| 1861 |
is( $patron_1A_1->can_edit_item( $library_1B->id ), 1, "patron_1A_1 can see patron_1B, from its group" ); |
| 1862 |
is( $patron_1A_1->can_edit_item( $library_2A->id ), 1, "patron_1A_1 can see patron_1A_2, from another group" ); |
| 1863 |
|
| 1864 |
t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 }); |
| 1865 |
is( $patron_1A_2->can_edit_item( $library_1A->id ), 1, "patron_1A_2 can see patron_1A_1, from its library" ); |
| 1866 |
is( $patron_1A_2->can_edit_item( $library_1B->id ), 1, "patron_1A_2 can see patron_1B, from its group" ); |
| 1867 |
is( $patron_1A_2->can_edit_item( $library_2A->id ), 0, "patron_1A_2 can NOT see patron_2A, from another group" ); |
| 1868 |
}; |
| 1869 |
|
| 1870 |
$schema->storage->txn_rollback; |
| 1871 |
}; |