Permalink
Browse files

Item13995: Fix search $changes

It was always returning a summary.  Add a unit test to validate the
legal forms.
  $changes, text diff of last 2 revisions
  $changes(n) text diff between rev n and last rev.
  $changes() - undefined rev results in simple summary
  • Loading branch information...
1 parent 984b26f commit 4379bceb6ef2b24c40c6f8633b06228a0c1a4adb @gac410 gac410 committed Feb 28, 2016
Showing with 72 additions and 1 deletion.
  1. +69 −0 UnitTestContrib/test/unit/Fn_SEARCH.pm
  2. +3 −1 core/lib/Foswiki/Search.pm
@@ -6188,6 +6188,75 @@ pagerformat: \$web=$this->{test_web}", $result
return;
}
+sub test_Item13995 {
+ my $this = shift;
+
+ # Create 3 revisions
+ my ($topicObject) =
+ Foswiki::Func::readTopic( $this->{test_web}, 'RevTopic' );
+ $topicObject->text("Drums Beat");
+ $topicObject->save( forcenewrevision => 1 );
+ $topicObject->text("BLEEGLE blah/matchme.blah");
+ $topicObject->save( forcenewrevision => 1 );
+ $topicObject->text("BELLS Ring");
+ $topicObject->save( forcenewrevision => 1 );
+ $topicObject->finish();
+
+ #Simple $changes - compare Rev 2 - Rev 3
+ my $result = $this->{test_topicObject}->expandMacros(
+ '%SEARCH{"1"
+ type="query"
+ web="%WEB%"
+ topic="RevTopic"
+ nonoise="on"
+ format="FOO $changes$n"
+}%'
+ );
+
+ my $expected = <<"EXP";
+FOO <nop>$this->{test_web}.RevTopic
+-<nop>BLEEGLE blah/matchme.blah
++<nop>BELLS Ring
+EXP
+ $this->assert_equals( $expected, $result );
+
+ #$changes(1) - compare Rev 1 - Rev 3
+ $result = $this->{test_topicObject}->expandMacros(
+ '%SEARCH{"1"
+ type="query"
+ web="%WEB%"
+ topic="RevTopic"
+ nonoise="on"
+ format="FOO $changes(1)$n"
+}%'
+ );
+
+ $expected = <<"EXP";
+FOO <nop>$this->{test_web}.RevTopic
+-Drums Beat
++<nop>BELLS Ring
+EXP
+ $this->assert_equals( $expected, $result );
+
+ #$changes() - undef rev, generate a summary
+ $result = $this->{test_topicObject}->expandMacros(
+ '%SEARCH{"1"
+ type="query"
+ web="%WEB%"
+ topic="RevTopic"
+ nonoise="on"
+ format="FOO $changes()$n"
+}%'
+ );
+
+ $expected = <<"EXP";
+FOO <nop>$this->{test_web}.RevTopic <nop>BELLS Ring
+EXP
+ $this->assert_equals( $expected, $result );
+
+ return;
+}
+
sub test_Item9502 {
my $this = shift;
@@ -1304,7 +1304,9 @@ s/\$formfield\(\s*([^\)]*)\s*\)/displayFormField( $item, $1, $newLine )/ges;
if ( defined( $item->topic ) ) {
$out =~ s/\$summary(?:\(([^\)]*)\))?/
$item->summariseText( $1, $text, $searchOptions )/ges;
- $out =~ s/\$changes(?:\(([^\)]*)\))?/
+ $out =~
+ s/\$changes(?!\()/$item->summariseChanges(undef,$revNum)/ges;
+ $out =~ s/\$changes(?:\(([^\)]*)\))/
$item->summariseChanges(Foswiki::Store::cleanUpRevID($1), $revNum)/ges;
$out =~ s/\$formfield\(\s*([^\)]*)\s*\)/
displayFormField( $item, $1, $newLine )/ges;

0 comments on commit 4379bce

Please sign in to comment.