#!/usr/bin/env perl
use warnings;
use strict;
=head1 DESCRIPTION
test PHP data parser
=cut
use Jifty::Test tests => 11;
use Data::Dump qw/dump/;
use_ok('A3C::PHP');
$A3C::PHP::debug = 0; # mostly to prevent "used only once" warning
$A3C::PHP::debug = 1 if @ARGV;
ok( my $data = A3C::PHP->parse( << '__PHP_CONFIG__'
<?
$_foo = 42;
$_bar = "is bar";
$_baz = 'once';
$_baz = "twice";
$double_quoted = "this is \"quoted\" string";
$single_quoted = 'and \'another\' one';
?>
__PHP_CONFIG__
), 'parse');
diag dump( $data );
is_deeply( $data, {
_foo => 42,
_bar => "is bar",
_baz => "twice",
double_quoted => 'this is "quoted" string',
single_quoted => "and 'another' one",
}, 'correct' );
ok( my $config = Jifty->config->app('strix'), 'strix config' );
ok( my $dir = $config->{dir}, 'found strix dir' );
ok( -e $dir, "$dir exists" );
sub php2data {
my ( $php_path, $expected ) = @_;
ok( my $data = A3C::PHP->parse_file( $php_path ), "parse_file( $php_path )");
diag "data = ",dump( $data );
is_deeply( $data, $expected, 'correct' );
}
php2data( 't/test.php',
{
array1 => [123],
array2 => [123, 456, 789],
array3 => ["abc"],
array4 => ["abc", "def", "ghi"],
array5 => ["test", "NJ, the garden state"],
array6 => ["foo"],
hash1 => { a => 1 },
hash2 => { a => 1, b => 2, c => 3 },
hash3 => { 1 => "a", "123.45" => "moog", foo => "bar" },
hash4 => { abe => "Abraham Lincoln", larry => "Larry Wall" },
hash5 => { constant => "NJ and you, perfect together" },
hash6 => { foo => "bar" },
number1 => 123,
number2 => "123.45",
string1 => "McHenry, IL",
string2 => "Trenton, NJ",
}
);
SKIP: {
skip 'need function support', 1;
php2data( "$dir/etc/cms-qa/conf.php" );
}
php2data( "$dir/etc/new/conf.php",
{
_dbname => "new",
_dbserver => "localhost",
_site_admin => "portal\@skole.hr",
_site_is_root => 1,
_site_name => "Otvaranje sitea \x{161}kole",
_skole_external_uid => 0,
}
);