[Rt-commit] rt branch 5.0/format-html-cf-changes-in-history created. rt-5.0.2-116-g584e287f31

BPS Git Server git at git.bestpractical.com
Wed Apr 20 20:44:45 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/format-html-cf-changes-in-history has been created
        at  584e287f31cf238896c9f233bb52bef6a2883e9b (commit)

- Log -----------------------------------------------------------------
commit 584e287f31cf238896c9f233bb52bef6a2883e9b
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Apr 21 04:41:10 2022 +0800

    Test HTML custom field changes

diff --git a/t/web/cf_html.t b/t/web/cf_html.t
new file mode 100644
index 0000000000..cd8b66a44c
--- /dev/null
+++ b/t/web/cf_html.t
@@ -0,0 +1,106 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my $content = join ' ', ('<h3>The quick brown fox jumps over the lazy dog.</h3>') x 5;
+$content = join '<br>', $content, $content, $content;
+
+my $escaped_content = $content;
+RT::Interface::Web::EscapeHTML( \$escaped_content );
+
+my $cf = RT::CustomField->new( RT->SystemUser );
+$cf->Load('Content');
+ok( $cf->Id, 'Found custom field' );
+
+my $article = RT::Article->new( RT->SystemUser );
+my ( $ret, $msg ) = $article->Create( Class => 'General', Name => 'Test html content' );
+ok( $ret, 'Created article' );
+
+my ( $base, $m ) = RT::Test->started_ok;
+
+$m->login;
+
+my $cf_input = RT::Interface::Web::GetCustomFieldInputName(
+    Object      => $article,
+    CustomField => $cf,
+);
+
+$m->get_ok( '/Articles/Article/Edit.html?id=' . $article->Id );
+
+$m->submit_form_ok(
+    {
+        with_fields => {
+            $cf_input => $content,
+        },
+    },
+    'Set content'
+);
+
+$m->content_contains( "<li>Content $escaped_content added</li>", 'content found' );
+$m->save_content('/tmp/x.html');
+
+my $new_content         = '<h3>The quick brown fox jumps over the lazy dog.</h3>';
+my $escaped_new_content = $new_content;
+RT::Interface::Web::EscapeHTML( \$escaped_new_content );
+
+$m->submit_form_ok(
+    {
+        with_fields => {
+            $cf_input => $new_content,
+
+        },
+    },
+    'Update content'
+);
+
+$m->content_contains( "<li>Content $escaped_content changed to $escaped_new_content</li>", 'Content was updated' );
+
+my $newer_content         = '<h3>The quick yellow fox jumps over the lazy dog.</h3>';
+my $escaped_newer_content = $newer_content;
+RT::Interface::Web::EscapeHTML( \$escaped_newer_content );
+
+$m->submit_form_ok(
+    {
+        with_fields => {
+            $cf_input => $newer_content,
+
+        },
+    },
+    'Update content again'
+);
+
+$m->content_contains( "<li>Content $escaped_new_content changed to $escaped_newer_content</li>",
+    'Content was updated' );
+
+my $txn = $article->Transactions->Last;
+$m->get_ok( '/Helpers/TextDiff?TransactionId=' . $txn->id );
+$m->content_like( qr{<del>brown\s*</del><ins>yellow\s*</ins>}, 'text diff has the brown => yellow change' );
+
+$m->back;
+$m->follow_link_ok( { text => 'Display' } );
+$m->content_contains( $newer_content, 'Content on display page' );
+
+$m->back;
+$m->submit_form_ok(
+    {
+        with_fields => {
+            $cf_input => '',
+        },
+    },
+    'Delete content'
+);
+
+$m->content_contains( "<li>$escaped_newer_content is no longer a value for custom field Content</li>",
+    'Content was deleted' );
+
+$m->follow_link_ok( { text => 'History' } );
+$m->content_like(
+    qr/Content\sadded.+\Q$content\E.+
+       Content\schanged.+From:.+\Q$content\E.+To:.+\Q$new_content\E.+
+       Content\schanged.+From:.+\Q$new_content\E.+To:.+\Q$newer_content\E.+
+       Content\sdeleted.+\Q$newer_content\E/xs,
+    'Content change details'
+);
+
+done_testing;

commit 27bafb7f174e3224965b72e45efd99864a5a821e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Apr 21 02:44:56 2022 +0800

    Format html custom field changes like other text ones
    
    This is to show the diff, which was implemented in 290067f80a.
    
    Here we call the corresponding ShowCustomField... components to render
    content, which is more precise(as Text/Wikitext/HTML are treated a bit
    differently). As these components append a newline to the output, we
    need to use a more tolerant regex in tests.

diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index e6a5746ce0..cf95c1c6cd 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1054,7 +1054,7 @@ sub _CanonicalizeRoleName {
                     $new = $date->AsString( Time => 0, Timezone => 'UTC' );
                 }
             }
-            elsif ( $cf->Type =~ /text/i) {
+            elsif ( $cf->Type =~ /text|html/i) {
                 if (!defined($old) || ($old eq '')) {
                     return ( "[_1] added", $field);   #loc()
                 }
diff --git a/share/html/Elements/ShowTransaction b/share/html/Elements/ShowTransaction
index a90c767338..d91b1a349d 100644
--- a/share/html/Elements/ShowTransaction
+++ b/share/html/Elements/ShowTransaction
@@ -88,13 +88,12 @@ $m->comp(
 %     my $cf = RT::CustomField->new( $session{CurrentUser} );
 %     $cf->SetContextObject( $Transaction->Object );
 %     $cf->Load( $Transaction->Field );
-%     if ($cf->Id && $cf->Type =~ /text/i) {
-%        $old = $Transaction->OldValue // loc('(no value)');
-%        $old = $m->comp('/Elements/ScrubHTML', Content => $old);
-%        $old =~ s|\n|<br />|g;
-%        $new = $Transaction->NewValue // loc('(no value)');
-%        $new = $m->comp('/Elements/ScrubHTML', Content => $new);
-%        $new =~ s|\n|<br />|g;
+%     if ($cf->Id && $cf->Type =~ /text|html/i) {
+%        my $comp = '/Elements/ShowCustomField' . $cf->Type;
+%        my $old_ref = $Transaction->OldReferenceObject;
+%        $old = $old_ref ? $m->scomp($comp, Object => $old_ref) : loc('(no value)');
+%        my $new_ref = $Transaction->NewReferenceObject;
+%        $new = $new_ref ? $m->scomp($comp, Object => $new_ref) : loc('(no value)');
 <div class="details hidden" id="txn-<% $Transaction->Id %>-details">
 % if ( $old eq loc('(no value)')  ) {
   <div class="form-row">
@@ -211,7 +210,7 @@ elsif ($txn_type eq 'CustomField' && $Transaction->Field) {
     my $cf = RT::CustomField->new( $session{CurrentUser} );
     $cf->SetContextObject( $Transaction->Object );
     $cf->Load( $Transaction->Field );
-    if ($cf->Id && $cf->Type =~ /text/i) {
+    if ($cf->Id && $cf->Type =~ /text|html/i) {
         push @actions, { class => 'toggle-txn-details', title => loc('Show Details'), path => '#' };
     }
 }
diff --git a/t/web/cf_textarea.t b/t/web/cf_textarea.t
index a15aa5edc1..85df90969f 100644
--- a/t/web/cf_textarea.t
+++ b/t/web/cf_textarea.t
@@ -123,8 +123,8 @@ $m->follow_link_ok( { text => 'Display' } );
 $content =~ s!\n+!!g;
 $m->text_like(
     qr/TheTextarea\sadded.+\Q$content\E.+
-       TheTextarea\schanged.+From:\Q$content\ETo:\Q$new_content\E.+
-       TheTextarea\schanged.+From:\Q$new_content\ETo:\Q$newer_content\E.+
+       TheTextarea\schanged.+From:\Q$content\E\s*To:\Q$new_content\E.+
+       TheTextarea\schanged.+From:\Q$new_content\E\s*To:\Q$newer_content\E.+
        TheTextarea\sdeleted.+\Q$newer_content\E/xs,
     'textarea change details'
 );

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list