Bug 17600: Standardize our EXPORT_OK
[srvgit] / t / lib / Koha / Plugin / Test.pm
index e34b61d..3656539 100644 (file)
@@ -4,7 +4,9 @@ package Koha::Plugin::Test;
 use Modern::Perl;
 
 use Koha::Exceptions::Exception;
-use Mojo::JSON qw(decode_json);
+use Koha::Plugins::Tab;
+
+use Mojo::JSON qw( decode_json );
 
 ## Required for all plugins
 use base qw(Koha::Plugins::Base);
@@ -125,6 +127,11 @@ sub api_namespace {
     return "testplugin";
 }
 
+sub after_hold_create {
+    my ( $self, $param ) = @_;
+    Koha::Exceptions::Exception->throw("after_hold_create called with parameter " . ref($param) );
+}
+
 sub after_biblio_action {
     my ( $self, $params ) = @_;
     my $action    = $params->{action} // '';
@@ -139,7 +146,6 @@ sub after_biblio_action {
     }
 }
 
-
 sub after_item_action {
     my ( $self, $params ) = @_;
     my $action  = $params->{action} // '';
@@ -147,30 +153,47 @@ sub after_item_action {
     my $item_id = $params->{item_id};
 
     if ( $action ne 'delete' ) {
-        Koha::Exceptions::Exception->throw("after_item_action called with action: $action, ref: " . ref($item) );
+        my $itemnumber_defined = (defined $item->itemnumber) ? 'yes' : 'no';
+        my $item_id_defined    = (defined $item_id) ? 'yes' : 'no';
+        Koha::Exceptions::Exception->throw("after_item_action called with action: $action, ref: " . ref($item) . " ".
+                                           "item_id defined: $item_id_defined ".
+                                           "itemnumber defined: $itemnumber_defined" );
     }
     else {
         Koha::Exceptions::Exception->throw("after_item_action called with action: $action" ) if $item_id;
     }
 }
 
+sub after_circ_action {
+    my ( $self, $params ) = @_;
+
+    my $action   = $params->{action};
+    my $checkout = $params->{payload}->{checkout};
+    my $payload  = $params->{payload};
+
+    my $type = $payload->{type};
+
+    if ( $action eq 'renewal' ) {
+        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
+    }
+    elsif ( $action eq 'checkout') {
+        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout) . " type: $type");
+    }
+    elsif ( $action eq 'checkin' ) {
+        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
+    }
+}
+
 sub api_routes {
     my ( $self, $args ) = @_;
 
     my $spec = qq{
 {
-  "/patrons/{patron_id}/bother": {
-    "put": {
-      "x-mojo-to": "Koha::Plugin::Test#bother",
+  "/patrons/bother": {
+    "get": {
+      "x-mojo-to": "Test::Controller#bother",
       "operationId": "BotherPatron",
       "tags": ["patrons"],
-      "parameters": [{
-        "name": "patron_id",
-        "in": "path",
-        "description": "Internal patron identifier",
-        "required": true,
-        "type": "integer"
-      }],
       "produces": [
         "application/json"
       ],
@@ -187,16 +210,16 @@ sub api_routes {
                 }
           }
         },
-        "404": {
+        "401": {
           "description": "An error occurred",
           "schema": {
               "type": "object",
-                "properties": {
-                  "error": {
-                    "description": "An explanation for the error",
-                    "type": "string"
-                  }
+              "properties": {
+                "error": {
+                  "description": "An explanation for the error",
+                  "type": "string"
                 }
+              }
           }
         }
       },
@@ -206,6 +229,42 @@ sub api_routes {
         }
       }
     }
+  },
+  "/public/patrons/bother": {
+    "get": {
+      "x-mojo-to": "Test::Controller#bother",
+      "operationId": "PubliclyBotherPatron",
+      "tags": ["patrons"],
+      "produces": [
+        "application/json"
+      ],
+      "responses": {
+        "200": {
+          "description": "A bothered patron",
+          "schema": {
+              "type": "object",
+              "properties": {
+                "bothered": {
+                  "description": "If the patron has been bothered",
+                  "type": "boolean"
+                }
+              }
+          }
+        },
+        "401": {
+          "description": "Authentication required",
+          "schema": {
+            "type": "object",
+            "properties": {
+              "error": {
+                "description": "An explanation for the error",
+                "type": "string"
+              }
+            }
+          }
+        }
+      }
+    }
   }
 }
     };
@@ -213,6 +272,44 @@ sub api_routes {
     return decode_json($spec);
 }
 
+sub check_password {
+    my ( $self, $args ) = @_;
+
+    my $password = $args->{'password'};
+    if ( $password && $password =~ m/^\d{4}$/ ) {
+        return { error => 0 };
+    }
+    else {
+        return {
+            error => 1,
+            msg   => "PIN should be four digits"
+        };
+    }
+}
+
+sub intranet_catalog_biblio_tab {
+    my @tabs;
+    push @tabs,
+      Koha::Plugins::Tab->new(
+        {
+            title   => 'Tab 1',
+            content => 'This is content for tab 1'
+        }
+      );
+
+    push @tabs,
+      Koha::Plugins::Tab->new(
+        {
+            title   => 'Tab 2',
+            content => 'This is content for tab 2'
+        }
+      );
+
+    return @tabs;
+}
+
 sub _private_sub {
     return "";
 }
+
+1;