4 use File::Spec::Functions qw/catfile catdir/;
9 plan skip_all => 'Enable this optional test with $ENV{C_M_DBIC_SCHEMA_TESTAPP}'
10 unless $ENV{C_M_DBIC_SCHEMA_TESTAPP};
12 # XXX this test needs a re-write to fully test the current set of capabilities...
15 [ 'TestSchema', 'DBIC::Schema', '' ],
16 [ 'TestSchemaDSN', 'DBIC::Schema', qw/fakedsn fakeuser fakepass/, '{ AutoCommit => 1 }' ],
17 [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', q|moniker_map={ roles => 'ROLE' }|, 'constraint=^users\z', 'dbi:SQLite:testdb.db' ],
18 [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', q|moniker_map={ roles => 'ROLE' }|, 'constraint=^users\z', 'dbi:SQLite:testdb.db', '', '', q|on_connect_do=['select 1', 'select 2']| ],
19 [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', q|moniker_map={ roles => 'ROLE' }|, 'dbi:SQLite:testdb.db', q|on_connect_do=['select 1', 'select 2']| ],
20 [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', 'inflect_singular=sub { $_[0] =~ /\A(.+?)(_id)?\z/; $1 }', q{moniker_map=sub { return join('', map ucfirst, split(/[\W_]+/, lc $_[0])); }}, 'dbi:SQLite:testdb.db' ],
23 my $test_dir = $FindBin::Bin;
24 my $blib_dir = catdir ($test_dir, '..', 'blib', 'lib');
25 my $cat_dir = catdir ($test_dir, 'TestApp');
26 my $catlib_dir = catdir ($cat_dir, 'lib');
27 my $schema_dir = catdir ($catlib_dir, 'TestSchemaDSN');
28 my $creator = catfile($cat_dir, 'script', 'testapp_create.pl');
29 my $model_dir = catdir ($catlib_dir, 'TestApp', 'Model');
30 my $db = catfile($cat_dir, 'testdb.db');
34 foreach my $bin (split /(?:$Config{path_sep}|:)/, $ENV{PATH}) {
35 my $file = catfile($bin, 'catalyst.pl');
42 plan skip_all => 'catalyst.pl not found' unless $catalyst_pl;
45 system("$^X $catalyst_pl TestApp");
49 my $dbh = DBI->connect("dbi:SQLite:$db", '', '', {
50 RaiseError => 1, PrintError => 0
54 id INTEGER PRIMARY KEY,
65 id INTEGER PRIMARY KEY,
71 foreach my $tparam (@$test_params) {
72 my ($model, $helper, @args) = @$tparam;
76 system($^X, "-I$blib_dir", $creator, 'model', $model, $helper, $model, @args);
78 my $model_path = catfile($model_dir, $model . '.pm');
79 ok( -f $model_path, "$model_path is a file" );
80 my $compile_rv = system("$^X -I$blib_dir -I$catlib_dir -c $model_path");
81 ok($compile_rv == 0, "perl -c $model_path");
83 if (grep /create=static/, @args) {
84 my @result_files = result_files();
86 if (grep /constraint/, @args) {
87 is scalar @result_files, 1, 'constraint works';
89 is scalar @result_files, 2, 'correct number of tables';
92 for my $file (@result_files) {
93 my $code = code_for($file);
95 like $code, qr/use Moose;\n/, 'use_moose enabled';
96 like $code, qr/__PACKAGE__->meta->make_immutable;\n/, 'use_moose enabled';
101 # Test that use_moose=1 is not applied to existing non-moose schemas (RT#60558)
105 system($^X, "-I$blib_dir", $creator, 'model',
106 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
107 'create=static', 'use_moose=0', 'dbi:SQLite:testdb.db'
110 my @result_files = result_files();
112 for my $file (@result_files) {
113 my $code = code_for($file);
115 unlike $code, qr/use Moose;\n/, 'non use_moose=1 schema';
116 unlike $code, qr/__PACKAGE__->meta->make_immutable;\n/, 'non use_moose=1 schema';
119 system($^X, "-I$blib_dir", $creator, 'model',
120 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
121 'create=static', 'dbi:SQLite:testdb.db'
124 for my $file (@result_files) {
125 my $code = code_for($file);
127 unlike $code, qr/use Moose;\n/,
128 'non use_moose=1 schema not upgraded to use_moose=1';
129 unlike $code, qr/__PACKAGE__->meta->make_immutable;\n/,
130 'non use_moose=1 schema not upgraded to use_moose=1';
134 # Test that a moose schema is not detected as a non-moose schema due to an
139 system($^X, "-I$blib_dir", $creator, 'model',
140 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
141 'create=static', 'dbi:SQLite:testdb.db'
144 mkdir "$schema_dir/.svn";
145 open my $fh, '>', "$schema_dir/.svn/foo"
146 or die "Could not open $schema_dir/.svn/foo for writing: $!";
147 print $fh "gargle\n";
150 mkdir "$schema_dir/Result/.svn";
151 open $fh, '>', "$schema_dir/Result/.svn/foo"
152 or die "Could not open $schema_dir/Result/.svn/foo for writing: $!";
156 system($^X, "-I$blib_dir", $creator, 'model',
157 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
158 'create=static', 'dbi:SQLite:testdb.db'
161 for my $file (result_files()) {
162 my $code = code_for($file);
164 like $code, qr/use Moose;\n/,
165 'use_moose detection not confused by version control files';
166 like $code, qr/__PACKAGE__->meta->make_immutable;\n/,
167 'use_moose detection not confused by version control files';
174 my $name = $File::Find::name;
175 if(-d $name) { rmdir $name or warn "Cannot rmdir $name: $!" }
176 else { unlink $name or die "Cannot unlink $name: $!" }
180 return unless -d $schema_dir;
181 finddepth(\&rm_rf, $schema_dir);
182 unlink "${schema_dir}.pm";
188 open my $fh, '<', $file;
189 my $code = do { local $/; <$fh> };
196 my $result_dir = catfile($schema_dir, 'Result');
200 opendir my $dir, $result_dir
201 or die "Could not open $result_dir: $!";
203 while (my $file = readdir $dir) {
204 next unless $file =~ /\.pm\z/;
206 push @results, catfile($result_dir, $file);
215 if ($ENV{C_M_DBIC_SCHEMA_TESTAPP}) {
217 finddepth(\&rm_rf, $cat_dir);
221 # vim:sts=3 sw=3 et tw=80: