[Codestriker-commits] CVS update: codestriker/test/CodestrikerTest MainPage.pm Page.pm
Brought to you by:
sits
From: <si...@us...> - 2004-12-14 21:39:59
|
User: sits Date: 04/12/14 13:39:50 Modified: test/CodestrikerTest MainPage.pm Page.pm Added: test usecompression.t Log: Test for compression from Jason Index: usecompression.t =================================================================== RCS file: usecompression.t diff -N usecompression.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ usecompression.t 14 Dec 2004 21:39:46 -0000 1.1 @@ -0,0 +1,61 @@ + +use strict; +use warnings; + +use Test::More qw(no_plan); + +use CodestrikerTest::Config; +use CodestrikerTest::MainPage; +use CodestrikerTest::Page; +use CodestrikerTest::PageFactory; +use CodestrikerTest::Util; + +CodestrikerTest::Config::ProcessCommandLine(); + +# make sure we can do this not compressed. +CodestrikerTest::Config::SetConfigOption(qq|\$use_compression = 0;|); + +my $main = CodestrikerTest::PageFactory->CreatePage($CodestrikerTest::Config::main_url); + +ok( $main->IsCompressed() == 0,"main not IsCompressed" ); + +# now do the rest of the test compressed. +CodestrikerTest::Config::SetConfigOption(qq|\$use_compression = 1;|); + +my $commpressed_comment_tag = "Source was sent compressed."; + +# create page with no params +$main = CodestrikerTest::PageFactory->CreatePage($CodestrikerTest::Config::main_url); + +ok( $main->IsCompressed(),"main IsCompressed" ); + +my $newTopic = $main->GetNewTopicPage(); + +ok( $newTopic,"Verify new topic page" ); + +ok( $newTopic->{response}->content =~ /$commpressed_comment_tag/ , "look $commpressed_comment_tag comment"); + +my $confirmPage; + +my $titleName = MakeNewTopicName(); + +$confirmPage = $newTopic->CreateNewTopic( + topic_title=>$titleName, + topic_description=>'d', + email=>$CodestrikerTest::Config::email_adddress[0] , + reviewers=>$CodestrikerTest::Config::email_adddress[1], + topic_file=>'newtopic.t'); + +ok( $confirmPage->TopicCreated(),"create topic \"$titleName\"" ); + +ok( $confirmPage->IsCompressed(),"confirmPage IsCompressed" ); + +ok($main->Get(),"get main page"); + +ok( my $topic_content = $main->GetLink($titleName),"get link \"$titleName\""); + +ok( $topic_content->IsCompressed(),"IsCompressed" ); + + +0; + Index: MainPage.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/test/CodestrikerTest/MainPage.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MainPage.pm 8 Sep 2004 03:48:57 -0000 1.2 +++ MainPage.pm 14 Dec 2004 21:39:49 -0000 1.3 @@ -28,28 +28,28 @@ { my ($self,%params) = @_; - unless ( exists( $params{topic_title} ) ) + unless ( exists($params{topic_title}) ) { my $titleName = MakeNewTopicName(); $params{topic_title} = $titleName; } - unless ( exists( $params{topic_description} ) ) + unless ( exists($params{topic_description}) ) { $params{topic_description} = "description"; } - unless ( exists( $params{email} ) ) + unless ( exists($params{email}) ) { $params{email} = $CodestrikerTest::Config::email_adddress[0]; } - unless ( exists( $params{reviewers} ) ) + unless ( exists($params{reviewers}) ) { $params{reviewers} = $CodestrikerTest::Config::email_adddress[1]; } - unless ( exists( $params{topic_file} ) ) + unless ( exists($params{topic_file}) ) { $params{topic_file} = 'newtopic.t'; } Index: Page.pm =================================================================== RCS file: /cvsroot/codestriker/codestriker/test/CodestrikerTest/Page.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Page.pm 8 Sep 2004 03:48:57 -0000 1.2 +++ Page.pm 14 Dec 2004 21:39:49 -0000 1.3 @@ -10,6 +10,7 @@ use CodestrikerTest::PageFactory; use HTML::Lint; use Test::More; +use Compress::Zlib; sub new { @@ -45,6 +46,9 @@ delete $self->{links}; delete $self->{forms}; + # need to test the compression config. + $request->header('Accept-Encoding','gzip'); + my $ua = LWP::UserAgent->new; # tell LWP that it is ok to be redirected after a post command, as is done @@ -53,8 +57,16 @@ $self->{response} = $ua->request($request); + # uncompress it if it was sent compressed. + if ( defined($self->{response}) && $self->IsCompressed() ) + { + $self->{response}->content( + Compress::Zlib::memGunzip($self->{response}->content)); + } + if ($self->{response}->is_success) { + $self->_ParsePageHTML(); } else @@ -271,5 +283,21 @@ } +# returns true if the page was returned compressed. +sub IsCompressed +{ + my ($self) = @_; + + if ( !exists( $self->{response} ) ) + { + ok( $self->Get(),"get page $self->{url} from IsCompressed"); + } + + my $encoding = $self->{response}->header( 'Content-Encoding'); + + # uncompress it if it was sent compressed. + return defined($encoding) && $encoding eq 'x-gzip'; +} + 1; \ No newline at end of file |