Bug 28772: Fix Koha/Object.t
Koha::ApiKeys is no longer the simple object we need to test Koha::Object->store, let use Koha::Library::Groups Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
bded25d262
commit
206cafb8e8
1 changed files with 28 additions and 23 deletions
|
@ -32,7 +32,7 @@ use Koha::Acquisition::Orders;
|
||||||
use Koha::DateUtils qw( dt_from_string );
|
use Koha::DateUtils qw( dt_from_string );
|
||||||
use Koha::Libraries;
|
use Koha::Libraries;
|
||||||
use Koha::Patrons;
|
use Koha::Patrons;
|
||||||
use Koha::ApiKeys;
|
use Koha::Library::Groups;
|
||||||
|
|
||||||
use JSON;
|
use JSON;
|
||||||
use Scalar::Util qw( isvstring );
|
use Scalar::Util qw( isvstring );
|
||||||
|
@ -628,24 +628,29 @@ subtest 'store() tests' => sub {
|
||||||
|
|
||||||
plan tests => 16;
|
plan tests => 16;
|
||||||
|
|
||||||
# Using Koha::ApiKey to test Koha::Object>-store
|
# Using Koha::Library::Groups to test Koha::Object>-store
|
||||||
# Simple object with foreign keys and unique key
|
# Simple object with foreign keys and unique key
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
# Create a patron to make sure its ID doesn't exist on the DB
|
# Create a library to make sure its ID doesn't exist on the DB
|
||||||
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
my $library = $builder->build_object({ class => 'Koha::Libraries' });
|
||||||
my $patron_id = $patron->id;
|
my $branchcode = $library->branchcode;
|
||||||
$patron->delete;
|
$library->delete;
|
||||||
|
|
||||||
my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' });
|
my $library_group = Koha::Library::Group->new(
|
||||||
|
{
|
||||||
|
branchcode => $library->branchcode,
|
||||||
|
title => 'a title',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
my $dbh = $schema->storage->dbh;
|
my $dbh = $schema->storage->dbh;
|
||||||
{
|
{
|
||||||
local *STDERR;
|
local *STDERR;
|
||||||
open STDERR, '>', '/dev/null';
|
open STDERR, '>', '/dev/null';
|
||||||
throws_ok
|
throws_ok
|
||||||
{ $api_key->store }
|
{ $library_group->store }
|
||||||
'Koha::Exceptions::Object::FKConstraint',
|
'Koha::Exceptions::Object::FKConstraint',
|
||||||
'Exception is thrown correctly';
|
'Exception is thrown correctly';
|
||||||
is(
|
is(
|
||||||
|
@ -655,21 +660,21 @@ subtest 'store() tests' => sub {
|
||||||
);
|
);
|
||||||
is(
|
is(
|
||||||
$@->broken_fk,
|
$@->broken_fk,
|
||||||
'patron_id',
|
'branchcode',
|
||||||
'Exception field is correct'
|
'Exception field is correct'
|
||||||
);
|
);
|
||||||
|
|
||||||
$patron = $builder->build_object({ class => 'Koha::Patrons' });
|
$library_group = $builder->build_object({ class => 'Koha::Library::Groups' });
|
||||||
$api_key = $builder->build_object({ class => 'Koha::ApiKeys' });
|
|
||||||
|
|
||||||
my $new_api_key = Koha::ApiKey->new({
|
my $new_library_group = Koha::Library::Group->new(
|
||||||
patron_id => $patron_id,
|
{
|
||||||
secret => $api_key->secret,
|
branchcode => $library_group->branchcode,
|
||||||
description => 'a description',
|
title => $library_group->title,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
throws_ok
|
throws_ok
|
||||||
{ $new_api_key->store }
|
{ $new_library_group->store }
|
||||||
'Koha::Exceptions::Object::DuplicateID',
|
'Koha::Exceptions::Object::DuplicateID',
|
||||||
'Exception is thrown correctly';
|
'Exception is thrown correctly';
|
||||||
|
|
||||||
|
@ -681,18 +686,18 @@ subtest 'store() tests' => sub {
|
||||||
|
|
||||||
like(
|
like(
|
||||||
$@->duplicate_id,
|
$@->duplicate_id,
|
||||||
qr/(api_keys\.)?secret/,
|
qr/(library_groups\.)?title/,
|
||||||
'Exception field is correct (note that MySQL 8 is displaying the tablename)'
|
'Exception field is correct (note that MySQL 8 is displaying the tablename)'
|
||||||
);
|
);
|
||||||
close STDERR;
|
close STDERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Successful test
|
# Successful test
|
||||||
$api_key->set({ secret => 'Manuel' });
|
$library_group->set({ title => 'Manuel' });
|
||||||
my $ret = $api_key->store;
|
my $ret = $library_group->store;
|
||||||
is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' );
|
is( ref($ret), 'Koha::Library::Group', 'store() returns the object on success' );
|
||||||
|
|
||||||
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
|
$library = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||||
my $patron_category = $builder->build_object(
|
my $patron_category = $builder->build_object(
|
||||||
{
|
{
|
||||||
class => 'Koha::Patron::Categories',
|
class => 'Koha::Patron::Categories',
|
||||||
|
@ -700,7 +705,7 @@ subtest 'store() tests' => sub {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$patron = eval {
|
my $patron = eval {
|
||||||
Koha::Patron->new(
|
Koha::Patron->new(
|
||||||
{
|
{
|
||||||
categorycode => $patron_category->categorycode,
|
categorycode => $patron_category->categorycode,
|
||||||
|
|
Loading…
Reference in a new issue