Commit | Line | Data |
605fcea8 |
1 | use strict; |
b564fc4b |
2 | use warnings; |
71130750 |
3 | use Test::More; |
b564fc4b |
4 | use DBIx::Class::Schema::Loader::Utils qw/slurp_file write_file/; |
5 | use namespace::clean; |
6 | use File::Temp (); |
71130750 |
7 | use lib qw(t/lib); |
8 | use dbixcsl_dumper_tests; |
9 | my $t = 'dbixcsl_dumper_tests'; |
a4187fdf |
10 | |
71130750 |
11 | $t->cleanup; |
a4187fdf |
12 | |
6dde4613 |
13 | # test loading external content |
71130750 |
14 | $t->dump_test( |
15 | classname => 'DBICTest::Schema::_no_skip_load_external', |
71130750 |
16 | regexes => { |
17 | Foo => [ |
f8c2ca5e |
18 | qr/package DBICTest::Schema::_no_skip_load_external::Foo;.*\nour \$skip_me = "bad mojo";\n1;/s |
6dde4613 |
19 | ], |
71130750 |
20 | }, |
6dde4613 |
21 | ); |
22 | |
23 | # test skipping external content |
71130750 |
24 | $t->dump_test( |
25 | classname => 'DBICTest::Schema::_skip_load_external', |
26 | options => { |
900195eb |
27 | skip_load_external => 1, |
71130750 |
28 | }, |
71130750 |
29 | neg_regexes => { |
30 | Foo => [ |
f8c2ca5e |
31 | qr/package DBICTest::Schema::_skip_load_external::Foo;.*\nour \$skip_me = "bad mojo";\n1;/s |
6dde4613 |
32 | ], |
71130750 |
33 | }, |
6dde4613 |
34 | ); |
35 | |
71130750 |
36 | $t->cleanup; |
73099af4 |
37 | # test config_file |
71130750 |
38 | { |
39 | my $config_file = File::Temp->new (UNLINK => 1); |
73099af4 |
40 | |
71130750 |
41 | print $config_file "{ skip_relationships => 1 }\n"; |
42 | close $config_file; |
73099af4 |
43 | |
71130750 |
44 | $t->dump_test( |
1a8fd949 |
45 | classname => 'DBICTest::Schema::_config_file', |
71130750 |
46 | options => { config_file => "$config_file" }, |
73099af4 |
47 | neg_regexes => { |
71130750 |
48 | Foo => [ |
49 | qr/has_many/, |
50 | ], |
73099af4 |
51 | }, |
71130750 |
52 | ); |
53 | } |
c9cf9b4d |
54 | |
71130750 |
55 | # proper exception |
56 | $t->dump_test( |
1a8fd949 |
57 | classname => 'DBICTest::Schema::_clashing_monikers', |
71130750 |
58 | test_db_class => 'make_dbictest_db_clashing_monikers', |
c4a69b87 |
59 | error => qr/tables (?:"bar", "bars"|"bars", "bar") reduced to the same source moniker 'Bar'/, |
c9cf9b4d |
60 | ); |
61 | |
c9cf9b4d |
62 | |
71130750 |
63 | $t->cleanup; |
c9cf9b4d |
64 | |
c0a0986f |
65 | # test naming => { column_accessors => 'preserve' } |
8007f3a7 |
66 | # also test POD for unique constraint |
c0a0986f |
67 | $t->dump_test( |
68 | classname => 'DBICTest::Schema::_preserve_column_accessors', |
69 | test_db_class => 'make_dbictest_db_with_unique', |
70 | options => { naming => { column_accessors => 'preserve' } }, |
c0a0986f |
71 | neg_regexes => { |
72 | RouteChange => [ |
73 | qr/\baccessor\b/, |
74 | ], |
75 | }, |
8007f3a7 |
76 | regexes => { |
77 | Baz => [ |
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/, |
79 | ], |
80 | } |
c0a0986f |
81 | ); |
82 | |
83 | $t->cleanup; |
84 | |
b33d5949 |
85 | # test that rels are sorted |
86 | $t->dump_test( |
87 | classname => 'DBICTest::Schema::_sorted_rels', |
88 | test_db_class => 'make_dbictest_db_with_unique', |
b33d5949 |
89 | regexes => { |
90 | Baz => [ |
91 | qr/->might_have\(\n "quux".*->belongs_to\(\n "station_visited"/s, |
92 | ], |
93 | } |
94 | ); |
95 | |
96 | $t->cleanup; |
97 | |
6d358d58 |
98 | $t->dump_test( |
99 | classname => 'DBICTest::Schema::_sorted_uniqs', |
100 | test_db_class => 'make_dbictest_db_multi_unique', |
101 | regexes => { |
102 | Bar => [ |
103 | qr/->add_unique_constraint\("uniq1_unique".*->add_unique_constraint\("uniq2_unique"/s, |
104 | ], |
105 | }, |
106 | ); |
107 | |
108 | $t->cleanup; |
109 | |
c0a0986f |
110 | # test naming => { monikers => 'plural' } |
111 | $t->dump_test( |
112 | classname => 'DBICTest::Schema::_plural_monikers', |
113 | options => { naming => { monikers => 'plural' } }, |
c0a0986f |
114 | regexes => { |
115 | Foos => [ |
116 | qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Foos\n\n=cut\n\n/, |
117 | ], |
118 | Bars => [ |
119 | qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Bars\n\n=cut\n\n/, |
120 | ], |
121 | }, |
122 | ); |
123 | |
124 | $t->cleanup; |
125 | |
126 | # test naming => { monikers => 'singular' } |
127 | $t->dump_test( |
128 | classname => 'DBICTest::Schema::_singular_monikers', |
129 | test_db_class => 'make_dbictest_db_plural_tables', |
130 | options => { naming => { monikers => 'singular' } }, |
c0a0986f |
131 | regexes => { |
132 | Foo => [ |
133 | qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Foo\n\n=cut\n\n/, |
134 | ], |
135 | Bar => [ |
136 | qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Bar\n\n=cut\n\n/, |
137 | ], |
138 | }, |
139 | ); |
140 | |
141 | $t->cleanup; |
142 | |
143 | # test naming => { monikers => 'preserve' } |
144 | $t->dump_test( |
145 | classname => 'DBICTest::Schema::_preserve_monikers', |
146 | test_db_class => 'make_dbictest_db_plural_tables', |
147 | options => { naming => { monikers => 'preserve' } }, |
c0a0986f |
148 | regexes => { |
149 | Foos => [ |
150 | qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Foos\n\n=cut\n\n/, |
151 | ], |
152 | Bars => [ |
153 | qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Bars\n\n=cut\n\n/, |
154 | ], |
155 | }, |
156 | ); |
157 | |
158 | $t->cleanup; |
159 | |
c6c8787c |
160 | # test out the POD and "use utf8;" |
71130750 |
161 | $t->dump_test( |
162 | classname => 'DBICTest::DumpMore::1', |
163 | options => { |
164 | custom_column_info => sub { |
165 | my ($table, $col, $info) = @_; |
166 | return +{ extra => { is_footext => 1 } } if $col eq 'footext'; |
06e06245 |
167 | }, |
a8acb698 |
168 | result_base_class => 'My::ResultBaseClass', |
06e06245 |
169 | additional_classes => 'TestAdditional', |
170 | additional_base_classes => 'TestAdditionalBase', |
171 | left_base_classes => 'TestLeftBase', |
172 | components => [ 'TestComponent', '+TestComponentFQN' ], |
71130750 |
173 | }, |
71130750 |
174 | regexes => { |
175 | schema => [ |
c6c8787c |
176 | qr/^use utf8;\n/, |
71130750 |
177 | qr/package DBICTest::DumpMore::1;/, |
178 | qr/->load_classes/, |
c9cf9b4d |
179 | ], |
71130750 |
180 | Foo => [ |
c6c8787c |
181 | qr/^use utf8;\n/, |
71130750 |
182 | qr/package DBICTest::DumpMore::1::Foo;/, |
61c8fd6d |
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/, |
017d9734 |
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/, |
8007f3a7 |
189 | qr/\n=head1 TABLE: C<foo>\n\n=cut\n\n__PACKAGE__->table\("foo"\);\n\n/, |
06e06245 |
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/, |
7c304e59 |
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/, |
8007f3a7 |
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/, |
06e06245 |
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/, |
71130750 |
196 | qr/1;\n$/, |
c9cf9b4d |
197 | ], |
71130750 |
198 | Bar => [ |
c6c8787c |
199 | qr/^use utf8;\n/, |
71130750 |
200 | qr/package DBICTest::DumpMore::1::Bar;/, |
61c8fd6d |
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/, |
017d9734 |
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/, |
8007f3a7 |
207 | qr/\n=head1 TABLE: C<bar>\n\n=cut\n\n__PACKAGE__->table\("bar"\);\n\n/, |
06e06245 |
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/, |
8007f3a7 |
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/, |
06e06245 |
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/, |
214 | qr/\n1;\n$/, |
c9cf9b4d |
215 | ], |
71130750 |
216 | }, |
c9cf9b4d |
217 | ); |
218 | |
71130750 |
219 | $t->append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX}); |
f812ef60 |
220 | |
9de8c789 |
221 | |
71130750 |
222 | $t->dump_test( |
223 | classname => 'DBICTest::DumpMore::1', |
71130750 |
224 | regexes => { |
225 | schema => [ |
226 | qr/package DBICTest::DumpMore::1;/, |
227 | qr/->load_classes/, |
a4187fdf |
228 | ], |
71130750 |
229 | Foo => [ |
230 | qr/package DBICTest::DumpMore::1::Foo;/, |
231 | qr/->set_primary_key/, |
232 | qr/1;\n# XXX This is my custom content XXX/, |
233 | ], |
234 | Bar => [ |
235 | qr/package DBICTest::DumpMore::1::Bar;/, |
236 | qr/->set_primary_key/, |
237 | qr/1;\n$/, |
238 | ], |
239 | }, |
a4187fdf |
240 | ); |
241 | |
a4187fdf |
242 | |
71130750 |
243 | $t->dump_test( |
244 | classname => 'DBICTest::DumpMore::1', |
245 | options => { |
246 | really_erase_my_files => 1 |
247 | }, |
71130750 |
248 | regexes => { |
249 | schema => [ |
250 | qr/package DBICTest::DumpMore::1;/, |
251 | qr/->load_classes/, |
a4187fdf |
252 | ], |
71130750 |
253 | Foo => [ |
254 | qr/package DBICTest::DumpMore::1::Foo;/, |
255 | qr/->set_primary_key/, |
256 | qr/1;\n$/, |
a4187fdf |
257 | ], |
71130750 |
258 | Bar => [ |
259 | qr/package DBICTest::DumpMore::1::Bar;/, |
260 | qr/->set_primary_key/, |
261 | qr/1;\n$/, |
262 | ], |
263 | }, |
264 | neg_regexes => { |
265 | Foo => [ |
266 | qr/# XXX This is my custom content XXX/, |
267 | ], |
268 | }, |
492dce8d |
269 | ); |
270 | |
eac5494b |
271 | |
71130750 |
272 | $t->cleanup; |
273 | |
274 | # test namespaces |
275 | $t->dump_test( |
276 | classname => 'DBICTest::DumpMore::1', |
277 | options => { |
278 | use_namespaces => 1, |
279 | generate_pod => 0 |
280 | }, |
71130750 |
281 | neg_regexes => { |
282 | 'Result/Foo' => [ |
283 | qr/^=/m, |
492dce8d |
284 | ], |
71130750 |
285 | }, |
a4187fdf |
286 | ); |
605fcea8 |
287 | |
eac5494b |
288 | |
71130750 |
289 | $t->dump_test( |
290 | classname => 'DBICTest::DumpMore::1', |
291 | options => { |
292 | db_schema => 'foo_schema', |
293 | qualify_objects => 1, |
294 | use_namespaces => 1 |
295 | }, |
c4a69b87 |
296 | warnings => [ |
297 | qr/^db_schema is not supported on SQLite/, |
298 | ], |
71130750 |
299 | regexes => { |
300 | 'Result/Foo' => [ |
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, |
69219349 |
304 | ], |
71130750 |
305 | }, |
69219349 |
306 | ); |
307 | |
9890b10c |
308 | # test qualify_objects |
309 | $t->dump_test( |
310 | classname => 'DBICTest::DumpMore::1', |
311 | options => { |
312 | db_schema => [ 'foo_schema', 'bar_schema' ], |
313 | qualify_objects => 0, |
314 | use_namespaces => 1, |
315 | }, |
316 | warnings => [ |
317 | qr/^db_schema is not supported on SQLite/, |
318 | ], |
319 | regexes => { |
320 | 'Result/Foo' => [ |
321 | # the table name should not include the db schema |
322 | qr/^\Q__PACKAGE__->table("foo");\E/m, |
323 | ], |
324 | 'Result/Bar' => [ |
325 | # the table name should not include the db schema |
326 | qr/^\Q__PACKAGE__->table("bar");\E/m, |
327 | ], |
328 | }, |
329 | ); |
330 | |
c4a69b87 |
331 | # test moniker_parts |
332 | $t->dump_test( |
333 | classname => 'DBICTest::DumpMore::1', |
334 | options => { |
335 | db_schema => 'my_schema', |
336 | moniker_parts => ['_schema', 'name'], |
337 | qualify_objects => 1, |
338 | use_namespaces => 1, |
339 | }, |
340 | warnings => [ |
341 | qr/^db_schema is not supported on SQLite/, |
342 | ], |
343 | regexes => { |
344 | 'Result/MySchemaFoo' => [ |
345 | qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m, |
848731a7 |
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, |
348 | ], |
349 | }, |
350 | ); |
351 | |
352 | # test moniker_part_separator |
353 | $t->dump_test( |
354 | classname => 'DBICTest::DumpMore::1', |
355 | options => { |
356 | db_schema => 'my_schema', |
357 | moniker_parts => ['_schema', 'name'], |
358 | moniker_part_separator => '::', |
359 | qualify_objects => 1, |
360 | use_namespaces => 1, |
361 | }, |
362 | warnings => [ |
363 | qr/^db_schema is not supported on SQLite/, |
364 | ], |
365 | regexes => { |
366 | 'Result/MySchema/Foo' => [ |
76e9a92a |
367 | qr/^package DBICTest::DumpMore::1::Result::MySchema::Foo;/m, |
848731a7 |
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, |
c4a69b87 |
371 | ], |
372 | }, |
373 | ); |
374 | |
b187901e |
375 | # test moniker_part_separator + moniker_map + recursive constraints |
fc972571 |
376 | $t->dump_test( |
377 | classname => 'DBICTest::DumpMore::1', |
378 | options => { |
379 | db_schema => 'my_schema', |
380 | moniker_parts => ['_schema', 'name'], |
381 | moniker_part_separator => '::', |
382 | qualify_objects => 1, |
383 | use_namespaces => 1, |
384 | moniker_map => { |
385 | my_schema => { foo => "MySchema::Floop" }, |
b187901e |
386 | }, |
387 | constraint => [ [ qr/my_schema/ => qr/foo|bar/ ] ], |
388 | exclude => [ [ qr/my_schema/ => qr/bar/ ] ], |
fc972571 |
389 | }, |
f56e3f73 |
390 | generated_results => [qw(MySchema::Floop)], |
fc972571 |
391 | warnings => [ |
392 | qr/^db_schema is not supported on SQLite/, |
393 | ], |
394 | regexes => { |
395 | 'Result/MySchema/Floop' => [ |
76e9a92a |
396 | qr/^package DBICTest::DumpMore::1::Result::MySchema::Floop;/m, |
fc972571 |
397 | qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m, |
b187901e |
398 | ], |
399 | }, |
400 | neg_regexes => { |
401 | 'Result/MySchema/Floop' => [ |
402 | # the bar table should not be loaded, so no relationship should exist |
fc972571 |
403 | qr/^__PACKAGE__->has_many\(\n "bars"/m, |
404 | ], |
405 | }, |
406 | ); |
407 | |
392d1c58 |
408 | # test moniker_map + moniker_part_map |
409 | $t->dump_test( |
410 | classname => 'DBICTest::DumpMore::1', |
411 | options => { |
412 | db_schema => 'my_schema', |
413 | moniker_parts => ['_schema', 'name'], |
414 | moniker_part_separator => '::', |
415 | moniker_part_map => { |
416 | _schema => { |
417 | my_schema => 'OtherSchema', |
418 | }, |
419 | }, |
420 | moniker_map => { |
421 | my_schema => { |
422 | foo => 'MySchema::Floop', |
423 | }, |
424 | }, |
425 | qualify_objects => 1, |
426 | use_namespaces => 1, |
427 | }, |
428 | warnings => [ |
429 | qr/^db_schema is not supported on SQLite/, |
430 | ], |
431 | regexes => { |
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, |
437 | ], |
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, |
443 | ], |
444 | |
445 | }, |
446 | ); |
447 | |
448 | |
449 | |
71130750 |
450 | $t->dump_test( |
451 | classname => 'DBICTest::DumpMore::1', |
452 | options => { |
453 | use_namespaces => 1 |
454 | }, |
71130750 |
455 | regexes => { |
456 | schema => [ |
457 | qr/package DBICTest::DumpMore::1;/, |
458 | qr/->load_namespaces/, |
f44ecc2f |
459 | ], |
71130750 |
460 | 'Result/Foo' => [ |
461 | qr/package DBICTest::DumpMore::1::Result::Foo;/, |
462 | qr/->set_primary_key/, |
463 | qr/1;\n$/, |
464 | ], |
465 | 'Result/Bar' => [ |
466 | qr/package DBICTest::DumpMore::1::Result::Bar;/, |
467 | qr/->set_primary_key/, |
468 | qr/1;\n$/, |
469 | ], |
470 | }, |
f44ecc2f |
471 | ); |
472 | |
eac5494b |
473 | |
71130750 |
474 | $t->dump_test( |
475 | classname => 'DBICTest::DumpMore::1', |
476 | options => { |
477 | use_namespaces => 1, |
478 | result_namespace => 'Res', |
479 | resultset_namespace => 'RSet', |
480 | default_resultset_class => 'RSetBase', |
481 | }, |
71130750 |
482 | regexes => { |
483 | schema => [ |
484 | qr/package DBICTest::DumpMore::1;/, |
485 | qr/->load_namespaces/, |
eb28f95b |
486 | qr/result_namespace => "Res"/, |
487 | qr/resultset_namespace => "RSet"/, |
488 | qr/default_resultset_class => "RSetBase"/, |
f44ecc2f |
489 | ], |
71130750 |
490 | 'Res/Foo' => [ |
491 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
492 | qr/->set_primary_key/, |
493 | qr/1;\n$/, |
494 | ], |
495 | 'Res/Bar' => [ |
496 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
497 | qr/->set_primary_key/, |
498 | qr/1;\n$/, |
499 | ], |
500 | }, |
f44ecc2f |
501 | ); |
502 | |
eac5494b |
503 | |
71130750 |
504 | $t->dump_test( |
505 | classname => 'DBICTest::DumpMore::1', |
506 | options => { |
507 | use_namespaces => 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', |
513 | }, |
71130750 |
514 | regexes => { |
515 | schema => [ |
516 | qr/package DBICTest::DumpMore::1;/, |
517 | qr/->load_namespaces/, |
eb28f95b |
518 | qr/result_namespace => "\+DBICTest::DumpMore::1::Res"/, |
519 | qr/resultset_namespace => "RSet"/, |
520 | qr/default_resultset_class => "RSetBase"/, |
71130750 |
521 | qr/use base 'My::SchemaBaseClass'/, |
f44ecc2f |
522 | ], |
71130750 |
523 | 'Res/Foo' => [ |
524 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
525 | qr/use base 'My::ResultBaseClass'/, |
526 | qr/->set_primary_key/, |
527 | qr/1;\n$/, |
528 | ], |
529 | 'Res/Bar' => [ |
530 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
531 | qr/use base 'My::ResultBaseClass'/, |
532 | qr/->set_primary_key/, |
533 | qr/1;\n$/, |
534 | ], |
535 | }, |
f44ecc2f |
536 | ); |
c634fde9 |
537 | |
71130750 |
538 | $t->dump_test( |
539 | classname => 'DBICTest::DumpMore::1', |
540 | options => { |
541 | use_namespaces => 1, |
542 | result_base_class => 'My::MissingResultBaseClass', |
543 | }, |
544 | error => qr/My::MissingResultBaseClass.*is not installed/, |
8048320c |
545 | ); |
f44ecc2f |
546 | |
667f1a0b |
547 | # test quote_char in connect_info for dbicdump |
548 | $t->dump_test( |
549 | classname => 'DBICTest::DumpMore::1', |
550 | extra_connect_info => [ |
551 | '', |
552 | '', |
553 | { quote_char => '"' }, |
554 | ], |
667f1a0b |
555 | ); |
556 | |
b564fc4b |
557 | # test fix for RT#70507 (end comment and 1; gets lost if left with actual |
558 | # custom content) |
559 | |
560 | $t->dump_test( |
561 | classname => 'DBICTest::DumpMore::Upgrade', |
562 | options => { |
563 | use_namespaces => 0, |
564 | }, |
565 | ); |
566 | |
567 | my $file = $t->class_file('DBICTest::DumpMore::Upgrade::Foo'); |
568 | |
569 | my $code = slurp_file $file; |
570 | |
571 | $code =~ s/(?=# You can replace)/sub custom_method { 'custom_method works' }\n0;\n\n/; |
572 | |
573 | write_file $file, $code; |
574 | |
575 | $t->dump_test( |
576 | classname => 'DBICTest::DumpMore::Upgrade', |
577 | options => { |
578 | use_namespaces => 1, |
579 | }, |
f56e3f73 |
580 | generated_results => [qw(Foo Bar)], |
b564fc4b |
581 | regexes => { |
582 | 'Result/Foo' => [ |
7c304e59 |
583 | qr/sub custom_method \{ 'custom_method works' \}\n0;\n\n# You can replace.*\n1;\n\z/, |
b564fc4b |
584 | ], |
585 | }, |
586 | ); |
587 | |
28310f24 |
588 | # test dry-run mode |
589 | $t->dump_test( |
590 | classname => 'DBICTest::DumpMore::DryRun', |
591 | options => { |
592 | dry_run => 1, |
593 | }, |
f56e3f73 |
594 | generated_results => [qw(Foo Bar)], |
28310f24 |
595 | ); |
596 | |
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" ); |
601 | |
c43d9f47 |
602 | # test omit_version (RT#92300) |
603 | $t->dump_test( |
604 | classname => 'DBICTest::DumpMore::omit_version', |
605 | options => { |
606 | omit_version => 1, |
607 | }, |
608 | regexes => { |
609 | Foo => [ |
610 | qr/^\# Created by DBIx::Class::Schema::Loader @ \d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$/m, |
611 | ], |
612 | }, |
613 | ); |
614 | |
615 | # test omit_timestamp (RT#92300) |
616 | $t->dump_test( |
617 | classname => 'DBICTest::DumpMore::omit_timestamp', |
618 | options => { |
619 | omit_timestamp => 1, |
620 | }, |
621 | regexes => { |
622 | Foo => [ |
623 | qr/^\# Created by DBIx::Class::Schema::Loader v[\d.]+$/m, |
624 | ], |
625 | }, |
626 | ); |
627 | |
628 | # test omit_version and omit_timestamp simultaneously (RT#92300) |
629 | $t->dump_test( |
630 | classname => 'DBICTest::DumpMore::omit_both', |
631 | options => { |
632 | omit_version => 1, |
633 | omit_timestamp => 1, |
634 | }, |
635 | # A positive regex here would match the top comment |
636 | neg_regexes => { |
637 | Foo => [ |
638 | qr/^\# Created by DBIx::Class::Schema::Loader.+$/m, |
639 | ], |
640 | }, |
641 | ); |
642 | |
d27f2b7b |
643 | done_testing; |
c0a0986f |
644 | # vim:et sts=4 sw=4 tw=0: |