Merge 'trunk' into 'replication_dedux'
[dbsrgits/DBIx-Class.git] / t / 85utf8.t
CommitLineData
70350518 1use strict;
2use warnings;
e59c17fe 3
70350518 4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
e59c17fe 7
a47e1233 8my $schema = DBICTest->init_schema();
e59c17fe 9
337c98ef 10if ($] <= 5.008000) {
11
12 eval 'use Encode; 1' or plan skip_all => 'Need Encode run this test';
13
14} else {
15
16 eval 'use utf8; 1' or plan skip_all => 'Need utf8 run this test';
17}
e59c17fe 18
404939a4 19plan tests => 3;
e59c17fe 20
404939a4 21DBICTest::Schema::CD->load_components('UTF8Columns');
22DBICTest::Schema::CD->utf8_columns('title');
70350518 23Class::C3->reinitialize();
24
8236f0dc 25my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'øni', year => 'foo' } );
70350518 26my $utf8_char = 'uniuni';
e59c17fe 27
337c98ef 28if ($] <= 5.008000) {
29
30 ok( Encode::is_utf8( $cd->title ), 'got title with utf8 flag' );
31 ok( !Encode::is_utf8( $cd->year ), 'got year without utf8 flag' );
32
33 Encode::_utf8_on($utf8_char);
34 $cd->title($utf8_char);
35 ok( !Encode::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
36
37} else {
38
39 ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
40 ok( !utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
41
42 utf8::decode($utf8_char);
43 $cd->title($utf8_char);
44 ok( !utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
45}