From b6ba4c3b850a85ea024125a984fdc7001883cdfb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 26 Apr 2024 14:24:08 +0100 Subject: [PATCH] Bug 35657: Unit tests for relation accessor additions This patch adds the unit tests for the new 'assignee' relation accessors added to Koha::Ticket and Koha::Ticket::Update classes. --- t/db_dependent/Koha/Ticket.t | 23 ++++++++++++++++++++++- t/db_dependent/Koha/Ticket/Update.t | 23 ++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Ticket.t b/t/db_dependent/Koha/Ticket.t index 7734f6de676..cc1798ef190 100755 --- a/t/db_dependent/Koha/Ticket.t +++ b/t/db_dependent/Koha/Ticket.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use t::lib::TestBuilder; use t::lib::Mocks; @@ -51,6 +51,27 @@ subtest 'reporter() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'assignee() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $ticket = $builder->build_object( + { + class => 'Koha::Tickets', + value => { assignee_id => $patron->id } + } + ); + + my $assignee = $ticket->assignee; + is( ref($assignee), 'Koha::Patron', 'Koha::Ticket->assignee returns a Koha::Patron object' ); + is( $assignee->id, $patron->id, 'Koha::Ticket->assignee returns the right Koha::Patron' ); + + $schema->storage->txn_rollback; +}; + subtest 'resolver() tests' => sub { plan tests => 2; diff --git a/t/db_dependent/Koha/Ticket/Update.t b/t/db_dependent/Koha/Ticket/Update.t index ebd1b4997dc..ec33fa89fc7 100755 --- a/t/db_dependent/Koha/Ticket/Update.t +++ b/t/db_dependent/Koha/Ticket/Update.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use t::lib::TestBuilder; use Koha::Database; @@ -73,6 +73,27 @@ subtest 'user() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'assignee() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $assignee = $builder->build_object( { class => 'Koha::Patrons' } ); + my $update = $builder->build_object( + { + class => 'Koha::Ticket::Updates', + value => { assignee_id => $assignee->id } + } + ); + + my $linked_assignee = $update->assignee; + is( ref($linked_assignee), 'Koha::Patron', 'Koha::Ticket::Update->assignee returns a Koha::Patron object' ); + is( $linked_assignee->id, $assignee->id, 'Koha::Ticket::Update->assignee returns the right Koha::Patron' ); + + $schema->storage->txn_rollback; +}; + subtest 'strings_map() tests' => sub { plan tests => 16; -- 2.44.0