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 => [ |
18 | qr/package DBICTest::Schema::_no_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/ |
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 => [ |
31 | qr/package DBICTest::Schema::_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/ |
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/, |
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 | }, |
390 | warnings => [ |
391 | qr/^db_schema is not supported on SQLite/, |
392 | ], |
393 | regexes => { |
394 | 'Result/MySchema/Floop' => [ |
76e9a92a |
395 | qr/^package DBICTest::DumpMore::1::Result::MySchema::Floop;/m, |
fc972571 |
396 | qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m, |
b187901e |
397 | ], |
398 | }, |
399 | neg_regexes => { |
400 | 'Result/MySchema/Floop' => [ |
401 | # the bar table should not be loaded, so no relationship should exist |
fc972571 |
402 | qr/^__PACKAGE__->has_many\(\n "bars"/m, |
403 | ], |
404 | }, |
405 | ); |
406 | |
392d1c58 |
407 | # test moniker_map + moniker_part_map |
408 | $t->dump_test( |
409 | classname => 'DBICTest::DumpMore::1', |
410 | options => { |
411 | db_schema => 'my_schema', |
412 | moniker_parts => ['_schema', 'name'], |
413 | moniker_part_separator => '::', |
414 | moniker_part_map => { |
415 | _schema => { |
416 | my_schema => 'OtherSchema', |
417 | }, |
418 | }, |
419 | moniker_map => { |
420 | my_schema => { |
421 | foo => 'MySchema::Floop', |
422 | }, |
423 | }, |
424 | qualify_objects => 1, |
425 | use_namespaces => 1, |
426 | }, |
427 | warnings => [ |
428 | qr/^db_schema is not supported on SQLite/, |
429 | ], |
430 | regexes => { |
431 | 'Result/MySchema/Floop' => [ |
432 | qr/^package DBICTest::DumpMore::1::Result::MySchema::Floop;/m, |
433 | qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m, |
434 | # the has_many relname should not have the schema in it, but the class should |
435 | qr/^__PACKAGE__->has_many\(\n "bars",\n "DBICTest::DumpMore::1::Result::OtherSchema::Bar"/m, |
436 | ], |
437 | 'Result/OtherSchema/Bar' => [ |
438 | qr/^package DBICTest::DumpMore::1::Result::OtherSchema::Bar;/m, |
439 | qr/^\Q__PACKAGE__->table("my_schema.bar");\E/m, |
440 | # the has_many relname should not have the schema in it, but the class should |
441 | qr/^__PACKAGE__->belongs_to\(\n "fooref",\n "DBICTest::DumpMore::1::Result::MySchema::Floop"/m, |
442 | ], |
443 | |
444 | }, |
445 | ); |
446 | |
447 | |
448 | |
71130750 |
449 | $t->dump_test( |
450 | classname => 'DBICTest::DumpMore::1', |
451 | options => { |
452 | use_namespaces => 1 |
453 | }, |
71130750 |
454 | regexes => { |
455 | schema => [ |
456 | qr/package DBICTest::DumpMore::1;/, |
457 | qr/->load_namespaces/, |
f44ecc2f |
458 | ], |
71130750 |
459 | 'Result/Foo' => [ |
460 | qr/package DBICTest::DumpMore::1::Result::Foo;/, |
461 | qr/->set_primary_key/, |
462 | qr/1;\n$/, |
463 | ], |
464 | 'Result/Bar' => [ |
465 | qr/package DBICTest::DumpMore::1::Result::Bar;/, |
466 | qr/->set_primary_key/, |
467 | qr/1;\n$/, |
468 | ], |
469 | }, |
f44ecc2f |
470 | ); |
471 | |
eac5494b |
472 | |
71130750 |
473 | $t->dump_test( |
474 | classname => 'DBICTest::DumpMore::1', |
475 | options => { |
476 | use_namespaces => 1, |
477 | result_namespace => 'Res', |
478 | resultset_namespace => 'RSet', |
479 | default_resultset_class => 'RSetBase', |
480 | }, |
71130750 |
481 | regexes => { |
482 | schema => [ |
483 | qr/package DBICTest::DumpMore::1;/, |
484 | qr/->load_namespaces/, |
eb28f95b |
485 | qr/result_namespace => "Res"/, |
486 | qr/resultset_namespace => "RSet"/, |
487 | qr/default_resultset_class => "RSetBase"/, |
f44ecc2f |
488 | ], |
71130750 |
489 | 'Res/Foo' => [ |
490 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
491 | qr/->set_primary_key/, |
492 | qr/1;\n$/, |
493 | ], |
494 | 'Res/Bar' => [ |
495 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
496 | qr/->set_primary_key/, |
497 | qr/1;\n$/, |
498 | ], |
499 | }, |
f44ecc2f |
500 | ); |
501 | |
eac5494b |
502 | |
71130750 |
503 | $t->dump_test( |
504 | classname => 'DBICTest::DumpMore::1', |
505 | options => { |
506 | use_namespaces => 1, |
507 | result_namespace => '+DBICTest::DumpMore::1::Res', |
508 | resultset_namespace => 'RSet', |
509 | default_resultset_class => 'RSetBase', |
510 | result_base_class => 'My::ResultBaseClass', |
511 | schema_base_class => 'My::SchemaBaseClass', |
512 | }, |
71130750 |
513 | regexes => { |
514 | schema => [ |
515 | qr/package DBICTest::DumpMore::1;/, |
516 | qr/->load_namespaces/, |
eb28f95b |
517 | qr/result_namespace => "\+DBICTest::DumpMore::1::Res"/, |
518 | qr/resultset_namespace => "RSet"/, |
519 | qr/default_resultset_class => "RSetBase"/, |
71130750 |
520 | qr/use base 'My::SchemaBaseClass'/, |
f44ecc2f |
521 | ], |
71130750 |
522 | 'Res/Foo' => [ |
523 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
524 | qr/use base 'My::ResultBaseClass'/, |
525 | qr/->set_primary_key/, |
526 | qr/1;\n$/, |
527 | ], |
528 | 'Res/Bar' => [ |
529 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
530 | qr/use base 'My::ResultBaseClass'/, |
531 | qr/->set_primary_key/, |
532 | qr/1;\n$/, |
533 | ], |
534 | }, |
f44ecc2f |
535 | ); |
c634fde9 |
536 | |
71130750 |
537 | $t->dump_test( |
538 | classname => 'DBICTest::DumpMore::1', |
539 | options => { |
540 | use_namespaces => 1, |
541 | result_base_class => 'My::MissingResultBaseClass', |
542 | }, |
543 | error => qr/My::MissingResultBaseClass.*is not installed/, |
8048320c |
544 | ); |
f44ecc2f |
545 | |
667f1a0b |
546 | # test quote_char in connect_info for dbicdump |
547 | $t->dump_test( |
548 | classname => 'DBICTest::DumpMore::1', |
549 | extra_connect_info => [ |
550 | '', |
551 | '', |
552 | { quote_char => '"' }, |
553 | ], |
667f1a0b |
554 | ); |
555 | |
b564fc4b |
556 | # test fix for RT#70507 (end comment and 1; gets lost if left with actual |
557 | # custom content) |
558 | |
559 | $t->dump_test( |
560 | classname => 'DBICTest::DumpMore::Upgrade', |
561 | options => { |
562 | use_namespaces => 0, |
563 | }, |
564 | ); |
565 | |
566 | my $file = $t->class_file('DBICTest::DumpMore::Upgrade::Foo'); |
567 | |
568 | my $code = slurp_file $file; |
569 | |
570 | $code =~ s/(?=# You can replace)/sub custom_method { 'custom_method works' }\n0;\n\n/; |
571 | |
572 | write_file $file, $code; |
573 | |
574 | $t->dump_test( |
575 | classname => 'DBICTest::DumpMore::Upgrade', |
576 | options => { |
577 | use_namespaces => 1, |
578 | }, |
579 | regexes => { |
580 | 'Result/Foo' => [ |
581 | qr/sub custom_method { 'custom_method works' }\n0;\n\n# You can replace.*\n1;\n\z/, |
582 | ], |
583 | }, |
584 | ); |
585 | |
28310f24 |
586 | # test dry-run mode |
587 | $t->dump_test( |
588 | classname => 'DBICTest::DumpMore::DryRun', |
589 | options => { |
590 | dry_run => 1, |
591 | }, |
592 | ); |
593 | |
594 | my $schema_file = $t->class_file('DBICTest::DumpMore::DryRun'); |
595 | ok( !-e $schema_file, "dry-run doesn't create file for schema class" ); |
596 | (my $schema_dir = $schema_file) =~ s/\.pm\z//; |
597 | ok( !-e $schema_dir, "dry-run doesn't create subdirectory for schema namespace" ); |
598 | |
d27f2b7b |
599 | done_testing; |
c0a0986f |
600 | # vim:et sts=4 sw=4 tw=0: |