Skip to content

Commit

Permalink
Item11135: Convert Foswiki::Meta->load readTopic
Browse files Browse the repository at this point in the history
Conflicts:

	test/unit/FoswikiFnTestCase.pm
	test/unit/RegisterTests.pm

git-svn-id: http://svn.foswiki.org/branches/Release01x01@13847 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Jan 28, 2012
1 parent 6952086 commit 119630a
Show file tree
Hide file tree
Showing 26 changed files with 488 additions and 472 deletions.
23 changes: 11 additions & 12 deletions UnitTestContrib/test/unit/AutoAttachTests.pm
@@ -1,17 +1,17 @@
use strict;

# Test cases:
# 1) Autoattach = off. Save a topic referring to an attachmentMissing that does not exist.
# 2) Add attachmentAdded into the attachment area for that topic, circumventing Foswiki
# 3) Turn autoattach = on. Ask for the list of attachments. attachmentAdded should appear. attachmentMissing should not.

package AutoAttachTests;
use FoswikiFnTestCase;
use strict;
use warnings;

use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );

use strict;
use Foswiki;
use Foswiki::Meta;
use Foswiki::Func();
use Error qw( :try );
use Foswiki::UI::Save;
use Foswiki::OopsException;
Expand All @@ -33,9 +33,10 @@ sub set_up_topic {
my $topic = shift;
my $text = "hi";

my $topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic, $text );
my ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, $topic );
$topicObject->text($text);
$topicObject->save();
$topicObject->finish();
}

# We create a topic with a missing attachment
Expand All @@ -48,8 +49,7 @@ sub addMissingAttachment {

$this->assert( $this->{session}->topicExists( $this->{test_web}, $topic ) );

my $topicObject =
Foswiki::Meta->load( $this->{session}, $this->{test_web}, $topic );
my ($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, $topic );

$topicObject->putKeyed(
'FILEATTACHMENT',
Expand Down Expand Up @@ -192,8 +192,7 @@ sub verify_normal_attachment {
my $doNotLogChanges = 0;
my $doUnlock = 1;

my $meta =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, $topic );
my ($meta) = Foswiki::Func::readTopic( $this->{test_web}, $topic );
$meta->attach(
name => $attachment,
file => "$TWiki::cfg{TempfileDir}/$attachment",
Expand All @@ -217,7 +216,7 @@ sub simulate_view {
$this->{session}->{webName} = $web;
$this->{session}->{topicName} = $topic;

my $meta = Foswiki::Meta->load( $this->{session}, $web, $topic );
my ($meta) = Foswiki::Func::readTopic( $web, $topic );

$this->{session}->{webName} = $oldWebName;
$this->{session}->{topicName} = $oldTopicName;
Expand Down
6 changes: 3 additions & 3 deletions UnitTestContrib/test/unit/ClientTests.pm
Expand Up @@ -25,9 +25,9 @@ sub set_up {
$this->SUPER::set_up();
$EDIT_UI_FN ||= $this->getUIFn('edit');
$VIEW_UI_FN ||= $this->getUIFn('view');
my $topicObject = Foswiki::Meta->new(
$this->{session}, $this->{test_web},
$this->{test_topic}, <<'CONSTRAINT');
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$topicObject->text(<<'CONSTRAINT');
* Set ALLOWTOPICCHANGE = AdminGroup
CONSTRAINT
$topicObject->save();
Expand Down
11 changes: 5 additions & 6 deletions UnitTestContrib/test/unit/ExpandMacrosTests.pm
@@ -1,10 +1,10 @@
use strict;

# tests for the correct expansion of macros

package ExpandMacrosTests;
use strict;
use warnings;

use FoswikiFnTestCase;
use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );

use Foswiki;
Expand Down Expand Up @@ -227,9 +227,8 @@ sub _testExpand {

sub _expand {
my ( $this, $tml ) = @_;
my $topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web},
$this->{test_topic} );
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
return $topicObject->expandMacros($tml);
}

Expand Down
24 changes: 13 additions & 11 deletions UnitTestContrib/test/unit/Fn_FORMAT.pm
@@ -1,10 +1,10 @@
use strict;

#test the FORMAT rendering operator extracted from legacy SEARCH

package Fn_FORMAT;
use strict;
use warnings;

use FoswikiFnTestCase;
use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );

use Foswiki;
Expand Down Expand Up @@ -204,10 +204,11 @@ This text is fill in text which is there to ensure that the unique word below do
%META:FIELD{name="Name" attributes="" title="Name" value="!AnnaAnchor"}%
HERE

my $topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web},
'FormattedSearchTopic1', $text );
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'FormattedSearchTopic1' );
$topicObject->text($text);
$topicObject->save();
$topicObject->finish();
}

sub test_same_topic_listed_twice {
Expand Down Expand Up @@ -326,14 +327,15 @@ sub test_validatepattern {
sub test_formatOfLinks {
my $this = shift;

my $topicObject = Foswiki::Meta->new(
$this->{session},
$this->{test_web}, 'Item977', "---+ Apache
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'Item977' );
$topicObject->text( <<'HERE');
---+ Apache
Apache is the [[http://www.apache.org/httpd/][well known web server]].
"
);
HERE
$topicObject->save();
$topicObject->finish();

my $result =
$this->{test_topicObject}
Expand Down
71 changes: 34 additions & 37 deletions UnitTestContrib/test/unit/Fn_FORMFIELD.pm
@@ -1,10 +1,12 @@
# tests for the correct expansion of FORMFIELD

package Fn_FORMFIELD;
use FoswikiFnTestCase;
use strict;
use warnings;

use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );

use strict;
use Error qw( :try );

sub new {
Expand All @@ -22,14 +24,15 @@ sub set_up {
sub _createTopic {
my ( $this, $web, $topicObject ) = @_;

my $formTopicObject =
Foswiki::Meta->new( $this->{session}, $web, 'TestForm', <<FORM);
my ($formTopicObject) = Foswiki::Func::readTopic( $web, 'TestForm' );
$formTopicObject->text(<<FORM);
| *Name* | *Type* | *Size* |
| Marjorie | text | 30 |
| Priscilla | text | 30 |
| Daphne | text | 30 |
FORM
$formTopicObject->save();
$formTopicObject->finish();

$topicObject->put( 'FORM', { name => 'TestForm' } );
$topicObject->putKeyed( 'FIELD',
Expand All @@ -44,25 +47,25 @@ FORM
sub test_FORMFIELD_simple {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros("%FORMFIELD%");
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros("%FORMFIELD%");
$this->assert_str_equals( '', $result );
}

sub test_FORMFIELD_byname {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Marjorie"}%');
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Marjorie"}%');
$this->assert_str_equals( '99', $result );
}

# default="..." Text shown when no value is defined for the field
sub test_FORMFIELD_default {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Priscilla"}%');
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Priscilla"}%');
$this->assert_str_equals( '', $result );
$result = $topicObject->expandMacros(
'%FORMFIELD{"Priscilla" default="Clementina" alttext="Cressida"}%');
Expand All @@ -82,8 +85,8 @@ sub test_FORMFIELD_default {
sub test_FORMFIELD_alttext {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Ffiona"}%');
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Ffiona"}%');
$this->assert_str_equals( '', $result );
$result =
$topicObject->expandMacros('%FORMFIELD{"Ffiona" alttext="Candida"}%');
Expand All @@ -101,8 +104,8 @@ sub test_FORMFIELD_alttext {
sub test_FORMFIELD_format {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros(
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros(
'%FORMFIELD{"Marjorie" format="$name/$dollar$value/$title/$form"}%');
$this->assert_str_equals( 'Marjorie/$99/Number/TestForm', $result );
$result = $topicObject->expandMacros('%FORMFIELD{"Marjorie" format=""}%');
Expand Down Expand Up @@ -135,19 +138,17 @@ sub test_FORMFIELD_format {
sub test_FORMFIELD_topic {
my $this = shift;

my $topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, 'TestForm' );
my ($topicObject) =
Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
$this->{session}->{webName} = $this->{test_web};
my $result = $topicObject->expandMacros('%FORMFIELD{"Marjorie"}%');
$this->assert_str_equals( '', $result );
$result = $topicObject->expandMacros(
'%FORMFIELD{"Marjorie" topic="' . $this->{test_topic} . '"}%' );
$this->assert_str_equals( '99', $result );
$topicObject = Foswiki::Meta->new(
$this->{session},
$Foswiki::cfg{SystemWebName},
$Foswiki::cfg{HomeTopicName}
);
$topicObject->finish();
($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{SystemWebName},
$Foswiki::cfg{HomeTopicName} );
$result = $topicObject->expandMacros(
'%FORMFIELD{"Marjorie" topic="' . $this->{test_topic} . '"}%' );
$this->assert_str_equals( '', $result );
Expand All @@ -157,6 +158,7 @@ sub test_FORMFIELD_topic {
. $this->{test_topic}
. '"}%' );
$this->assert_str_equals( '99', $result );
$topicObject->finish();
}

# web="..."
Expand All @@ -167,13 +169,11 @@ sub test_FORMFIELD_web {
$this->{other_web} = "$this->{test_web}other";
my $webObject = Foswiki::Meta->new( $this->{session}, $this->{other_web} );
$webObject->populateNewWeb();
my $topicObject =
Foswiki::Meta->new( $this->{session}, $this->{other_web},
$this->{test_topic} );
my ($topicObject) =
Foswiki::Func::readTopic( $this->{other_web}, $this->{test_topic} );
$this->_createTopic( $this->{other_web}, $topicObject );

$topicObject =
Foswiki::Meta->new( $this->{session}, $this->{test_web}, 'TestForm' );
($topicObject) = Foswiki::Func::readTopic( $this->{test_web}, 'TestForm' );
$this->{session}->{webName} = $this->{test_web};

my $result = $topicObject->expandMacros('%FORMFIELD{"Marjorie"}%');
Expand All @@ -185,11 +185,8 @@ sub test_FORMFIELD_web {
. $this->{test_topic}
. '"}%' );
$this->assert_str_equals( '99', $result );
$topicObject = Foswiki::Meta->new(
$this->{session},
$Foswiki::cfg{SystemWebName},
$Foswiki::cfg{HomeTopicName}
);
($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{SystemWebName},
$Foswiki::cfg{HomeTopicName} );
$result =
$topicObject->expandMacros( '%FORMFIELD{"Marjorie" web="'
. $this->{other_web}
Expand All @@ -206,8 +203,8 @@ sub test_FORMFIELD_web {
sub test_FORMFIELD_render_nops {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Daphne"}%');
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros('%FORMFIELD{"Daphne"}%');
$this->assert_str_equals( '<nop>ElleBelle', $result );
$result = $topicObject->expandMacros(
'%FORMFIELD{"Ffiona" alttext="!NiceAsPie" default="Cressida"}%');
Expand All @@ -224,8 +221,8 @@ sub test_FORMFIELD_render_nops {
sub test_FORMFIELD_Item9269 {
my $this = shift;

my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros(
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros(
'%FORMFIELD{"Daphne" format="$dollarvalue = $value"}%');
$this->assert_str_equals( '$value = <nop>ElleBelle', $result );
}
Expand All @@ -234,8 +231,8 @@ sub test_FORMFIELD_Item10398 {
my $this = shift;

#topic does not exist.
my $topicObject = $this->{test_topicObject};
my $result = $topicObject->expandMacros(
my ($topicObject) = $this->{test_topicObject};
my $result = $topicObject->expandMacros(
'%FORMFIELD{"Daphne" format="$dollarvalue = $value" topic="SomeNonExistantTopicThatReallyShouldNotBeThere"}%'
);
$this->assert_str_equals( '', $result );
Expand Down

0 comments on commit 119630a

Please sign in to comment.