1# --
2# Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
3# --
4# This software comes with ABSOLUTELY NO WARRANTY. For details, see
5# the enclosed file COPYING for license information (GPL). If you
6# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
7# --
8
9## no critic (Modules::RequireExplicitPackage)
10use strict;
11use warnings;
12use utf8;
13
14use vars (qw($Self));
15
16use Kernel::System::VariableCheck qw(:all);
17
18# get state objects
19my $StateObject = $Kernel::OM->Get('Kernel::System::ProcessManagement::DB::Process::State');
20
21my $LocalStateList = $StateObject->{StateList};
22
23my $UserID = 1;
24
25#
26# StateList tests
27#
28my $StateList = $StateObject->StateList();
29
30$Self->IsNot(
31    ref $StateList,
32    'HASH',
33    'StateList Test 1: Empty params | should not be HASH',
34);
35$Self->Is(
36    $StateList,
37    undef,
38    'StateList Test 1: Empty params | should be undef',
39);
40
41$StateList = $StateObject->StateList( UserID => $UserID );
42
43$Self->Is(
44    ref $StateList,
45    'HASH',
46    'StateList Test 1: Empty params | should be HASH',
47);
48$Self->IsDeeply(
49    $StateList,
50    $LocalStateList,
51    'StateList Test 2: Correct | should be undef',
52);
53
54#
55# StateLookup tests
56#
57my @Tests = (
58    {
59        Name    => 'StateLookup Test1: No params',
60        Config  => {},
61        Success => 0,
62    },
63    {
64        Name   => 'StateLookup Test2: No EntityID and Name',
65        Config => {
66            EntityID => undef,
67            Name     => undef,
68            UserID   => $UserID,
69        },
70        Success => 0,
71    },
72    {
73        Name   => 'StateLookup Test3: No UserID',
74        Config => {
75            ID     => 'S1',
76            Name   => undef,
77            UserID => undef,
78        },
79        Success => 0,
80    },
81    {
82        Name   => 'StateLookup Test4: Wrong EntityID',
83        Config => {
84            EntityID => 'NonExistent',
85            Name     => undef,
86            UserID   => $UserID,
87        },
88        Success => 0,
89    },
90    {
91        Name   => 'StateLookup Test5: Wrong Name',
92        Config => {
93            EntityID => undef,
94            Name     => 'NonExistent',
95            UserID   => $UserID,
96        },
97        Success => 0,
98    },
99    {
100        Name   => 'StateLookup Test6: EntityID 1',
101        Config => {
102            EntityID => 'S1',
103            Name     => undef,
104            UserID   => $UserID,
105        },
106        Result  => 'Active',
107        Success => 1,
108    },
109    {
110        Name   => 'StateLookup Test7: EntityID 2',
111        Config => {
112            EntityID => 'S2',
113            Name     => undef,
114            UserID   => $UserID,
115        },
116        Result  => 'Inactive',
117        Success => 1,
118    },
119    {
120        Name   => 'StateLookup Test8: EntityID 3',
121        Config => {
122            EntityID => 'S3',
123            Name     => undef,
124            UserID   => $UserID,
125        },
126        Result  => 'FadeAway',
127        Success => 1,
128    },
129
130    {
131        Name   => 'StateLookup Test9: Name Active',
132        Config => {
133            EntityID => undef,
134            Name     => 'Active',
135            UserID   => $UserID,
136        },
137        Result  => 'S1',
138        Success => 1,
139    },
140    {
141        Name   => 'StateLookup Test10: Name Inactive',
142        Config => {
143            EntityID => undef,
144            Name     => 'Inactive',
145            UserID   => $UserID,
146        },
147        Result  => 'S2',
148        Success => 1,
149    },
150    {
151        Name   => 'StateLookup Test11: Name FadeAway',
152        Config => {
153            EntotyID => undef,
154            Name     => 'FadeAway',
155            UserID   => $UserID,
156        },
157        Result  => 'S3',
158        Success => 1,
159    },
160);
161
162for my $Test (@Tests) {
163    my $Result = $StateObject->StateLookup( %{ $Test->{Config} } );
164
165    if ( $Test->{Success} ) {
166        $Self->IsNot(
167            $Result,
168            undef,
169            "$Test->{Name} | Result should not undef",
170        );
171        $Self->Is(
172            $Result,
173            $Test->{Result},
174            "$Test->{Name} | Result should be $Test->{Result}",
175        );
176    }
177    else {
178        $Self->Is(
179            $Result,
180            undef,
181            "$Test->{Name} | Result should be undef",
182        );
183    }
184}
185
1861;
187