Skip to content

Commit

Permalink
Item11440: Resurrect Selenium tests, use readTopic
Browse files Browse the repository at this point in the history
   * Address a few (but not all) perlcriticisms
   * Use Foswiki::Func::readTopic rather than Foswiki::Meta->new
   * Add a skip method so FoswikiSuite reminds us selenium tests exist
   * Commented some code that was killing the tests; for some reason we
     were doing a save in between browser-edit & browser-save? This
     caused a save oops, rather than a redirect back to view as the
     tests expect.

git-svn-id: http://svn.foswiki.org/branches/Release01x01@13858 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Jan 30, 2012
1 parent af3839e commit f1845d6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
16 changes: 7 additions & 9 deletions WysiwygPlugin/test/unit/WysiwygPlugin/BrowserEditorInterface.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# See bottom of file for license and copyright information
package BrowserEditorInterface;
use strict;
use warnings;

package BrowserEditorInterface;

# This package encapsulates the interface to the wysiwyg editor

use Scalar::Util;
Expand Down Expand Up @@ -52,16 +51,15 @@ sub init {
print STDERR "BrowserEditorInterface::init()\n" if _DEBUG;

if ( not $this->{_initWebPreferences} ) {
my $topicObject = Foswiki::Meta->new(
$this->{_test}->{session},
$this->{_test}->{test_web},
$Foswiki::cfg{WebPrefsTopicName},
<<"HERE"
my ($topicObject) =
Foswiki::Func::readTopic( $this->{_test}->{test_web},
$Foswiki::cfg{WebPrefsTopicName} );
$topicObject->text( <<"HERE");
* Set SKIN=pattern
* Set ALLOWTOPICCHANGE=$this->{_test}->{test_user_wikiname}
HERE
);
$topicObject->save();
$topicObject->finish();

$this->{_initWebPreferences} = 1;
}
Expand Down Expand Up @@ -331,7 +329,7 @@ sub selectWysiwygMode {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
44 changes: 26 additions & 18 deletions WysiwygPlugin/test/unit/WysiwygPlugin/BrowserTranslatorTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ package BrowserTranslatorTests;

use Encode;

use FoswikiSeleniumTestCase;
use TranslatorBase;
use FoswikiSeleniumTestCase();
use TranslatorBase();
our @ISA = qw( FoswikiSeleniumTestCase TranslatorBase );

use BrowserEditorInterface;
use Foswiki::Func;
use Foswiki::Plugins::WysiwygPlugin::Handlers;
use Foswiki::Plugins::WysiwygPlugin::Constants;
use BrowserEditorInterface();
use Foswiki::Func();
use Foswiki::Plugins::WysiwygPlugin::Handlers();
use Foswiki::Plugins::WysiwygPlugin::Constants();

# The following big table contains all the testcases. These are
# used to add a bunch of functions to the symbol table of this
Expand Down Expand Up @@ -447,6 +447,7 @@ sub new {
my $self = shift()->SUPER::new( 'BrowserTranslator', @_ );

$self->{editor} = BrowserEditorInterface->new($self);
BrowserTranslatorTests->gen_compare_tests( 'verify', $data );

return $self;
}
Expand Down Expand Up @@ -502,27 +503,36 @@ sub verify_editSaveTopicWithUnnamedUnicodeEntity {

# Create the test topic
my $topicName = $this->{test_topic} . "For9170";
my $topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topicName,
"Before${testText}After\n" );
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $topicName );
$topicObject->text("Before${testText}After\n");
$topicObject->save();
$topicObject->finish();

# Open the test topic in the wysiwyg editor
$this->{editor}->openWysiwygEditor( $this->{test_web}, $topicName );

# Write rubbish over the topic, which will be overwritten on save
$topicObject->text("Rubbish");
$topicObject->save();
undef $topicObject;
# PH Commented this out below in Item11440, it causes Foswiki to redirect
# back to the save oops "merged with new revision while you were
# editing..." screen, rather than view as the tests expect.
#
## Write rubbish over the topic, which will be overwritten on save
#($topicObject) =
# Foswiki::Func::readTopic( $this->{test_web}, $topicName);
#$topicObject->text("Rubbish");
#
#$topicObject->save();
#$topicObject->finish();
#undef $topicObject;

# Save from the editor
$this->{editor}->save();

# Reload the topic and check that the content is as expected
$topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topicName );
($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, $topicName );

my $text = $topicObject->text();
$topicObject->finish();

# Isolate the portion of interest
$text =~ s/.*Before//ms or $this->assert( 0, $text );
Expand Down Expand Up @@ -596,14 +606,12 @@ sub compareHTML_TML {
$this->assert_tml_equals( $args->{tml}, $actualTml, $args->{name} );
}

BrowserTranslatorTests->gen_compare_tests( 'verify', $data );

1;

__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
10 changes: 5 additions & 5 deletions WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorBase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,26 @@ sub gen_compare_tests {
if ( ( $mask & $datum->{exec} ) & $TML2HTML ) {
my $fn = $class . '::' . $method . 'TML2HTML_' . $datum->{name};
no strict 'refs';
*$fn = sub { my $this = shift; $this->compareTML_HTML($datum) };
*{$fn} = sub { my $this = shift; $this->compareTML_HTML($datum) };
use strict 'refs';
}
if ( ( $mask & $datum->{exec} ) & $HTML2TML ) {
my $fn = $class . '::' . $method . 'HTML2TML_' . $datum->{name};
no strict 'refs';
*$fn = sub { my $this = shift; $this->compareHTML_TML($datum) };
*{$fn} = sub { my $this = shift; $this->compareHTML_TML($datum) };
use strict 'refs';
}
if ( ( $mask & $datum->{exec} ) & $ROUNDTRIP ) {
my $fn = $class . '::' . $method . 'ROUNDTRIP_' . $datum->{name};
no strict 'refs';
*$fn = sub { my $this = shift; $this->compareRoundTrip($datum) };
*{$fn} = sub { my $this = shift; $this->compareRoundTrip($datum) };
use strict 'refs';
}
if ( ( $mask & $datum->{exec} ) & $CANNOTWYSIWYG ) {
my $fn =
$class . '::' . $method . 'CANNOTWYSIWYG_' . $datum->{name};
no strict 'refs';
*$fn =
*{$fn} =
sub { my $this = shift; $this->compareNotWysiwygEditable($datum) };
use strict 'refs';
}
Expand Down Expand Up @@ -170,7 +170,7 @@ sub assert_tml_not_equals {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down

0 comments on commit f1845d6

Please sign in to comment.