1 |
#!/usr/bin/env perl |
2 |
use warnings; |
3 |
use strict; |
4 |
|
5 |
=head1 DESCRIPTION |
6 |
|
7 |
test PHP data parser |
8 |
|
9 |
=cut |
10 |
|
11 |
use Jifty::Test tests => 11; |
12 |
|
13 |
use Data::Dump qw/dump/; |
14 |
|
15 |
use_ok('A3C::PHP'); |
16 |
|
17 |
$A3C::PHP::debug = 0; # mostly to prevent "used only once" warning |
18 |
$A3C::PHP::debug = 1 if @ARGV; |
19 |
|
20 |
ok( my $data = A3C::PHP->parse( << '__PHP_CONFIG__' |
21 |
<? |
22 |
$_foo = 42; |
23 |
$_bar = "is bar"; |
24 |
|
25 |
$_baz = 'once'; |
26 |
$_baz = "twice"; |
27 |
|
28 |
$double_quoted = "this is \"quoted\" string"; |
29 |
$single_quoted = 'and \'another\' one'; |
30 |
?> |
31 |
__PHP_CONFIG__ |
32 |
), 'parse'); |
33 |
|
34 |
diag dump( $data ); |
35 |
is_deeply( $data, { |
36 |
_foo => 42, |
37 |
_bar => "is bar", |
38 |
_baz => "twice", |
39 |
double_quoted => 'this is "quoted" string', |
40 |
single_quoted => "and 'another' one", |
41 |
}, 'correct' ); |
42 |
|
43 |
ok( my $config = Jifty->config->app('strix'), 'strix config' ); |
44 |
ok( my $dir = $config->{dir}, 'found strix dir' ); |
45 |
ok( -e $dir, "$dir exists" ); |
46 |
|
47 |
sub php2data { |
48 |
my ( $php_path, $expected ) = @_; |
49 |
ok( my $data = A3C::PHP->parse_file( $php_path ), "parse_file( $php_path )"); |
50 |
diag "data = ",dump( $data ); |
51 |
is_deeply( $data, $expected, 'correct' ); |
52 |
} |
53 |
|
54 |
php2data( 't/test.php', |
55 |
{ |
56 |
array1 => [123], |
57 |
array2 => [123, 456, 789], |
58 |
array3 => ["abc"], |
59 |
array4 => ["abc", "def", "ghi"], |
60 |
array5 => ["test", "NJ, the garden state"], |
61 |
array6 => ["foo"], |
62 |
hash1 => { a => 1 }, |
63 |
hash2 => { a => 1, b => 2, c => 3 }, |
64 |
hash3 => { 1 => "a", "123.45" => "moog", foo => "bar" }, |
65 |
hash4 => { abe => "Abraham Lincoln", larry => "Larry Wall" }, |
66 |
hash5 => { constant => "NJ and you, perfect together" }, |
67 |
hash6 => { foo => "bar" }, |
68 |
number1 => 123, |
69 |
number2 => "123.45", |
70 |
string1 => "McHenry, IL", |
71 |
string2 => "Trenton, NJ", |
72 |
} |
73 |
); |
74 |
|
75 |
SKIP: { |
76 |
skip 'need function support', 1; |
77 |
php2data( "$dir/etc/cms-qa/conf.php" ); |
78 |
} |
79 |
|
80 |
php2data( "$dir/etc/new/conf.php", |
81 |
{ |
82 |
_dbname => "new", |
83 |
_dbserver => "localhost", |
84 |
_site_admin => "portal\@skole.hr", |
85 |
_site_is_root => 1, |
86 |
_site_name => "Otvaranje sitea \x{161}kole", |
87 |
_skole_external_uid => 0, |
88 |
} |
89 |
); |
90 |
|