Adding a test for unicode
[dbsrgits/DBIx-Class-Fixtures.git] / t / lib / DBICTest.pm
index bf36d1b..69d0c74 100755 (executable)
@@ -5,6 +5,8 @@ use strict;
 use warnings;
 use DBICTest::Schema;
 
+use utf8;
+
 =head1 NAME
 
 DBICTest - Library to be used by DBIx::Class test scripts.
@@ -60,7 +62,7 @@ sub init_schema {
 
     my $schema;
 
-    my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1 });
+    my @connect_info = ($dsn, $dbuser, $dbpass, { AutoCommit => 1, sqlite_unicode => 1 });
 
     if ($args{compose_connection}) {
       $schema = DBICTest::Schema->compose_connection(
@@ -97,11 +99,20 @@ sub deploy_schema {
     my $schema = shift;
 
     my $file = shift || $self->get_ddl_file($schema);
-    open IN, $file;
+    open(  my $fh, "<",$file ) or die "couldnt open $file, $!";
     my $sql;
-    { local $/ = undef; $sql = <IN>; }
-    close IN;
-    ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
+    { local $/ = undef; $sql = <$fh>; }
+
+    foreach my $line (split(/;\n/, $sql)) {
+      print "$line\n";
+      next if(!$line);
+      next if($line =~ /^--/);
+      next if($line =~ /^BEGIN TRANSACTION/m);
+      next if($line =~ /^COMMIT/m);
+      next if $line =~ /^\s+$/; # skip whitespace only
+
+      $schema->storage->dbh->do($line) || print "Error on SQL: $line\n";
+    }
 }
  
 
@@ -139,7 +150,8 @@ sub populate_schema {
         [ 1, 'Caterwauler McCrae' ],
         [ 2, 'Random Boy Band' ],
         [ 3, 'We Are Goth' ],
-        [ 4, '' ] # Test overridden new will default name to "Test Name" using use_create => 1.
+        [ 4, '' ], # Test overridden new will default name to "Test Name" using use_create => 1.
+        [ 32948, 'Big PK' ],
     ]);
 
     $schema->populate('CD', [
@@ -148,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, "We like girls and stuff", 2003 ],
+        [ 5, 2, "Unicode Chars ™ © • † ∑ α β « » → …", 2015 ],
         [ 6, 3, "Come Be Depressed With Us", 1998 ],
     ]);