5.8.1 is minimum required perl
[dbsrgits/DBIx-Class.git] / t / 85utf8.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7 use utf8;
8
9 my $schema = DBICTest->init_schema();
10
11 DBICTest::Schema::CD->load_components('UTF8Columns');
12 DBICTest::Schema::CD->utf8_columns('title');
13 Class::C3->reinitialize();
14
15 my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'øni', year => '2048' } );
16 my $utf8_char = 'uniuni';
17
18
19 ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
20 ok(! utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
21
22 utf8::decode($utf8_char);
23 $cd->title($utf8_char);
24 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
25
26
27 my $v_utf8 = "\x{219}";
28
29 $cd->update ({ title => $v_utf8 });
30 $cd->title($v_utf8);
31 ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
32
33 $cd->update ({ title => $v_utf8 });
34 $cd->title('something_else');
35 ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
36
37 TODO: {
38   local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
39   $cd = $schema->resultset('CD')->find ({ title => $v_utf8 }, { select => 'title', as => 'name' });
40   ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');
41 }
42
43 done_testing;