Skip to content

Commit

Permalink
Item1130: fatwilly and more tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/SetTopicValuesPlugin@2646 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Feb 24, 2009
1 parent 3fbfdd0 commit a8d9e7d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 56 deletions.
16 changes: 8 additions & 8 deletions lib/Foswiki/Plugins/SetTopicValuesPlugin.pm
Expand Up @@ -46,12 +46,12 @@ sub afterSaveHandler {
return if (defined($beforeSaveHandlerONCE));
#$beforeSaveHandlerONCE = 1;

print STDERR "afterSaveHandler - (".$_[2].".".$_[1].") ".$_[3]->getEmbeddedStoreForm()."\n";
#print STDERR "afterSaveHandler - (".$_[2].".".$_[1].") ".$_[3]->getEmbeddedStoreForm()."\n";

# do not uncomment, use $_[0], $_[1]... instead
### my ( $text, $topic, $web, $meta ) = @_;
Foswiki::Func::writeDebug( "- SetTopicValuesPlugin::beforeSaveHandler( $_[2].$_[1] )" ) if $debug;
my $cgi = TWiki::Func::getCgiQuery();
my $cgi = Foswiki::Func::getCgiQuery();

#TODO: we should be transactional by default - test that we can write to all topics, and take out leases

Expand All @@ -76,16 +76,16 @@ print STDERR "afterSaveHandler - (".$_[2].".".$_[1].") ".$_[3]->getEmbeddedStore
}

my $value = $cgi->param($key);
print STDERR "Set ($webTopic).($type)\($addr) = ($value)\n";
my ($sWeb, $sTopic) = TWiki::Func::normalizeWebTopicName($_[2], $webTopic);
if (TWiki::Func::topicExists($sWeb, $sTopic)) {
my( $sMeta, $sText ) = TWiki::Func::readTopic($sWeb, $sTopic);
#print STDERR "Set ($webTopic).($type)\($addr) = ($value)\n";
my ($sWeb, $sTopic) = Foswiki::Func::normalizeWebTopicName($_[2], $webTopic);
if (Foswiki::Func::topicExists($sWeb, $sTopic)) {
my( $sMeta, $sText ) = Foswiki::Func::readTopic($sWeb, $sTopic);
$type =~ s/S$//;
my $ma = $sMeta->get( $type, $addr );
print STDERR "test $ma";
#print STDERR "test $ma";
$ma->{value} = $value;
$sMeta->putKeyed($type, $ma );
TWiki::Func::saveTopic($sWeb, $sTopic, $sMeta, $sText);
Foswiki::Func::saveTopic($sWeb, $sTopic, $sMeta, $sText);
}
}
}
Expand Down
121 changes: 73 additions & 48 deletions test/unit/SetTopicValuesPlugin/SetTopicValuesPluginTests.pm
Expand Up @@ -31,7 +31,7 @@ sub set_up {
sub NOtear_down {
my $this = shift;

$this->{session} ->finish();
$this->{session}->finish();
$this->SUPER::tear_down();
}

Expand All @@ -40,10 +40,10 @@ sub NOtear_down {
# Verifies: that its worth testing further
sub test_SetTopicValuesPluginEnabled {
my $this = shift;

my $contexts = Foswiki::Func::getContext();
my $enabled = $contexts->{'SetTopicValuesPluginEnabled'};
my $enabled = $contexts->{'SetTopicValuesPluginEnabled'};

$this->assert($enabled);
}

Expand All @@ -52,78 +52,103 @@ sub test_SetTopicValuesPluginEnabled {
# Verifies: ?Set+SOMEPREF=something works
sub test_set_new_preference_on_new_topic {
my $this = shift;

my $query = new Unit::Request({
text => [ 'CORRECT' ],
'Set+NEWPREFERENCE' => 'someValue',
action => [ 'save' ],
topic => [ $this->{test_web}.'.DeleteTestSaveScriptTopic' ]
});

my $text = "CORRECT";

my $query = new Unit::Request(
{
text => [$text],
'Set+NEWPREFERENCE' => 'someValue',
action => ['save'],
topic => [ $this->{test_web} . '.DeleteTestSaveScriptTopic' ]
}
);
$this->{twiki}->finish();
$this->{twiki} = new Foswiki( $this->{test_user_login}, $query );
$this->capture( \&Foswiki::UI::Save::save, $this->{twiki});
my($meta, $text) = $this->{twiki}->{store}->readTopic(undef, $this->{test_web},
'DeleteTestSaveScriptTopic');
$this->assert_matches(qr/CORRECT/, $text);
$this->assert_null($meta->get('FORM'));
$this->capture( \&Foswiki::UI::Save::save, $this->{twiki} );
my ( $meta, $sText ) =
$this->{twiki}->{store}
->readTopic( undef, $this->{test_web}, 'DeleteTestSaveScriptTopic' );
$this->assert_matches( $text, $sText );
$this->assert_null( $meta->get('FORM') );

my $ma = $meta->get( 'PREFERENCE', 'NEWPREFERENCE' );
$this->assert_not_null($ma);
$this->assert_equals('someValue', $ma->{value});
$this->assert_equals( 'someValue', $ma->{value} );

my $pref = Foswiki::Func::getPreferencesValue("NEWPREFERENCE");
$this->assert_equals( 'someValue', $pref );
}

# ----------------------------------------------------------------------
# Purpose: create a new topic with a PREFERENCE set
# Verifies: ?Set+SOMEPREF=something works even when there is a Setting in the topic text
sub test_set_preference_on_new_topic {
my $this = shift;

my $text = "CORRECT\n * Set NEWPREFERENCE= wrongValue\n bah";

my $query = new Unit::Request({
text => [ $text ],
'Set+NEWPREFERENCE' => 'someValue',
action => [ 'save' ],
topic => [ $this->{test_web}.'.DeleteTestSaveScriptTopic' ]
});

my $query = new Unit::Request(
{
text => [$text],
'Set+NEWPREFERENCE' => 'someValue',
action => ['save'],
topic => [ $this->{test_web} . '.DeleteTestSaveScriptTopic' ]
}
);
$this->{twiki}->finish();
$this->{twiki} = new Foswiki( $this->{test_user_login}, $query );
$this->capture( \&Foswiki::UI::Save::save, $this->{twiki});
my($meta, $sText) = $this->{twiki}->{store}->readTopic(undef, $this->{test_web},
'DeleteTestSaveScriptTopic');
$this->assert_matches($text, $sText);
$this->assert_null($meta->get('FORM'));
$this->capture( \&Foswiki::UI::Save::save, $this->{twiki} );
my ( $meta, $sText ) =
$this->{twiki}->{store}
->readTopic( undef, $this->{test_web}, 'DeleteTestSaveScriptTopic' );
$this->assert_matches( $text, $sText );
$this->assert_null( $meta->get('FORM') );

my $ma = $meta->get( 'PREFERENCE', 'NEWPREFERENCE' );
$this->assert_not_null($ma);
$this->assert_equals('someValue', $ma->{value});
$this->assert_equals( 'someValue', $ma->{value} );

my $pref = Foswiki::Func::getPreferencesValue("NEWPREFERENCE");
$this->assert_equals( 'someValue', $pref );
}

# ----------------------------------------------------------------------
# Purpose: create a new topic with a PREFERENCE set
# Verifies: ?Set+SOMEPREF=something works even when there is a Setting in the topic text
sub test_set_preference_on_new_topic {
# Purpose: change the setting on an existing topic.
# Verifies: ?Set+SOMEPREF=something on an existing topic.
sub test_set_new_preference_on_existing_topic {
my $this = shift;


my $oopsUrl =
Foswiki::Func::saveTopicText( $this->{test_web},
'DeleteTestSaveScriptTopic', 'cracker' );
$this->assert_matches( '', $oopsUrl );

my $text = "CORRECT";

my $query = new Unit::Request({
text => [ $text ],
'Set+NEWPREFERENCE' => 'someValue',
action => [ 'save' ],
topic => [ $this->{test_web}.'.DeleteTestSaveScriptTopic' ]
});

my $query = new Unit::Request(
{
text => [$text],
'Set+NEWPREFERENCE' => 'someValue',
action => ['save'],
topic => [ $this->{test_web} . '.DeleteTestSaveScriptTopic' ]
}
);
$this->{twiki}->finish();
$this->{twiki} = new Foswiki( $this->{test_user_login}, $query );
$this->capture( \&Foswiki::UI::Save::save, $this->{twiki});
my($meta, $sText) = $this->{twiki}->{store}->readTopic(undef, $this->{test_web},
'DeleteTestSaveScriptTopic');
$this->assert_matches($text, $sText);
$this->assert_null($meta->get('FORM'));
$this->capture( \&Foswiki::UI::Save::save, $this->{twiki} );
my ( $meta, $sText ) =
$this->{twiki}->{store}
->readTopic( undef, $this->{test_web}, 'DeleteTestSaveScriptTopic' );
$this->assert_matches( $text, $sText );
$this->assert_null( $meta->get('FORM') );

my $ma = $meta->get( 'PREFERENCE', 'NEWPREFERENCE' );
$this->assert_not_null($ma);
$this->assert_equals('someValue', $ma->{value});
$this->assert_equals( 'someValue', $ma->{value} );

my $pref = Foswiki::Func::getPreferencesValue("NEWPREFERENCE");
$this->assert_equals( 'someValue', $pref );
}

1;

0 comments on commit a8d9e7d

Please sign in to comment.