File: 038_Pass_Variables.t

package info (click to toggle)
libpetal-perl 2.19-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,076 kB
  • ctags: 166
  • sloc: perl: 4,732; xml: 726; makefile: 43
file content (84 lines) | stat: -rw-r--r-- 2,441 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl
use warnings;
use strict;
use lib ('lib');
use Test::More 'no_plan';
use Petal;

$Petal::BASE_DIR     = './t/data/pass_variables';
$Petal::DISK_CACHE   = 0;
$Petal::MEMORY_CACHE = 0;
$Petal::TAINT        = 1;

my $string;
my $vars = { test => bless({}, 'Test'), foo => bless({}, 'Foo') };

$string = Petal->new( 'replace.html' )->process( $vars );
like( $string, qr/Object 0: Foo/, "foo (petal:replace)" );
like( $string, qr/Object 1: Foo/, "foo (petal:replace)" );
like( $string, qr/Object 2: Bar/, "bar (petal:replace)" );
like( $string, qr/Object 3: Foo/, "foo (?var?)" );
like( $string, qr/Object 4: Bar/, "bar (?var?)" );
#diag( $string );

$string = Petal->new( 'content.html' )->process( $vars );
like( $string, qr/Object 0: .+?Foo/, "foo (petal:content)" );
like( $string, qr/Object 1: .+?Foo/, "foo (petal:content)" );
like( $string, qr/Object 2: .+?Bar/, "bar (petal:content)" );
#diag( $string );

$string = Petal->new( 'set.html' )->process( $vars );
like( $string, qr/Object 0: Foo/, "foo (petal:set)" );
like( $string, qr/Object 1: Foo/, "foo (petal:set)" );
like( $string, qr/Object 2: Foo/, "foo (?var set:?)" );
#diag( $string );

$string = Petal->new( 'if.html' )->process( $vars );
like( $string, qr/Object 0: Foo/, "foo (petal:if)" );
like( $string, qr/Object 1: Foo/, "foo (petal:if)" );
like( $string, qr/Object 2: Foo/, "foo (?if?)" );
#diag( $string );

$string = Petal->new( 'attributes.html' )->process( $vars );
like( $string, qr/Object 0: .+?Foo/, "foo (petal:attributes)" );
like( $string, qr/Object 1: .+?Foo/, "foo (petal:attributes)" );
like( $string, qr/Object 2: .+?Bar/, "bar (petal:attributes)" );
#diag( $string );

$string = Petal->new( 'repeat.html' )->process( $vars );
like( $string, qr/Object 1: Foo/, "baz (petal:if)" );
like( $string, qr/Object 2: Foo/, "baz (petal:if)" );
#diag( $string );

$string = Petal->new( 'no_arguments.html' )->process( $vars );
like( $string, qr/No arguments passed/, "no args passed" );
#diag( $string );


package Test;
sub object_type {
    my $self = shift;
    my $obj  = shift;
    return ref($obj);
}

sub sub_test { bless {}, 'Test'; }

sub list {
    return [ shift->object_type( shift ) ];
}

sub no_arguments {
    my $self = shift;
    my $new  = bless {}, 'Test';
    $new->{no_args} = 1 unless (@_);
    return $new;
}

sub got_no_arguments {
    my $self = shift;
    return $self->{no_args};
}

package Foo;
sub bar { bless {}, 'Bar'; }