13 plan skip_all => 'Test needs ' .
14 DBIx::Class::Optional::Dependencies->req_missing_for('test_admin_script')
15 unless DBIx::Class::Optional::Dependencies->req_ok_for('test_admin_script');
17 # just in case the user env has stuff in it
18 delete $ENV{JSON_ANY_ORDER};
24 $ENV{PERL5LIB} = join ($Config{path_sep}, @INC);
26 my @json_backends = qw/XS JSON DWIW/;
28 # test the script is setting @INC properly
29 test_exec (qw|-It/lib/testinclude --schema=DBICTestAdminInc --connect=[] --insert|);
30 cmp_ok ( $? >> 8, '==', 70, 'Correct exit code from connecting a custom INC schema' );
32 # test that config works properly
35 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --create --connect=["klaatu","barada","nikto"]|);
36 cmp_ok( $? >> 8, '==', 71, 'Correct schema loaded via config' ) || exit;
39 # test that config-file works properly
40 test_exec(qw|-It/lib/testinclude --schema=DBICTestConfig --config=t/lib/admincfgtest.json --config-stanza=Model::Gort --deploy|);
41 cmp_ok ($? >> 8, '==', 71, 'Correct schema loaded via testconfig');
43 for my $js (@json_backends) {
45 eval {JSON::Any->import ($js) };
47 skip ("JSON backend $js is not available, skip testing", 1) if $@;
49 local $ENV{JSON_ANY_ORDER} = $js;
50 eval { test_dbicadmin () };
58 my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run
60 my $employees = $schema->resultset('Employee');
62 test_exec( default_args(), qw|--op=insert --set={"name":"Matt"}| );
63 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: insert count" );
65 my $employee = $employees->find(1);
66 ok( ($employee->name() eq 'Matt'), "$ENV{JSON_ANY_ORDER}: insert valid" );
68 test_exec( default_args(), qw|--op=update --set={"name":"Trout"}| );
69 $employee = $employees->find(1);
70 ok( ($employee->name() eq 'Trout'), "$ENV{JSON_ANY_ORDER}: update" );
72 test_exec( default_args(), qw|--op=insert --set={"name":"Aran"}| );
75 skip ("MSWin32 doesn't support -|", 1) if $^O eq 'MSWin32';
77 my ($perl) = $^X =~ /(.*)/;
79 open(my $fh, "-|", ( $perl, '-MDBICTest::RunMode', 'script/dbicadmin', default_args(), qw|--op=select --attrs={"order_by":"name"}| ) ) or die $!;
80 my $data = do { local $/; <$fh> };
82 if (!ok( ($data=~/Aran.*Trout/s), "$ENV{JSON_ANY_ORDER}: select with attrs" )) {
83 diag ("data from select is $data")
87 test_exec( default_args(), qw|--op=delete --where={"name":"Trout"}| );
88 ok( ($employees->count()==1), "$ENV{JSON_ANY_ORDER}: delete" );
92 my $dsn = JSON::Any->encode([
93 'dbi:SQLite:dbname=' . DBICTest->_sqlite_dbfilename,
100 qw|--quiet --schema=DBICTest::Schema --class=Employee|,
102 qw|--force -I testincludenoniterference|,
107 my ($perl) = $^X =~ /(.*)/;
109 my @args = ($perl, '-MDBICTest::RunMode', File::Spec->catfile(qw(script dbicadmin)), @_);
111 if ($^O eq 'MSWin32') {
112 require Win32::ShellQuote; # included in test optdeps
113 @args = Win32::ShellQuote::quote_system_list(@args);