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