Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
70350518 |
3 | use strict; |
55087b99 |
4 | use warnings; |
e59c17fe |
5 | |
70350518 |
6 | use Test::More; |
d38cd95c |
7 | use Test::Warn; |
c0329273 |
8 | |
70350518 |
9 | use DBICTest; |
e59c17fe |
10 | |
72ae8e40 |
11 | { |
12 | package A::Comp; |
13 | use base 'DBIx::Class'; |
14 | sub store_column { shift->next::method (@_) }; |
15 | 1; |
16 | } |
17 | |
18 | { |
19 | package A::SubComp; |
20 | use base 'A::Comp'; |
1415f198 |
21 | |
72ae8e40 |
22 | 1; |
23 | } |
7146f619 |
24 | |
72ae8e40 |
25 | warnings_are ( |
26 | sub { |
3c2a505c |
27 | local $ENV{DBIC_UTF8COLUMNS_OK} = 1; |
1415f198 |
28 | package A::Test1; |
72ae8e40 |
29 | use base 'DBIx::Class::Core'; |
30 | __PACKAGE__->load_components(qw(Core +A::Comp Ordered UTF8Columns)); |
1415f198 |
31 | __PACKAGE__->load_components(qw(Ordered +A::SubComp Row UTF8Columns Core)); |
32 | sub store_column { shift->next::method (@_) }; |
72ae8e40 |
33 | 1; |
34 | }, |
35 | [], |
36 | 'no spurious warnings issued', |
37 | ); |
38 | |
70c28808 |
39 | warnings_like ( |
40 | sub { |
eed5492f |
41 | local $ENV{DBIC_UTF8COLUMNS_OK}; |
70c28808 |
42 | package A::Test1Loud; |
43 | use base 'DBIx::Class::Core'; |
44 | __PACKAGE__->load_components(qw(Core +A::Comp Ordered UTF8Columns)); |
45 | __PACKAGE__->load_components(qw(Ordered +A::SubComp Row UTF8Columns Core)); |
46 | sub store_column { shift->next::method (@_) }; |
47 | 1; |
48 | }, |
49 | [qr/Use of DBIx::Class::UTF8Columns is strongly discouraged/], |
50 | 'issued deprecation warning', |
51 | ); |
52 | |
53 | |
1415f198 |
54 | my $test1_mro; |
72ae8e40 |
55 | my $idx = 0; |
1415f198 |
56 | for (@{mro::get_linear_isa ('A::Test1')} ) { |
57 | $test1_mro->{$_} = $idx++; |
72ae8e40 |
58 | } |
59 | |
1415f198 |
60 | cmp_ok ($test1_mro->{'A::SubComp'}, '<', $test1_mro->{'A::Comp'}, 'mro of Test1 correct (A::SubComp before A::Comp)' ); |
61 | cmp_ok ($test1_mro->{'A::Comp'}, '<', $test1_mro->{'DBIx::Class::UTF8Columns'}, 'mro of Test1 correct (A::Comp before UTF8Col)' ); |
62 | cmp_ok ($test1_mro->{'DBIx::Class::UTF8Columns'}, '<', $test1_mro->{'DBIx::Class::Core'}, 'mro of Test1 correct (UTF8Col before Core)' ); |
63 | cmp_ok ($test1_mro->{'DBIx::Class::Core'}, '<', $test1_mro->{'DBIx::Class::Row'}, 'mro of Test1 correct (Core before Row)' ); |
64 | |
1415f198 |
65 | warnings_like ( |
66 | sub { |
67 | package A::Test2; |
68 | use base 'DBIx::Class::Core'; |
69 | __PACKAGE__->load_components(qw(UTF8Columns +A::Comp)); |
70 | sub store_column { shift->next::method (@_) }; |
71 | 1; |
72 | }, |
73 | [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::Comp\)/], |
74 | 'incorrect order warning issued (violator defines)', |
75 | ); |
76 | |
77 | warnings_like ( |
78 | sub { |
79 | package A::Test3; |
80 | use base 'DBIx::Class::Core'; |
81 | __PACKAGE__->load_components(qw(UTF8Columns +A::SubComp)); |
82 | sub store_column { shift->next::method (@_) }; |
83 | 1; |
84 | }, |
85 | [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::SubComp \(via A::Comp\)\)/], |
86 | 'incorrect order warning issued (violator inherits)', |
87 | ); |
72ae8e40 |
88 | |
a47e1233 |
89 | my $schema = DBICTest->init_schema(); |
404939a4 |
90 | DBICTest::Schema::CD->load_components('UTF8Columns'); |
91 | DBICTest::Schema::CD->utf8_columns('title'); |
cc8ffd7b |
92 | Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO; |
70350518 |
93 | |
fed2c7d7 |
94 | # as per http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm#utf8 |
95 | binmode (Test::More->builder->$_, ':utf8') for qw/output failure_output todo_output/; |
cdd254a5 |
96 | |
97 | my $bytestream_title = my $utf8_title = "weird \x{466} stuff"; |
98 | utf8::encode($bytestream_title); |
99 | cmp_ok ($bytestream_title, 'ne', $utf8_title, 'unicode/raw differ (sanity check)'); |
100 | |
2cfc22dd |
101 | my $cd; |
4ca1fd6f |
102 | { |
cdd254a5 |
103 | local $TODO = "This has been broken since rev 1191, Mar 2006"; |
2cfc22dd |
104 | |
105 | $schema->is_executed_sql_bind( sub { |
106 | $cd = $schema->resultset('CD')->create( { artist => 1, title => $utf8_title, year => '2048' } ) |
107 | }, [[ |
108 | 'INSERT INTO cd ( artist, title, year) VALUES ( ?, ?, ? )', |
109 | [ { dbic_colname => "artist", sqlt_datatype => "integer" } |
110 | => 1 ], |
111 | [ { dbic_colname => "title", sqlt_datatype => "varchar", sqlt_size => 100 } |
112 | => $bytestream_title ], |
113 | [ { dbic_colname => "year", sqlt_datatype => "varchar", sqlt_size => 100 } |
114 | => 2048 ], |
115 | ]], 'INSERT: raw bytes sent to the database' ); |
116 | }; |
cdd254a5 |
117 | |
118 | # this should be using the cursor directly, no inflation/processing of any sort |
119 | my ($raw_db_title) = $schema->resultset('CD') |
120 | ->search ($cd->ident_condition) |
121 | ->get_column('title') |
122 | ->_resultset |
123 | ->cursor |
124 | ->next; |
125 | |
126 | is ($raw_db_title, $bytestream_title, 'INSERT: raw bytes retrieved from database'); |
127 | |
128 | for my $reloaded (0, 1) { |
129 | my $test = $reloaded ? 'reloaded' : 'stored'; |
130 | $cd->discard_changes if $reloaded; |
1d0057bd |
131 | |
cdd254a5 |
132 | ok( utf8::is_utf8( $cd->title ), "got $test title with utf8 flag" ); |
133 | ok(! utf8::is_utf8( $cd->{_column_data}{title} ), "in-object $test title without utf8" ); |
134 | |
135 | ok(! utf8::is_utf8( $cd->year ), "got $test year without utf8 flag" ); |
136 | ok(! utf8::is_utf8( $cd->{_column_data}{year} ), "in-object $test year without utf8" ); |
137 | } |
138 | |
139 | $cd->title('nonunicode'); |
140 | ok(! utf8::is_utf8( $cd->title ), 'update title without utf8 flag' ); |
141 | ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less title' ); |
142 | |
143 | $cd->update; |
144 | $cd->discard_changes; |
145 | ok(! utf8::is_utf8( $cd->title ), 'reloaded title without utf8 flag' ); |
146 | ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'reloaded utf8-less title' ); |
147 | |
148 | $bytestream_title = $utf8_title = "something \x{219} else"; |
149 | utf8::encode($bytestream_title); |
150 | |
2cfc22dd |
151 | $schema->is_executed_sql_bind( sub { |
152 | $cd->update ({ title => $utf8_title }); |
153 | }, [ |
154 | [ 'BEGIN' ], |
155 | [ |
156 | 'UPDATE cd SET title = ? WHERE cdid = ?', |
157 | [ { dbic_colname => "title", sqlt_datatype => "varchar", sqlt_size => 100 } |
158 | => $bytestream_title ], |
159 | [ { dbic_colname => "cdid", sqlt_datatype => "integer" } |
160 | => 6 ], |
161 | ], |
162 | [ 'COMMIT' ], |
163 | ], 'UPDATE: raw bytes sent to the database'); |
5cfb131d |
164 | |
cdd254a5 |
165 | ($raw_db_title) = $schema->resultset('CD') |
166 | ->search ($cd->ident_condition) |
167 | ->get_column('title') |
168 | ->_resultset |
169 | ->cursor |
170 | ->next; |
171 | is ($raw_db_title, $bytestream_title, 'UPDATE: raw bytes retrieved from database'); |
172 | |
173 | $cd->discard_changes; |
174 | $cd->title($utf8_title); |
1d0057bd |
175 | ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' ); |
176 | |
cdd254a5 |
177 | $cd->update ({ title => $utf8_title }); |
1d0057bd |
178 | $cd->title('something_else'); |
179 | ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different'); |
db087eb1 |
180 | |
4ca1fd6f |
181 | { |
db087eb1 |
182 | local $TODO = 'There is currently no way to propagate aliases to inflate_result()'; |
cdd254a5 |
183 | $cd = $schema->resultset('CD')->find ({ title => $utf8_title }, { select => 'title', as => 'name' }); |
55087b99 |
184 | ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as'); |
db087eb1 |
185 | } |
186 | |
55087b99 |
187 | done_testing; |