From feb232900b10a7d2331729801930f6a6f52c6a98 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 18 Dec 2017 13:47:53 -0300 Subject: [PATCH] Bug 19828: Unit tests This patch introduces unit tests for the changes this bug introduces to Koha::Object->store. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Koha/Object.t => FAIL: Tests should fail because the changes are not implemented on this patch --- t/db_dependent/Koha/Object.t | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index 5f91415596..edc67ecc8c 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -17,7 +17,8 @@ use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; +use Test::Exception; use Test::Warn; use C4::Context; @@ -218,3 +219,36 @@ subtest "Test update method" => sub { $schema->storage->txn_rollback; }; + +subtest 'store() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + # Create a category to make sure its ID doesn't exist on the DB + my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); + my $category_id = $category->id; + $category->delete; + + my $patron = Koha::Patron->new({ categorycode => $category_id }); + + my $print_error = $schema->storage->dbh->{PrintError}; + $schema->storage->dbh->{PrintError} = 0; + throws_ok + { $patron->store } + 'Koha::Exceptions::Object::FKConstraint', + 'Exception is thrown correctly'; + is( + $@->message, + "Broken FK constraint", + 'Exception message is correct' + ); + is( + $@->broken_fk, + 'categorycode', + 'Exception message is correct' + ); + $schema->storage->dbh->{PrintError} = $print_error; + $schema->storage->txn_rollback; +}; -- 2.14.1