Bugzilla – Attachment 107318 Details for
Bug 20256
Add ability to limit editing of items to home library or library group
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20256: Add unit tests
Bug-20256-Add-unit-tests.patch (text/plain), 5.28 KB, created by
Kyle M Hall (khall)
on 2020-07-24 11:35:24 UTC
(
hide
)
Description:
Bug 20256: Add unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-07-24 11:35:24 UTC
Size:
5.28 KB
patch
obsolete
>From 04dde2d7b8538b7f489eaf5b21e0ee328f027708 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Fri, 29 Mar 2019 14:58:00 -0400 >Subject: [PATCH] Bug 20256: Add unit tests > >Signed-off-by: Bob Bennhoff - CLiC <bbennhoff@clicweb.org> >--- > t/db_dependent/Koha/Patrons.t | 75 ++++++++++++++++++++++++++++++++++- > 1 file changed, 74 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 4f434adc3c..ac2a518584 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -2201,6 +2201,79 @@ subtest 'extended_attributes' => sub { > ## Do we need a filtered? > #$limited_value = $patron_1->get_extended_attribute( $attribute_type_limited->code ); > #is( $limited_value, undef, ); >+}; > >- $schema->storage->txn_rollback; >+subtest 'libraries_where_can_edit_items + can_edit_item' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ my $dbh = $schema->storage->dbh; >+ >+ $dbh->do("DELETE FROM library_groups"); >+ >+ # group1 >+ # library_1A >+ # library_1B >+ # group2 >+ # library_2A >+ my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_limit_item_editing => 1 } )->store; >+ my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_limit_item_editing => 1 } )->store; >+ my $library_1A = $builder->build( { source => 'Branch' } ); >+ my $library_1B = $builder->build( { source => 'Branch' } ); >+ my $library_2A = $builder->build( { source => 'Branch' } ); >+ $library_1A = Koha::Libraries->find( $library_1A->{branchcode} ); >+ $library_1B = Koha::Libraries->find( $library_1B->{branchcode} ); >+ $library_2A = Koha::Libraries->find( $library_2A->{branchcode} ); >+ Koha::Library::Group->new( { branchcode => $library_1A->branchcode, parent_id => $group_1->id } )->store; >+ Koha::Library::Group->new( { branchcode => $library_1B->branchcode, parent_id => $group_1->id } )->store; >+ Koha::Library::Group->new( { branchcode => $library_2A->branchcode, parent_id => $group_2->id } )->store; >+ >+ my $sth = C4::Context->dbh->prepare(q|INSERT INTO user_permissions( borrowernumber, module_bit, code ) VALUES (?, 9, ?)|); # 9 for editcatalogue >+ # 2 patrons from library_1A (group1) >+ # patron_1A_1 see patron's infos from outside its group >+ # Setting flags => undef to not be considered as superlibrarian >+ my $patron_1A_1 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }}); >+ $patron_1A_1 = Koha::Patrons->find( $patron_1A_1->{borrowernumber} ); >+ $sth->execute( $patron_1A_1->borrowernumber, 'edit_items' ); >+ $sth->execute( $patron_1A_1->borrowernumber, 'edit_any_item' ); >+ # patron_1A_2 can only see patron's info from its group >+ my $patron_1A_2 = $builder->build({ source => 'Borrower', value => { branchcode => $library_1A->branchcode, flags => undef, }}); >+ $patron_1A_2 = Koha::Patrons->find( $patron_1A_2->{borrowernumber} ); >+ $sth->execute( $patron_1A_2->borrowernumber, 'edit_items' ); >+ # 1 patron from library_1B (group1) >+ my $patron_1B = $builder->build({ source => 'Borrower', value => { branchcode => $library_1B->branchcode, flags => undef, }}); >+ $patron_1B = Koha::Patrons->find( $patron_1B->{borrowernumber} ); >+ # 1 patron from library_2A (group2) can only see patron's info from its group >+ my $patron_2A = $builder->build({ source => 'Borrower', value => { branchcode => $library_2A->branchcode, flags => undef, }}); >+ $patron_2A = Koha::Patrons->find( $patron_2A->{borrowernumber} ); >+ $sth->execute( $patron_2A->borrowernumber, 'edit_items' ); >+ >+ subtest 'libraries_where_can_edit_items' => sub { >+ plan tests => 3; >+ >+ my @branchcodes; >+ >+ @branchcodes = $patron_1A_1->libraries_where_can_edit_items; >+ is_deeply( \@branchcodes, [], "patron_1A_1 has edit_any_item => No restrictions" ); >+ >+ @branchcodes = $patron_1A_2->libraries_where_can_edit_items; >+ 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" ); >+ >+ @branchcodes = $patron_2A->libraries_where_can_edit_items; >+ is_deeply( \@branchcodes, [$library_2A->branchcode], "patron_2A doesn't have edit_any_item => Can only see patron's from its group" ); >+ }; >+ >+ subtest 'can_edit_item' => sub { >+ plan tests => 6; >+ >+ t::lib::Mocks::mock_userenv({ patron => $patron_1A_1 }); >+ is( $patron_1A_1->can_edit_item( $library_1A->id ), 1, "patron_1A_1 can see patron_1A_2, from its library" ); >+ is( $patron_1A_1->can_edit_item( $library_1B->id ), 1, "patron_1A_1 can see patron_1B, from its group" ); >+ is( $patron_1A_1->can_edit_item( $library_2A->id ), 1, "patron_1A_1 can see patron_1A_2, from another group" ); >+ >+ t::lib::Mocks::mock_userenv({ patron => $patron_1A_2 }); >+ is( $patron_1A_2->can_edit_item( $library_1A->id ), 1, "patron_1A_2 can see patron_1A_1, from its library" ); >+ is( $patron_1A_2->can_edit_item( $library_1B->id ), 1, "patron_1A_2 can see patron_1B, from its group" ); >+ is( $patron_1A_2->can_edit_item( $library_2A->id ), 0, "patron_1A_2 can NOT see patron_2A, from another group" ); >+ }; > }; >-- >2.24.1 (Apple Git-126)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20256
:
87226
|
87227
|
87228
|
87229
|
87230
|
87231
|
87232
|
87233
|
87262
|
87263
|
87264
|
87265
|
87266
|
87267
|
87268
|
87269
|
87270
|
88537
|
88539
|
88541
|
88542
|
88543
|
88544
|
88545
|
88546
|
88547
|
88632
|
88702
|
88703
|
88704
|
88705
|
88935
|
88936
|
96015
|
96016
|
96017
|
96018
|
96019
|
96020
|
96021
|
96022
|
96023
|
96024
|
96025
|
96026
|
96027
|
96028
|
96029
|
96030
|
96031
|
96032
|
96033
|
102622
|
102623
|
102624
|
102625
|
102626
|
102627
|
102628
|
102629
|
102630
|
102631
|
102632
|
102633
|
102634
|
102635
|
102636
|
102637
|
102638
|
102639
|
102640
|
102641
|
102642
|
102703
|
102704
|
102705
|
102706
|
102707
|
102708
|
102709
|
102710
|
102711
|
102712
|
102713
|
102714
|
102715
|
102716
|
102717
|
102718
|
102719
|
102720
|
102721
|
102722
|
102732
|
102733
|
102734
|
102735
|
102736
|
102737
|
102738
|
102739
|
102740
|
102741
|
102742
|
102743
|
102744
|
102745
|
102746
|
102747
|
102748
|
102749
|
102750
|
102751
|
107312
|
107313
|
107314
|
107315
|
107316
|
107317
|
107318
|
107319
|
107320
|
107321
|
107322
|
107323
|
107324
|
107325
|
107326
|
107327
|
107328
|
107329
|
107330
|
108851
|
108852
|
108853
|
108854
|
108855
|
108856
|
108857
|
108858
|
108859
|
108860
|
108861
|
108862
|
108863
|
108864
|
108865
|
108866
|
108867
|
108868
|
108869
|
108870
|
109939
|
110005
|
113706
|
113707
|
113708
|
113709
|
113710
|
113711
|
113712
|
113713
|
113714
|
113715
|
113716
|
113717
|
113718
|
113719
|
113720
|
113721
|
113722
|
113723
|
113724
|
113725
|
113726
|
113727
|
113728
|
116042
|
116043
|
116044
|
116045
|
116046
|
116047
|
116048
|
116049
|
116050
|
116051
|
116052
|
116053
|
116054
|
116055
|
116056
|
116057
|
116058
|
116059
|
116060
|
116061
|
116062
|
116063
|
116064
|
120055
|
120056
|
120057
|
120058
|
120059
|
120060
|
120061
|
120062
|
120063
|
120064
|
120065
|
120066
|
120067
|
120068
|
120069
|
120070
|
120071
|
120072
|
120073
|
120074
|
120075
|
120076
|
121771
|
121772
|
121773
|
121774
|
121775
|
121776
|
121777
|
121778
|
121779
|
121780
|
121781
|
121782
|
121783
|
121785
|
121786
|
121787
|
121788
|
121789
|
121790
|
121791
|
121792
|
124286
|
124287
|
124288
|
124289
|
124290
|
124291
|
124292
|
124293
|
124294
|
124295
|
124296
|
124297
|
124298
|
124299
|
124300
|
124301
|
124302
|
124303
|
124304
|
124305
|
124306
|
124307
|
124321
|
128734
|
128735
|
128736
|
128737
|
128738
|
128739
|
128740
|
128741
|
128742
|
128743
|
128744
|
128745
|
128746
|
128747
|
128748
|
128749
|
128750
|
128751
|
128752
|
128753
|
131676
|
131677
|
131678
|
131679
|
131680
|
131681
|
131682
|
131683
|
131684
|
131685
|
131686
|
131687
|
131688
|
131689
|
131690
|
131691
|
131692
|
131693
|
131694
|
131695
|
131696
|
131697
|
132483
|
132484
|
132486
|
132917
|
134375
|
134376
|
134377
|
139135
|
139136
|
139137
|
139138
|
139139
|
139140
|
139141
|
139142
|
139143
|
139144
|
139145
|
139146
|
139147
|
139148
|
139149
|
139150
|
139151
|
139152
|
139153
|
139154
|
139155
|
139156
|
139157
|
139158
|
139159
|
139160
|
139161
|
139162
|
139163
|
143527
|
143529
|
143530
|
143531
|
143532
|
143533
|
143534
|
143535
|
143536
|
143537
|
143538
|
143539
|
143540
|
143541
|
143542
|
143543
|
143544
|
143545
|
143546
|
143547
|
143548
|
143549
|
143550
|
143551
|
143552
|
143553
|
143554
|
143555
|
143556
|
145286
|
145287
|
145288
|
145289
|
145290
|
145291
|
145292
|
145293
|
145482
|
145483
|
145484
|
145485
|
145486
|
145487
|
145488
|
145489
|
145809
|
145810
|
145811
|
145812
|
145813
|
145814
|
145815
|
145816
|
145887
|
145888
|
145889
|
145890
|
145891
|
145892
|
145893
|
145894
|
145895
|
145896
|
145951
|
145952
|
145953
|
145954
|
145955