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 => 8; |
12 |
|
13 |
use Data::Dump qw/dump/; |
14 |
|
15 |
use_ok('A3C::PHP'); |
16 |
|
17 |
$A3C::PHP::debug = 1 if @ARGV; |
18 |
|
19 |
ok( my $data = A3C::PHP->parse( << '__PHP_CONFIG__' |
20 |
<? |
21 |
$_foo = 42; |
22 |
$_bar = "is bar"; |
23 |
|
24 |
$_baz = 'once'; |
25 |
$_baz = "twice"; |
26 |
?> |
27 |
__PHP_CONFIG__ |
28 |
), 'parse'); |
29 |
|
30 |
diag dump( $data ); |
31 |
is_deeply( $data, { _foo => 42, _bar => "is bar", _baz => "twice" }, 'correct' ); |
32 |
|
33 |
sub php2data { |
34 |
my ( $php_path, $expected ) = @_; |
35 |
ok( my $data = A3C::PHP->parse_file( $php_path ), "parse_file( $php_path )"); |
36 |
diag "data = ",dump( $data ); |
37 |
is_deeply( $data, $expected, 'correct' ); |
38 |
} |
39 |
|
40 |
php2data( 't/test.php', |
41 |
{ |
42 |
array1 => [123], |
43 |
array2 => [123, 456, 789], |
44 |
array3 => ["abc"], |
45 |
array4 => ["abc", "def", "ghi"], |
46 |
array5 => ["test", "NJ, the garden state"], |
47 |
array6 => ["foo"], |
48 |
hash1 => { a => 1 }, |
49 |
hash2 => { a => 1, b => 2, c => 3 }, |
50 |
hash3 => { 1 => "a", "123.45" => "moog", foo => "bar" }, |
51 |
hash4 => { abe => "Abraham Lincoln", larry => "Larry Wall" }, |
52 |
hash5 => { constant => "NJ and you, perfect together" }, |
53 |
hash6 => { foo => "bar" }, |
54 |
number1 => 123, |
55 |
number2 => "123.45", |
56 |
string1 => "McHenry, IL", |
57 |
string2 => "Trenton, NJ", |
58 |
} |
59 |
); |
60 |
|
61 |
SKIP: { |
62 |
skip 'need function support', 1; |
63 |
php2data( 'data/strix/etc/cms-qa/conf.php' ); |
64 |
} |
65 |
|
66 |
php2data( 'data/strix/etc/new/conf.php', |
67 |
{ |
68 |
_dbname => "new", |
69 |
_dbserver => "localhost", |
70 |
_site_admin => "portal\@skole.hr", |
71 |
_site_is_root => 1, |
72 |
_site_name => "Otvaranje sitea \x{161}kole", |
73 |
_skole_external_uid => 0, |
74 |
} |
75 |
); |
76 |
|