X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=t%2Flib%2FKoha%2FPlugin%2FTest.pm;h=36565397b77487715808b2f8daf9e1823b3111b0;hb=9d6d641d1f8b77271800f43bc027b651f9aea52b;hp=7bf51df1dfffb0ef74df108dc684664af7908bb2;hpb=a37637e30357258885e9d0c1c7a30366869dcb08;p=srvgit diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm index 7bf51df1df..36565397b7 100644 --- a/t/lib/Koha/Plugin/Test.pm +++ b/t/lib/Koha/Plugin/Test.pm @@ -3,7 +3,10 @@ package Koha::Plugin::Test; ## It's good practice to use Modern::Perl use Modern::Perl; -use Mojo::JSON qw(decode_json); +use Koha::Exceptions::Exception; +use Koha::Plugins::Tab; + +use Mojo::JSON qw( decode_json ); ## Required for all plugins use base qw(Koha::Plugins::Base); @@ -45,6 +48,16 @@ sub to_marc { return "Koha::Plugin::Test::to_marc"; } +sub intranet_catalog_biblio_enhancements_toolbar_button { + my ( $self, $args ) = @_; + return "Koha::Plugin::Test::intranet_catalog_biblio_enhancements_toolbar_button"; +} + +sub intranet_catalog_biblio_enhancements { + my ( $self, $args ) = @_; + return "Koha::Plugin::Test::intranet_catalog_biblio_enhancements"; +} + sub opac_online_payment { my ( $self, $args ) = @_; return "Koha::Plugin::Test::opac_online_payment"; @@ -114,23 +127,73 @@ 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} // ''; + my $biblio = $params->{biblio}; + my $biblio_id = $params->{biblio_id}; + + if ( $action ne 'delete' ) { + Koha::Exceptions::Exception->throw("after_biblio_action called with action: $action, ref: " . ref($biblio) ); + } + else { + Koha::Exceptions::Exception->throw("after_biblio_action called with action: $action") if $biblio_id; + } +} + +sub after_item_action { + my ( $self, $params ) = @_; + my $action = $params->{action} // ''; + my $item = $params->{item}; + my $item_id = $params->{item_id}; + + if ( $action ne 'delete' ) { + 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" ], @@ -147,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" } + } } } }, @@ -166,9 +229,87 @@ 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" + } + } + } + } + } + } } } }; 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;