4 use File::Spec::Functions qw/catfile catdir/;
8 plan skip_all => 'Enable this optional test with $ENV{C_M_DBIC_SCHEMA_TESTAPP}'
9 unless $ENV{C_M_DBIC_SCHEMA_TESTAPP};
11 # XXX this test needs a re-write to fully test the current set of capabilities...
14 [ 'TestSchema', 'DBIC::Schema', '' ],
15 [ 'TestSchemaDSN', 'DBIC::Schema', qw/fakedsn fakeuser fakepass/, '{ AutoCommit => 1 }' ],
16 [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', q|moniker_map={ roles => 'ROLE' }|, 'constraint=^users\z', 'dbi:SQLite:testdb.db' ],
17 [ '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']| ],
18 [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', q|moniker_map={ roles => 'ROLE' }|, 'dbi:SQLite:testdb.db', q|on_connect_do=['select 1', 'select 2']| ],
19 [ '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' ],
22 my $test_dir = $FindBin::Bin;
23 my $blib_dir = catdir ($test_dir, '..', 'blib', 'lib');
24 my $cat_dir = catdir ($test_dir, 'TestApp');
25 my $catlib_dir = catdir ($cat_dir, 'lib');
26 my $schema_dir = catdir ($catlib_dir, 'TestSchemaDSN');
27 my $creator = catfile($cat_dir, 'script', 'testapp_create.pl');
28 my $model_dir = catdir ($catlib_dir, 'TestApp', 'Model');
29 my $db = catdir ($cat_dir, 'testdb.db');
33 foreach my $bin (split /(?:$Config{path_sep}|:)/, $ENV{PATH}) {
34 my $file = catfile($bin, 'catalyst.pl');
41 plan skip_all => 'catalyst.pl not found' unless $catalyst_pl;
44 system("$^X $catalyst_pl TestApp");
48 open my $sql, '|-', "sqlite3 $db" or die $!;
51 id INTEGER PRIMARY KEY,
60 id INTEGER PRIMARY KEY,
66 foreach my $tparam (@$test_params) {
67 my ($model, $helper, @args) = @$tparam;
71 system($^X, "-I$blib_dir", $creator, 'model', $model, $helper, $model, @args);
73 my $model_path = catfile($model_dir, $model . '.pm');
74 ok( -f $model_path, "$model_path is a file" );
75 my $compile_rv = system("$^X -I$blib_dir -I$catlib_dir -c $model_path");
76 ok($compile_rv == 0, "perl -c $model_path");
78 if (grep /create=static/, @args) {
79 my @result_files = result_files();
81 if (grep /constraint/, @args) {
82 is scalar @result_files, 1, 'constraint works';
84 is scalar @result_files, 2, 'correct number of tables';
87 for my $file (@result_files) {
88 my $code = code_for($file);
90 like $code, qr/use Moose;\n/, 'use_moose enabled';
91 like $code, qr/__PACKAGE__->meta->make_immutable;\n/, 'use_moose enabled';
96 # Test that use_moose=1 is not applied to existing non-moose schemas (RT#60558)
100 system($^X, "-I$blib_dir", $creator, 'model',
101 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
102 'create=static', 'use_moose=0', 'dbi:SQLite:testdb.db'
105 my @result_files = result_files();
107 for my $file (@result_files) {
108 my $code = code_for($file);
110 unlike $code, qr/use Moose;\n/, 'non use_moose=1 schema';
111 unlike $code, qr/__PACKAGE__->meta->make_immutable;\n/, 'non use_moose=1 schema';
114 system($^X, "-I$blib_dir", $creator, 'model',
115 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
116 'create=static', 'dbi:SQLite:testdb.db'
119 for my $file (@result_files) {
120 my $code = code_for($file);
122 unlike $code, qr/use Moose;\n/,
123 'non use_moose=1 schema not upgraded to use_moose=1';
124 unlike $code, qr/__PACKAGE__->meta->make_immutable;\n/,
125 'non use_moose=1 schema not upgraded to use_moose=1';
129 # Test that a moose schema is not detected as a non-moose schema due to an
134 system($^X, "-I$blib_dir", $creator, 'model',
135 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
136 'create=static', 'dbi:SQLite:testdb.db'
139 mkdir "$schema_dir/.svn";
140 open my $fh, '>', "$schema_dir/.svn/foo"
141 or die "Could not open $schema_dir/.svn/foo for writing: $!";
142 print $fh "gargle\n";
145 mkdir "$schema_dir/Result/.svn";
146 open $fh, '>', "$schema_dir/Result/.svn/foo"
147 or die "Could not open $schema_dir/Result/.svn/foo for writing: $!";
151 system($^X, "-I$blib_dir", $creator, 'model',
152 'TestSchemaDSN', 'DBIC::Schema', 'TestSchemaDSN',
153 'create=static', 'dbi:SQLite:testdb.db'
156 for my $file (result_files()) {
157 my $code = code_for($file);
159 like $code, qr/use Moose;\n/,
160 'use_moose detection not confused by version control files';
161 like $code, qr/__PACKAGE__->meta->make_immutable;\n/,
162 'use_moose detection not confused by version control files';
169 my $name = $File::Find::name;
170 if(-d $name) { rmdir $name or warn "Cannot rmdir $name: $!" }
171 else { unlink $name or die "Cannot unlink $name: $!" }
175 return unless -d $schema_dir;
176 finddepth(\&rm_rf, $schema_dir);
177 unlink "${schema_dir}.pm";
183 open my $fh, '<', $file;
184 my $code = do { local $/; <$fh> };
191 my $result_dir = catfile($schema_dir, 'Result');
195 opendir my $dir, $result_dir
196 or die "Could not open $result_dir: $!";
198 while (my $file = readdir $dir) {
199 next unless $file =~ /\.pm\z/;
201 push @results, catfile($result_dir, $file);
210 if ($ENV{C_M_DBIC_SCHEMA_TESTAPP}) {
212 finddepth(\&rm_rf, $cat_dir);
216 # vim:sts=3 sw=3 et tw=80: