Bug 24606: (QA follow-up) Add test for encoding/decoding
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 17 Nov 2022 10:15:30 +0000 (10:15 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 18 Nov 2022 15:04:27 +0000 (12:04 -0300)
NOTE: I have the impression that this unit test is quite
rudimentary. I do not see the apply function tested?

Test plan:
Run t/db_dependent/Koha/Item/Templates.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
tcohen amended: stray deps
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Item/Template.pm
t/db_dependent/Koha/Item/Templates.t

index 8adf9ea..3c0e40f 100644 (file)
@@ -17,8 +17,7 @@ package Koha::Item::Template;
 
 use Modern::Perl;
 
-use Encode qw(encode_utf8);
-use JSON   qw(encode_json decode_json);
+use JSON;
 
 use base qw(Koha::Object);
 
index 1a7bc25..dca1e66 100755 (executable)
@@ -18,6 +18,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
+use utf8;
 
 use Koha::Database;
 
@@ -31,7 +32,7 @@ my $builder = t::lib::TestBuilder->new;
 use_ok("Koha::Item::Templates");
 
 subtest 'get_available' => sub {
-    plan tests => 2;
+    plan tests => 3;
 
     $schema->storage->txn_begin;
 
@@ -78,10 +79,12 @@ subtest 'get_available' => sub {
         {
             patron_id => $patron_2->id,
             name      => 'My template',
-            contents  => { location => 'test' },
+            contents  => { location => 'test๐Ÿ™‚' },
             is_shared => 0,
         }
-    )->store();
+    )->store;
+    $unshared_template->discard_changes; # refresh
+    is( $unshared_template->decoded_contents->{location}, 'test๐Ÿ™‚', 'Tested encoding/decoding' );
 
     my $templates = Koha::Item::Templates->get_available( $patron_1->id );
     is( $templates->{owned}->count, 1, "Got back one owned template" );