12 use base 'DBIx::Class';
13 sub store_column { shift->next::method (@_) };
26 local $ENV{DBIC_UTF8COLUMNS_OK} = 1;
28 use base 'DBIx::Class::Core';
29 __PACKAGE__->load_components(qw(Core +A::Comp Ordered UTF8Columns));
30 __PACKAGE__->load_components(qw(Ordered +A::SubComp Row UTF8Columns Core));
31 sub store_column { shift->next::method (@_) };
35 'no spurious warnings issued',
40 local $ENV{DBIC_UTF8COLUMNS_OK};
42 use base 'DBIx::Class::Core';
43 __PACKAGE__->load_components(qw(Core +A::Comp Ordered UTF8Columns));
44 __PACKAGE__->load_components(qw(Ordered +A::SubComp Row UTF8Columns Core));
45 sub store_column { shift->next::method (@_) };
48 [qr/Use of DBIx::Class::UTF8Columns is strongly discouraged/],
49 'issued deprecation warning',
55 for (@{mro::get_linear_isa ('A::Test1')} ) {
56 $test1_mro->{$_} = $idx++;
59 cmp_ok ($test1_mro->{'A::SubComp'}, '<', $test1_mro->{'A::Comp'}, 'mro of Test1 correct (A::SubComp before A::Comp)' );
60 cmp_ok ($test1_mro->{'A::Comp'}, '<', $test1_mro->{'DBIx::Class::UTF8Columns'}, 'mro of Test1 correct (A::Comp before UTF8Col)' );
61 cmp_ok ($test1_mro->{'DBIx::Class::UTF8Columns'}, '<', $test1_mro->{'DBIx::Class::Core'}, 'mro of Test1 correct (UTF8Col before Core)' );
62 cmp_ok ($test1_mro->{'DBIx::Class::Core'}, '<', $test1_mro->{'DBIx::Class::Row'}, 'mro of Test1 correct (Core before Row)' );
67 use base 'DBIx::Class::Core';
68 __PACKAGE__->load_components(qw(UTF8Columns +A::Comp));
69 sub store_column { shift->next::method (@_) };
72 [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::Comp\)/],
73 'incorrect order warning issued (violator defines)',
79 use base 'DBIx::Class::Core';
80 __PACKAGE__->load_components(qw(UTF8Columns +A::SubComp));
81 sub store_column { shift->next::method (@_) };
84 [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::SubComp \(via A::Comp\)\)/],
85 'incorrect order warning issued (violator inherits)',
88 my $schema = DBICTest->init_schema();
89 DBICTest::Schema::CD->load_components('UTF8Columns');
90 DBICTest::Schema::CD->utf8_columns('title');
91 Class::C3->reinitialize();
93 # as per http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm#utf8
94 binmode (Test::More->builder->$_, ':utf8') for qw/output failure_output todo_output/;
96 my $bytestream_title = my $utf8_title = "weird \x{466} stuff";
97 utf8::encode($bytestream_title);
98 cmp_ok ($bytestream_title, 'ne', $utf8_title, 'unicode/raw differ (sanity check)');
100 my $storage = $schema->storage;
102 my $debugobj = DBIC::DebugObj->new (\$sql, \@bind);
103 my ($orig_debug, $orig_debugobj) = ($storage->debug, $storage->debugobj);
104 $storage->debugobj ($debugobj);
107 my $cd = $schema->resultset('CD')->create( { artist => 1, title => $utf8_title, year => '2048' } );
109 $storage->debugobj ($orig_debugobj);
110 $storage->debug ($orig_debug);
112 # bind values are always alphabetically ordered by column, thus [1]
113 # the single quotes are an artefact of the debug-system
115 local $TODO = "This has been broken since rev 1191, Mar 2006";
116 is ($bind[1], "'$bytestream_title'", 'INSERT: raw bytes sent to the database');
119 # this should be using the cursor directly, no inflation/processing of any sort
120 my ($raw_db_title) = $schema->resultset('CD')
121 ->search ($cd->ident_condition)
122 ->get_column('title')
127 is ($raw_db_title, $bytestream_title, 'INSERT: raw bytes retrieved from database');
129 for my $reloaded (0, 1) {
130 my $test = $reloaded ? 'reloaded' : 'stored';
131 $cd->discard_changes if $reloaded;
133 ok( utf8::is_utf8( $cd->title ), "got $test title with utf8 flag" );
134 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), "in-object $test title without utf8" );
136 ok(! utf8::is_utf8( $cd->year ), "got $test year without utf8 flag" );
137 ok(! utf8::is_utf8( $cd->{_column_data}{year} ), "in-object $test year without utf8" );
140 $cd->title('nonunicode');
141 ok(! utf8::is_utf8( $cd->title ), 'update title without utf8 flag' );
142 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less title' );
145 $cd->discard_changes;
146 ok(! utf8::is_utf8( $cd->title ), 'reloaded title without utf8 flag' );
147 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'reloaded utf8-less title' );
149 $bytestream_title = $utf8_title = "something \x{219} else";
150 utf8::encode($bytestream_title);
153 $storage->debugobj ($debugobj);
156 $cd->update ({ title => $utf8_title });
158 $storage->debugobj ($orig_debugobj);
159 $storage->debug ($orig_debug);
161 is ($bind[0], "'$bytestream_title'", 'UPDATE: raw bytes sent to the database');
162 ($raw_db_title) = $schema->resultset('CD')
163 ->search ($cd->ident_condition)
164 ->get_column('title')
168 is ($raw_db_title, $bytestream_title, 'UPDATE: raw bytes retrieved from database');
170 $cd->discard_changes;
171 $cd->title($utf8_title);
172 ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
174 $cd->update ({ title => $utf8_title });
175 $cd->title('something_else');
176 ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
179 local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
180 $cd = $schema->resultset('CD')->find ({ title => $utf8_title }, { select => 'title', as => 'name' });
181 ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');