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;/, |
06e06245 |
182 | qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\n/, |
a8acb698 |
183 | qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\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;/, |
06e06245 |
198 | qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\n/, |
a8acb698 |
199 | qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\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 | |
215 | |
71130750 |
216 | $t->append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX}); |
f812ef60 |
217 | |
9de8c789 |
218 | |
71130750 |
219 | $t->dump_test( |
220 | classname => 'DBICTest::DumpMore::1', |
221 | warnings => [ |
222 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
223 | qr/Schema dump completed/, |
224 | ], |
225 | regexes => { |
226 | schema => [ |
227 | qr/package DBICTest::DumpMore::1;/, |
228 | qr/->load_classes/, |
a4187fdf |
229 | ], |
71130750 |
230 | Foo => [ |
231 | qr/package DBICTest::DumpMore::1::Foo;/, |
232 | qr/->set_primary_key/, |
233 | qr/1;\n# XXX This is my custom content XXX/, |
234 | ], |
235 | Bar => [ |
236 | qr/package DBICTest::DumpMore::1::Bar;/, |
237 | qr/->set_primary_key/, |
238 | qr/1;\n$/, |
239 | ], |
240 | }, |
a4187fdf |
241 | ); |
242 | |
a4187fdf |
243 | |
71130750 |
244 | $t->dump_test( |
245 | classname => 'DBICTest::DumpMore::1', |
246 | options => { |
247 | really_erase_my_files => 1 |
248 | }, |
249 | warnings => [ |
250 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
251 | qr/Deleting existing file /, |
252 | qr/Deleting existing file /, |
253 | qr/Deleting existing file /, |
254 | qr/Schema dump completed/, |
255 | ], |
256 | regexes => { |
257 | schema => [ |
258 | qr/package DBICTest::DumpMore::1;/, |
259 | qr/->load_classes/, |
a4187fdf |
260 | ], |
71130750 |
261 | Foo => [ |
262 | qr/package DBICTest::DumpMore::1::Foo;/, |
263 | qr/->set_primary_key/, |
264 | qr/1;\n$/, |
a4187fdf |
265 | ], |
71130750 |
266 | Bar => [ |
267 | qr/package DBICTest::DumpMore::1::Bar;/, |
268 | qr/->set_primary_key/, |
269 | qr/1;\n$/, |
270 | ], |
271 | }, |
272 | neg_regexes => { |
273 | Foo => [ |
274 | qr/# XXX This is my custom content XXX/, |
275 | ], |
276 | }, |
492dce8d |
277 | ); |
278 | |
eac5494b |
279 | |
71130750 |
280 | $t->cleanup; |
281 | |
282 | # test namespaces |
283 | $t->dump_test( |
284 | classname => 'DBICTest::DumpMore::1', |
285 | options => { |
286 | use_namespaces => 1, |
287 | generate_pod => 0 |
288 | }, |
289 | warnings => [ |
290 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
291 | qr/Schema dump completed/, |
292 | ], |
293 | neg_regexes => { |
294 | 'Result/Foo' => [ |
295 | qr/^=/m, |
492dce8d |
296 | ], |
71130750 |
297 | }, |
a4187fdf |
298 | ); |
605fcea8 |
299 | |
eac5494b |
300 | |
71130750 |
301 | $t->dump_test( |
302 | classname => 'DBICTest::DumpMore::1', |
303 | options => { |
304 | db_schema => 'foo_schema', |
305 | qualify_objects => 1, |
306 | use_namespaces => 1 |
307 | }, |
308 | warnings => [ |
309 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
310 | qr/Schema dump completed/, |
311 | ], |
312 | regexes => { |
313 | 'Result/Foo' => [ |
314 | qr/^\Q__PACKAGE__->table("foo_schema.foo");\E/m, |
315 | # the has_many relname should not have the schema in it! |
316 | qr/^__PACKAGE__->has_many\(\n "bars"/m, |
69219349 |
317 | ], |
71130750 |
318 | }, |
69219349 |
319 | ); |
320 | |
71130750 |
321 | $t->dump_test( |
322 | classname => 'DBICTest::DumpMore::1', |
323 | options => { |
324 | use_namespaces => 1 |
325 | }, |
326 | warnings => [ |
327 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
328 | qr/Schema dump completed/, |
329 | ], |
330 | regexes => { |
331 | schema => [ |
332 | qr/package DBICTest::DumpMore::1;/, |
333 | qr/->load_namespaces/, |
f44ecc2f |
334 | ], |
71130750 |
335 | 'Result/Foo' => [ |
336 | qr/package DBICTest::DumpMore::1::Result::Foo;/, |
337 | qr/->set_primary_key/, |
338 | qr/1;\n$/, |
339 | ], |
340 | 'Result/Bar' => [ |
341 | qr/package DBICTest::DumpMore::1::Result::Bar;/, |
342 | qr/->set_primary_key/, |
343 | qr/1;\n$/, |
344 | ], |
345 | }, |
f44ecc2f |
346 | ); |
347 | |
eac5494b |
348 | |
71130750 |
349 | $t->dump_test( |
350 | classname => 'DBICTest::DumpMore::1', |
351 | options => { |
352 | use_namespaces => 1, |
353 | result_namespace => 'Res', |
354 | resultset_namespace => 'RSet', |
355 | default_resultset_class => 'RSetBase', |
356 | }, |
357 | warnings => [ |
358 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
359 | qr/Schema dump completed/, |
360 | ], |
361 | regexes => { |
362 | schema => [ |
363 | qr/package DBICTest::DumpMore::1;/, |
364 | qr/->load_namespaces/, |
365 | qr/result_namespace => 'Res'/, |
366 | qr/resultset_namespace => 'RSet'/, |
367 | qr/default_resultset_class => 'RSetBase'/, |
f44ecc2f |
368 | ], |
71130750 |
369 | 'Res/Foo' => [ |
370 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
371 | qr/->set_primary_key/, |
372 | qr/1;\n$/, |
373 | ], |
374 | 'Res/Bar' => [ |
375 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
376 | qr/->set_primary_key/, |
377 | qr/1;\n$/, |
378 | ], |
379 | }, |
f44ecc2f |
380 | ); |
381 | |
eac5494b |
382 | |
71130750 |
383 | $t->dump_test( |
384 | classname => 'DBICTest::DumpMore::1', |
385 | options => { |
386 | use_namespaces => 1, |
387 | result_namespace => '+DBICTest::DumpMore::1::Res', |
388 | resultset_namespace => 'RSet', |
389 | default_resultset_class => 'RSetBase', |
390 | result_base_class => 'My::ResultBaseClass', |
391 | schema_base_class => 'My::SchemaBaseClass', |
392 | }, |
393 | warnings => [ |
394 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
395 | qr/Schema dump completed/, |
396 | ], |
397 | regexes => { |
398 | schema => [ |
399 | qr/package DBICTest::DumpMore::1;/, |
400 | qr/->load_namespaces/, |
401 | qr/result_namespace => '\+DBICTest::DumpMore::1::Res'/, |
402 | qr/resultset_namespace => 'RSet'/, |
403 | qr/default_resultset_class => 'RSetBase'/, |
404 | qr/use base 'My::SchemaBaseClass'/, |
f44ecc2f |
405 | ], |
71130750 |
406 | 'Res/Foo' => [ |
407 | qr/package DBICTest::DumpMore::1::Res::Foo;/, |
408 | qr/use base 'My::ResultBaseClass'/, |
409 | qr/->set_primary_key/, |
410 | qr/1;\n$/, |
411 | ], |
412 | 'Res/Bar' => [ |
413 | qr/package DBICTest::DumpMore::1::Res::Bar;/, |
414 | qr/use base 'My::ResultBaseClass'/, |
415 | qr/->set_primary_key/, |
416 | qr/1;\n$/, |
417 | ], |
418 | }, |
f44ecc2f |
419 | ); |
c634fde9 |
420 | |
eac5494b |
421 | |
71130750 |
422 | $t->dump_test( |
423 | classname => 'DBICTest::DumpMore::1', |
424 | options => { |
425 | use_namespaces => 1, |
426 | result_base_class => 'My::MissingResultBaseClass', |
427 | }, |
428 | error => qr/My::MissingResultBaseClass.*is not installed/, |
8048320c |
429 | ); |
f44ecc2f |
430 | |
667f1a0b |
431 | # test quote_char in connect_info for dbicdump |
432 | $t->dump_test( |
433 | classname => 'DBICTest::DumpMore::1', |
434 | extra_connect_info => [ |
435 | '', |
436 | '', |
437 | { quote_char => '"' }, |
438 | ], |
439 | warnings => [ |
440 | qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /, |
441 | qr/Schema dump completed/, |
442 | ], |
443 | ); |
444 | |
d27f2b7b |
445 | done_testing; |
c0a0986f |
446 | # vim:et sts=4 sw=4 tw=0: |