Commit | Line | Data |
71130750 |
1 | use warnings; |
605fcea8 |
2 | use strict; |
ff746964 |
3 | |
71130750 |
4 | use File::Temp (); |
5 | use Test::More; |
605fcea8 |
6 | |
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', |
16 | warnings => [ |
17 | qr/Dumping manual schema for DBICTest::Schema::_no_skip_load_external to directory /, |
18 | qr/Schema dump completed/, |
19 | ], |
20 | regexes => { |
21 | Foo => [ |
22 | qr/package DBICTest::Schema::_no_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/ |
6dde4613 |
23 | ], |
71130750 |
24 | }, |
6dde4613 |
25 | ); |
26 | |
27 | # test skipping external content |
71130750 |
28 | $t->dump_test( |
29 | classname => 'DBICTest::Schema::_skip_load_external', |
30 | options => { |
31 | skip_load_external => 1 |
32 | }, |
33 | warnings => [ |
34 | qr/Dumping manual schema for DBICTest::Schema::_skip_load_external to directory /, |
35 | qr/Schema dump completed/, |
36 | ], |
37 | neg_regexes => { |
38 | Foo => [ |
39 | qr/package DBICTest::Schema::_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/ |
6dde4613 |
40 | ], |
71130750 |
41 | }, |
6dde4613 |
42 | ); |
43 | |
71130750 |
44 | $t->cleanup; |
73099af4 |
45 | # test config_file |
71130750 |
46 | { |
47 | my $config_file = File::Temp->new (UNLINK => 1); |
73099af4 |
48 | |
71130750 |
49 | print $config_file "{ skip_relationships => 1 }\n"; |
50 | close $config_file; |
73099af4 |
51 | |
71130750 |
52 | $t->dump_test( |
1a8fd949 |
53 | classname => 'DBICTest::Schema::_config_file', |
71130750 |
54 | options => { config_file => "$config_file" }, |
73099af4 |
55 | warnings => [ |
1a8fd949 |
56 | qr/Dumping manual schema for DBICTest::Schema::_config_file to directory /, |
71130750 |
57 | qr/Schema dump completed/, |
73099af4 |
58 | ], |
59 | neg_regexes => { |
71130750 |
60 | Foo => [ |
61 | qr/has_many/, |
62 | ], |
73099af4 |
63 | }, |
71130750 |
64 | ); |
65 | } |
c9cf9b4d |
66 | |
71130750 |
67 | # proper exception |
68 | $t->dump_test( |
1a8fd949 |
69 | classname => 'DBICTest::Schema::_clashing_monikers', |
71130750 |
70 | test_db_class => 'make_dbictest_db_clashing_monikers', |
71 | error => qr/tables 'bar', 'bars' reduced to the same source moniker 'Bar'/, |
c9cf9b4d |
72 | ); |
73 | |
c9cf9b4d |
74 | |
71130750 |
75 | $t->cleanup; |
c9cf9b4d |
76 | |
c0a0986f |
77 | # test naming => { column_accessors => 'preserve' } |
78 | $t->dump_test( |
79 | classname => 'DBICTest::Schema::_preserve_column_accessors', |
80 | test_db_class => 'make_dbictest_db_with_unique', |
81 | options => { naming => { column_accessors => 'preserve' } }, |
82 | warnings => [ |
83 | qr/Dumping manual schema for DBICTest::Schema::_preserve_column_accessors to directory /, |
84 | qr/Schema dump completed/, |
85 | ], |
86 | neg_regexes => { |
87 | RouteChange => [ |
88 | qr/\baccessor\b/, |
89 | ], |
90 | }, |
91 | ); |
92 | |
93 | $t->cleanup; |
94 | |
95 | # test naming => { monikers => 'plural' } |
96 | $t->dump_test( |
97 | classname => 'DBICTest::Schema::_plural_monikers', |
98 | options => { naming => { monikers => 'plural' } }, |
99 | warnings => [ |
100 | qr/Dumping manual schema for DBICTest::Schema::_plural_monikers to directory /, |
101 | qr/Schema dump completed/, |
102 | ], |
103 | regexes => { |
104 | Foos => [ |
105 | qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Foos\n\n=cut\n\n/, |
106 | ], |
107 | Bars => [ |
108 | qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Bars\n\n=cut\n\n/, |
109 | ], |
110 | }, |
111 | ); |
112 | |
113 | $t->cleanup; |
114 | |
115 | # test naming => { monikers => 'singular' } |
116 | $t->dump_test( |
117 | classname => 'DBICTest::Schema::_singular_monikers', |
118 | test_db_class => 'make_dbictest_db_plural_tables', |
119 | options => { naming => { monikers => 'singular' } }, |
120 | warnings => [ |
121 | qr/Dumping manual schema for DBICTest::Schema::_singular_monikers to directory /, |
122 | qr/Schema dump completed/, |
123 | ], |
124 | regexes => { |
125 | Foo => [ |
126 | qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Foo\n\n=cut\n\n/, |
127 | ], |
128 | Bar => [ |
129 | qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Bar\n\n=cut\n\n/, |
130 | ], |
131 | }, |
132 | ); |
133 | |
134 | $t->cleanup; |
135 | |
136 | # test naming => { monikers => 'preserve' } |
137 | $t->dump_test( |
138 | classname => 'DBICTest::Schema::_preserve_monikers', |
139 | test_db_class => 'make_dbictest_db_plural_tables', |
140 | options => { naming => { monikers => 'preserve' } }, |
141 | warnings => [ |
142 | qr/Dumping manual schema for DBICTest::Schema::_preserve_monikers to directory /, |
143 | qr/Schema dump completed/, |
144 | ], |
145 | regexes => { |
146 | Foos => [ |
147 | qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Foos\n\n=cut\n\n/, |
148 | ], |
149 | Bars => [ |
150 | qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Bars\n\n=cut\n\n/, |
151 | ], |
152 | }, |
153 | ); |
154 | |
155 | $t->cleanup; |
156 | |
71130750 |
157 | # test out the POD |
158 | $t->dump_test( |
159 | classname => 'DBICTest::DumpMore::1', |
160 | options => { |
161 | custom_column_info => sub { |
162 | my ($table, $col, $info) = @_; |
163 | return +{ extra => { is_footext => 1 } } if $col eq 'footext'; |
06e06245 |
164 | }, |
a8acb698 |
165 | result_base_class => 'My::ResultBaseClass', |
06e06245 |
166 | additional_classes => 'TestAdditional', |
167 | additional_base_classes => 'TestAdditionalBase', |
168 | left_base_classes => 'TestLeftBase', |
169 | components => [ 'TestComponent', '+TestComponentFQN' ], |
71130750 |
170 | }, |
171 | warnings => [ |
172 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
173 | qr/Schema dump completed/, |
174 | ], |
175 | regexes => { |
176 | schema => [ |
177 | qr/package DBICTest::DumpMore::1;/, |
178 | qr/->load_classes/, |
c9cf9b4d |
179 | ], |
71130750 |
180 | Foo => [ |
181 | qr/package DBICTest::DumpMore::1::Foo;/, |
61c8fd6d |
182 | qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\nuse strict;\nuse warnings;\n\n/, |
183 | qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/, |
017d9734 |
184 | qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/, |
185 | qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/, |
186 | qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/, |
187 | 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/, |
06e06245 |
188 | qr/\n=head1 ACCESSORS\n\n/, |
189 | qr/\n=head2 fooid\n\n data_type: 'integer'\n is_auto_increment: 1\n is_nullable: 0\n\n/, |
190 | qr/\n=head2 footext\n\n data_type: 'text'\n default_value: 'footext'\n extra: {is_footext => 1}\n is_nullable: 1\n\n/, |
71130750 |
191 | qr/->set_primary_key/, |
06e06245 |
192 | qr/\n=head1 RELATIONS\n\n/, |
193 | qr/\n=head2 bars\n\nType: has_many\n\nRelated object: L<DBICTest::DumpMore::1::Bar>\n\n=cut\n\n/, |
71130750 |
194 | qr/1;\n$/, |
c9cf9b4d |
195 | ], |
71130750 |
196 | Bar => [ |
197 | qr/package DBICTest::DumpMore::1::Bar;/, |
61c8fd6d |
198 | qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\nuse strict;\nuse warnings;\n\n/, |
199 | qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/, |
017d9734 |
200 | qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/, |
201 | qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/, |
202 | qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/, |
203 | 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/, |
06e06245 |
204 | qr/\n=head1 ACCESSORS\n\n/, |
205 | qr/\n=head2 barid\n\n data_type: 'integer'\n is_auto_increment: 1\n is_nullable: 0\n\n/, |
206 | qr/\n=head2 fooref\n\n data_type: 'integer'\n is_foreign_key: 1\n is_nullable: 1\n\n/, |
71130750 |
207 | qr/->set_primary_key/, |
06e06245 |
208 | qr/\n=head1 RELATIONS\n\n/, |
209 | qr/\n=head2 fooref\n\nType: belongs_to\n\nRelated object: L<DBICTest::DumpMore::1::Foo>\n\n=cut\n\n/, |
210 | qr/\n1;\n$/, |
c9cf9b4d |
211 | ], |
71130750 |
212 | }, |
c9cf9b4d |
213 | ); |
214 | |
71130750 |
215 | $t->append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX}); |
f812ef60 |
216 | |
9de8c789 |
217 | |
71130750 |
218 | $t->dump_test( |
219 | classname => 'DBICTest::DumpMore::1', |
220 | warnings => [ |
221 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
222 | qr/Schema dump completed/, |
223 | ], |
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 | }, |
248 | warnings => [ |
249 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
250 | qr/Deleting existing file /, |
251 | qr/Deleting existing file /, |
252 | qr/Deleting existing file /, |
253 | qr/Schema dump completed/, |
254 | ], |
255 | regexes => { |
256 | schema => [ |
257 | qr/package DBICTest::DumpMore::1;/, |
258 | qr/->load_classes/, |
a4187fdf |
259 | ], |
71130750 |
260 | Foo => [ |
261 | qr/package DBICTest::DumpMore::1::Foo;/, |
262 | qr/->set_primary_key/, |
263 | qr/1;\n$/, |
a4187fdf |
264 | ], |
71130750 |
265 | Bar => [ |
266 | qr/package DBICTest::DumpMore::1::Bar;/, |
267 | qr/->set_primary_key/, |
268 | qr/1;\n$/, |
269 | ], |
270 | }, |
271 | neg_regexes => { |
272 | Foo => [ |
273 | qr/# XXX This is my custom content XXX/, |
274 | ], |
275 | }, |
492dce8d |
276 | ); |
277 | |
eac5494b |
278 | |
71130750 |
279 | $t->cleanup; |
280 | |
281 | # test namespaces |
282 | $t->dump_test( |
283 | classname => 'DBICTest::DumpMore::1', |
284 | options => { |
285 | use_namespaces => 1, |
286 | generate_pod => 0 |
287 | }, |
288 | warnings => [ |
289 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
290 | qr/Schema dump completed/, |
291 | ], |
292 | neg_regexes => { |
293 | 'Result/Foo' => [ |
294 | qr/^=/m, |
492dce8d |
295 | ], |
71130750 |
296 | }, |
a4187fdf |
297 | ); |
605fcea8 |
298 | |
eac5494b |
299 | |
71130750 |
300 | $t->dump_test( |
301 | classname => 'DBICTest::DumpMore::1', |
302 | options => { |
303 | db_schema => 'foo_schema', |
304 | qualify_objects => 1, |
305 | use_namespaces => 1 |
306 | }, |
307 | warnings => [ |
308 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
309 | qr/Schema dump completed/, |
310 | ], |
311 | regexes => { |
312 | 'Result/Foo' => [ |
313 | qr/^\Q__PACKAGE__->table("foo_schema.foo");\E/m, |
314 | # the has_many relname should not have the schema in it! |
315 | qr/^__PACKAGE__->has_many\(\n "bars"/m, |
69219349 |
316 | ], |
71130750 |
317 | }, |
69219349 |
318 | ); |
319 | |
71130750 |
320 | $t->dump_test( |
321 | classname => 'DBICTest::DumpMore::1', |
322 | options => { |
323 | use_namespaces => 1 |
324 | }, |
325 | warnings => [ |
326 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
327 | qr/Schema dump completed/, |
328 | ], |
329 | regexes => { |
330 | schema => [ |
331 | qr/package DBICTest::DumpMore::1;/, |
332 | qr/->load_namespaces/, |
f44ecc2f |
333 | ], |
71130750 |
334 | 'Result/Foo' => [ |
335 | qr/package DBICTest::DumpMore::1::Result::Foo;/, |
336 | qr/->set_primary_key/, |
337 | qr/1;\n$/, |
338 | ], |
339 | 'Result/Bar' => [ |
340 | qr/package DBICTest::DumpMore::1::Result::Bar;/, |
341 | qr/->set_primary_key/, |
342 | qr/1;\n$/, |
343 | ], |
344 | }, |
f44ecc2f |
345 | ); |
346 | |
eac5494b |
347 | |
71130750 |
348 | $t->dump_test( |
349 | classname => 'DBICTest::DumpMore::1', |
350 | options => { |
351 | use_namespaces => 1, |
352 | result_namespace => 'Res', |
353 | resultset_namespace => 'RSet', |
354 | default_resultset_class => 'RSetBase', |
355 | }, |
356 | warnings => [ |
357 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
358 | qr/Schema dump completed/, |
359 | ], |
360 | regexes => { |
361 | schema => [ |
362 | qr/package DBICTest::DumpMore::1;/, |
363 | qr/->load_namespaces/, |
364 | qr/result_namespace => 'Res'/, |
365 | qr/resultset_namespace => 'RSet'/, |
366 | qr/default_resultset_class => 'RSetBase'/, |
f44ecc2f |
367 | ], |
71130750 |
368 | 'Res/Foo' => [ |
369 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
370 | qr/->set_primary_key/, |
371 | qr/1;\n$/, |
372 | ], |
373 | 'Res/Bar' => [ |
374 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
375 | qr/->set_primary_key/, |
376 | qr/1;\n$/, |
377 | ], |
378 | }, |
f44ecc2f |
379 | ); |
380 | |
eac5494b |
381 | |
71130750 |
382 | $t->dump_test( |
383 | classname => 'DBICTest::DumpMore::1', |
384 | options => { |
385 | use_namespaces => 1, |
386 | result_namespace => '+DBICTest::DumpMore::1::Res', |
387 | resultset_namespace => 'RSet', |
388 | default_resultset_class => 'RSetBase', |
389 | result_base_class => 'My::ResultBaseClass', |
390 | schema_base_class => 'My::SchemaBaseClass', |
391 | }, |
392 | warnings => [ |
393 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
394 | qr/Schema dump completed/, |
395 | ], |
396 | regexes => { |
397 | schema => [ |
398 | qr/package DBICTest::DumpMore::1;/, |
399 | qr/->load_namespaces/, |
400 | qr/result_namespace => '\+DBICTest::DumpMore::1::Res'/, |
401 | qr/resultset_namespace => 'RSet'/, |
402 | qr/default_resultset_class => 'RSetBase'/, |
403 | qr/use base 'My::SchemaBaseClass'/, |
f44ecc2f |
404 | ], |
71130750 |
405 | 'Res/Foo' => [ |
406 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
407 | qr/use base 'My::ResultBaseClass'/, |
408 | qr/->set_primary_key/, |
409 | qr/1;\n$/, |
410 | ], |
411 | 'Res/Bar' => [ |
412 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
413 | qr/use base 'My::ResultBaseClass'/, |
414 | qr/->set_primary_key/, |
415 | qr/1;\n$/, |
416 | ], |
417 | }, |
f44ecc2f |
418 | ); |
c634fde9 |
419 | |
eac5494b |
420 | |
71130750 |
421 | $t->dump_test( |
422 | classname => 'DBICTest::DumpMore::1', |
423 | options => { |
424 | use_namespaces => 1, |
425 | result_base_class => 'My::MissingResultBaseClass', |
426 | }, |
427 | error => qr/My::MissingResultBaseClass.*is not installed/, |
8048320c |
428 | ); |
f44ecc2f |
429 | |
667f1a0b |
430 | # test quote_char in connect_info for dbicdump |
431 | $t->dump_test( |
432 | classname => 'DBICTest::DumpMore::1', |
433 | extra_connect_info => [ |
434 | '', |
435 | '', |
436 | { quote_char => '"' }, |
437 | ], |
438 | warnings => [ |
439 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
440 | qr/Schema dump completed/, |
441 | ], |
442 | ); |
443 | |
d27f2b7b |
444 | done_testing; |
c0a0986f |
445 | # vim:et sts=4 sw=4 tw=0: |