diff --git a/t/Session/Output.t b/t/Session/Output.t index ec7c1bb80..be3d992ac 100644 --- a/t/Session/Output.t +++ b/t/Session/Output.t @@ -35,33 +35,31 @@ my $recentVersion = $^V gt v5.8; SKIP: { skip "You have an old perl", $skip_tests unless $recentVersion; - my $stdoutBuffer; - close STDOUT; - open STDOUT, '>', \$stdoutBuffer or die "Unable to tie STDOUT to a variable: $!\n"; - my $otherHandleBuffer; open my $otherHandle, '>', \$otherHandleBuffer or die "Unable to create second filehandle: $!\n"; - $output->setHandle(undef); + my $request = $session->request; + + $output->setHandle(undef); is($output->{_handle}, undef, 'setHandle: handle cleared'); $output->print('Hello STDOUT'); - is($stdoutBuffer, 'Hello STDOUT', 'print with no handle goes to STDOUT'); + is($request->get_output, 'Hello STDOUT', 'print with no handle goes to STDOUT'); $output->print(' more stuff'); - is($stdoutBuffer, 'Hello STDOUT more stuff', 'print: tied variables accumulate'); + is($request->get_output, 'Hello STDOUT more stuff', 'print: tied variables accumulate'); $session->user({userId => 3}); $output->print('^#;'); - like($stdoutBuffer, qr/3\Z/, 'print: macro processing'); + like($request->get_output, qr/3\Z/, 'print: macro processing'); $output->print('^#;', 1); - like($stdoutBuffer, qr/\^#;\Z/, 'print: macro processing skipped'); + like($request->get_output, qr/\^#;\Z/, 'print: macro processing skipped'); $output->setHandle($otherHandle); $output->print('New content'); is($otherHandleBuffer, 'New content', 'print: set to explicit handle'); - unlike($stdoutBuffer, qr/New content\Z/, 'print: no leakage back to STDOUT'); + unlike($request->get_output, qr/New content\Z/, 'print: no leakage back to STDOUT'); } diff --git a/t/Session/Style.t b/t/Session/Style.t index 9c678beb7..3471501ba 100644 --- a/t/Session/Style.t +++ b/t/Session/Style.t @@ -452,15 +452,12 @@ sub sendImmediate { SKIP: { skip "You have an old perl", 1 if $crappyPerl; - close STDOUT; - my $buffer; - open STDOUT, '>', \$buffer or die "Unable to point handle at variable: $!\n"; + my $request = $style->session->request; + $request->clear_output; $style->sent(1); $style->$action($output); - like($buffer, qr/$output/, $comment); + like($request->get_output, qr/$output/, $comment); $style->sent(0); - close STDOUT; - open STDOUT, '>-' or die "Unable to restore STDOUT: $!\n"; } } diff --git a/t/lib/WebGUI/PseudoRequest.pm b/t/lib/WebGUI/PseudoRequest.pm index fd5adbdb3..87578d305 100644 --- a/t/lib/WebGUI/PseudoRequest.pm +++ b/t/lib/WebGUI/PseudoRequest.pm @@ -349,6 +349,26 @@ sub setup_param { #---------------------------------------------------------------------------- +sub clear_output { + my $self = shift; + $self->{output} = ''; +} + +sub get_output { + my $self = shift; + return $self->{output}; +} + +sub print { + my $self = shift; + $self->{output} ||= ''; + for my $p (@_) { + $self->{output} .= $p; + } +} + +#---------------------------------------------------------------------------- + =head2 protocol ( $value ) Getter and setter for protocol. If $value is passed in, it will set the protocol of