From 9df4709edbd033e19fd1beba416283b474ef594e Mon Sep 17 00:00:00 2001 From: Wainui Witika-Park Date: Mon, 20 Sep 2021 10:58:35 +0000 Subject: [PATCH] Revert "Bug 28772: Fix Koha/Object.t" This reverts commit 711bde5f5729c9adaa0e61bc6776835511c3441d. --- t/db_dependent/Koha/Object.t | 116 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 61 deletions(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 82b30ae9ec..a6595b76aa 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -30,7 +30,7 @@ use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Libraries; use Koha::Patrons; -use Koha::Library::Groups; +use Koha::ApiKeys; use Scalar::Util qw( isvstring ); use Try::Tiny; @@ -563,75 +563,69 @@ subtest 'store() tests' => sub { plan tests => 16; - # Using Koha::Library::Groups to test Koha::Object>-store + # Using Koha::ApiKey to test Koha::Object>-store # Simple object with foreign keys and unique key $schema->storage->txn_begin; - # 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; + # 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; - my $library_group = Koha::Library::Group->new( - { - branchcode => $library->branchcode, - title => 'a title', - } + my $api_key = Koha::ApiKey->new({ patron_id => $patron_id, secret => 'a secret', description => 'a description' }); + + my $print_error = $schema->storage->dbh->{PrintError}; + $schema->storage->dbh->{PrintError} = 0; + throws_ok + { $api_key->store } + 'Koha::Exceptions::Object::FKConstraint', + 'Exception is thrown correctly'; + is( + $@->message, + "Broken FK constraint", + 'Exception message is correct' + ); + is( + $@->broken_fk, + 'patron_id', + 'Exception field is correct' ); - my $dbh = $schema->storage->dbh; - { - local $dbh->{PrintError} = 0; - local $dbh->{RaiseError} = 0; - throws_ok - { $library_group->store } - 'Koha::Exceptions::Object::FKConstraint', - 'Exception is thrown correctly'; - is( - $@->message, - "Broken FK constraint", - 'Exception message is correct' - ); - is( - $@->broken_fk, - 'branchcode', - 'Exception field is correct' - ); - - $library_group = $builder->build_object({ class => 'Koha::Library::Groups' }); - - my $new_library_group = Koha::Library::Group->new( - { - branchcode => $library_group->branchcode, - title => $library_group->title, - } - ); - - throws_ok - { $new_library_group->store } - 'Koha::Exceptions::Object::DuplicateID', - 'Exception is thrown correctly'; - - is( - $@->message, - 'Duplicate ID', - 'Exception message is correct' - ); - - like( - $@->duplicate_id, - qr/(library_groups\.)?title/, - 'Exception field is correct (note that MySQL 8 is displaying the tablename)' - ); - } + $patron = $builder->build_object({ class => 'Koha::Patrons' }); + $api_key = $builder->build_object({ class => 'Koha::ApiKeys' }); + + my $new_api_key = Koha::ApiKey->new({ + patron_id => $patron_id, + secret => $api_key->secret, + description => 'a description', + }); + + throws_ok + { $new_api_key->store } + 'Koha::Exceptions::Object::DuplicateID', + 'Exception is thrown correctly'; + + is( + $@->message, + 'Duplicate ID', + 'Exception message is correct' + ); + + like( + $@->duplicate_id, + qr/(api_keys\.)?secret/, + 'Exception field is correct (note that MySQL 8 is displaying the tablename)' + ); + + $schema->storage->dbh->{PrintError} = $print_error; # Successful test - $library_group->set({ title => 'Manuel' }); - my $ret = $library_group->store; - is( ref($ret), 'Koha::Library::Group', 'store() returns the object on success' ); + $api_key->set({ secret => 'Manuel' }); + my $ret = $api_key->store; + is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' ); - $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $patron_category = $builder->build_object( { class => 'Koha::Patron::Categories', @@ -639,7 +633,7 @@ subtest 'store() tests' => sub { } ); - my $patron = eval { + $patron = eval { Koha::Patron->new( { categorycode => $patron_category->categorycode, -- 2.39.5