Skip to content

Commit

Permalink
Item10558: Meta::summariseChanges is broken
Browse files Browse the repository at this point in the history
It needs to load the old revision that it's going to compare

Also needs a unit test.  This is a start - need to write tests for other
combinations of revisions, including missing revs.

git-svn-id: http://svn.foswiki.org/trunk@11259 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Mar 29, 2011
1 parent 74e5263 commit 69372f5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
63 changes: 63 additions & 0 deletions UnitTestContrib/test/unit/MetaTests.pm
Expand Up @@ -793,6 +793,69 @@ sub test_getRevisionHistory {
$this->assert(!$revIt->hasNext());
}

sub test_summariseChanges {
my $this = shift;
my $topicObject = Foswiki::Meta->new(
$this->{session}, $this->{test_web}, 'RevIt', "Line 1\nLine 2\nLine 3" );
$this->assert_equals(1, $topicObject->save());
$topicObject =
Foswiki::Meta->load($this->{session}, $this->{test_web}, 'RevIt' );
my $revIt = $topicObject->getRevisionHistory();
$this->assert($revIt->hasNext());
$this->assert_equals(1, $revIt->next());
$this->assert(!$revIt->hasNext());
#print "REV1 \n(".$topicObject->text().")\n";

$topicObject->text("Line 1\n\nLine 3");
$this->assert_equals(
2, $topicObject->save(forcenewrevision => 1));
$topicObject =
Foswiki::Meta->load($this->{session}, $this->{test_web}, 'RevIt' );
$revIt = $topicObject->getRevisionHistory();
$this->assert($revIt->hasNext());
$this->assert_equals(2, $revIt->next());
$this->assert($revIt->hasNext());
$this->assert_equals(1, $revIt->next());
$this->assert(!$revIt->hasNext());
#print "REV2 \n(".$topicObject->text().")\n";

$topicObject->text("Line 1\n<nop>SomeOtherData\nLine 3");
$this->assert_equals(
3, $topicObject->save(forcenewrevision => 1));
$topicObject =
Foswiki::Meta->load($this->{session}, $this->{test_web}, 'RevIt' );
$revIt = $topicObject->getRevisionHistory();
$this->assert($revIt->hasNext());
$this->assert_equals(3, $revIt->next());
$this->assert($revIt->hasNext());
$this->assert_equals(2, $revIt->next());
$this->assert($revIt->hasNext());
$this->assert_equals(1, $revIt->next());
$this->assert(!$revIt->hasNext());
#print "REV3 \n(".$topicObject->text().")\n";

# Verify the plain text summary
my $diff = $topicObject->summariseChanges('1', '3', 0);
#print "\nTEXT rev1:rev3\n" . $diff . "\n";
my $expected = <<RESULT;
Line 1
-Line 2
+ nop <nop>SomeOtherData
Line 3
-<nop>TemporaryMetaTestsTestWebMetaTests.RevIt 1
+<nop>TemporaryMetaTestsTestWebMetaTests.RevIt 3
RESULT
chomp $expected;
$this->assert_equals( $expected, $diff);

# Verify the HTML summary
#print "\nHTML rev1:rev3\n" . $topicObject->summariseChanges('1', '3', 1) . "\n";
$this->assert_equals(
" Line 1<br /><del>Line 2</del><br /><ins> nop SomeOtherData</ins><br /> Line 3<br /><del>TemporaryMetaTestsTestWebMetaTests.RevIt 1</del><br /><ins>TemporaryMetaTestsTestWebMetaTests.RevIt 3</ins>",
$topicObject->summariseChanges('1', '3', 1)
);
}

sub test_haveAccess {
my $this = shift;

Expand Down
4 changes: 2 additions & 2 deletions core/lib/Foswiki/Meta.pm
Expand Up @@ -3442,11 +3442,11 @@ sub summariseChanges {
$renderer->TML2PlainText( $ntext, $this, 'nonop' ) . "\n"
. $this->stringify($metaPick);

my $oldTopicObject = $this->new( $session, $this->web, $this->topic );
my $oldTopicObject = Foswiki::Meta->load( $session, $this->web, $this->topic, $orev );
unless ( $oldTopicObject->haveAccess('VIEW') ) {

# No access to old rev, make a blank topic object
$oldTopicObject = $this->new( $session, $this->web, $this->topic, '' );
$oldTopicObject = Foswiki::Meta->new( $session, $this->web, $this->topic, '' );
}
my $otext =
$renderer->TML2PlainText( $oldTopicObject->text(), $oldTopicObject,
Expand Down

0 comments on commit 69372f5

Please sign in to comment.