Enhance warning test a bit (seems to fail on 5.8)
[dbsrgits/DBIx-Class.git] / t / 85utf8.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Warn;
6 use lib qw(t/lib);
7 use DBICTest;
8 use utf8;
9
10 warning_like (sub {
11
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 }, qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding store_column \(A::Comp\)/ );
22
23
24 my $schema = DBICTest->init_schema();
25
26 DBICTest::Schema::CD->load_components('UTF8Columns');
27 DBICTest::Schema::CD->utf8_columns('title');
28 Class::C3->reinitialize();
29
30 my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'øni', year => '2048' } );
31 my $utf8_char = 'uniuni';
32
33
34 ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
35 ok(! utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
36
37 utf8::decode($utf8_char);
38 $cd->title($utf8_char);
39 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
40
41
42 my $v_utf8 = "\x{219}";
43
44 $cd->update ({ title => $v_utf8 });
45 $cd->title($v_utf8);
46 ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
47
48 $cd->update ({ title => $v_utf8 });
49 $cd->title('something_else');
50 ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
51
52 TODO: {
53   local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
54   $cd = $schema->resultset('CD')->find ({ title => $v_utf8 }, { select => 'title', as => 'name' });
55   ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');
56 }
57
58 done_testing;