subtest 'token-based tests' => sub {
if ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef } ) ) {
- plan tests => 12;
+ plan tests => 14;
}
else {
plan skip_all => 'Net::OAuth2::AuthorizationServer not available';
my $access_token = $t->tx->res->json->{access_token};
- # With access token and permissions, it returns 200
- #$patron->flags(2**4)->store;
-
my $stash;
+ my $interface;
+ my $userenv;
my $tx = $t->ua->build_tx(GET => '/api/v1/acquisitions/orders');
$tx->req->headers->authorization("Bearer $access_token");
$tx->req->headers->header( 'x-koha-embed' => 'fund' );
- $t->app->hook(after_dispatch => sub { $stash = shift->stash });
+ $t->app->hook(after_dispatch => sub {
+ $stash = shift->stash;
+ $interface = C4::Context->interface;
+ $userenv = C4::Context->userenv;
+ });
+
+ # With access token and permissions, it returns 200
+ #$patron->flags(2**4)->store;
$t->request_ok($tx)->status_is(200);
my $user = $stash->{'koha.user'};
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
+ is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' );
+ is( $interface, 'api', "Interface correctly set to \'api\'" );
my $embed = $stash->{'koha.embed'};
ok( defined $embed, 'The embed hashref is generated and stashed' );
subtest 'cookie-based tests' => sub {
- plan tests => 6;
+ plan tests => 8;
$schema->storage->txn_begin;
$tx->req->env( { REMOTE_ADDR => $remote_address } );
my $stash;
- $t->app->hook(after_dispatch => sub { $stash = shift->stash });
+ my $interface;
+ my $userenv;
+
+ $t->app->hook(after_dispatch => sub {
+ $stash = shift->stash;
+ $interface = C4::Context->interface;
+ $userenv = C4::Context->userenv;
+ });
+
$t->request_ok($tx)->status_is(200);
my $user = $stash->{'koha.user'};
ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
is( $user->borrowernumber, $borrowernumber, 'The stashed user is the right one' );
+ is( $userenv->{number}, $borrowernumber, 'userenv set correctly' );
+ is( $interface, 'api', "Interface correctly set to \'api\'" );
subtest 'logged-out tests' => sub {
plan tests => 3;
subtest 'success tests' => sub {
- plan tests => 5;
+ plan tests => 10;
$schema->storage->txn_begin;
$patron->set_password({ password => $password });
my $userid = $patron->userid;
+ my $stash;
+ my $interface;
+ my $userenv;
+
+ $t->app->hook(after_dispatch => sub {
+ $stash = shift->stash;
+ $interface = C4::Context->interface;
+ $userenv = C4::Context->userenv;
+ });
+
$t->get_ok("//$userid:$password@/api/v1/patrons")
->status_is( 200, 'Successful authentication and permissions check' );
+ my $user = $stash->{'koha.user'};
+ ok( defined $user, 'The \'koha.user\' object is defined in the stash') and
+ is( ref($user), 'Koha::Patron', 'Stashed koha.user object type is Koha::Patron') and
+ is( $user->borrowernumber, $patron->borrowernumber, 'The stashed user is the right one' );
+ is( $userenv->{number}, $patron->borrowernumber, 'userenv set correctly' );
+ is( $interface, 'api', "Interface correctly set to \'api\'" );
+
$patron->flags(undef)->store;
$t->get_ok("//$userid:$password@/api/v1/patrons")