3 # This file is part of Koha
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 2;
22 use Koha::ERM::Agreements;
24 use Koha::DateUtils qw( dt_from_string );
26 use t::lib::TestBuilder;
28 my $schema = Koha::Database->new->schema;
29 my $builder = t::lib::TestBuilder->new;
31 subtest 'periods' => sub {
35 $schema->storage->txn_begin;
38 $builder->build_object( { class => 'Koha::ERM::Agreements' } );
39 is( $agreement->periods->count, 0, "no period yet" );
41 my $today = dt_from_string;
44 started_on => $today->ymd,
45 ended_on => $today->clone->add( days => 1 )->ymd,
46 cancellation_deadline => $today->clone->add( years => 1 )->ymd,
47 notes => 'just some notes'
50 started_on => $today->ymd,
52 cancellation_deadline => undef,
57 $agreement->periods($periods);
59 my $retrieved_periods = $agreement->periods;
60 is( ref($retrieved_periods), 'Koha::ERM::Agreement::Periods' );
62 [ map { delete $_->{agreement_id}; delete $_->{agreement_period_id}; $_ }
63 @{ $retrieved_periods->unblessed } ];
64 is_deeply( $retrieved_periods, $periods );
65 $agreement->periods( [] );
66 is( $agreement->periods->count, 0 );
68 $schema->storage->txn_rollback;
71 subtest 'user_role' => sub {
75 $schema->storage->txn_begin;
78 $builder->build_object( { class => 'Koha::ERM::Agreements' } );
79 is( $agreement->user_roles->count, 0, "no user yet" );
81 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
83 my $role = 'TEST_ROLE';
84 $builder->build_object(
86 class => 'Koha::AuthorisedValues',
88 category => 'ERM_USER_ROLES',
89 authorised_value => 'TEST_ROLE',
90 lib => 'a role for testing'
97 user_id => $patron->borrowernumber,
102 $agreement->user_roles($user_roles);
104 my $retrieved_user_roles = $agreement->user_roles;
105 is( ref($retrieved_user_roles), 'Koha::ERM::UserRoles' );
106 $retrieved_user_roles =
107 [ map { delete $_->{agreement_id}; $_ }
108 @{ $retrieved_user_roles->unblessed } ];
109 is_deeply( $retrieved_user_roles, $user_roles );
110 $agreement->user_roles( [] );
111 is( $agreement->user_roles->count, 0 );
113 $schema->storage->txn_rollback;