Skip to content

Commit

Permalink
Item13897: Bug fixes and more tests adaptations.
Browse files Browse the repository at this point in the history
- Disabled testing of iso8859-1 store encoding on OSX. It is sensless – see
Item13997.
  • Loading branch information
vrurg committed Feb 29, 2016
1 parent 9a02e79 commit 54fddfb
Show file tree
Hide file tree
Showing 11 changed files with 886 additions and 702 deletions.
16 changes: 8 additions & 8 deletions RCSStoreContrib/lib/Foswiki/Store/Rcs/Store.pm
Expand Up @@ -341,7 +341,7 @@ sub _getAttachmentVersionInfo {
$this->getHandler( $topicObject->web, $topicObject->topic,
$attachment );
$info = $handler->getInfo( $rev || 0 );
$info->{author} = _decode( $info->{author} );
$info->{author} = _decode( $info->{author} );
$info->{comment} = _decode( $info->{comment} );
}

Expand All @@ -366,7 +366,7 @@ sub getVersionInfo {
else {
# Load into a new object to avoid blowing away the object we
# were passed; then selectively get the bits we want.
my $dummy = Foswiki::Meta->new($topicObject);
my $dummy = Foswiki::Meta->new( session => $topicObject );
$dummy->loadVersion();
$info = $dummy->get('TOPICINFO');
$topicObject->put( 'TOPICINFO', $info );
Expand All @@ -377,8 +377,8 @@ sub getVersionInfo {
if ( not defined $info ) {
my $handler =
$this->getHandler( $topicObject->web, $topicObject->topic );
$info = $handler->getInfo($rev);
$info->{author} = _decode( $info->{author} );
$info = $handler->getInfo($rev);
$info->{author} = _decode( $info->{author} );
$info->{comment} = _decode( $info->{comment} );
}

Expand Down Expand Up @@ -574,7 +574,7 @@ sub eachChange {

my @changes;
@changes = reverse grep { $_->{time} >= $since } $handler->readChanges();
return Foswiki::ListIterator->new( \@changes );
return Foswiki::ListIterator->new( list => \@changes );
}

sub getApproxRevTime {
Expand All @@ -590,7 +590,7 @@ sub eachAttachment {
my $handler = $this->getHandler( $topicObject->web, $topicObject->topic );
my @list = $handler->getAttachmentList();
require Foswiki::ListIterator;
return new Foswiki::ListIterator( \@list );
return new Foswiki::ListIterator( list => \@list );
}

sub eachTopic {
Expand All @@ -600,7 +600,7 @@ sub eachTopic {
my @list = $handler->getTopicNames();

require Foswiki::ListIterator;
return new Foswiki::ListIterator( \@list );
return new Foswiki::ListIterator( list => \@list );
}

sub eachWeb {
Expand All @@ -624,7 +624,7 @@ sub eachWeb {
}
@list = sort(@list);
require Foswiki::ListIterator;
return new Foswiki::ListIterator( \@list );
return new Foswiki::ListIterator( list => \@list );
}

sub remove {
Expand Down
97 changes: 44 additions & 53 deletions UnitTestContrib/test/unit/FoswikiSeleniumTestCase.pm
Expand Up @@ -3,20 +3,20 @@
# The FoswikiFnTestCase restrictions also apply.

package FoswikiSeleniumTestCase;
use strict;
use warnings;

use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );
use v5.14;

use Encode;
use Foswiki();
use Unit::Request();
use Unit::Response();
use Foswiki::UI::Register();
use Error qw( :try );
use Try::Tiny;
use Scalar::Util qw( weaken );

use Moo;
use namespace::clean;
extends qw( FoswikiFnTestCase );

my $startWait;
my $doze;

Expand Down Expand Up @@ -51,6 +51,14 @@ my $testsRunWithoutRestartingBrowsers = 0;

my $debug = 0;

has selenium_timeout => ( is => 'rw', default => 30000, );
has useSeleniumError =>
( is => 'rw', lazy => 1, default => sub { $_[0]->_loadSeleniumInterface; }, );
has seleniumBrowsers =>
( is => 'rw', lazy => 1, default => sub { $_[0]->_loadSeleniumBrowsers; }, );
has browser => ( is => 'rw', );
has selenium => ( is => 'rw', );

sub skip {
my ( $this, $test ) = @_;
my $browsers = $Foswiki::cfg{UnitTestContrib}{SeleniumRc}{Browsers};
Expand All @@ -61,16 +69,15 @@ sub skip {
"No browsers configured in \$Foswiki::cfg{UnitTestContrib}{SeleniumRc}{Browsers}";
}

if ( $this->{useSeleniumError} ) {
$reason = "Cannot run Selenium-based tests: $this->{useSeleniumError}";
if ( $this->useSeleniumError ) {
$reason = "Cannot run Selenium-based tests: $this->useSeleniumError";
}

return $reason;
}

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
sub BUILD {
my $this = shift;

#if ( defined $currentTest ) {
# $this->assert( 0,
Expand All @@ -81,21 +88,13 @@ sub new {
#}
$currentTest = $this;
weaken($currentTest); # Ensure the destructor is called at the normal time

$this->{selenium_timeout} = 30_000; # Same as WWW::Selenium's default value
$this->{useSeleniumError} = $this->_loadSeleniumInterface;
$this->{seleniumBrowsers} = $this->_loadSeleniumBrowsers;

$this->timeout( $Foswiki::cfg{UnitTestContrib}{SeleniumRc}{BaseTimeout} );

return $this;
}

END {
_shutDownSeleniumBrowsers() if $browsers;
}

sub DESTROY {
sub DEMOLISH {
my $this = shift;
if ( not defined($currentTest) or $currentTest != $this ) {
$this->assert( 0,
Expand All @@ -109,16 +108,14 @@ sub DESTROY {
_shutDownSeleniumBrowsers();
$testsRunWithoutRestartingBrowsers = 0;
}

$this->SUPER::DESTROY if $this->can('SUPER::DESTROY');
}

sub fixture_groups {
my ( $this, $suite ) = @_;

return \@BrowserFixtureGroups if @BrowserFixtureGroups;

for my $browser ( keys %{ $this->{seleniumBrowsers} } ) {
for my $browser ( keys %{ $this->seleniumBrowsers } ) {
my $onBrowser = "on$browser";
push @BrowserFixtureGroups, $onBrowser;

Expand All @@ -135,11 +132,11 @@ sub selectBrowser {
my $browserName = shift;
$this->assert( defined($browserName), "Browser name not specified" );
$this->assert(
exists( $this->{seleniumBrowsers}->{$browserName} ),
exists( $this->seleniumBrowsers->{$browserName} ),
"No Test::WWW:Selenium object for $browserName"
);
$this->{browser} = $browserName;
$this->{selenium} = $this->{seleniumBrowsers}->{$browserName};
$this->browser($browserName);
$this->selenium( $this->seleniumBrowsers->{$browserName} );
}

sub _loadSeleniumInterface {
Expand Down Expand Up @@ -187,7 +184,7 @@ sub _loadSeleniumBrowsers {
$config{error_callback} = \&_errorCallback;

my $selenium;
if ( $this->{useSeleniumError} ) {
if ( $this->useSeleniumError ) {
$browsers->{$browser} = undef;
}
else {
Expand Down Expand Up @@ -239,43 +236,37 @@ sub _shutDownSeleniumBrowsers {

sub browserName {
my $this = shift;
return $this->{browser};
}

sub selenium {
my $this = shift;
return $this->{selenium};
return $this->browser;
}

sub login {
my $this = shift;

#SMELL: Assumes TemplateLogin
$this->{selenium}->open_ok(
$this->selenium->open_ok(
Foswiki::Func::getScriptUrl(
$this->{test_web}, $this->{test_topic}, 'login'
$this->test_web, $this->test_topic, 'login'
)
);
my $usernameInputFieldLocator = 'css=input[name="username"]';
$this->{selenium}->wait_for_element_present( $usernameInputFieldLocator,
$this->{selenium_timeout} );
$this->{selenium}->type_ok( $usernameInputFieldLocator,
$this->selenium->wait_for_element_present( $usernameInputFieldLocator,
$this->selenium_timeout );
$this->selenium->type_ok( $usernameInputFieldLocator,
$Foswiki::cfg{UnitTestContrib}{SeleniumRc}{Username} );

my $passwordInputFieldLocator = 'css=input[name="password"]';
$this->assertElementIsPresent($passwordInputFieldLocator);
$this->{selenium}->type_ok( $passwordInputFieldLocator,
$this->selenium->type_ok( $passwordInputFieldLocator,
$Foswiki::cfg{UnitTestContrib}{SeleniumRc}{Password} );

my $loginFormLocator = 'css=form[name="loginform"]';
$this->assertElementIsPresent($loginFormLocator);
$this->{selenium}->click_ok('css=input.foswikiSubmit[type="submit"]');
$this->{selenium}->wait_for_page_to_load( $this->{selenium_timeout} );
$this->selenium->click_ok('css=input.foswikiSubmit[type="submit"]');
$this->selenium->wait_for_page_to_load( $this->selenium_timeout );

my $postLoginLocation = $this->{selenium}->get_location();
my $postLoginLocation = $this->selenium->get_location();
my $viewUrl =
Foswiki::Func::getScriptUrl( $this->{test_web}, $this->{test_topic},
'view' );
Foswiki::Func::getScriptUrl( $this->test_web, $this->test_topic, 'view' );
$this->assert_matches( qr/\Q$viewUrl\E$/, $postLoginLocation );
}

Expand All @@ -284,7 +275,7 @@ sub type {
my $locator = shift;
my $text = shift;

# If you pass too much text to $this->{selenium}->type()
# If you pass too much text to $this->selenium->type()
# then the test fails with a 414 error from the selenium server.
# That can happen quite easily when pasting topic text into
# the edit form's textarea
Expand All @@ -306,21 +297,21 @@ sub type {
$start += $maxChars;
my $javascript =
qq/selenium.browserbot.findElement("$locator").value $assignOperator "$chunk";/;
$this->{selenium}->get_eval($javascript);
$this->selenium->get_eval($javascript);

#sleep 2;
}
}
else {
$this->{selenium}->type( $locator, $text );
$this->selenium->type( $locator, $text );
}
}

sub timeout {
my $this = shift;
my $timeout = shift;
$this->{selenium_timeout} = $timeout if $timeout;
return $this->{selenium_timeout};
$this->selenium_timeout($timeout) if $timeout;
return $this->selenium_timeout;
}

sub waitFor {
Expand All @@ -329,7 +320,7 @@ sub waitFor {
my $message = shift;
my $args = shift;
my $timeout = shift;
$timeout ||= $this->{selenium_timeout};
$timeout ||= $this->selenium_timeout;
$args ||= [];
my $result;
my $elapsed = 0;
Expand All @@ -347,7 +338,7 @@ sub assertElementIsPresent {
my $locator = shift;
my $message = shift;
$message ||= "Element $locator is not present";
$this->assert( $this->{selenium}->is_element_present($locator), $message );
$this->assert( $this->selenium->is_element_present($locator), $message );

return;
}
Expand All @@ -357,7 +348,7 @@ sub assertElementIsVisible {
my $locator = shift;
my $message = shift;
$message ||= "Element $locator is not visible";
$this->assert( $this->{selenium}->is_visible($locator), $message );
$this->assert( $this->selenium->is_visible($locator), $message );

return;
}
Expand All @@ -368,7 +359,7 @@ sub assertElementIsNotVisible {
my $message = shift;
$this->assertElementIsPresent($locator);
$message ||= "Element $locator is visible";
$this->assert( not $this->{selenium}->is_visible($locator), $message );
$this->assert( not $this->selenium->is_visible($locator), $message );

return;
}
Expand Down
13 changes: 10 additions & 3 deletions UnitTestContrib/test/unit/FoswikiStoreTestCase.pm
Expand Up @@ -9,6 +9,7 @@ use utf8;
# Subclasses are expected to implement set_up_for_verify()
#
use File::Spec();
use Try::Tiny;

use Moo;
use namespace::clean;
Expand Down Expand Up @@ -113,6 +114,11 @@ sub fixture_groups {
}
}

my @encoding_groups = qw(utf8);
unless ( $^O =~ /darwin/i ) {
push @encoding_groups, 'iso8859';
}

#return ( [ 'PlainFile' ], [ 'utf8' ] );
if ($Foswiki::UNICODE) {
if ( Cwd::cwd() =~ m/[^\p{ASCII}]/ ) {
Expand All @@ -121,7 +127,7 @@ sub fixture_groups {
return ( \@groups, [ 'utf8', ] );
}
else {
return ( \@groups, [ 'iso8859', 'utf8', ] );
return ( \@groups, [@encoding_groups] );
}
}
else {
Expand Down Expand Up @@ -161,7 +167,7 @@ sub utf8 {
undef $Foswiki::cfg{Store}{Encoding};
$this->t_web('Temporary普通话Web1');
$this->t_web2('Temporary国语Web2');
$this->t_topic('Testру́сскийTopic');
$this->t_topic('TestукраїнськийTopic');
$this->t_datafile("Šňá徊ťěř.gif");
$this->t_datapath( "$Foswiki::cfg{TempfileDir}/" . $this->t_datafile );
$this->t_datafile2("پښتانهټبرونه.gif");
Expand All @@ -177,7 +183,8 @@ sub iso8859 {
$Foswiki::cfg{Store}{Encoding} = 'iso-8859-1';
my $s =
Encode::decode( 'iso-8859-1',
join( '', map( chr($_), ( 160 .. 255 ) ) ) );
join( '', map { chr($_) } ( 160 .. 200 ) ) );

my $n = $s;
$n =~ s/$Foswiki::cfg{NameFilter}//g;
$this->t_web("Temporary${n}Web1");
Expand Down

0 comments on commit 54fddfb

Please sign in to comment.