4 use Test::More tests => 8;
7 use t::lib::TestBuilder;
11 use_ok('Koha::Patron::Modification');
12 use_ok('Koha::Patron::Modifications');
15 my $schema = Koha::Database->new->schema;
16 $schema->storage->txn_begin;
18 my $dbh = C4::Context->dbh;
19 $dbh->do("DELETE FROM borrower_modifications");
21 ## Create new pending modification
22 Koha::Patron::Modification->new(
24 verification_token => '1234567890',
30 ## Get the new pending modification
32 Koha::Patron::Modifications->find( { verification_token => '1234567890' } );
34 ## Verify we get the same data
35 is( $borrower->surname, 'Hall', 'Found modification has matching surname' );
37 ## Create new pending modification for a patron
38 my $builder = t::lib::TestBuilder->new;
39 my $borr1 = $builder->build( { source => 'Borrower' } )->{borrowernumber};
41 my $m1 = Koha::Patron::Modification->new(
43 borrowernumber => $borr1,
50 is( Koha::Patron::Modifications->pending_count,
51 1, 'Test pending_count()' );
53 ## Create new pending modification for another patron
54 my $borr2 = $builder->build( { source => 'Borrower' } )->{borrowernumber};
55 my $m2 = Koha::Patron::Modification->new(
57 borrowernumber => $borr2,
65 Koha::Patron::Modifications->pending_count(), 2,
66 'Add a new pending modification and test pending_count() again'
69 ## Check GetPendingModifications
70 my $pendings = Koha::Patron::Modifications->pending;
72 sort ( $pendings->[0]->{firstname}, $pendings->[1]->{firstname} );
73 ok( $firstnames_mod[0] eq 'Kyle', 'Test pending()' );
74 ok( $firstnames_mod[1] eq 'Sandy', 'Test pending() again' );
76 ## This should delete the row from the table
79 ## Save a copy of the borrowers original data
80 my $old_borrower = GetMember( borrowernumber => $borr1 );
82 ## Apply the modifications
85 ## Get a copy of the borrowers current data
86 my $new_borrower = GetMember( borrowernumber => $borr1 );
88 ## Check to see that the approved modifications were saved
89 ok( $new_borrower->{'surname'} eq 'Hall',
90 'Test approve() applys modification to borrower' );