4 use Test::More tests => 10;
7 use t::lib::TestBuilder;
13 use_ok('Koha::Patron::Modification');
14 use_ok('Koha::Patron::Modifications');
17 my $schema = Koha::Database->new->schema;
18 $schema->storage->txn_begin;
20 my $dbh = C4::Context->dbh;
21 $dbh->do("DELETE FROM borrower_modifications");
23 ## Create new pending modification
24 Koha::Patron::Modification->new(
26 verification_token => '1234567890',
32 ## Ensure duplicate verification tokens cannot be added to the database
34 Koha::Patron::Modification->new(
36 verification_token => '1234567890',
42 ok( $_->isa('Koha::Exceptions::Patron::Modification::DuplicateVerificationToken'),
43 'Attempting to add a duplicate verification token to the database should raise a Koha::Exceptions::Koha::Patron::Modification::DuplicateVerificationToken exception' );
44 is( $_->message, "Duplicate verification token 1234567890", 'Exception carries the right message' );
47 ## Get the new pending modification
49 Koha::Patron::Modifications->find( { verification_token => '1234567890' } );
51 ## Verify we get the same data
52 is( $borrower->surname, 'Hall', 'Found modification has matching surname' );
54 ## Create new pending modification for a patron
55 my $builder = t::lib::TestBuilder->new;
56 my $borr1 = $builder->build( { source => 'Borrower' } )->{borrowernumber};
58 my $m1 = Koha::Patron::Modification->new(
60 borrowernumber => $borr1,
67 is( Koha::Patron::Modifications->pending_count,
68 1, 'Test pending_count()' );
70 ## Create new pending modification for another patron
71 my $borr2 = $builder->build( { source => 'Borrower' } )->{borrowernumber};
72 my $m2 = Koha::Patron::Modification->new(
74 borrowernumber => $borr2,
82 Koha::Patron::Modifications->pending_count(), 2,
83 'Add a new pending modification and test pending_count() again'
86 ## Check GetPendingModifications
87 my $pendings = Koha::Patron::Modifications->pending;
89 sort ( $pendings->[0]->{firstname}, $pendings->[1]->{firstname} );
90 ok( $firstnames_mod[0] eq 'Kyle', 'Test pending()' );
91 ok( $firstnames_mod[1] eq 'Sandy', 'Test pending() again' );
93 ## This should delete the row from the table
96 ## Save a copy of the borrowers original data
97 my $old_borrower = GetMember( borrowernumber => $borr1 );
99 ## Apply the modifications
102 ## Get a copy of the borrowers current data
103 my $new_borrower = GetMember( borrowernumber => $borr1 );
105 ## Check to see that the approved modifications were saved
106 ok( $new_borrower->{'surname'} eq 'Hall',
107 'Test approve() applies modification to borrower' );