/[A3C]/t/40-php.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /t/40-php.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 148 - (show annotations)
Tue Jun 3 10:23:52 2008 UTC (15 years, 9 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2000 byte(s)
support escaped quotes in quoted strings
(used for site names in our configurations)

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26