Skip to content

Commit

Permalink
Item13897: Intermidiate commit, totally unchecked.
Browse files Browse the repository at this point in the history
- Initial Moo-fication FormDefTests and Foswiki::Meta.

- Moved META keys from object hash to meta attribute: $this->meta->{$type}.
Suggested development direction is to split Foswiki::Meta into
Foswiki::Entity (or whatever other name is considered suitable) and actual
Foswiki::Meta. The meta attribute of Foswiki::Entity class should be
instantinated into Foswiki::Meta and delegate some methods onto the parent
object/class for compatibility. This way we can separate topic and meta
storages for perfomance and flexilibity matters.
  • Loading branch information
vrurg committed Jan 23, 2016
1 parent 44a6257 commit d4974a3
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 480 deletions.
96 changes: 38 additions & 58 deletions UnitTestContrib/test/unit/FormDefTests.pm
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# Copyright (C) 2006 WikiRing http://wikiring.com
# Tests for form def parser
package FormDefTests;

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

use Foswiki;
use Foswiki::Form;
use Try::Tiny;

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

use Assert;
use Error qw( :try );

sub test_minimalForm {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* |
| Date | date | 30 |
FORM
$topicObject->save();
$topicObject->finish();
my $def =
Foswiki::Form->new( $this->{session}, $this->{test_web}, 'TestForm' );
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );
$this->assert($def);
$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('Date');
Expand All @@ -42,8 +41,7 @@ FORM
sub test_allCols {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* | *Value* | *Tooltip* | *Attributes* |
| Select | select | 2..4 | a,b,c | Tippity | M |
Expand All @@ -56,8 +54,7 @@ sub test_allCols {
FORM
$topicObject->save();
$topicObject->finish();
my $def =
Foswiki::Form->new( $this->{session}, $this->{test_web}, 'TestForm' );
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 7, scalar @{ $def->getFields() } );
my $f = $def->getField('Select');
Expand Down Expand Up @@ -122,16 +119,15 @@ FORM
sub test_valsFromOtherTopic {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* | *Value* |
| Vals Elsewhere | select | | |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'ValsElsewhere' );
Foswiki::Func::readTopic( $this->test_web, 'ValsElsewhere' );
$topicObject->text( <<'FORM');
| *Name* |
| ValOne |
Expand All @@ -141,8 +137,7 @@ FORM
$topicObject->save();
$topicObject->finish();

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

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('ValsElsewhere');
Expand All @@ -163,15 +158,15 @@ FORM
sub test_squabValRef {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my $test_web = $this->test_web;
my ($topicObject) = Foswiki::Func::readTopic( $test_web, 'TestForm' );
$topicObject->text( <<"FORM");
| *Name* | *Type* | *Size* | *Value* |
| [[$this->{test_web}.Splodge][Vals Elsewhere]] | select | | |
| [[$test_web.Splodge][Vals Elsewhere]] | select | | |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'Splodge' );
($topicObject) = Foswiki::Func::readTopic( $test_web, 'Splodge' );
$topicObject->text( <<'FORM');
| *Name* |
| ValOne |
Expand All @@ -180,8 +175,7 @@ FORM
FORM
$topicObject->save();
$topicObject->finish();
my $def =
Foswiki::Form->new( $this->{session}, $this->{test_web}, 'TestForm' );
my $def = Foswiki::Form->new( $this->session, $test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('ValsElsewhere');
Expand All @@ -190,8 +184,7 @@ FORM
$this->assert_str_equals( 'Vals Elsewhere', $f->{title} );
$this->assert_str_equals( 'ValOne,RowName,Age',
join( ',', @{ $f->getOptions() } ) );
$this->assert_str_equals( $this->{test_web} . '.Splodge',
$f->{definingTopic} );
$this->assert_str_equals( $test_web . '.Splodge', $f->{definingTopic} );
$def->finish();

return;
Expand All @@ -200,30 +193,26 @@ FORM
sub test_searchForOptions {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* | *Value* |
| Ecks | select | 1 | %SEARCH{"^\\| (Age\|Beauty)" type="regex" nonoise="on" separator="," format="$topic"}% |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' );
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' );
$topicObject->text( <<'FORM');
| Age |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeTwo' );
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeTwo' );
$topicObject->text( <<'FORM');
| Beauty |
FORM
$topicObject->save();
$topicObject->finish();
my $def =
Foswiki::Form->new( $this->{session}, $this->{test_web}, 'TestForm' );
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('Ecks');
Expand All @@ -237,30 +226,26 @@ FORM
sub test_searchForOptionsQuery {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* | *Value* |
| Ecks | select | 1 | %SEARCH{"text=~'^\\| (Age\|Beauty)'" type="query" nonoise="on" separator="," format="$topic"}% |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' );
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' );
$topicObject->text( <<FORM);
| Age |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeTwo' );
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeTwo' );
$topicObject->text( <<FORM);
| Beauty |
FORM
$topicObject->save();
$topicObject->finish();
my $def =
new Foswiki::Form( $this->{session}, $this->{test_web}, 'TestForm' );
my $def = new Foswiki::Form( $this->session, $this->test_web, 'TestForm' );

$this->assert_equals( 1, scalar @{ $def->getFields() } );
my $f = $def->getField('Ecks');
Expand All @@ -274,32 +259,29 @@ sub test_Item6082 {

# Form definition that requires the form definition to be loaded before
# it can be loaded.
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* | *Value* | *Tooltip message* | *Attributes* |
| Why | text | 32 | | Mandatory field | M |
| Ecks | select | 1 | %SEARCH{"TestForm.Ecks~'Blah*'" type="query" order="topic" separator="," format="$topic;$formfield(Ecks)" nonoise="on"}% | | |
FORM
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' );
($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' );
$topicObject->text( <<'FORM');
%META:FORM{name="TestForm"}%
%META:FIELD{name="Ecks" title="X" value="Blah"}%
FORM
$topicObject->save();
$topicObject->finish();

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

my $f = $def->getField('Ecks');
$this->assert_str_equals( 'SplodgeOne;Blah',
join( ',', sort @{ $f->getOptions() } ) );

my ($meta) = Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$meta->renderFormForDisplay();
$def->finish();
$meta->finish();
Expand All @@ -310,16 +292,16 @@ FORM
sub test_makeFromMeta {
my $this = shift;
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' );
Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' );
$topicObject->text( <<'FORM');
%META:FORM{name="NonExistantForm"}%
%META:FIELD{name="Ecks" title="X" value="Blah"}%
FORM
$topicObject->save();
$topicObject->finish();
my ($meta) = Foswiki::Func::readTopic( $this->{test_web}, 'SplodgeOne' );
my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SplodgeOne' );
my $form =
Foswiki::Form->new( $this->{session}, $this->{test_web},
Foswiki::Form->new( $this->session, $this->test_web,
'NonExistantForm', $meta );
my $f = $form->getField('Ecks');
$this->assert_str_equals( '', $f->getDefaultValue() );
Expand All @@ -335,16 +317,14 @@ FORM
sub test_Item972_selectPlusValues {
my $this = shift;

my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'TestForm' );
$topicObject->text( <<'FORM');
| *Name* | *Type* | *Size* | *Value* | *Tooltip* | *Attributes* |
| Select | select+values | 5 | , =0, One, Two=2, Th%72ee=III, Four | Various values |
FORM
$topicObject->save();
$topicObject->finish();
my $def =
Foswiki::Form->new( $this->{session}, $this->{test_web}, 'TestForm' );
my $def = Foswiki::Form->new( $this->session, $this->test_web, 'TestForm' );

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

$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserWikiName} );
my $formObj =
Foswiki::Form->new( $this->{session}, $Foswiki::cfg{SystemWebName},
Foswiki::Form->new( $this->session, $Foswiki::cfg{SystemWebName},
'UserForm' );
$this->assert( $formObj->isa('Foswiki::Form') );
my @fields = $formObj->getFields();
Expand Down
4 changes: 3 additions & 1 deletion core/lib/Foswiki/Exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Basic principles behind exceptions:
1. =Foswiki::Exception= is utilizing =Throwable= role. Requires this module to be installed.
1. Exception classes inheritance shall form a tree of relationships for fine-grained error hadling.
The latter item might be illustrated with the following expample (for inherited classes =Foswiki::Exception= prefix is skipped for simplicity though it is recommended for code readability):
The latter item might be illustrated with the following expample (for inherited
classes =Foswiki::Exception= prefix is skipped for simplicity though it is
recommended for code readability):
* Foswiki::Exception
* Core
Expand Down

0 comments on commit d4974a3

Please sign in to comment.