remove alignment mark on base64 md5
[dbsrgits/DBIx-Class.git] / t / 85utf8.t
CommitLineData
70350518 1use strict;
2use warnings;
e59c17fe 3
70350518 4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
e59c17fe 7
a47e1233 8my $schema = DBICTest->init_schema();
e59c17fe 9
337c98ef 10if ($] <= 5.008000) {
11
12 eval 'use Encode; 1' or plan skip_all => 'Need Encode run this test';
13
14} else {
15
16 eval 'use utf8; 1' or plan skip_all => 'Need utf8 run this test';
17}
e59c17fe 18
db087eb1 19plan tests => 6;
e59c17fe 20
404939a4 21DBICTest::Schema::CD->load_components('UTF8Columns');
22DBICTest::Schema::CD->utf8_columns('title');
70350518 23Class::C3->reinitialize();
24
db087eb1 25my $cd = $schema->resultset('CD')->create( { artist => 1, title => 'øni', year => '2048' } );
70350518 26my $utf8_char = 'uniuni';
e59c17fe 27
337c98ef 28
db087eb1 29ok( _is_utf8( $cd->title ), 'got title with utf8 flag' );
30ok(! _is_utf8( $cd->year ), 'got year without utf8 flag' );
337c98ef 31
db087eb1 32_force_utf8($utf8_char);
33$cd->title($utf8_char);
34ok(! _is_utf8( $cd->{_column_data}{title} ), 'store utf8-less chars' );
337c98ef 35
1d0057bd 36
37my $v_utf8 = "\x{219}";
38
39$cd->update ({ title => $v_utf8 });
40$cd->title($v_utf8);
41ok( !$cd->is_column_changed('title'), 'column is not dirty after setting the same unicode value' );
42
43$cd->update ({ title => $v_utf8 });
44$cd->title('something_else');
45ok( $cd->is_column_changed('title'), 'column is dirty after setting to something completely different');
db087eb1 46
47TODO: {
48 local $TODO = 'There is currently no way to propagate aliases to inflate_result()';
49 $cd = $schema->resultset('CD')->find ({ title => $v_utf8 }, { select => 'title', as => 'name' });
50 ok (_is_utf8( $cd->get_column ('name') ), 'utf8 flag propagates via as');
51}
52
53
54sub _force_utf8 {
55 if ($] <= 5.008000) {
56 Encode::_utf8_on ($_[0]);
57 }
58 else {
59 utf8::decode ($_[0]);
60 }
61}
62
63sub _is_utf8 {
64 if ($] <= 5.008000) {
65 return Encode::is_utf8 (shift);
66 }
67 else {
68 return utf8::is_utf8 (shift);
69 }
70}