Bug 22051: Unit tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 28 Dec 2018 15:15:36 +0000 (12:15 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 31 Jan 2019 17:13:40 +0000 (17:13 +0000)
Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Charles Farmer <charles.farmer@inLibro.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

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

t/db_dependent/Koha/Object.t

index ca0ef5f..cf40ea9 100755 (executable)
@@ -242,7 +242,7 @@ subtest "Test update method" => sub {
 
 subtest 'store() tests' => sub {
 
-    plan tests => 7;
+    plan tests => 8;
 
     # Using Koha::ApiKey to test Koha::Object>-store
     # Simple object with foreign keys and unique key
@@ -306,6 +306,23 @@ subtest 'store() tests' => sub {
     my $ret = $api_key->store;
     is( ref($ret), 'Koha::ApiKey', 'store() returns the object on success' );
 
+    subtest 'Bad value tests' => sub {
+
+        plan tests => 1;
+
+        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
+
+        my $print_error = $schema->storage->dbh->{PrintError};
+        $schema->storage->dbh->{PrintError} = 0;
+
+        throws_ok
+            { $patron->lastseen('wrong_value')->store; }
+            'Koha::Exceptions::Object::BadValue',
+            'Exception thrown correctly';
+
+        $schema->storage->dbh->{PrintError} = $print_error;
+    };
+
     $schema->storage->txn_rollback;
 };