4 use DBIx::Class::Schema::Loader::Utils qw/slurp_file write_file/;
8 use dbixcsl_dumper_tests;
9 my $t = 'dbixcsl_dumper_tests';
13 # test loading external content
15 classname => 'DBICTest::Schema::_no_skip_load_external',
18 qr/package DBICTest::Schema::_no_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
23 # test skipping external content
25 classname => 'DBICTest::Schema::_skip_load_external',
27 skip_load_external => 1,
31 qr/package DBICTest::Schema::_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
39 my $config_file = File::Temp->new (UNLINK => 1);
41 print $config_file "{ skip_relationships => 1 }\n";
45 classname => 'DBICTest::Schema::_config_file',
46 options => { config_file => "$config_file" },
57 classname => 'DBICTest::Schema::_clashing_monikers',
58 test_db_class => 'make_dbictest_db_clashing_monikers',
59 error => qr/tables (?:"bar", "bars"|"bars", "bar") reduced to the same source moniker 'Bar'/,
65 # test naming => { column_accessors => 'preserve' }
66 # also test POD for unique constraint
68 classname => 'DBICTest::Schema::_preserve_column_accessors',
69 test_db_class => 'make_dbictest_db_with_unique',
70 options => { naming => { column_accessors => 'preserve' } },
78 qr/\n\n=head1 UNIQUE CONSTRAINTS\n\n=head2 C<baz_num_unique>\n\n=over 4\n\n=item \* L<\/baz_num>\n\n=back\n\n=cut\n\n__PACKAGE__->add_unique_constraint\("baz_num_unique"\, \["baz_num"\]\);\n\n/,
85 # test that rels are sorted
87 classname => 'DBICTest::Schema::_sorted_rels',
88 test_db_class => 'make_dbictest_db_with_unique',
91 qr/->might_have\(\n "quux".*->belongs_to\(\n "station_visited"/s,
99 classname => 'DBICTest::Schema::_sorted_uniqs',
100 test_db_class => 'make_dbictest_db_multi_unique',
103 qr/->add_unique_constraint\("uniq1_unique".*->add_unique_constraint\("uniq2_unique"/s,
110 # test naming => { monikers => 'plural' }
112 classname => 'DBICTest::Schema::_plural_monikers',
113 options => { naming => { monikers => 'plural' } },
116 qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Foos\n\n=cut\n\n/,
119 qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Bars\n\n=cut\n\n/,
126 # test naming => { monikers => 'singular' }
128 classname => 'DBICTest::Schema::_singular_monikers',
129 test_db_class => 'make_dbictest_db_plural_tables',
130 options => { naming => { monikers => 'singular' } },
133 qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Foo\n\n=cut\n\n/,
136 qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Bar\n\n=cut\n\n/,
143 # test naming => { monikers => 'preserve' }
145 classname => 'DBICTest::Schema::_preserve_monikers',
146 test_db_class => 'make_dbictest_db_plural_tables',
147 options => { naming => { monikers => 'preserve' } },
150 qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Foos\n\n=cut\n\n/,
153 qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Bars\n\n=cut\n\n/,
160 # test out the POD and "use utf8;"
162 classname => 'DBICTest::DumpMore::1',
164 custom_column_info => sub {
165 my ($table, $col, $info) = @_;
166 return +{ extra => { is_footext => 1 } } if $col eq 'footext';
168 result_base_class => 'My::ResultBaseClass',
169 additional_classes => 'TestAdditional',
170 additional_base_classes => 'TestAdditionalBase',
171 left_base_classes => 'TestLeftBase',
172 components => [ 'TestComponent', '+TestComponentFQN' ],
177 qr/package DBICTest::DumpMore::1;/,
182 qr/package DBICTest::DumpMore::1::Foo;/,
183 qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\nuse strict;\nuse warnings;\n\n/,
184 qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/,
185 qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/,
186 qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
187 qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
188 qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
189 qr/\n=head1 TABLE: C<foo>\n\n=cut\n\n__PACKAGE__->table\("foo"\);\n\n/,
190 qr/\n=head1 ACCESSORS\n\n/,
191 qr/\n=head2 fooid\n\n data_type: 'integer'\n is_auto_increment: 1\n is_nullable: 0\n\n/,
192 qr/\n=head2 footext\n\n data_type: 'text'\n default_value: 'footext'\n extra: {is_footext => 1}\n is_nullable: 1\n\n/,
193 qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/fooid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("fooid"\);\n/,
194 qr/\n=head1 RELATIONS\n\n/,
195 qr/\n=head2 bars\n\nType: has_many\n\nRelated object: L<DBICTest::DumpMore::1::Bar>\n\n=cut\n\n/,
200 qr/package DBICTest::DumpMore::1::Bar;/,
201 qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\nuse strict;\nuse warnings;\n\n/,
202 qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/,
203 qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/,
204 qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
205 qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
206 qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
207 qr/\n=head1 TABLE: C<bar>\n\n=cut\n\n__PACKAGE__->table\("bar"\);\n\n/,
208 qr/\n=head1 ACCESSORS\n\n/,
209 qr/\n=head2 barid\n\n data_type: 'integer'\n is_auto_increment: 1\n is_nullable: 0\n\n/,
210 qr/\n=head2 fooref\n\n data_type: 'integer'\n is_foreign_key: 1\n is_nullable: 1\n\n/,
211 qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/barid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("barid"\);\n/,
212 qr/\n=head1 RELATIONS\n\n/,
213 qr/\n=head2 fooref\n\nType: belongs_to\n\nRelated object: L<DBICTest::DumpMore::1::Foo>\n\n=cut\n\n/,
219 $t->append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX});
223 classname => 'DBICTest::DumpMore::1',
226 qr/package DBICTest::DumpMore::1;/,
230 qr/package DBICTest::DumpMore::1::Foo;/,
231 qr/->set_primary_key/,
232 qr/1;\n# XXX This is my custom content XXX/,
235 qr/package DBICTest::DumpMore::1::Bar;/,
236 qr/->set_primary_key/,
244 classname => 'DBICTest::DumpMore::1',
246 really_erase_my_files => 1
250 qr/package DBICTest::DumpMore::1;/,
254 qr/package DBICTest::DumpMore::1::Foo;/,
255 qr/->set_primary_key/,
259 qr/package DBICTest::DumpMore::1::Bar;/,
260 qr/->set_primary_key/,
266 qr/# XXX This is my custom content XXX/,
276 classname => 'DBICTest::DumpMore::1',
290 classname => 'DBICTest::DumpMore::1',
292 db_schema => 'foo_schema',
293 qualify_objects => 1,
297 qr/^db_schema is not supported on SQLite/,
301 qr/^\Q__PACKAGE__->table("foo_schema.foo");\E/m,
302 # the has_many relname should not have the schema in it!
303 qr/^__PACKAGE__->has_many\(\n "bars"/m,
308 # test qualify_objects
310 classname => 'DBICTest::DumpMore::1',
312 db_schema => [ 'foo_schema', 'bar_schema' ],
313 qualify_objects => 0,
317 qr/^db_schema is not supported on SQLite/,
321 # the table name should not include the db schema
322 qr/^\Q__PACKAGE__->table("foo");\E/m,
325 # the table name should not include the db schema
326 qr/^\Q__PACKAGE__->table("bar");\E/m,
333 classname => 'DBICTest::DumpMore::1',
335 db_schema => 'my_schema',
336 moniker_parts => ['_schema', 'name'],
337 qualify_objects => 1,
341 qr/^db_schema is not supported on SQLite/,
344 'Result/MySchemaFoo' => [
345 qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m,
346 # the has_many relname should not have the schema in it, but the class should
347 qr/^__PACKAGE__->has_many\(\n "bars",\n "DBICTest::DumpMore::1::Result::MySchemaBar"/m,
352 # test moniker_part_separator
354 classname => 'DBICTest::DumpMore::1',
356 db_schema => 'my_schema',
357 moniker_parts => ['_schema', 'name'],
358 moniker_part_separator => '::',
359 qualify_objects => 1,
363 qr/^db_schema is not supported on SQLite/,
366 'Result/MySchema/Foo' => [
367 qr/^package DBICTest::DumpMore::1::Result::MySchema::Foo;/m,
368 qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m,
369 # the has_many relname should not have the schema in it, but the class should
370 qr/^__PACKAGE__->has_many\(\n "bars",\n "DBICTest::DumpMore::1::Result::MySchema::Bar"/m,
375 # test moniker_part_separator + moniker_map + recursive constraints
377 classname => 'DBICTest::DumpMore::1',
379 db_schema => 'my_schema',
380 moniker_parts => ['_schema', 'name'],
381 moniker_part_separator => '::',
382 qualify_objects => 1,
385 my_schema => { foo => "MySchema::Floop" },
387 constraint => [ [ qr/my_schema/ => qr/foo|bar/ ] ],
388 exclude => [ [ qr/my_schema/ => qr/bar/ ] ],
390 generated_results => [qw(MySchema::Floop)],
392 qr/^db_schema is not supported on SQLite/,
395 'Result/MySchema/Floop' => [
396 qr/^package DBICTest::DumpMore::1::Result::MySchema::Floop;/m,
397 qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m,
401 'Result/MySchema/Floop' => [
402 # the bar table should not be loaded, so no relationship should exist
403 qr/^__PACKAGE__->has_many\(\n "bars"/m,
408 # test moniker_map + moniker_part_map
410 classname => 'DBICTest::DumpMore::1',
412 db_schema => 'my_schema',
413 moniker_parts => ['_schema', 'name'],
414 moniker_part_separator => '::',
415 moniker_part_map => {
417 my_schema => 'OtherSchema',
422 foo => 'MySchema::Floop',
425 qualify_objects => 1,
429 qr/^db_schema is not supported on SQLite/,
432 'Result/MySchema/Floop' => [
433 qr/^package DBICTest::DumpMore::1::Result::MySchema::Floop;/m,
434 qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m,
435 # the has_many relname should not have the schema in it, but the class should
436 qr/^__PACKAGE__->has_many\(\n "bars",\n "DBICTest::DumpMore::1::Result::OtherSchema::Bar"/m,
438 'Result/OtherSchema/Bar' => [
439 qr/^package DBICTest::DumpMore::1::Result::OtherSchema::Bar;/m,
440 qr/^\Q__PACKAGE__->table("my_schema.bar");\E/m,
441 # the has_many relname should not have the schema in it, but the class should
442 qr/^__PACKAGE__->belongs_to\(\n "fooref",\n "DBICTest::DumpMore::1::Result::MySchema::Floop"/m,
451 classname => 'DBICTest::DumpMore::1',
457 qr/package DBICTest::DumpMore::1;/,
458 qr/->load_namespaces/,
461 qr/package DBICTest::DumpMore::1::Result::Foo;/,
462 qr/->set_primary_key/,
466 qr/package DBICTest::DumpMore::1::Result::Bar;/,
467 qr/->set_primary_key/,
475 classname => 'DBICTest::DumpMore::1',
478 result_namespace => 'Res',
479 resultset_namespace => 'RSet',
480 default_resultset_class => 'RSetBase',
484 qr/package DBICTest::DumpMore::1;/,
485 qr/->load_namespaces/,
486 qr/result_namespace => "Res"/,
487 qr/resultset_namespace => "RSet"/,
488 qr/default_resultset_class => "RSetBase"/,
491 qr/package DBICTest::DumpMore::1::Res::Foo;/,
492 qr/->set_primary_key/,
496 qr/package DBICTest::DumpMore::1::Res::Bar;/,
497 qr/->set_primary_key/,
505 classname => 'DBICTest::DumpMore::1',
508 result_namespace => '+DBICTest::DumpMore::1::Res',
509 resultset_namespace => 'RSet',
510 default_resultset_class => 'RSetBase',
511 result_base_class => 'My::ResultBaseClass',
512 schema_base_class => 'My::SchemaBaseClass',
516 qr/package DBICTest::DumpMore::1;/,
517 qr/->load_namespaces/,
518 qr/result_namespace => "\+DBICTest::DumpMore::1::Res"/,
519 qr/resultset_namespace => "RSet"/,
520 qr/default_resultset_class => "RSetBase"/,
521 qr/use base 'My::SchemaBaseClass'/,
524 qr/package DBICTest::DumpMore::1::Res::Foo;/,
525 qr/use base 'My::ResultBaseClass'/,
526 qr/->set_primary_key/,
530 qr/package DBICTest::DumpMore::1::Res::Bar;/,
531 qr/use base 'My::ResultBaseClass'/,
532 qr/->set_primary_key/,
539 classname => 'DBICTest::DumpMore::1',
542 result_base_class => 'My::MissingResultBaseClass',
544 error => qr/My::MissingResultBaseClass.*is not installed/,
547 # test quote_char in connect_info for dbicdump
549 classname => 'DBICTest::DumpMore::1',
550 extra_connect_info => [
553 { quote_char => '"' },
557 # test fix for RT#70507 (end comment and 1; gets lost if left with actual
561 classname => 'DBICTest::DumpMore::Upgrade',
567 my $file = $t->class_file('DBICTest::DumpMore::Upgrade::Foo');
569 my $code = slurp_file $file;
571 $code =~ s/(?=# You can replace)/sub custom_method { 'custom_method works' }\n0;\n\n/;
573 write_file $file, $code;
576 classname => 'DBICTest::DumpMore::Upgrade',
580 generated_results => [qw(Foo Bar)],
583 qr/sub custom_method { 'custom_method works' }\n0;\n\n# You can replace.*\n1;\n\z/,
590 classname => 'DBICTest::DumpMore::DryRun',
594 generated_results => [qw(Foo Bar)],
597 my $schema_file = $t->class_file('DBICTest::DumpMore::DryRun');
598 ok( !-e $schema_file, "dry-run doesn't create file for schema class" );
599 (my $schema_dir = $schema_file) =~ s/\.pm\z//;
600 ok( !-e $schema_dir, "dry-run doesn't create subdirectory for schema namespace" );
602 # test omit_version (RT#92300)
604 classname => 'DBICTest::DumpMore::omit_version',
610 qr/^\# Created by DBIx::Class::Schema::Loader @ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/m,
615 # test omit_timestamp (RT#92300)
617 classname => 'DBICTest::DumpMore::omit_timestamp',
623 qr/^\# Created by DBIx::Class::Schema::Loader v[\d.]+$/m,
628 # test omit_version and omit_timestamp simultaneously (RT#92300)
630 classname => 'DBICTest::DumpMore::omit_both',
635 # A positive regex here would match the top comment
638 qr/^\# Created by DBIx::Class::Schema::Loader.+$/m,
644 # vim:et sts=4 sw=4 tw=0: