Skip to content

Commit

Permalink
Item13897: A lot of bugs fixed & some tests are passing again.
Browse files Browse the repository at this point in the history
- First major change involing Moo/Moose specific functionality:
Foswiki::Prefs::BaseBackend is now a role, not a base class for other
preference classes.

- Complete Moo-fication of preferences.

- Renamed meta attribute of Foswiki::Meta class to metaData to avoid
possible clashes with Moo::Object meta() method.

- Renamed Foswiki::Meta::load() to Foswiki::Meta::loadCached(). Thanks to
TitanOfOld and JulianLevens for their advices!

- Foswiki::Object now accepts an object in its =$class= argument to have
support for clone-alike methods.

- New isa validator: Foswiki::Object::isaHASH.

- Use of Foswiki::Exception->rethrow() in Plguin.pm.

- Renamed suite attribute of FoswikiFnTestCase to testSuite for
compatibility with TestSuite.pm.
  • Loading branch information
vrurg committed Jan 29, 2016
1 parent cd9a15e commit 0f8803f
Show file tree
Hide file tree
Showing 22 changed files with 470 additions and 357 deletions.
3 changes: 1 addition & 2 deletions PreferencesPlugin/lib/Foswiki/Plugins/PreferencesPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ sub beforeCommonTagsHandler {

# SMELL: Unpublished API. No choice, though :-(
require Foswiki::Form; # SMELL
$formDef =
Foswiki::Form->load( $Foswiki::Plugins::SESSION, $formWeb, $form );
$formDef = Foswiki::Form->loadCached( $Foswiki::Plugins::SESSION, $formWeb, $form );
}

my $query = Foswiki::Func::getCgiQuery();
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/AccessControlTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ around BUILDARGS => sub {

# We need to override the suite parameter.
my %args = @_;
$args{suite} = 'AccessControl';
$args{testSuite} = 'AccessControl';
return $orig->( $class, %args );
};

Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/AddToHeadTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ around BUILDARGS => sub {

# We need to override the suite parameter.
my %args = @_;
$args{suite} = 'SortedHeadTests';
$args{testSuite} = 'SortedHeadTests';
return $orig->( $class, %args );
};

Expand Down
27 changes: 17 additions & 10 deletions UnitTestContrib/test/unit/FormDefTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ sub test_minimalForm {
FORM
$topicObject->save();
$topicObject->finish();
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );
$this->assert($def);
$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('Date');
Expand Down Expand Up @@ -54,7 +55,8 @@ sub test_allCols {
FORM
$topicObject->save();
$topicObject->finish();
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 7, scalar @{ $def->getFields() } );
my $f = $def->getField('Select');
Expand Down Expand Up @@ -137,7 +139,8 @@ FORM
$topicObject->save();
$topicObject->finish();

my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('ValsElsewhere');
Expand Down Expand Up @@ -175,7 +178,8 @@ FORM
FORM
$topicObject->save();
$topicObject->finish();
my $def = Foswiki::Form->new( $this->session, $test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('ValsElsewhere');
Expand Down Expand Up @@ -212,7 +216,8 @@ FORM
FORM
$topicObject->save();
$topicObject->finish();
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('Ecks');
Expand Down Expand Up @@ -246,7 +251,7 @@ FORM
$topicObject->save();
$topicObject->finish();
my $def =
Foswiki::Form->load( $this->session, $this->test_web, 'TestForm' );
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('Ecks');
Expand Down Expand Up @@ -276,7 +281,8 @@ FORM
$topicObject->save();
$topicObject->finish();

my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );

my $f = $def->getField('Ecks');
$this->assert_str_equals( 'SplodgeOne;Blah',
Expand All @@ -302,7 +308,7 @@ FORM
$topicObject->finish();
my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' );
my $form =
Foswiki::Form->new( $this->session, $this->test_web,
Foswiki::Form->loadCached( $this->session, $this->test_web,
'NonExistantForm', $meta );
my $f = $form->getField('Ecks');
$this->assert_str_equals( '', $f->getDefaultValue() );
Expand All @@ -325,7 +331,8 @@ sub test_Item972_selectPlusValues {
FORM
$topicObject->save();
$topicObject->finish();
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
my $def =
Foswiki::Form->loadCached( $this->session, $this->test_web, 'TestForm' );

my $f = $def->getField('Select');
$this->assert_str_equals( 'select+values', $f->{type} );
Expand All @@ -343,7 +350,7 @@ sub test_Item10987_formObjClass {

$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserWikiName} );
my $formObj =
Foswiki::Form->new( $this->session, $Foswiki::cfg{SystemWebName},
Foswiki::Form->loadCached( $this->session, $Foswiki::cfg{SystemWebName},
'UserForm' );
$this->assert( $formObj->isa('Foswiki::Form') );
my @fields = $formObj->getFields();
Expand Down
11 changes: 6 additions & 5 deletions UnitTestContrib/test/unit/FoswikiFnTestCase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ use Unit::Request();
use Unit::Response();
use Foswiki::UI::Register();
use Try::Tiny;
use Carp qw(cluck);

our @mails;

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

has suite => (
has testSuite => (
is => 'ro',
required => 1,
);
Expand All @@ -45,19 +46,19 @@ has test_web => (
lazy => 1,
clearer => 1,
builder => sub {
my $suite = $_[0]->suite;
return 'Temporary' . $suite . 'TestWeb' . $suite;
my $testSuite = $_[0]->testSuite;
return 'Temporary' . $testSuite . 'TestWeb' . $testSuite;
},
);
has test_topic => (
is => 'rw',
lazy => 1,
builder => sub { return 'TestTopic' . $_[0]->suite; },
builder => sub { return 'TestTopic' . $_[0]->testSuite; },
);
has users_web => (
is => 'rw',
lazy => 1,
builder => sub { return 'Temporary' . $_[0]->suite . 'UsersWeb'; },
builder => sub { return 'Temporary' . $_[0]->testSuite . 'UsersWeb'; },
);
has test_user_forename => ( is => 'rw', );
has test_user_surname => ( is => 'rw', );
Expand Down
3 changes: 2 additions & 1 deletion core/lib/Foswiki/Compatibility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ sub upgradeCategoryTable {
}

require Foswiki::Form;
my $def = Foswiki::Form->load( $session, $web, $defaultFormTemplate );
my $def =
Foswiki::Form->loadCached( $session, $web, $defaultFormTemplate );
$meta->put( 'FORM', { name => $defaultFormTemplate } );

foreach my $fieldDef ( @{ $def->getFields() } ) {
Expand Down
16 changes: 9 additions & 7 deletions core/lib/Foswiki/Form.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ has def => (
predicate => 1,
);
has fields => (
is => 'rw',
lazy => 1,
is => 'rw',
lazy => 1,
clearer => 1,
);
has mandatoryFieldsPresent => (
is => 'rw',
Expand Down Expand Up @@ -126,7 +127,8 @@ sub _validateWebTopic {
# XXX vrurg ClassMethod load() is supposed to replace the old new() method and
# become a new constructor. Required to stay in compliance with Moo architecture
# and avoid replacing of the standard new() method.
sub load {
# SMELL Foswiki::Meta already defines load() method. Need another name.
sub loadCached {
my ( $class, $session, $web, $form, $def ) = @_;

my ( $vweb, $vtopic ) = _validateWebTopic( $session, $web, $form );
Expand All @@ -144,7 +146,7 @@ sub load {
session => $session,
web => $vweb,
form => $vtopic,
_via_load => 1,
_indirect => 1,
( defined $def ? ( def => $def ) : () ),
);
}
Expand All @@ -163,12 +165,12 @@ around BUILDARGS => sub {
$params->{topic} = $vtopic;

# Avoid direct calls to $class::new().
ASSERT( $params->{_via_load},
"${class}::new() has been use directly. Use ${class}::load() instead."
ASSERT( $params->{_indirect},
"${class}::new() has been use directly. Use ${class}->loadCached() instead."
);

# No more need to pollute properties with this key.
delete $params->{_via_load};
delete $params->{_indirect};

# Got to have either a def or a topic
unless ( $params->{def} || $session->topicExists( $vweb, $vtopic ) ) {
Expand Down

0 comments on commit 0f8803f

Please sign in to comment.