Bug 21610: Add tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 18 Oct 2018 21:38:18 +0000 (18:38 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 4 Feb 2019 11:12:05 +0000 (11:12 +0000)
Adding few tests to Koha/Object.t in order to highlight what we are
trying to fix.

Note that Koha::ItemType->store was wrong for notforloan, the default
value should be null
    `notforloan` smallint(6) DEFAULT NULL,
but the previous fix (bug 21599) made it default to '0'

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

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

t/db_dependent/Koha/Object.t

index cf40ea9..fb57218 100755 (executable)
@@ -242,7 +242,7 @@ subtest "Test update method" => sub {
 
 subtest 'store() tests' => sub {
 
-    plan tests => 8;
+    plan tests => 16;
 
     # Using Koha::ApiKey to test Koha::Object>-store
     # Simple object with foreign keys and unique key
@@ -306,6 +306,45 @@ subtest 'store() tests' => sub {
     my $ret = $api_key->store;
     is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' );
 
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $patron_category = $builder->build_object(
+        {
+            class => 'Koha::Patron::Categories',
+            value => { category_type => 'P', enrolmentfee => 0 }
+        }
+    );
+
+    $patron = eval {
+        Koha::Patron->new(
+            {
+                categorycode    => $patron_category->categorycode,
+                branchcode      => $library->branchcode,
+                dateofbirth     => "", # date will be set to NULL
+                sms_provider_id => "", # Integer will be set to NULL
+                privacy         => "", # privacy cannot be NULL but has a default value
+            }
+        )->store;
+    };
+    is( $@, '', 'No error should be raised by ->store if empty strings are passed' );
+    is( $patron->privacy, 1, 'Default value for privacy should be set to 1' );
+    is( $patron->dateofbirth,     undef, 'dateofbirth must have been set to undef');
+    is( $patron->sms_provider_id, undef, 'sms_provider_id must have been set to undef');
+
+    my $itemtype = eval {
+        Koha::ItemType->new(
+            {
+                itemtype        => 'IT4test',
+                rentalcharge    => "",
+                notforloan      => "",
+                hideinopac      => "",
+            }
+        )->store;
+    };
+    is( $@, '', 'No error should be raised by ->store if empty strings are passed' );
+    is( $itemtype->rentalcharge, undef, 'decimal DEFAULT NULL should default to null');
+    is( $itemtype->notforloan, undef, 'int DEFAULT NULL should default to null');
+    is( $itemtype->hideinopac, 0, 'int NOT NULL DEFAULT 0 should default to 0');
+
     subtest 'Bad value tests' => sub {
 
         plan tests => 1;