Skip to content

Commit

Permalink
Item12466: fix META
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@16665 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Apr 16, 2013
1 parent c4dfcf9 commit e93547a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
75 changes: 46 additions & 29 deletions UnitTestContrib/test/unit/MetaTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,34 @@ my $args2 = {
value => "3"
};

my $web = "TemporaryZoopyDoopy";
my $args3 = {
name => "c",
value => "1"
};

my $topic = "NoTopic";
my $m1;

sub set_up {
my $this = shift;
$this->SUPER::set_up();
$this->createNewFoswikiSession();

$m1 = Foswiki::Meta->new( $this->{session}, $web, $topic );
$m1->put( "TOPICINFO", $args0 );
$m1->putKeyed( "FIELD", $args0 );
$m1->putKeyed( "FIELD", $args2 );

return;
}

sub tear_down {
my $this = shift;
$this->removeWebFixture( $this->{session}, $web )
if $this->{session}->webExists($web);
$m1->finish();
$this->SUPER::tear_down();
Foswiki::Func::saveTopic( $this->{test_web}, "MetaTestsForm", undef,
<<FORM);
| *Name* | *Type* | *Size* | *Values* | *Tooltip message* |
| a | text | 40 | | |
| b | text | 40 | | |
| c | select+values | 1 | one=1, two=2, three=3 | | |
FORM

return;
}

# Field that can only have one copy
sub test_single {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

$meta->put( "TOPICINFO", $args0 );
my $vals = $meta->get("TOPICINFO");
Expand All @@ -79,7 +76,8 @@ sub test_single {

sub test_multiple {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

$meta->putKeyed( "FIELD", $args0 );
my $vals = $meta->get( "FIELD", "a" );
Expand All @@ -106,7 +104,8 @@ sub test_multiple {
# Field with value 0 and value '' This does not cover Item8738
sub test_zero_empty {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

my $args_zero = {
name => "a",
Expand Down Expand Up @@ -135,7 +134,8 @@ sub test_zero_empty {

sub test_removeSingle {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

$meta->put( "TOPICINFO", $args0 );
$this->assert( $meta->count("TOPICINFO") == 1, "Should be one item" );
Expand All @@ -149,7 +149,8 @@ sub test_removeSingle {

sub test_removeMultiple {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

$meta->putKeyed( "FIELD", $args0 );
$meta->putKeyed( "FIELD", $args2 );
Expand All @@ -174,7 +175,8 @@ sub test_removeMultiple {

sub test_foreach {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

$meta->putKeyed( "FIELD", { name => "a", value => "aval" } );
$meta->putKeyed( "FIELD", { name => "b", value => "bval" } );
Expand Down Expand Up @@ -223,14 +225,15 @@ sub fleegle {

sub test_copyFrom {
my $this = shift;
my $meta = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );

$meta->putKeyed( "FIELD", { name => "a", value => "aval" } );
$meta->putKeyed( "FIELD", { name => "b", value => "bval" } );
$meta->putKeyed( "FIELD", { name => "c", value => "cval" } );
$meta->put( "FINAGLE", { name => "a", value => "aval" } );

my $new = Foswiki::Meta->new( $this->{session}, $web, $topic );
my $new = Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );
$new->copyFrom($meta);

my $d = {};
Expand All @@ -242,7 +245,7 @@ sub test_copyFrom {
$this->assert_str_equals( "", $d->{collected} );

$new->finish();
$new = Foswiki::Meta->new( $this->{session}, $web, $topic );
$new = Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );
$new->copyFrom( $meta, 'FIELD' );

$new->forEachSelectedValue( qr/^FIELD$/, qr/^value$/, \&fleegle, $d );
Expand All @@ -252,7 +255,7 @@ sub test_copyFrom {
$this->assert_str_equals( "", $d->{collected} );

$new->finish();
$new = Foswiki::Meta->new( $this->{session}, $web, $topic );
$new = Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );
$new->copyFrom( $meta, 'FIELD', qr/^(a|b)$/ );
$new->forEachSelectedValue( qr/^FIELD$/, qr/^value$/, \&fleegle, $d );
$this->assert( $d->{collected} =~ s/FIELD.value:aval;// );
Expand All @@ -264,11 +267,25 @@ sub test_copyFrom {
return;
}

sub test_formfield {
my $this = shift;

my $m1 = Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );
$m1->put( "TOPICINFO", $args0 );
$m1->putKeyed( "FORM", { name => "MetaTestsForm" } );
$m1->putKeyed( "FIELD", $args3 );

my $str = $m1->expandMacros('%META{"formfield" name="c" display="on"}%');
$this->assert_str_equals( "one", $str );
$str = $m1->expandMacros('%META{"formfield" name="c"}%');
$this->assert_str_equals( "1", $str );

$m1->finish();
}

sub test_parent {
my $this = shift;
my $webObject = Foswiki::Meta->new( $this->{session}, $web );
$webObject->populateNewWeb();
$webObject->finish();
my $web = $this->{test_web};

my $testTopic = "TestParent";
for my $depth ( 1 .. 5 ) {
Expand Down
2 changes: 2 additions & 0 deletions core/data/System/VarMETA.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Parameters:
to be used in tables, etc. =$n= indicates a newline character.
* =bar="..."=: by default, each vertical bar is rewritten to an HTML
entity so as to not be mistaken for a table separator.
* =display="on"= - only used with ="formfield"=, retrieves the *displayed* value of a =*+values= formfield type, as against the default, *stored*, value.
* =topic="Main.WebPreferences"= - optional parameter to select which topic to get the meta-data from.
<blockquote class="foswikiHelp">%X% Use of ="formfield"= is *deprecated* in favour of the much
more powerful =QUERY= macro.</blockquote>

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Form/Checkbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sub renderForDisplay {

$this->getOptions();

if ( !$attrs->{nomap} && $this->isValueMapped() ) {
if ( $attrs->{display} && $this->isValueMapped() ) {
my @vals = ();
foreach my $val ( split( /\s*,\s*/, $value ) ) {
if ( defined( $this->{valueMap}{$val} ) ) {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Form/Select.pm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ sub renderForDisplay {

$this->getOptions();

if ( !$attrs->{nomap} && $this->isValueMapped() ) {
if ( $attrs->{display} && $this->isValueMapped() ) {
my @vals = ();
foreach my $val ( split( /\s*,\s*/, $value ) ) {
if ( defined( $this->{valueMap}{$val} ) ) {
Expand Down
8 changes: 4 additions & 4 deletions core/lib/Foswiki/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1272,13 +1272,13 @@ sub displayFormField {
my ( $meta, $args ) = @_;
my ( $name, @params ) = split( /,\s*/, $args );
my $nomap = 1; # default is to show the unmapped value
my $breakArgs = '';
my $displayedVal = 0; # default is to show the unmapped value
my $breakArgs = '';
if (@params) {
if ( $params[0] eq 'display' ) {
# The displayed value is required
$nomap = 0;
$displayedVal = 1;
shift @params;
}
$breakArgs = join( ',', @params );
Expand All @@ -1294,7 +1294,7 @@ sub displayFormField {
break => $breakArgs,
protectdollar => 1,
showhidden => 1,
nomap => $nomap
display => $displayedVal
}
);
}
Expand Down

0 comments on commit e93547a

Please sign in to comment.