Merge 'chaining_fixes' into 'trunk'
[dbsrgits/DBIx-Class.git] / t / 85utf8.t
CommitLineData
70350518 1use strict;
55087b99 2use warnings;
e59c17fe 3
70350518 4use Test::More;
d38cd95c 5use Test::Warn;
70350518 6use lib qw(t/lib);
7use DBICTest;
e59c17fe 8
7146f619 9warning_like (
10 sub {
11 package A::Comp;
12 use base 'DBIx::Class';
13 sub store_column { shift->next::method (@_) };
14 1;
15
16 package A::Test;
17 use base 'DBIx::Class::Core';
18 __PACKAGE__->load_components(qw(UTF8Columns +A::Comp));
19 1;
20 },
21 qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding store_column \(A::Comp\)/,
22 'incorrect order warning issued',
23);
d38cd95c 24
a47e1233 25my $schema = DBICTest->init_schema();
404939a4 26DBICTest::Schema::CD->load_components('UTF8Columns');
27DBICTest::Schema::CD->utf8_columns('title');
70350518 28Class::C3->reinitialize();
29
a786c458 30my $cd = $schema->resultset('CD')->create( { artist => 1, title => "weird\x{466}stuff", year => '2048' } );
337c98ef 31
55087b99 32ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
a786c458 33ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store title without utf8' );
34
55087b99 35ok(! utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
a786c458 36ok(! utf8::is_utf8( $cd->{_column_data}{year} ), 'store year without utf8' );
337c98ef 37
a786c458 38$cd->title('nonunicode');
39ok(! utf8::is_utf8( $cd->title ), 'got title without utf8 flag' );
55087b99 40ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
337c98ef 41
1d0057bd 42
43my $v_utf8 = "\x{219}";
44
45$cd->update ({ title => $v_utf8 });
46$cd->title($v_utf8);
47ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
48
49$cd->update ({ title => $v_utf8 });
50$cd->title('something_else');
51ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
db087eb1 52
53TODO: {
54 local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
55 $cd = $schema->resultset('CD')->find ({ title => $v_utf8 }, { select => 'title', as => 'name' });
55087b99 56 ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');
db087eb1 57}
58
55087b99 59done_testing;