Adding a test for unicode
Jens Gassmann [Sat, 11 Apr 2015 09:52:54 +0000 (11:52 +0200)]
lib/DBIx/Class/Fixtures.pm
t/19-populate-unicode.t [new file with mode: 0644]
t/lib/DBICTest.pm
t/var/configs/unicode.json [new file with mode: 0644]
t/var/fixtures/CD/5.fix

index 81b2569..36f8d0e 100644 (file)
@@ -898,6 +898,7 @@ sub dump_object {
 
     # do the actual dumping
     my $serialized = Dump(\%ds)->Out();
+
     $file->print($serialized);
   }
 
diff --git a/t/19-populate-unicode.t b/t/19-populate-unicode.t
new file mode 100644 (file)
index 0000000..ab5fce1
--- /dev/null
@@ -0,0 +1,53 @@
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More no_plan;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+use Data::Dumper;
+use IO::All;
+use utf8;
+
+# set up and populate schema
+ok( my $schema = DBICTest->init_schema(), 'got schema' );
+my $config_dir = io->catfile(qw't var configs')->name;
+
+# do dump
+ok(
+    my $fixtures = DBIx::Class::Fixtures->new(
+        {
+            config_dir => $config_dir,
+            debug      => 0
+        }
+    ),
+    'object created with correct config dir'
+);
+
+DBICTest->clear_schema($schema);
+DBICTest->populate_schema($schema);
+
+ok(
+    $fixtures->dump(
+        {
+            schema    => $schema,
+            directory => io->catfile(qw't var fixtures')->name,
+            config    => "unicode.json",
+        }
+    ),
+    "unicode dump executed okay"
+);
+
+$fixtures->populate(
+    {
+        connection_details => [ 'dbi:SQLite:' . io->catfile(qw[ t var DBIxClass.db ])->name, '', '' ],
+       directory          => io->catfile(qw't var fixtures')->name,
+        schema             => $schema,
+        no_deploy          => 1,
+        use_find_or_create => 1,
+    }
+);
+
+my $cd = $schema->resultset('CD')->find( { cdid => 5 });
+
+is($cd->title, "Unicode Chars ™ © • † ∑ α β « » → …", "Unicode chars found");
index 8e4c560..69d0c74 100755 (executable)
@@ -160,7 +160,7 @@ sub populate_schema {
         [ 2, 1, "Forkful of bees", 2001 ],
         [ 3, 1, "Caterwaulin' Blues", 1997 ],
         [ 4, 2, "Generic Manufactured Singles", 2001 ],
-        [ 5, 2, "Wir übertreiben überhaupt nicht", 2003 ],
+        [ 5, 2, "Unicode Chars ™ © • † ∑ α β « » → …", 2015 ],
         [ 6, 3, "Come Be Depressed With Us", 1998 ],
     ]);
 
diff --git a/t/var/configs/unicode.json b/t/var/configs/unicode.json
new file mode 100644 (file)
index 0000000..adc21a6
--- /dev/null
@@ -0,0 +1,12 @@
+{
+        "might_have": {
+            "fetch": 0
+        },
+        "has_many": {
+            "fetch": 0
+        },
+        "sets": [{
+            "class": "CD",
+            "quantity": "all"
+        }]
+}
index 7fb848f..0912382 100644 (file)
@@ -1,6 +1,6 @@
 $HASH1 = {
            artist => 2,
            cdid   => 5,
-           title  => "Wir \374bertreiben \374berhaupt nicht",
-           year   => 2003
+           title  => "Unicode Chars \x{2122} \251 \x{2022} \x{2020} \x{2211} \x{3b1} \x{3b2} \253 \273 \x{2192} \x{2026}",
+           year   => 2015
          };