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 for (@{mro::get_linear_isa ('A::Test1')} ) {
41 $test1_mro->{$_} = $idx++;
44 cmp_ok ($test1_mro->{'A::SubComp'}, '<', $test1_mro->{'A::Comp'}, 'mro of Test1 correct (A::SubComp before A::Comp)' );
45 cmp_ok ($test1_mro->{'A::Comp'}, '<', $test1_mro->{'DBIx::Class::UTF8Columns'}, 'mro of Test1 correct (A::Comp before UTF8Col)' );
46 cmp_ok ($test1_mro->{'DBIx::Class::UTF8Columns'}, '<', $test1_mro->{'DBIx::Class::Core'}, 'mro of Test1 correct (UTF8Col before Core)' );
47 cmp_ok ($test1_mro->{'DBIx::Class::Core'}, '<', $test1_mro->{'DBIx::Class::Row'}, 'mro of Test1 correct (Core before Row)' );
52 use base 'DBIx::Class::Core';
53 __PACKAGE__->load_components(qw(UTF8Columns +A::Comp));
54 sub store_column { shift->next::method (@_) };
57 [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::Comp\)/],
58 'incorrect order warning issued (violator defines)',
64 use base 'DBIx::Class::Core';
65 __PACKAGE__->load_components(qw(UTF8Columns +A::SubComp));
66 sub store_column { shift->next::method (@_) };
69 [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding 'store_column' \(A::SubComp \(via A::Comp\)\)/],
70 'incorrect order warning issued (violator inherits)',
73 my $schema = DBICTest->init_schema();
74 DBICTest::Schema::CD->load_components('UTF8Columns');
75 DBICTest::Schema::CD->utf8_columns('title');
76 Class::C3->reinitialize();
78 # as per http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm#utf8
79 binmode (Test::More->builder->$_, ':utf8') for qw/output failure_output todo_output/;
81 my $bytestream_title = my $utf8_title = "weird \x{466} stuff";
82 utf8::encode($bytestream_title);
83 cmp_ok ($bytestream_title, 'ne', $utf8_title, 'unicode/raw differ (sanity check)');
85 my $storage = $schema->storage;
87 my $debugobj = DBIC::DebugObj->new (\$sql, \@bind);
88 my ($orig_debug, $orig_debugobj) = ($storage->debug, $storage->debugobj);
89 $storage->debugobj ($debugobj);
92 my $cd = $schema->resultset('CD')->create( { artist => 1, title => $utf8_title, year => '2048' } );
94 $storage->debugobj ($orig_debugobj);
95 $storage->debug ($orig_debug);
97 # bind values are always alphabetically ordered by column, thus [1]
98 # the single quotes are an artefact of the debug-system
100 local $TODO = "This has been broken since rev 1191, Mar 2006";
101 is ($bind[1], "'$bytestream_title'", 'INSERT: raw bytes sent to the database');
104 # this should be using the cursor directly, no inflation/processing of any sort
105 my ($raw_db_title) = $schema->resultset('CD')
106 ->search ($cd->ident_condition)
107 ->get_column('title')
112 is ($raw_db_title, $bytestream_title, 'INSERT: raw bytes retrieved from database');
114 for my $reloaded (0, 1) {
115 my $test = $reloaded ? 'reloaded' : 'stored';
116 $cd->discard_changes if $reloaded;
118 ok( utf8::is_utf8( $cd->title ), "got $test title with utf8 flag" );
119 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), "in-object $test title without utf8" );
121 ok(! utf8::is_utf8( $cd->year ), "got $test year without utf8 flag" );
122 ok(! utf8::is_utf8( $cd->{_column_data}{year} ), "in-object $test year without utf8" );
125 $cd->title('nonunicode');
126 ok(! utf8::is_utf8( $cd->title ), 'update title without utf8 flag' );
127 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'store utf8-less title' );
130 $cd->discard_changes;
131 ok(! utf8::is_utf8( $cd->title ), 'reloaded title without utf8 flag' );
132 ok(! utf8::is_utf8( $cd->{_column_data}{title} ), 'reloaded utf8-less title' );
134 $bytestream_title = $utf8_title = "something \x{219} else";
135 utf8::encode($bytestream_title);
138 $storage->debugobj ($debugobj);
141 $cd->update ({ title => $utf8_title });
143 $storage->debugobj ($orig_debugobj);
144 $storage->debug ($orig_debug);
146 is ($bind[0], "'$bytestream_title'", 'UPDATE: raw bytes sent to the database');
147 ($raw_db_title) = $schema->resultset('CD')
148 ->search ($cd->ident_condition)
149 ->get_column('title')
153 is ($raw_db_title, $bytestream_title, 'UPDATE: raw bytes retrieved from database');
155 $cd->discard_changes;
156 $cd->title($utf8_title);
157 ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
159 $cd->update ({ title => $utf8_title });
160 $cd->title('something_else');
161 ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
164 local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
165 $cd = $schema->resultset('CD')->find ({ title => $utf8_title }, { select => 'title', as => 'name' });
166 ok (utf8::is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');