764b5a6b2b22f2d8af918770321408f1acf6df12
[koha-equinox.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 intranet_catalog_biblio_enhancements_toolbar_button {
49     my ( $self, $args ) = @_;
50     return "Koha::Plugin::Test::intranet_catalog_biblio_enhancements_toolbar_button";
51 }
52
53 sub intranet_catalog_biblio_enhancements {
54     my ( $self, $args ) = @_;
55     return "Koha::Plugin::Test::intranet_catalog_biblio_enhancements";
56 }
57
58 sub opac_online_payment {
59     my ( $self, $args ) = @_;
60     return "Koha::Plugin::Test::opac_online_payment";
61 }
62
63 sub opac_online_payment_begin {
64     my ( $self, $args ) = @_;
65     return "Koha::Plugin::Test::opac_online_payment_begin";
66 }
67
68 sub opac_online_payment_end {
69     my ( $self, $args ) = @_;
70     return "Koha::Plugin::Test::opac_online_payment_end";
71 }
72
73 sub opac_head {
74     my ( $self, $args ) = @_;
75     return "Koha::Plugin::Test::opac_head";
76 }
77
78 sub opac_js {
79     my ( $self, $args ) = @_;
80     return "Koha::Plugin::Test::opac_js";
81 }
82
83 sub intranet_head {
84     my ( $self, $args ) = @_;
85     return "Koha::Plugin::Test::intranet_head";
86 }
87
88 sub intranet_js {
89     my ( $self, $args ) = @_;
90     return "Koha::Plugin::Test::intranet_js";
91 }
92
93 sub configure {
94     my ( $self, $args ) = @_;
95     return "Koha::Plugin::Test::configure";;
96 }
97
98 sub install {
99     my ( $self, $args ) = @_;
100     return "Koha::Plugin::Test::install";
101 }
102
103 sub upgrade {
104     my ( $self, $args ) = @_;
105     return "Koha::Plugin::Test::upgrade";
106 }
107
108 sub uninstall {
109     my ( $self, $args ) = @_;
110     return "Koha::Plugin::Test::uninstall";
111 }
112
113 sub test_output {
114     my ( $self ) = @_;
115     $self->output( '¡Hola output!', 'json' );
116 }
117
118 sub test_output_html {
119     my ( $self ) = @_;
120     $self->output_html( '¡Hola output_html!' );
121 }
122
123 sub api_namespace {
124     return "testplugin";
125 }
126
127 sub api_routes {
128     my ( $self, $args ) = @_;
129
130     my $spec = qq{
131 {
132   "/patrons/{patron_id}/bother": {
133     "put": {
134       "x-mojo-to": "Koha::Plugin::Test#bother",
135       "operationId": "BotherPatron",
136       "tags": ["patrons"],
137       "parameters": [{
138         "name": "patron_id",
139         "in": "path",
140         "description": "Internal patron identifier",
141         "required": true,
142         "type": "integer"
143       }],
144       "produces": [
145         "application/json"
146       ],
147       "responses": {
148         "200": {
149           "description": "A bothered patron",
150           "schema": {
151               "type": "object",
152                 "properties": {
153                   "bothered": {
154                     "description": "If the patron has been bothered",
155                     "type": "boolean"
156                   }
157                 }
158           }
159         },
160         "404": {
161           "description": "An error occurred",
162           "schema": {
163               "type": "object",
164                 "properties": {
165                   "error": {
166                     "description": "An explanation for the error",
167                     "type": "string"
168                   }
169                 }
170           }
171         }
172       },
173       "x-koha-authorization": {
174         "permissions": {
175           "borrowers": "1"
176         }
177       }
178     }
179   }
180 }
181     };
182
183     return decode_json($spec);
184 }
185
186 sub _private_sub {
187     return "";
188 }