fix POD links
[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
72ae8e40 9{
10 package A::Comp;
11 use base 'DBIx::Class';
12 sub store_column { shift->next::method (@_) };
13 1;
14}
15
16{
17 package A::SubComp;
18 use base 'A::Comp';
1415f198 19
72ae8e40 20 1;
21}
7146f619 22
72ae8e40 23warnings_are (
24 sub {
1415f198 25 package A::Test1;
72ae8e40 26 use base 'DBIx::Class::Core';
27 __PACKAGE__->load_components(qw(Core +A::Comp Ordered UTF8Columns));
1415f198 28 __PACKAGE__->load_components(qw(Ordered +A::SubComp Row UTF8Columns Core));
29 sub store_column { shift->next::method (@_) };
72ae8e40 30 1;
31 },
32 [],
33 'no spurious warnings issued',
34);
35
1415f198 36my $test1_mro;
72ae8e40 37my $idx = 0;
1415f198 38for (@{mro::get_linear_isa ('A::Test1')} ) {
39 $test1_mro->{$_} = $idx++;
72ae8e40 40}
41
1415f198 42cmp_ok ($test1_mro->{'A::SubComp'}, '<', $test1_mro->{'A::Comp'}, 'mro of Test1 correct (A::SubComp before A::Comp)' );
43cmp_ok ($test1_mro->{'A::Comp'}, '<', $test1_mro->{'DBIx::Class::UTF8Columns'}, 'mro of Test1 correct (A::Comp before UTF8Col)' );
44cmp_ok ($test1_mro->{'DBIx::Class::UTF8Columns'}, '<', $test1_mro->{'DBIx::Class::Core'}, 'mro of Test1 correct (UTF8Col before Core)' );
45cmp_ok ($test1_mro->{'DBIx::Class::Core'}, '<', $test1_mro->{'DBIx::Class::Row'}, 'mro of Test1 correct (Core before Row)' );
46
47
48warnings_like (
49 sub {
50 package A::Test2;
51 use base 'DBIx::Class::Core';
52 __PACKAGE__->load_components(qw(UTF8Columns +A::Comp));
53 sub store_column { shift->next::method (@_) };
54 1;
55 },
56 [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::Comp\)/],
57 'incorrect order warning issued (violator defines)',
58);
59
60warnings_like (
61 sub {
62 package A::Test3;
63 use base 'DBIx::Class::Core';
64 __PACKAGE__->load_components(qw(UTF8Columns +A::SubComp));
65 sub store_column { shift->next::method (@_) };
66 1;
67 },
68 [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::SubComp \(via A::Comp\)\)/],
69 'incorrect order warning issued (violator inherits)',
70);
72ae8e40 71
a47e1233 72my $schema = DBICTest->init_schema();
404939a4 73DBICTest::Schema::CD->load_components('UTF8Columns');
74DBICTest::Schema::CD->utf8_columns('title');
70350518 75Class::C3->reinitialize();
76
a786c458 77my $cd = $schema->resultset('CD')->create( { artist => 1, title => "weird\x{466}stuff", year => '2048' } );
337c98ef 78
55087b99 79ok( utf8::is_utf8( $cd->title ), 'got title with utf8 flag' );
a786c458 80ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store title without utf8' );
81
55087b99 82ok(! utf8::is_utf8( $cd->year ), 'got year without utf8 flag' );
a786c458 83ok(! utf8::is_utf8( $cd->{_column_data}{year} ), 'store year without utf8' );
337c98ef 84
a786c458 85$cd->title('nonunicode');
86ok(! utf8::is_utf8( $cd->title ), 'got title without utf8 flag' );
55087b99 87ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
337c98ef 88
1d0057bd 89
90my $v_utf8 = "\x{219}";
91
92$cd->update ({ title => $v_utf8 });
93$cd->title($v_utf8);
94ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
95
96$cd->update ({ title => $v_utf8 });
97$cd->title('something_else');
98ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
db087eb1 99
100TODO: {
101 local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
102 $cd = $schema->resultset('CD')->find ({ title => $v_utf8 }, { select => 'title', as => 'name' });
55087b99 103 ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');
db087eb1 104}
105
55087b99 106done_testing;