@@ -, +, @@ --- t/db_dependent/Koha/Object.t | 53 ++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 23 deletions(-) --- a/t/db_dependent/Koha/Object.t +++ a/t/db_dependent/Koha/Object.t @@ -32,7 +32,7 @@ use Koha::Acquisition::Orders; use Koha::DateUtils qw( dt_from_string ); use Koha::Libraries; use Koha::Patrons; -use Koha::ApiKeys; +use Koha::Cash::Registers; use JSON; use Scalar::Util qw( isvstring ); @@ -628,24 +628,30 @@ subtest 'store() tests' => sub { plan tests => 16; - # Using Koha::ApiKey to test Koha::Object>-store + # Using Koha::Cash::Register to test Koha::Object>-store # Simple object with foreign keys and unique key $schema->storage->txn_begin; - # Create a patron to make sure its ID doesn't exist on the DB - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); - my $patron_id = $patron->id; - $patron->delete; + # Create a library to make sure its ID doesn't exist on the DB + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $branchcode = $library->branchcode; + $library->delete; - my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' }); + my $cash_register = Koha::Cash::Register->new( + { + branch => $library->branchcode, + name => 'a cash register', + description => 'a description', + } + ); my $dbh = $schema->storage->dbh; { local *STDERR; open STDERR, '>', '/dev/null'; throws_ok - { $api_key->store } + { $cash_register->store } 'Koha::Exceptions::Object::FKConstraint', 'Exception is thrown correctly'; is( @@ -655,21 +661,22 @@ subtest 'store() tests' => sub { ); is( $@->broken_fk, - 'patron_id', + 'branch', 'Exception field is correct' ); - $patron = $builder->build_object({ class => 'Koha::Patrons' }); - $api_key = $builder->build_object({ class => 'Koha::ApiKeys' }); + $cash_register = $builder->build_object({ class => 'Koha::Cash::Registers' }); - my $new_api_key = Koha::ApiKey->new({ - patron_id => $patron_id, - secret => $api_key->secret, - description => 'a description', - }); + my $new_cash_register = Koha::Cash::Register->new( + { + branch => $cash_register->branch, + name => $cash_register->name, + description => 'a description', + } + ); throws_ok - { $new_api_key->store } + { $new_cash_register->store } 'Koha::Exceptions::Object::DuplicateID', 'Exception is thrown correctly'; @@ -681,18 +688,18 @@ subtest 'store() tests' => sub { like( $@->duplicate_id, - qr/(api_keys\.)?secret/, + qr/(cash_register\.)?name/, 'Exception field is correct (note that MySQL 8 is displaying the tablename)' ); close STDERR; } # Successful test - $api_key->set({ secret => 'Manuel' }); - my $ret = $api_key->store; - is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' ); + $cash_register->set({ name => 'Manuel' }); + my $ret = $cash_register->store; + is( ref($ret), 'Koha::Cash::Register', '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( { class => 'Koha::Patron::Categories', @@ -700,7 +707,7 @@ subtest 'store() tests' => sub { } ); - $patron = eval { + my $patron = eval { Koha::Patron->new( { categorycode => $patron_category->categorycode, --