Bug 25875: Unit test
authorNick Clemens <nick@bywatersolutions.com>
Thu, 25 Jun 2020 10:38:16 +0000 (10:38 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 29 Jun 2020 10:37:02 +0000 (12:37 +0200)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/db_dependent/Utils/Datatables_Members.t

index e0632c4..25128d8 100644 (file)
@@ -501,7 +501,7 @@ subtest 'Search by any borrowers field (bug 17374)' => sub {
 };
 
 subtest 'Search with permissions' => sub {
-    plan tests => 2;
+    plan tests => 4;
 
     my $superlibrarian = $builder->build_object(
         {
@@ -549,6 +549,39 @@ subtest 'Search with permissions' => sub {
         ],
         'We got the 3 patrons we expected'
     );
+
+    C4::Context->dbh->do(
+        q|INSERT INTO user_permissions(borrowernumber, module_bit, code) VALUES(?,?,?)|,
+        undef,
+        $librarian_with_subpermission->borrowernumber,
+        13,
+        'moderate_comments'
+    );
+    $search_results = C4::Utils::DataTables::Members::search(
+        {
+            searchmember     => "",
+            searchfieldstype => 'standard',
+            searchtype       => 'contain',
+            branchcode       => $branchcode,
+            has_permission   => {
+                permission    => 'suggestions',
+                subpermission => 'suggestions_manage'
+            },
+            dt_params => { iDisplayLength => 3, iDisplayStart => 0 },
+        }
+    );
+    is( $search_results->{iTotalDisplayRecords},
+        3, "We find 3 patrons with suggestions_manage permission" );
+    is_deeply(
+        [ sort map { $_->{borrowernumber} } @{ $search_results->{patrons} } ],
+        [
+            $superlibrarian->borrowernumber,
+            $librarian_with_full_permission->borrowernumber,
+            $librarian_with_subpermission->borrowernumber
+        ],
+        'We got the 3 patrons we expected'
+    );
+
 };
 
 subtest 'return values' => sub {