Bug 36328: (QA follow-up) Expand tests and reorder elements to clarify differences

Also tidy

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 42d388c80fcdd98c2594ad7b111b8e40c991388a)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Nick Clemens 2024-04-01 16:03:37 +00:00 committed by Fridolin Somers
parent fb1c48da9a
commit e413db6083
2 changed files with 16 additions and 8 deletions

View File

@ -27,10 +27,10 @@ use HTML::Scrubber;
use C4::Context;
my %scrubbertypes = (
default => {}, # place holder, default settings are below as fallbacks in call to constructor
tag => {}, # uses defaults
default => {}, # place holder, default settings are below as fallbacks in call to constructor
tag => {}, # uses defaults
comment => { allow => [qw( br b i em big small strong )], },
note => { allow => [qw[ p b i u hr br em big small strong span div ]] },
note => { allow => [qw[ br b i em big small strong u hr span div p ]] },
staff => {
default => [ 1 => { '*' => 1 } ],
comment => 1,
@ -46,11 +46,11 @@ sub new {
}
my $settings = $scrubbertypes{$type};
my $scrubber = HTML::Scrubber->new(
allow => exists $settings->{allow} ? $settings->{allow} : [],
rules => exists $settings->{rules} ? $settings->{rules} : [],
allow => exists $settings->{allow} ? $settings->{allow} : [],
rules => exists $settings->{rules} ? $settings->{rules} : [],
default => exists $settings->{default} ? $settings->{default} : [ 0 => { '*' => 0 } ],
comment => exists $settings->{comment} ? $settings->{comment} : 0,
note => exists $settings->{note} ? $settings->{note} : 0,
note => exists $settings->{note} ? $settings->{note} : 0,
process => 0,
);
return $scrubber;

View File

@ -3,7 +3,7 @@
use Modern::Perl;
$| = 1;
use Test::More tests => 30;
use Test::More tests => 31;
use Test::Warn;
BEGIN {
@ -82,4 +82,12 @@ if ($@) {
pass("Test should have failed on entry of 'Client' and it did. YAY!");
}
is( C4::Scrubber->new('note')->scrub('<span>Allow span</span>'), '<span>Allow span</span>' );
my $scrub_text =
'<div><span><p><b>bold</b><i>ital</i><em>emphatic</em><big>embiggen</big><small>shrink</small><strong>strongbad</strong><br><u>under</u><hr></p></span></div>';
my $scrub_comment =
'<b>bold</b><i>ital</i><em>emphatic</em><big>embiggen</big><small>shrink</small><strong>strongbad</strong><br>under';
is( C4::Scrubber->new('comment')->scrub($scrub_text), $scrub_comment, "Comment scrubber removes expected elements" );
is(
C4::Scrubber->new('note')->scrub($scrub_text), $scrub_text,
"Note scrubber removes (additional) expected elements"
);