Fugly 5.8 workaround
[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 (
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 );
25
26 my $schema = DBICTest->init_schema();
27 DBICTest::Schema::CD->load_components('UTF8Columns');
28 DBICTest::Schema::CD->utf8_columns('title');
29 Class::C3->reinitialize();
30
31 my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'øni', year => '2048' } );
32 my $utf8_char = 'uniuni';
33
34
35 ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
36 ok(! utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
37
38 utf8::decode($utf8_char);
39 $cd->title($utf8_char);
40 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
41
42
43 my $v_utf8 = "\x{219}";
44
45 $cd->update ({ title => $v_utf8 });
46 $cd->title($v_utf8);
47 ok( !$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');
51 ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
52
53 TODO: {
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' });
56   ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');
57 }
58
59 done_testing;