Bug 11853: Add tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 8 May 2019 21:37:40 +0000 (16:37 -0500)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 24 May 2019 13:45:27 +0000 (14:45 +0100)
Signed-off-by: Liz Rea <wizzyrea@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 735d23c299669b40d3e3e2a4fe21b88fc6cca00f)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/Koha/Patron/Modifications.t

index 955de72..377613b 100755 (executable)
@@ -19,7 +19,7 @@ use Modern::Perl;
 
 use utf8;
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 use Test::Exception;
 
 use t::lib::TestBuilder;
@@ -372,3 +372,42 @@ subtest 'pending_count() and pending() tests' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'dateofbirth tests' => sub {
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    # Cleaning the field
+    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { dateofbirth => '1980-01-01' } } );
+    my $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, dateofbirth => undef }
+    )->store;
+    $patron_modification->approve;
+
+    $patron->discard_changes;
+    is( $patron->dateofbirth, undef, 'dateofbirth must a been set to NULL if required' );
+
+    # FIXME ->approve must have been removed it, but it did not. There may be an hidden bug here.
+    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
+
+    # Adding a dateofbirth
+    $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, dateofbirth => '1980-02-02' }
+    )->store;
+    $patron_modification->approve;
+
+    $patron->discard_changes;
+    is( $patron->dateofbirth, '1980-02-02', 'dateofbirth must a been set' );
+
+    # FIXME ->approve must have been removed it, but it did not. There may be an hidden bug here.
+    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
+
+    # Modifying a dateofbirth
+    $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, dateofbirth => '1980-03-03' }
+    )->store;
+    $patron_modification->approve;
+
+    $patron->discard_changes;
+    is( $patron->dateofbirth, '1980-03-03', 'dateofbirth must a been updated' );
+
+    $schema->storage->txn_rollback;
+};