5 # Due to a bug in older versions of MakeMaker & Test::Harness, we must
6 # ensure the blib's are in @INC, else we might use the core CGI.pm
7 use lib qw(blib/lib blib/arch);
9 use Test::More tests => 12;
11 use_ok( 'CGI::Push' );
13 ok( my $q = CGI::Push->new(), 'create a new CGI::Push object' );
15 # test the simple_counter() method
16 like( join('', $q->simple_counter(10)) , '/updated.+?10.+?times./', 'counter' );
18 # test do_sleep, except we don't want to bog down the tests
19 # there's also a potential timing-related failure lurking here
20 # change this variable at your own risk
21 my $sleep_in_tests = 0;
24 skip( 'do_sleep() test may take a while', 1 ) unless $sleep_in_tests;
27 CGI::Push::do_sleep(2);
28 is(time - $time, 2, 'slept for a while' );
32 ok( ! defined $q->push_delay(), 'no initial delay' );
33 is( $q->push_delay(.5), .5, 'set a delay' );
35 my $out = tie *STDOUT, 'TieOut';
37 # next_page() to be called twice, last_page() once, no delay
39 -next_page => sub { return if $_[1] > 2; 'next page' },
40 -last_page => sub { 'last page' },
46 # this seems to appear on every page
47 like( $$out, '/WARNING: YOUR BROWSER/', 'unsupported browser warning' );
49 # these should appear correctly
50 is( ($$out =~ s/next page//g), 2, 'next_page callback called appropriately' );
51 is( ($$out =~ s/last page//g), 1, 'last_page callback called appropriately' );
53 # send a fake content type (header capitalization varies in CGI, CGI::Push)
55 $q->do_push(%vars, -type => 'fake' );
56 like( $$out, '/Content-[Tt]ype: fake/', 'set custom Content-type' );
58 # use our own counter, as $COUNTER in CGI::Push is now off
62 # no delay, custom headers from callback, only call callback once
68 return $_[0]->header('text/plain'), 'arduk';
72 # header capitalization again, our word should appear only once
73 like( $$out, '/ype: text\/plain/', 'set custom Content-type in next_page()' );
74 is( $$out =~ s/arduk//g, 1, 'found text from next_page()' );
79 bless( \(my $text), $_[0] );
84 $$self .= join( $/, @_ );