diff options
author | sunnavy <sunnavy@bestpractical.com> | 2022-04-20 23:41:10 +0300 |
---|---|---|
committer | sunnavy <sunnavy@bestpractical.com> | 2022-04-20 23:43:27 +0300 |
commit | 584e287f31cf238896c9f233bb52bef6a2883e9b (patch) | |
tree | 51a888e9b5583846c09c24a17e9568673ad3b891 | |
parent | 27bafb7f174e3224965b72e45efd99864a5a821e (diff) |
Test HTML custom field changes5.0/format-html-cf-changes-in-history
-rw-r--r-- | t/web/cf_html.t | 106 |
1 files changed, 106 insertions, 0 deletions
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; |