Commit | Line | Data |
d8d6276a |
1 | # vim: filetype=perl |
70350518 |
2 | use strict; |
3 | use warnings; |
d8d6276a |
4 | |
70350518 |
5 | use Test::More; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
d8d6276a |
8 | |
d8d6276a |
9 | |
e4c66bc8 |
10 | eval 'require JSON::Any'; |
11 | plan skip_all => 'Install JSON::Any to run this test' if ($@); |
d8d6276a |
12 | |
70350518 |
13 | eval 'require Text::CSV_XS'; |
14 | if ($@) { |
15 | eval 'require Text::CSV_PP'; |
16 | plan skip_all => 'Install Text::CSV_XS or Text::CSV_PP to run this test' if ($@); |
17 | } |
d8d6276a |
18 | |
d1b1377b |
19 | my @json_backends = qw/XS JSON DWIW Syck/; |
20 | my $tests_per_run = 5; |
d8d6276a |
21 | |
d1b1377b |
22 | plan tests => $tests_per_run * @json_backends; |
1405206e |
23 | |
d1b1377b |
24 | use JSON::Any; |
25 | for my $js (@json_backends) { |
1405206e |
26 | |
d1b1377b |
27 | eval {JSON::Any->import ($js) }; |
28 | SKIP: { |
2f3f9d21 |
29 | skip ("Json backend $js is not available, skip testing", $tests_per_run) if $@; |
0ffbc9ec |
30 | |
d1b1377b |
31 | $ENV{JSON_ANY_ORDER} = $js; |
32 | eval { test_dbicadmin () }; |
33 | diag $@ if $@; |
34 | } |
35 | } |
36 | |
37 | sub test_dbicadmin { |
38 | my $schema = DBICTest->init_schema( sqlite_use_file => 1 ); # reinit a fresh db for every run |
d8d6276a |
39 | |
d1b1377b |
40 | my $employees = $schema->resultset('Employee'); |
41 | my @cmd = ($^X, qw|script/dbicadmin --quiet --schema=DBICTest::Schema --class=Employee --tlibs|, q|--connect=["dbi:SQLite:dbname=t/var/DBIxClass.db","","",{"AutoCommit":1}]|, qw|--force --tlibs|); |
d8d6276a |
42 | |
d1b1377b |
43 | system(@cmd, qw|--op=insert --set={"name":"Matt"}|); |
44 | ok( ($employees->count()==1), 'insert count' ); |
d8d6276a |
45 | |
d1b1377b |
46 | my $employee = $employees->find(1); |
47 | ok( ($employee->name() eq 'Matt'), 'insert valid' ); |
d8d6276a |
48 | |
d1b1377b |
49 | system(@cmd, qw|--op=update --set={"name":"Trout"}|); |
50 | $employee = $employees->find(1); |
51 | ok( ($employee->name() eq 'Trout'), 'update' ); |
1405206e |
52 | |
d1b1377b |
53 | system(@cmd, qw|--op=insert --set={"name":"Aran"}|); |
70350518 |
54 | |
d1b1377b |
55 | open(my $fh, "-|", @cmd, qw|--op=select --attrs={"order_by":"name"}|) or die $!; |
56 | my $data = do { local $/; <$fh> }; |
57 | close($fh); |
58 | ok( ($data=~/Aran.*Trout/s), 'select with attrs' ); |
d8d6276a |
59 | |
d1b1377b |
60 | system(@cmd, qw|--op=delete --where={"name":"Trout"}|); |
61 | ok( ($employees->count()==1), 'delete' ); |
62 | } |