fix bug in UTF8Columns
[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;
55087b99 8use utf8;
e59c17fe 9
7146f619 10warning_like (
11 sub {
12 package A::Comp;
13 use base 'DBIx::Class';
14 sub store_column { shift->next::method (@_) };
15 1;
16
17 package A::Test;
18 use base 'DBIx::Class::Core';
19 __PACKAGE__->load_components(qw(UTF8Columns +A::Comp));
20 1;
21 },
22 qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding store_column \(A::Comp\)/,
23 'incorrect order warning issued',
24);
d38cd95c 25
a47e1233 26my $schema = DBICTest->init_schema();
404939a4 27DBICTest::Schema::CD->load_components('UTF8Columns');
28DBICTest::Schema::CD->utf8_columns('title');
70350518 29Class::C3->reinitialize();
30
db087eb1 31my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'øni', year => '2048' } );
70350518 32my $utf8_char = 'uniuni';
e59c17fe 33
337c98ef 34
55087b99 35ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
36ok(! utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
337c98ef 37
55087b99 38utf8::decode($utf8_char);
db087eb1 39$cd->title($utf8_char);
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;