Skip to content

Commit 5db8ff2

Browse files
committed
Issue #5564: fix unittest exceptions for input validation
1 parent 282ea49 commit 5db8ff2

2 files changed

Lines changed: 31 additions & 22 deletions

File tree

scripts/test/DynamicField/ObjectType/Article/ObjectDataGet.t

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use utf8;
2323
# CPAN modules
2424
use HTTP::Request::Common qw(GET);
2525
use Test2::V0;
26+
use Try::Tiny;
2627

2728
# OTOBO modules
2829
use Kernel::System::UnitTest::RegisterOM; # Set up $Kernel::OM
@@ -143,11 +144,7 @@ my @Tests = (
143144
UserID => 1,
144145
},
145146
Request => "Action=someaction;Subaction=somesubaction;ArticleID=-1",
146-
Success => 1,
147-
ExectedResult => {
148-
ObjectID => -1,
149-
Data => {},
150-
},
147+
Throws => 1,
151148
},
152149
{
153150
Name => 'Wrong ArticleID and TicketID in the request',
@@ -156,11 +153,7 @@ my @Tests = (
156153
UserID => 1,
157154
},
158155
Request => "Action=someaction;Subaction=somesubaction;ArticleID=-1;TicketID=-1",
159-
Success => 1,
160-
ExectedResult => {
161-
ObjectID => -1,
162-
Data => {},
163-
},
156+
Throws => 1,
164157
},
165158
{
166159
Name => 'Correct Article with wrong TicketID in the request',
@@ -169,11 +162,7 @@ my @Tests = (
169162
UserID => 1,
170163
},
171164
Request => "Action=someaction;Subaction=somesubaction;ArticleID=$ArticleID;TicketID=-1",
172-
Success => 1,
173-
ExectedResult => {
174-
ObjectID => $ArticleID,
175-
Data => {},
176-
},
165+
Throws => 1,
177166
},
178167
{
179168
Name => 'Correct Article without TicketID in the request',
@@ -208,6 +197,7 @@ my $ObjectHandlerObject = $Kernel::OM->Get('Kernel::System::DynamicField::Object
208197
TEST:
209198
for my $Test (@Tests) {
210199

200+
print STDERR "TEST: $Test->{Name} \n";
211201
# force the ParamObject to use the new request params
212202
my $QueryString = $Test->{Request} // '';
213203
$Kernel::OM->ObjectParamAdd(
@@ -217,7 +207,18 @@ for my $Test (@Tests) {
217207
);
218208

219209
# implicitly call Kernel::System::Web::Request->new();
220-
my %ObjectData = $ObjectHandlerObject->ObjectDataGet( %{ $Test->{Config} } );
210+
my %ObjectData;
211+
try {
212+
%ObjectData = $ObjectHandlerObject->ObjectDataGet( %{ $Test->{Config} } );
213+
}
214+
catch {
215+
216+
if( !$Test->{Throws} ) {
217+
218+
ok(0,"$Test->{Name} - not expected to throw");
219+
}
220+
next TEST;
221+
};
221222

222223
if ( !$Test->{Success} ) {
223224
is(

scripts/test/DynamicField/ObjectType/Ticket/ObjectDataGet.t

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use strict;
1818
use warnings;
1919
use utf8;
20+
use Try::Tiny;
2021

2122
# core modules
2223

@@ -129,11 +130,7 @@ my @Tests = (
129130
UserID => 1,
130131
},
131132
Request => "Action=someaction;Subaction=somesubaction;TicketID=-1",
132-
Success => 1,
133-
ExectedResult => {
134-
ObjectID => -1,
135-
Data => {},
136-
},
133+
Throws => 1,
137134
},
138135
{
139136
Name => 'Correct Ticket',
@@ -165,7 +162,18 @@ for my $Test (@Tests) {
165162
);
166163

167164
# implicitly call Kernel::System::Web::Request->new();
168-
my %ObjectData = $ObjectHandlerObject->ObjectDataGet( %{ $Test->{Config} } );
165+
my %ObjectData;
166+
try {
167+
%ObjectData = $ObjectHandlerObject->ObjectDataGet( %{ $Test->{Config} } );
168+
}
169+
catch {
170+
171+
if( !$Test->{Throws} ) {
172+
173+
ok( 0, "$Test->{Name} should not throw");
174+
}
175+
next TEST;
176+
};
169177

170178
if ( !$Test->{Success} ) {
171179
is(

0 commit comments

Comments
 (0)