Bug 20669: Add upgrade method to plugins
[koha.git] / t / lib / Koha / Plugin / Test.pm
1 package Koha::Plugin::Test;
2
3 ## It's good practice to use Modern::Perl
4 use Modern::Perl;
5
6 use Mojo::JSON qw(decode_json);
7
8 ## Required for all plugins
9 use base qw(Koha::Plugins::Base);
10
11 our $VERSION = 1.01;
12 our $metadata = {
13     name            => 'Test Plugin',
14     author          => 'Kyle M Hall',
15     description     => 'Test plugin',
16     date_authored   => '2013-01-14',
17     date_updated    => '2013-01-14',
18     minimum_version => '3.11',
19     maximum_version => undef,
20     version         => $VERSION,
21     my_example_tag  => 'find_me',
22 };
23
24 ## This is the minimum code required for a plugin's 'new' method
25 ## More can be added, but none should be removed
26 sub new {
27     my ( $class, $args ) = @_;
28     $args->{'metadata'} = $metadata;
29     my $self = $class->SUPER::new($args);
30     return $self;
31 }
32
33 sub report {
34     my ( $self, $args ) = @_;
35     return "Koha::Plugin::Test::report";
36 }
37
38 sub tool {
39     my ( $self, $args ) = @_;
40     return "Koha::Plugin::Test::tool";
41 }
42
43 sub to_marc {
44     my ( $self, $args ) = @_;
45     return "Koha::Plugin::Test::to_marc";
46 }
47
48 sub opac_online_payment {
49     my ( $self, $args ) = @_;
50     return "Koha::Plugin::Test::opac_online_payment";
51 }
52
53 sub opac_online_payment_begin {
54     my ( $self, $args ) = @_;
55     return "Koha::Plugin::Test::opac_online_payment_begin";
56 }
57
58 sub opac_online_payment_end {
59     my ( $self, $args ) = @_;
60     return "Koha::Plugin::Test::opac_online_payment_end";
61 }
62
63 sub opac_head {
64     my ( $self, $args ) = @_;
65     return "Koha::Plugin::Test::opac_head";
66 }
67
68 sub opac_js {
69     my ( $self, $args ) = @_;
70     return "Koha::Plugin::Test::opac_js";
71 }
72
73 sub configure {
74     my ( $self, $args ) = @_;
75     return "Koha::Plugin::Test::configure";;
76 }
77
78 sub install {
79     my ( $self, $args ) = @_;
80     return "Koha::Plugin::Test::install";
81 }
82
83 sub upgrade {
84     my ( $self, $args ) = @_;
85     return "Koha::Plugin::Test::upgrade";
86 }
87
88 sub uninstall {
89     my ( $self, $args ) = @_;
90     return "Koha::Plugin::Test::uninstall";
91 }
92
93 sub test_output {
94     my ( $self ) = @_;
95     $self->output( '¡Hola output!', 'json' );
96 }
97
98 sub test_output_html {
99     my ( $self ) = @_;
100     $self->output_html( '¡Hola output_html!' );
101 }
102
103 sub api_namespace {
104     return "testplugin";
105 }
106
107 sub api_routes {
108     my ( $self, $args ) = @_;
109
110     my $spec = qq{
111 {
112   "/patrons/{patron_id}/bother": {
113     "put": {
114       "x-mojo-to": "Koha::Plugin::Test#bother",
115       "operationId": "BotherPatron",
116       "tags": ["patrons"],
117       "parameters": [{
118         "name": "patron_id",
119         "in": "path",
120         "description": "Internal patron identifier",
121         "required": true,
122         "type": "integer"
123       }],
124       "produces": [
125         "application/json"
126       ],
127       "responses": {
128         "200": {
129           "description": "A bothered patron",
130           "schema": {
131               "type": "object",
132                 "properties": {
133                   "bothered": {
134                     "description": "If the patron has been bothered",
135                     "type": "boolean"
136                   }
137                 }
138           }
139         },
140         "404": {
141           "description": "An error occurred",
142           "schema": {
143               "type": "object",
144                 "properties": {
145                   "error": {
146                     "description": "An explanation for the error",
147                     "type": "string"
148                   }
149                 }
150           }
151         }
152       },
153       "x-koha-authorization": {
154         "permissions": {
155           "borrowers": "1"
156         }
157       }
158     }
159   }
160 }
161     };
162
163     return decode_json($spec);
164 }