2 # just in case the user env has stuff in it
3 delete $ENV{JSON_ANY_ORDER};
4 delete $ENV{DBICTEST_VERSION_WARNS_INDISCRIMINATELY};
6 do "./t/lib/ANFANG.pm" or die ( $@ || $! )
12 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_admin_script';
20 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
22 my @json_backends = qw(DWIW PP JSON CPANEL XS);
24 # test the script is setting @INC properly
25 test_exec (qw|-It/lib/testinclude --schema=DBICTestAdminInc --connect=[] --insert|);
26 cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from connecting a custom INC schema' );
28 # test that config works properly
31 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --create --connect=["klaatu","barada","nikto"]|);
32 cmp_ok( $? >> 8, '==', 71, 'Correct schema loaded via config' ) || exit;
35 # test that config-file works properly
36 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --config=t/lib/admincfgtest.json --config-stanza=Model::Gort --deploy|);
37 cmp_ok ($? >> 8, '==', 71, 'Correct schema loaded via testconfig');
39 for my $js (@json_backends) {
42 eval {JSON::Any->import ($js); 1 }
43 or skip ("JSON backend $js is not available, skip testing", 1);
45 local $ENV{JSON_ANY_ORDER} = $js;
46 eval { test_dbicadmin () };
54 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
56 my $employees = $schema->resultset('Employee');
58 test_exec( default_args(), qw|--op=insert --set={"name":"Matt"}| );
59 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
61 my $employee = $employees->find(1);
62 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
64 test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| );
65 $employee = $employees->find(1);
66 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
68 test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| );
71 skip ("MSWin32 doesn't support -|", 1) if $^O eq 'MSWin32';
73 my ($perl) = $^X =~ /(.*)/;
75 open(my $fh, "-|", ( $perl, '-MANFANG', 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
76 my $data = do { local $/; <$fh> };
78 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
79 diag ("data from select is $data")
83 test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| );
84 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
88 my $dsn = JSON::Any->encode([
89 'dbi:SQLite:dbname=' . DBICTest->_sqlite_dbfilename,
96 qw|--quiet --schema=DBICTest::Schema --class=Employee|,
98 qw|--force -I testincludenoniterference|,
103 my ($perl) = $^X =~ /(.*)/;
105 my @args = ($perl, '-MANFANG', 'script/dbicadmin', @_);
107 if ($^O eq 'MSWin32') {
108 require Win32::ShellQuote; # included in test optdeps
109 @args = Win32::ShellQuote::quote_system_list(@args);