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