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 Kernel::System::VariableCheck qw( IsArrayRefWithData IsHashRefWithData );
15
16use vars (qw($Self));
17
18$Kernel::OM->ObjectParamAdd(
19    'Kernel::System::UnitTest::Helper' => {
20        RestoreDatabase => 1,
21    },
22);
23my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
24
25# get config object
26my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
27
28#
29# Prepare valid config XML and Perl
30#
31my $ValidSettingXML = <<'EOF',
32<?xml version="1.0" encoding="utf-8" ?>
33<otrs_config version="2.0" init="Framework">
34    <Setting Name="Test1" Required="1" Valid="1">
35        <Description Translatable="1">Test 1.</Description>
36        <Navigation>Core::Ticket</Navigation>
37        <Value>
38            <Item ValueType="String" ValueRegex=".*">Test setting 1</Item>
39        </Value>
40    </Setting>
41    <Setting Name="Test2" Required="1" Valid="1">
42        <Description Translatable="1">Test 2.</Description>
43        <Navigation>Core::Ticket</Navigation>
44        <Value>
45            <Item ValueType="File">/usr/bin/gpg</Item>
46        </Value>
47    </Setting>
48</otrs_config>
49EOF
50
51    my $SysConfigXMLObject = $Kernel::OM->Get('Kernel::System::SysConfig::XML');
52
53my @DefaultSettingAddParams = $SysConfigXMLObject->SettingListParse(
54    XMLInput => $ValidSettingXML,
55);
56
57my $DateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
58$DateTimeObject->Add( Minutes => 30 );
59
60my $SysConfigDBObject = $Kernel::OM->Get('Kernel::System::SysConfig::DB');
61
62my $SettingName = 'ProductName ' . $HelperObject->GetRandomNumber();
63
64# Add default setting
65my $DefaultSettingID = $SysConfigDBObject->DefaultSettingAdd(
66    Name                     => $SettingName,
67    Description              => 'Defines the name of the application ...',
68    Navigation               => 'ASimple::Path::Structure',
69    IsInvisible              => 1,
70    IsReadonly               => 0,
71    IsRequired               => 1,
72    IsValid                  => 1,
73    HasConfigLevel           => 200,
74    UserModificationPossible => 0,
75    UserModificationActive   => 0,
76    XMLContentRaw            => $DefaultSettingAddParams[0]->{XMLContentRaw},
77    XMLContentParsed         => $DefaultSettingAddParams[0]->{XMLContentParsed},
78    XMLFilename              => 'UnitTest.xml',
79    EffectiveValue           => 'Test setting 1',
80    UserID                   => 1,
81);
82
83my $Result = $DefaultSettingID ? 1 : 0;
84
85$Self->Is(
86    $Result,
87    1,
88    'DefaultSettingAdd() must succeed.',
89);
90
91my $SettingName2 = 'CompanyName ' . $HelperObject->GetRandomNumber();
92
93# Add default setting
94my $DefaultSettingID2 = $SysConfigDBObject->DefaultSettingAdd(
95    Name                     => $SettingName2,
96    Description              => 'Defines the name of the company ...',
97    Navigation               => 'ASimple::Path::Structure',
98    IsInvisible              => 0,
99    IsReadonly               => 0,
100    IsRequired               => 1,
101    IsValid                  => 1,
102    HasConfigLevel           => 200,
103    UserModificationPossible => 1,
104    UserModificationActive   => 0,
105    XMLContentRaw            => $DefaultSettingAddParams[0]->{XMLContentRaw},
106    XMLContentParsed         => $DefaultSettingAddParams[0]->{XMLContentParsed},
107    XMLFilename              => 'UnitTest.xml',
108    EffectiveValue           => 'Test setting 2',
109    UserID                   => 1,
110);
111
112$Result = $DefaultSettingID2 ? 1 : 0;
113
114$Self->Is(
115    $Result,
116    1,
117    'DefaultSettingAdd() must succeed.',
118);
119
120# Get testing random number
121my $RandomNumber = $HelperObject->GetRandomNumber();
122
123# disable email checks to create new user
124$ConfigObject->Set(
125    Key   => 'CheckEmailAddresses',
126    Value => 0,
127);
128
129my $TestUserID;
130my $UserRand = 'example-user' . $RandomNumber;
131
132# get user object
133my $UserObject = $Kernel::OM->Get('Kernel::System::User');
134
135# add test user
136$TestUserID = $UserObject->UserAdd(
137    UserFirstname => 'Firstname Test1',
138    UserLastname  => 'Lastname Test1',
139    UserLogin     => $UserRand,
140    UserEmail     => $UserRand . '@example.com',
141    ValidID       => 1,
142    ChangeUserID  => 1,
143) || die "Could not create test user";
144
145# Test configuration
146my @Tests = (
147    {
148        Description => 'Complete testing cycle',
149        Config      => {
150            ModifiedSettingAdd => {
151                Data => {
152                    DefaultID      => $DefaultSettingID,
153                    Name           => $SettingName,
154                    TargetUserID   => 1,
155                    IsValid        => 1,
156                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
157                    UserID         => 1,
158                },
159                ExpectedResult => 1,
160            },
161            ModifiedSettingUpdate => {
162                Data => {
163                    DefaultID      => $DefaultSettingID,
164                    Name           => $SettingName,
165                    TargetUserID   => 1,
166                    IsValid        => 0,
167                    EffectiveValue => 'Служба поддержки (support)',
168                    UserID         => 1,
169                },
170                ExpectedResult => 1,
171            },
172        },
173    },
174    {
175        Description => 'Update only IsDirty flag',
176        Config      => {
177            ModifiedSettingAdd => {
178                Data => {
179                    DefaultID      => $DefaultSettingID,
180                    Name           => $SettingName,
181                    TargetUserID   => 1,
182                    IsValid        => 1,
183                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
184                    UserID         => 1,
185                },
186                ExpectedResult => 1,
187            },
188            ModifiedSettingUpdate => {
189                Data => {
190                    DefaultID      => $DefaultSettingID,
191                    Name           => $SettingName,
192                    TargetUserID   => 1,
193                    IsValid        => 1,
194                    IsDirty        => 0,
195                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
196                    UserID         => 1,
197                },
198                ExpectedResult => 1,
199            },
200        },
201    },
202    {
203        Description => 'Missing DefaultID',
204        Config      => {
205            ModifiedSettingAdd => {
206                Data => {
207
208                    Name                   => 'Missing DefaultID ' . $RandomNumber,
209                    TargetUserID           => $TestUserID,
210                    IsValid                => 1,
211                    UserModificationActive => 1,
212                    EffectiveValue         => '/usr/pgp',
213                    UserID                 => 1,
214                },
215                ExpectedResult => 0,
216            },
217        },
218    },
219    {
220        Description => 'Missing Name',
221        Config      => {
222            ModifiedSettingAdd => {
223                Data => {
224                    DefaultID              => $DefaultSettingID,
225                    TargetUserID           => $TestUserID,
226                    IsValid                => 1,
227                    UserModificationActive => 1,
228                    EffectiveValue         => '/usr/pgp',
229                    UserID                 => 1,
230                },
231                ExpectedResult => 0,
232            },
233        },
234    },
235    {
236        Description => 'Missing TargetUserID',
237        Config      => {
238            ModifiedSettingAdd => {
239                Data => {
240                    DefaultID              => $DefaultSettingID,
241                    Name                   => $SettingName,
242                    IsValid                => 1,
243                    UserModificationActive => 0,
244                    EffectiveValue         => '/usr/pgp',
245                    UserID                 => 1,
246                },
247                ExpectedResult => 1,
248            },
249        },
250    },
251    {
252        Description => 'Missing IsValid',
253        Config      => {
254            ModifiedSettingAdd => {
255                Data => {
256                    DefaultID      => $DefaultSettingID,
257                    Name           => $SettingName,
258                    TargetUserID   => 1,
259                    EffectiveValue => '/usr/pgp',
260                    UserID         => 1,
261                },
262                ExpectedResult => 1,
263            },
264        },
265    },
266    {
267        Description => 'Missing UserModificationActive',
268        Config      => {
269            ModifiedSettingAdd => {
270                Data => {
271                    DefaultID      => $DefaultSettingID,
272                    Name           => $SettingName,
273                    TargetUserID   => 1,
274                    IsValid        => 1,
275                    EffectiveValue => '/usr/pgp',
276                    UserID         => 1,
277                },
278                ExpectedResult => 1,
279            },
280        },
281    },
282    {
283        Description => 'Missing EffectiveValue',
284        Config      => {
285            ModifiedSettingAdd => {
286                Data => {
287                    DefaultID              => $DefaultSettingID,
288                    Name                   => $SettingName,
289                    TargetUserID           => $TestUserID,
290                    IsValid                => 1,
291                    UserModificationActive => 1,
292                    UserID                 => 1,
293                },
294                ExpectedResult => 0,
295            },
296        },
297    },
298    {
299        Description => 'Missing UserID',
300        Config      => {
301            ModifiedSettingAdd => {
302                Data => {
303                    DefaultID              => $DefaultSettingID,
304                    Name                   => $SettingName,
305                    TargetUserID           => $TestUserID,
306                    IsValid                => 1,
307                    UserModificationActive => 1,
308                    EffectiveValue         => '/usr/pgp',
309                },
310                ExpectedResult => 0,
311            },
312        },
313    },
314    {
315        Description => 'Take IsValid from Default',
316        Config      => {
317            ModifiedSettingAdd => {
318                Data => {
319                    DefaultID      => $DefaultSettingID,
320                    Name           => $SettingName,
321                    TargetUserID   => 1,
322                    EffectiveValue => 'AnyValue',
323                    UserID         => 1,
324                },
325                CheckDefaultValues => {
326                    IsValid => 1,
327                },
328                ExpectedResult => 1,
329            },
330            ModifiedSettingUpdate => {
331                Data => {
332                    DefaultID      => $DefaultSettingID,
333                    Name           => $SettingName,
334                    TargetUserID   => 1,
335                    EffectiveValue => 'Something new.',
336                    UserID         => 1,
337                },
338                CheckDefaultValues => {
339                    IsValid => 1,
340                },
341                ExpectedResult => 1,
342            },
343        },
344    },
345    {
346        Description => 'Take IsValid from Default and set it to a new value later',
347        Config      => {
348            ModifiedSettingAdd => {
349                Data => {
350                    DefaultID      => $DefaultSettingID,
351                    Name           => $SettingName,
352                    TargetUserID   => 1,
353                    EffectiveValue => 'This should be valid by default',
354                    UserID         => 1,
355                },
356                CheckDefaultValues => {
357                    IsValid => 1,
358                },
359                ExpectedResult => 1,
360            },
361            ModifiedSettingUpdate => {
362                Data => {
363                    DefaultID      => $DefaultSettingID,
364                    Name           => $SettingName,
365                    TargetUserID   => 1,
366                    IsValid        => 0,
367                    EffectiveValue => 'Set new IsValid value',
368                    UserID         => 1,
369                },
370                CheckDefaultValues => {
371                    IsValid => 0,
372                },
373                ExpectedResult => 1,
374            },
375        },
376    },
377    {
378        Description => 'TargetUserID && UserModificationActive at the same time aading a setting.',
379        Config      => {
380            ModifiedSettingAdd => {
381                Data => {
382                    DefaultID              => $DefaultSettingID,
383                    Name                   => $SettingName,
384                    TargetUserID           => $TestUserID,
385                    IsValid                => 1,
386                    UserModificationActive => 1,
387                    EffectiveValue         => '/usr/pgp',
388                    UserID                 => 1,
389                },
390                ExpectedResult => 0,
391            },
392        },
393    },
394    {
395        Description => 'TargetUserID && UserModificationActive at the same time updating a setting',
396        Config      => {
397            ModifiedSettingAdd => {
398                Data => {
399                    DefaultID      => $DefaultSettingID,
400                    Name           => $SettingName,
401                    TargetUserID   => 1,
402                    IsValid        => 1,
403                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
404                    UserID         => 1,
405                },
406                ExpectedResult => 1,
407            },
408            ModifiedSettingUpdate => {
409                Data => {
410                    DefaultID              => $DefaultSettingID,
411                    Name                   => $SettingName,
412                    TargetUserID           => 1,
413                    IsValid                => 0,
414                    UserModificationActive => 1,
415                    EffectiveValue         => 'Служба поддержки éáóíúß',
416                    UserID                 => 1,
417                },
418                ExpectedResult => 0,
419            },
420        },
421    },
422    {
423        Description =>
424            'ModifiedSettingAdd - Not possible to set UserModificationActive if not UserModificationPossible',
425        Config => {
426            ModifiedSettingAdd => {
427                Data => {
428                    DefaultID              => $DefaultSettingID,
429                    Name                   => $SettingName,
430                    IsValid                => 1,
431                    EffectiveValue         => 'öäüßüüäöäüß1öää?ÖÄPÜ',
432                    UserModificationActive => 1,
433                    UserID                 => 1,
434                },
435                ExpectedResult => 0,
436            },
437        },
438    },
439    {
440        Description => 'ModifiedSettingAdd - Not possible to set UserModificationActive for a user setting',
441        Config      => {
442            ModifiedSettingAdd => {
443                Data => {
444                    DefaultID              => $DefaultSettingID2,
445                    Name                   => $SettingName2,
446                    TargetUserID           => 1,
447                    IsValid                => 1,
448                    EffectiveValue         => 'öäüßüüäöäüß1öää?ÖÄPÜ',
449                    UserModificationActive => 1,
450                    UserID                 => 1,
451                },
452                ExpectedResult => 0,
453            },
454        },
455    },
456    {
457        Description =>
458            'ModifiedSettingAdd - Is possible to set UserModificationActive if UserModificationPossible in default',
459        Config => {
460            ModifiedSettingAdd => {
461                Data => {
462                    DefaultID              => $DefaultSettingID2,
463                    Name                   => $SettingName2,
464                    IsValid                => 1,
465                    EffectiveValue         => 'öäüßüüäöäüß1öää?ÖÄPÜ',
466                    UserModificationActive => 1,
467                    UserID                 => 1,
468                },
469                ExpectedResult => 1,
470            },
471        },
472    },
473    {
474        Description =>
475            'ModifiedSettingUpdate - Not possible to set UserModificationActive if not UserModificationPossible',
476        Config => {
477            ModifiedSettingAdd => {
478                Data => {
479                    DefaultID      => $DefaultSettingID,
480                    Name           => $SettingName,
481                    IsValid        => 1,
482                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
483                    UserID         => 1,
484                },
485                ExpectedResult => 1,
486            },
487            ModifiedSettingUpdate => {
488                Data => {
489                    DefaultID => $DefaultSettingID,
490                    Name      => $SettingName,
491
492                    # TargetUserID        => 1,
493                    IsValid                => 0,
494                    UserModificationActive => 1,
495                    EffectiveValue         => 'Служба поддержки éáóíúß',
496                    UserID                 => 1,
497                },
498                ExpectedResult => 0,
499            },
500        },
501    },
502    {
503        Description => 'ModifiedSettingUpdate - unset UserModificationActive is not possible any way',
504        Config      => {
505            ModifiedSettingAdd => {
506                Data => {
507                    DefaultID      => $DefaultSettingID,
508                    Name           => $SettingName,
509                    TargetUserID   => 1,
510                    IsValid        => 1,
511                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
512                    UserID         => 1,
513                },
514                ExpectedResult => 1,
515            },
516            ModifiedSettingUpdate => {
517                Data => {
518                    DefaultID              => $DefaultSettingID,
519                    Name                   => $SettingName,
520                    TargetUserID           => 1,
521                    IsValid                => 0,
522                    UserModificationActive => 0,
523                    EffectiveValue         => 'Служба поддержки éáóíúß',
524                    UserID                 => 1,
525                },
526                ExpectedResult => 0,
527            },
528        },
529    },
530    {
531        Description =>
532            'ModifiedSettingUpdate - if UserModificationActive is an empty value and not UserModificationPossible does not matter',
533        Config => {
534            ModifiedSettingAdd => {
535                Data => {
536                    DefaultID      => $DefaultSettingID,
537                    Name           => $SettingName,
538                    IsValid        => 1,
539                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
540                    UserID         => 1,
541                },
542                ExpectedResult => 1,
543            },
544            ModifiedSettingUpdate => {
545                Data => {
546                    DefaultID              => $DefaultSettingID,
547                    Name                   => $SettingName,
548                    IsValid                => 0,
549                    UserModificationActive => 0,
550                    EffectiveValue         => 'Служба поддержки éáóíúß',
551                    UserID                 => 1,
552                },
553                ExpectedResult => 1,
554            },
555        },
556    },
557    {
558        Description => 'ModifiedSettingUpdate - Is possible to set UserModificationActive if UserModificationPossible',
559        Config      => {
560            ModifiedSettingAdd => {
561                Data => {
562                    DefaultID      => $DefaultSettingID2,
563                    Name           => $SettingName2,
564                    IsValid        => 1,
565                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
566                    UserID         => 1,
567                },
568                ExpectedResult => 1,
569            },
570            ModifiedSettingUpdate => {
571                Data => {
572                    DefaultID              => $DefaultSettingID2,
573                    Name                   => $SettingName2,
574                    IsValid                => 0,
575                    UserModificationActive => 1,
576                    EffectiveValue         => 'Служба поддержки éáóíúß',
577                    UserID                 => 1,
578                },
579                ExpectedResult => 1,
580            },
581        },
582    },
583    {
584        Description => 'ModifiedSettingUpdate - unset UserModificationActive is possible any way',
585        Config      => {
586            ModifiedSettingAdd => {
587                Data => {
588                    DefaultID      => $DefaultSettingID2,
589                    Name           => $SettingName2,
590                    TargetUserID   => 1,
591                    IsValid        => 1,
592                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
593                    UserID         => 1,
594                },
595                ExpectedResult => 1,
596            },
597            ModifiedSettingUpdate => {
598                Data => {
599                    DefaultID              => $DefaultSettingID2,
600                    Name                   => $SettingName2,
601                    TargetUserID           => 1,
602                    IsValid                => 0,
603                    UserModificationActive => 0,
604                    EffectiveValue         => 'Служба поддержки éáóíúß',
605                    UserID                 => 1,
606                },
607                ExpectedResult => 0,
608            },
609        },
610    },
611    {
612        Description => 'ModifiedSettingUpdate - Set UserModificationActive when UserModificationPossible is set',
613        Config      => {
614            ModifiedSettingAdd => {
615                Data => {
616                    DefaultID      => $DefaultSettingID2,
617                    Name           => $SettingName2,
618                    IsValid        => 1,
619                    EffectiveValue => 'öäüßüüäöäüß1öää?ÖÄPÜ',
620                    UserID         => 1,
621                },
622                ExpectedResult => 1,
623            },
624            ModifiedSettingUpdate => {
625                Data => {
626                    DefaultID              => $DefaultSettingID2,
627                    Name                   => $SettingName2,
628                    IsValid                => 0,
629                    UserModificationActive => 1,
630                    EffectiveValue         => 'Служба поддержки éáóíúß',
631                    UserID                 => 1,
632                },
633                ExpectedResult => 1,
634            },
635        },
636    },
637
638);
639
640TEST:
641for my $Test (@Tests) {
642
643    my $CurrentDefaultSettingID = $Test->{Config}->{ModifiedSettingAdd}->{Data}->{DefaultID} || $DefaultSettingID;
644
645    # Lock setting
646    my $ExclusiveLockGUID = $SysConfigDBObject->DefaultSettingLock(
647        DefaultID => $CurrentDefaultSettingID,
648        UserID    => $Test->{Config}->{ModifiedSettingAdd}->{Data}->{TargetUserID} || 1,
649        Force     => 1,
650    );
651
652    my $IsLock = $SysConfigDBObject->DefaultSettingIsLocked(
653        DefaultID => $CurrentDefaultSettingID,
654    );
655
656    $Self->True(
657        $IsLock,
658        'Default setting must be lock.',
659    );
660
661    $Test->{Config}->{ModifiedSettingAdd}->{Data}->{ExclusiveLockGUID} = $ExclusiveLockGUID;
662
663    my $ModifiedSettingID = $SysConfigDBObject->ModifiedSettingAdd(
664        %{ $Test->{Config}->{ModifiedSettingAdd}->{Data} },
665    );
666
667    $Result = $ModifiedSettingID ? 1 : 0;
668    $Self->Is(
669        $Result,
670        $Test->{Config}->{ModifiedSettingAdd}->{ExpectedResult},
671        $Test->{Description}
672            . '-  ModifiedSettingAdd() must '
673            . ( $Test->{Config}->{ModifiedSettingAdd}->{ExpectedResult} ? 'succeed' : 'fail' )
674            . '.',
675    );
676
677    # Not Result means next tests will fail any way
678    # due not ModifiedSettingID available.
679    next TEST if !$Result;
680
681    # Test for ModifiedSettingGet()
682    my %ModifiedSetting = $SysConfigDBObject->ModifiedSettingGet( ModifiedID => $ModifiedSettingID );
683
684    # check values set by default if not defined in params
685    if ( IsHashRefWithData( $Test->{Config}->{ModifiedSettingAdd}->{CheckDefaultValues} ) ) {
686        for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingAdd}->{CheckDefaultValues} } ) {
687            $Self->Is(
688                $ModifiedSetting{$Key},
689                $Test->{Config}->{ModifiedSettingAdd}->{CheckDefaultValues}->{$Key},
690                $Test->{Description}
691                    . " - ModifiedSettingGet() checking default value for: $Key",
692            );
693        }
694    }
695
696    for my $Date (qw(CreateTime ChangeTime)) {
697        $Self->True(
698            $ModifiedSetting{$Date} =~ m{\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}} ? 1 : 0,
699            $Test->{Description}
700                . " - ModifiedSettingGet() checking $Date format",
701        );
702    }
703
704    my %ModifiedSettingToCompare;
705    for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingAdd}->{Data} } ) {
706        $ModifiedSettingToCompare{$Key} = $ModifiedSetting{$Key};
707
708        # Add missing items not reported by ModifiedSettingGet()
709        for my $Item (qw(UserID ExclusiveLockGUID)) {
710            if ( $Key eq $Item ) {
711                $ModifiedSettingToCompare{$Key} = $Test->{Config}->{ModifiedSettingAdd}->{Data}->{$Item};
712            }
713        }
714    }
715
716    $Self->IsDeeply(
717        \%ModifiedSettingToCompare,
718        $Test->{Config}->{ModifiedSettingAdd}->{Data},
719        $Test->{Description} . ' - ModifiedSettingGet() must return stored data.'
720    );
721
722    if ( !$Test->{Config}->{ModifiedSettingAdd}->{Data}->{TargetUserID} ) {
723
724        # Get by name and test it.
725        my %ModifiedSettingName
726            = $SysConfigDBObject->ModifiedSettingGet( Name => $Test->{Config}->{ModifiedSettingAdd}->{Data}->{Name} );
727
728        my %ModifiedSettingToCompareName;
729        for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingAdd}->{Data} } ) {
730            $ModifiedSettingToCompareName{$Key} = $ModifiedSettingName{$Key};
731
732            # Add missing items not reported by ModifiedSettingGet()
733            for my $Item (qw(UserID ExclusiveLockGUID)) {
734                if ( $Key eq $Item ) {
735                    $ModifiedSettingToCompareName{$Key} = $Test->{Config}->{ModifiedSettingAdd}->{Data}->{$Item};
736                }
737            }
738        }
739
740        $Self->IsDeeply(
741            \%ModifiedSettingToCompareName,
742            $Test->{Config}->{ModifiedSettingAdd}->{Data},
743            $Test->{Description} . ' - ModifiedSettingGet() must return stored data, requested by name.'
744        );
745    }
746
747    # If not data for update defined make not sense to execute testing
748    if ( exists $Test->{Config}->{ModifiedSettingUpdate} ) {
749
750        # Lock setting
751        my $ExclusiveLockGUID = $SysConfigDBObject->DefaultSettingLock(
752            DefaultID => $CurrentDefaultSettingID,
753            UserID    => $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{TargetUserID} || 1,
754            Force     => 1,
755        );
756
757        my $IsLock = $SysConfigDBObject->DefaultSettingIsLocked(
758            DefaultID => $CurrentDefaultSettingID,
759        );
760
761        $Self->True(
762            $IsLock,
763            'Default setting must be lock.',
764        );
765
766        $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{ExclusiveLockGUID} = $ExclusiveLockGUID;
767
768        # Test for ModifiedSettingUpdate()
769        $Result = $SysConfigDBObject->ModifiedSettingUpdate(
770            ModifiedID => $ModifiedSettingID,
771            %{ $Test->{Config}->{ModifiedSettingUpdate}->{Data} },
772        );
773
774        $Result = $Result ? 1 : 0;
775        $Self->Is(
776            $Result,
777            $Test->{Config}->{ModifiedSettingUpdate}->{ExpectedResult},
778            $Test->{Description}
779                . ' - ModifiedSettingUpdate() must '
780                . ( $Test->{Config}->{ModifiedSettingUpdate}->{ExpectedResult} ? 'succeed' : 'fail' )
781                . '.',
782        );
783
784        # If not have a base for comparison go to next test
785        if ( $Test->{Config}->{ModifiedSettingUpdate}->{ExpectedResult} ) {
786
787            # Test for ModifiedSettingGet()
788            %ModifiedSetting = $SysConfigDBObject->ModifiedSettingGet( ModifiedID => $ModifiedSettingID );
789
790            # check values set by default if not defined in params
791            if ( IsHashRefWithData( $Test->{Config}->{ModifiedSettingUpdate}->{CheckDefaultValues} ) ) {
792                for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingUpdate}->{CheckDefaultValues} } ) {
793                    $Self->Is(
794                        $ModifiedSetting{$Key},
795                        $Test->{Config}->{ModifiedSettingUpdate}->{CheckDefaultValues}->{$Key},
796                        $Test->{Description}
797                            . " - ModifiedSettingGet() checking default value for: $Key",
798                    );
799                }
800            }
801            for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingUpdate}->{Data} } ) {
802                $ModifiedSettingToCompare{$Key} = $ModifiedSetting{$Key};
803
804                # Add UserID or ExclusiveLockGUID as this not reported by ModifiedSettingGet()
805                if ( $Key eq 'UserID' || $Key eq 'ExclusiveLockGUID' ) {
806                    $ModifiedSettingToCompare{$Key} = $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{$Key};
807                }
808            }
809
810            if ( !$Test->{Config}->{ModifiedSettingUpdate}->{Data}->{TargetUserID} ) {
811
812                my %ModifiedSettingToCompareName;
813
814                # Get by Name and test it.
815                my %ModifiedSettingName = $SysConfigDBObject->ModifiedSettingGet(
816                    Name => $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{Name}
817                );
818                for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingUpdate}->{Data} } ) {
819                    $ModifiedSettingToCompareName{$Key} = $ModifiedSetting{$Key};
820
821                    # Add UserID or ExclusiveLockGUID as this not reported by ModifiedSettingGet()
822                    if ( $Key eq 'UserID' || $Key eq 'ExclusiveLockGUID' ) {
823                        $ModifiedSettingToCompareName{$Key} = $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{$Key};
824                    }
825                }
826
827                $Self->IsDeeply(
828                    \%ModifiedSettingToCompareName,
829                    $Test->{Config}->{ModifiedSettingUpdate}->{Data},
830                    $Test->{Description}
831                        . ' - Update - ModifiedSettingGet() must return stored data, requested by name.'
832                );
833            }
834
835            # Test for ModifiedSettingListGet()
836            my %ListGetParams;
837            for my $Item (qw(IsInvisible IsReadonly IsRequired IsValid HasConfigLevel UserModificationActive)) {
838                $ListGetParams{$Item} = $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{$Item};
839            }
840
841            $ListGetParams{ChangeBy} = $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{UserID};
842
843            my @ModifiedSettingList = $SysConfigDBObject->ModifiedSettingListGet(
844                %ListGetParams,
845            );
846
847            $Self->True(
848                IsArrayRefWithData( \@ModifiedSettingList ),
849                $Test->{Description} . ' - ModifiedSettingListGet() must return at least one setting.',
850            );
851
852            my @ModifiedSettings = grep { $_->{ModifiedID} == $ModifiedSettingID } @ModifiedSettingList;
853            $Self->True(
854                @ModifiedSettings == 1,
855                $Test->{Description} . ' - ModifiedSettingListGet() must return exactly one matching setting.',
856            );
857
858            my $ModifiedSetting = shift @ModifiedSettings;
859            %ModifiedSettingToCompare = ();
860            for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingUpdate}->{Data} } ) {
861                $ModifiedSettingToCompare{$Key} = $ModifiedSetting{$Key};
862
863                # Add UserID as this not reported by ModifiedSettingListGet()
864                if ( $Key eq 'UserID' || $Key eq 'ExclusiveLockGUID' ) {
865                    $ModifiedSettingToCompare{$Key} = $Test->{Config}->{ModifiedSettingUpdate}->{Data}->{$Key};
866                }
867            }
868
869            $Self->IsDeeply(
870                \%ModifiedSettingToCompare,
871                $Test->{Config}->{ModifiedSettingUpdate}->{Data},
872                $Test->{Description}
873                    . ' - ModifiedSettingListGet() must return stored data.'
874            );
875
876        }
877    }
878
879    if ($ModifiedSettingID) {
880
881        # Delete modified setting
882        my $Result = $SysConfigDBObject->ModifiedSettingDelete( ModifiedID => $ModifiedSettingID );
883        $Self->True(
884            $Result,
885            $Test->{Description} . ' - ModifiedSettingDelete() must succeed.',
886        );
887
888        # Test for ModifiedSettingGet()
889        %ModifiedSetting = $SysConfigDBObject->ModifiedSettingGet( ModifiedID => $ModifiedSettingID );
890        $Self->True(
891            ref \%ModifiedSetting eq 'HASH' && !%ModifiedSetting,
892            $Test->{Description}
893                . ' - ModifiedSettingGet() must return empty hash for deleted modified setting.',
894        );
895
896        # Test for ModifiedSettingListGet()
897        my @ModifiedSettingListByName = $SysConfigDBObject->ModifiedSettingListGet(
898            Name => $Test->{Config}->{ModifiedSettingAdd}->{Data},
899        );
900        $Self->True(
901            ref \@ModifiedSettingListByName eq 'ARRAY',
902            $Test->{Description} . ' - ModifiedSettingListGet() must return an array reference.',
903        );
904
905        @ModifiedSettingListByName = grep { $_->{ModifiedID} == $ModifiedSettingID } @ModifiedSettingListByName;
906        $Self->True(
907            @ModifiedSettingListByName == 0,
908            $Test->{Description}
909                . ' - ModifiedSettingListGet() must return no matching setting for deleted modified setting.',
910        );
911    }
912
913}
914
915# Lock setting
916my $ExclusiveLockGUID = $SysConfigDBObject->DefaultSettingLock(
917    DefaultID => $DefaultSettingID,
918    UserID    => 1,
919    Force     => 1,
920);
921
922# Add one Modified setting for version testing.
923my $ModifiedSettingID = $SysConfigDBObject->ModifiedSettingAdd(
924    DefaultID              => $DefaultSettingID,
925    Name                   => $SettingName,
926    Description            => 'A description for this setting áœ∑´®†¥¨ˆø',
927    Navigation             => 'ASimple::Path::Used',
928    IsInvisible            => 0,
929    IsReadonly             => 1,
930    IsRequired             => 1,
931    IsValid                => 1,
932    HasConfigLevel         => 300,
933    UserModificationActive => 0,
934    XMLContentRaw          => $DefaultSettingAddParams[0]->{XMLContentRaw},
935    XMLContentParsed       => $DefaultSettingAddParams[0]->{XMLContentParsed},
936    EffectiveValue         => 'Test setting 1',
937    ExclusiveLockGUID      => $ExclusiveLockGUID,
938    UserID                 => 1,
939);
940
941$Self->True(
942    $ModifiedSettingID,
943    'ModifiedSettingAdd used for version testing.',
944);
945
946my %DefaultSettingVersionGetLast = $SysConfigDBObject->DefaultSettingVersionGetLast(
947    DefaultID => $DefaultSettingID,
948);
949$Self->True(
950    \%DefaultSettingVersionGetLast,
951    'DefaultSettingVersionGetLast get version for default.',
952);
953
954my $DefaultSettingVersionID = $DefaultSettingVersionGetLast{DefaultVersionID};
955
956# Test configuration
957@Tests = (
958    {
959        Description => 'Complete testing cycle, not user identifier',
960        Config      => {
961            ModifiedSettingVersionAdd => {
962                Data => {
963                    DefaultVersionID       => $DefaultSettingVersionID,
964                    Name                   => $SettingName,
965                    IsValid                => 1,
966                    UserModificationActive => 0,
967                    TargetUserID           => $TestUserID,
968                    EffectiveValue         => 'ASimpleString',
969                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
970                    UserID                 => 1,
971                },
972                ExpectedResult => 1,
973            },
974        },
975    },
976    {
977        Description => 'Missing Default Version ID',
978        Config      => {
979            ModifiedSettingVersionAdd => {
980                Data => {
981
982                    # ModifiedID            => $ModifiedSettingID,
983                    Name                   => $SettingName,
984                    IsValid                => 1,
985                    UserModificationActive => 0,
986                    TargetUserID           => $TestUserID,
987                    EffectiveValue         => 'ASimpleString',
988                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
989                    UserID                 => 1,
990                },
991                ExpectedResult => 0,
992            },
993        },
994    },
995    {
996        Description => 'Missing Name',
997        Config      => {
998            ModifiedSettingVersionAdd => {
999                Data => {
1000                    DefaultVersionID       => $DefaultSettingVersionID,
1001                    IsValid                => 1,
1002                    UserModificationActive => 0,
1003                    TargetUserID           => $TestUserID,
1004                    EffectiveValue         => 'ASimpleString',
1005                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
1006                    UserID                 => 1,
1007                },
1008                ExpectedResult => 0,
1009            },
1010        },
1011    },
1012    {
1013        Description => 'Missing IsValid',
1014        Config      => {
1015            ModifiedSettingVersionAdd => {
1016                Data => {
1017                    DefaultVersionID       => $DefaultSettingVersionID,
1018                    Name                   => $SettingName,
1019                    UserModificationActive => 0,
1020                    TargetUserID           => $TestUserID,
1021                    EffectiveValue         => 'ASimpleString',
1022                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
1023                    UserID                 => 1,
1024                },
1025                ExpectedResult => 1,
1026            },
1027        },
1028    },
1029    {
1030        Description => 'Missing UserModificationActive',
1031        Config      => {
1032            ModifiedSettingVersionAdd => {
1033                Data => {
1034                    DefaultVersionID    => $DefaultSettingVersionID,
1035                    Name                => $SettingName,
1036                    IsValid             => 1,
1037                    TargetUserID        => $TestUserID,
1038                    EffectiveValue      => 'ASimpleString',
1039                    DeploymentTimeStamp => '2016-07-28 12:07:23',
1040                    UserID              => 1,
1041                },
1042                ExpectedResult => 1,
1043            },
1044        },
1045    },
1046    {
1047        Description => 'Missing TargetUserID',
1048        Config      => {
1049            ModifiedSettingVersionAdd => {
1050                Data => {
1051                    DefaultVersionID       => $DefaultSettingVersionID,
1052                    Name                   => $SettingName,
1053                    IsValid                => 1,
1054                    UserModificationActive => 0,
1055                    EffectiveValue         => 'ASimpleString',
1056                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
1057                    UserID                 => 1,
1058                },
1059                ExpectedResult => 1,
1060            },
1061        },
1062    },
1063    {
1064        Description => 'Missing EffectiveValue',
1065        Config      => {
1066            ModifiedSettingVersionAdd => {
1067                Data => {
1068                    DefaultVersionID       => $DefaultSettingVersionID,
1069                    Name                   => $SettingName,
1070                    IsValid                => 1,
1071                    UserModificationActive => 0,
1072                    TargetUserID           => $TestUserID,
1073                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
1074                    UserID                 => 1,
1075                },
1076                ExpectedResult => 0,
1077            },
1078        },
1079    },
1080    {
1081        Description => 'Missing DeploymentTimeStamp',
1082        Config      => {
1083            ModifiedSettingVersionAdd => {
1084                Data => {
1085                    DefaultVersionID       => $DefaultSettingVersionID,
1086                    Name                   => $SettingName,
1087                    IsValid                => 1,
1088                    UserModificationActive => 0,
1089                    TargetUserID           => $TestUserID,
1090                    EffectiveValue         => 'ASimpleString',
1091                    UserID                 => 1,
1092                },
1093                ExpectedResult => 0,
1094            },
1095        },
1096    },
1097    {
1098        Description => 'Missing UserID',
1099        Config      => {
1100            ModifiedSettingVersionAdd => {
1101                Data => {
1102                    DefaultVersionID       => $DefaultSettingVersionID,
1103                    Name                   => $SettingName,
1104                    IsValid                => 1,
1105                    UserModificationActive => 0,
1106                    TargetUserID           => $TestUserID,
1107                    EffectiveValue         => 'ASimpleString',
1108                    DeploymentTimeStamp    => '2016-07-28 12:07:23',
1109                },
1110                ExpectedResult => 0,
1111            },
1112        },
1113    },
1114);
1115
1116TESTVERSION:
1117for my $Test (@Tests) {
1118
1119    # Test for ModifiedSettingVersionAdd()
1120    my $ModifiedSettingVersionID = $SysConfigDBObject->ModifiedSettingVersionAdd(
1121        %{ $Test->{Config}->{ModifiedSettingVersionAdd}->{Data} }
1122    );
1123
1124    my $Result = $ModifiedSettingVersionID ? 1 : 0;
1125    $Self->Is(
1126        $Result,
1127        $Test->{Config}->{ModifiedSettingVersionAdd}->{ExpectedResult},
1128        $Test->{Description}
1129            . ' - ModifiedSettingVersionAdd() must '
1130            . ( $Test->{Config}->{ModifiedSettingVersionAdd}->{ExpectedResult} ? 'succeed' : 'fail' )
1131            . '.',
1132    );
1133
1134    # Not Result means next tests will fail any way
1135    # due not ModifiedSettingID available.
1136    next TESTVERSION if !$Result;
1137
1138    # Test for ModifiedSettingGet()
1139    my %ModifiedSettingVersion
1140        = $SysConfigDBObject->ModifiedSettingVersionGet( ModifiedVersionID => $ModifiedSettingVersionID );
1141    my %ModifiedSettingVersionToCompare;
1142    for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingVersionAdd}->{Data} } ) {
1143        $ModifiedSettingVersionToCompare{$Key} = $ModifiedSettingVersion{$Key};
1144
1145        # Add UserID as this not reported by ModifiedSettingVersionGet()
1146        if ( $Key eq 'UserID' ) {
1147            $ModifiedSettingVersionToCompare{$Key} = 1;
1148        }
1149    }
1150    use Data::Dumper;
1151    print STDERR "Debug - ModuleName - ModifiedSettingVersionToCompare = "
1152        . Dumper( \%ModifiedSettingVersionToCompare ) . "\n";
1153    $Self->IsDeeply(
1154        \%ModifiedSettingVersionToCompare,
1155        $Test->{Config}->{ModifiedSettingVersionAdd}->{Data},
1156        $Test->{Description} . ' - ModifiedSettingVersionGet() must return stored data.'
1157    );
1158
1159    my @ModifiedSettingVersionList = $SysConfigDBObject->ModifiedSettingVersionListGet(
1160        Name => $Test->{Config}->{ModifiedSettingVersionAdd}->{Data}->{Name},
1161    );
1162
1163    $Self->True(
1164        IsArrayRefWithData( \@ModifiedSettingVersionList ),
1165        $Test->{Description} . ' - ModifiedSettingVersionListGet() must return at least one setting.',
1166    );
1167
1168    my @ModifiedSettingVersions
1169        = grep { $_->{ModifiedVersionID} == $ModifiedSettingVersionID } @ModifiedSettingVersionList;
1170    $Self->True(
1171        @ModifiedSettingVersions == 1,
1172        $Test->{Description} . ' - ModifiedSettingVersionListGet() must return exactly one matching setting.',
1173    );
1174
1175    my $ModifiedSettingVersion = shift @ModifiedSettingVersions;
1176    %ModifiedSettingVersionToCompare = ();
1177    for my $Key ( sort keys %{ $Test->{Config}->{ModifiedSettingVersionUpdate}->{Data} } ) {
1178        $ModifiedSettingVersionToCompare{$Key} = $ModifiedSettingVersion{$Key};
1179
1180        # Add UserID as this not reported by ModifiedSettingVersionListGet()
1181        if ( $Key eq 'UserID' || $Key eq 'ExclusiveLockGUID' ) {
1182            $ModifiedSettingVersionToCompare{$Key} = $Test->{Config}->{ModifiedSettingVersionUpdate}->{Data}->{$Key};
1183        }
1184    }
1185
1186    $Self->IsDeeply(
1187        \%ModifiedSettingVersionToCompare,
1188        $Test->{Config}->{ModifiedSettingVersionUpdate}->{Data},
1189        $Test->{Description}
1190            . ' - ModifiedSettingVersionListGet() must return stored data.'
1191    );
1192
1193    # Delete modified setting
1194    $Result = $SysConfigDBObject->ModifiedSettingVersionDelete( ModifiedVersionID => $ModifiedSettingVersionID );
1195    $Self->True(
1196        $Result,
1197        $Test->{Description} . ' - ModifiedSettingVersionDelete() must succeed.',
1198    );
1199
1200    # Test for ModifiedSettingVersionGet()
1201    %ModifiedSettingVersion
1202        = $SysConfigDBObject->ModifiedSettingVersionGet( ModifiedVersionID => $ModifiedSettingVersionID );
1203    $Self->True(
1204        ref \%ModifiedSettingVersion eq 'HASH' && !%ModifiedSettingVersion,
1205        $Test->{Description}
1206            . ' - ModifiedSettingVersionGet() must return empty hash for deleted modified setting.',
1207    );
1208
1209    # Test for ModifiedSettingVersionListGet()
1210    @ModifiedSettingVersionList = $SysConfigDBObject->ModifiedSettingVersionListGet(
1211        Name => $Test->{Config}->{ModifiedSettingVersionAdd}->{Data}->{Name},
1212    );
1213    $Self->True(
1214        ref \@ModifiedSettingVersionList eq 'ARRAY',
1215        $Test->{Description} . ' - ModifiedSettingVersionListGet() must return an array reference.',
1216    );
1217
1218    @ModifiedSettingVersions = grep { $_->{ModifiedID} == $ModifiedSettingVersionID } @ModifiedSettingVersionList;
1219    $Self->True(
1220        @ModifiedSettingVersions == 0,
1221        $Test->{Description}
1222            . ' - ModifiedSettingVersionListGet() must return no matching setting for deleted modified setting.',
1223    );
1224}
1225
1226my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
1227
1228# Delete sysconfig_modified_version
1229return if !$DBObject->Do(
1230    SQL => 'DELETE FROM sysconfig_modified_version',
1231);
1232
1233# Delete sysconfig_modified
1234return if !$DBObject->Do(
1235    SQL => 'DELETE FROM sysconfig_modified',
1236);
1237
1238$ExclusiveLockGUID = $SysConfigDBObject->DefaultSettingLock(
1239    DefaultID => $DefaultSettingID,
1240    UserID    => 1,
1241    Force     => 1,
1242);
1243
1244my $ModifiedID = $SysConfigDBObject->ModifiedSettingAdd(
1245    DefaultID              => $DefaultSettingID,
1246    Name                   => $SettingName,
1247    IsValid                => 1,
1248    UserModificationActive => 0,
1249    EffectiveValue         => 'Modified1',
1250    ExclusiveLockGUID      => $ExclusiveLockGUID,
1251    UserID                 => 1,
1252);
1253
1254my $ModifiedVersionID = $SysConfigDBObject->ModifiedSettingVersionAdd(
1255    DefaultVersionID       => $DefaultSettingVersionID,
1256    Name                   => $SettingName,
1257    IsValid                => 1,
1258    UserModificationActive => 0,
1259    EffectiveValue         => 'Modified1',
1260    DeploymentTimeStamp    => '2015-12-12 12:00:00',
1261    UserID                 => 1,
1262);
1263
1264my %ModifiedSettingVersion = $SysConfigDBObject->ModifiedSettingVersionGetLast(
1265    Name => $SettingName,
1266);
1267
1268$Self->Is(
1269    $ModifiedSettingVersion{EffectiveValue},
1270    'Modified1',
1271    "ModifiedSettingVersionGetLast() 1"
1272);
1273
1274$ModifiedVersionID = $SysConfigDBObject->ModifiedSettingVersionAdd(
1275    DefaultVersionID       => $DefaultSettingVersionID,
1276    Name                   => $SettingName,
1277    IsValid                => 1,
1278    UserModificationActive => 0,
1279    EffectiveValue         => 'Modified2',
1280    DeploymentTimeStamp    => '2015-12-12 12:00:00',
1281    UserID                 => 1,
1282);
1283
1284%ModifiedSettingVersion = $SysConfigDBObject->ModifiedSettingVersionGetLast(
1285    Name => $SettingName,
1286);
1287
1288$Self->Is(
1289    $ModifiedSettingVersion{EffectiveValue},
1290    'Modified2',
1291    "ModifiedSettingVersionGetLast() 1"
1292);
1293
1294$SettingName2 = 'ProductName ' . $HelperObject->GetRandomNumber() . 2;
1295
1296# Add default setting
1297$DefaultSettingID2 = $SysConfigDBObject->DefaultSettingAdd(
1298    Name                     => $SettingName2,
1299    Description              => 'Defines the name of the application ...',
1300    Navigation               => 'ASimple::Path::Structure',
1301    IsInvisible              => 1,
1302    IsReadonly               => 0,
1303    IsRequired               => 1,
1304    IsValid                  => 1,
1305    HasConfigLevel           => 200,
1306    UserModificationPossible => 0,
1307    UserModificationActive   => 0,
1308    XMLContentRaw            => $DefaultSettingAddParams[0]->{XMLContentRaw},
1309    XMLContentParsed         => $DefaultSettingAddParams[0]->{XMLContentParsed},
1310    XMLFilename              => 'UnitTest.xml',
1311    EffectiveValue           => 'Test setting 1',
1312    UserID                   => 1,
1313);
1314
1315my $ExclusiveLockGUID2 = $SysConfigDBObject->DefaultSettingLock(
1316    DefaultID => $DefaultSettingID2,
1317    UserID    => 1,
1318    Force     => 1,
1319);
1320
1321my $ModifiedID2 = $SysConfigDBObject->ModifiedSettingAdd(
1322    DefaultID              => $DefaultSettingID2,
1323    Name                   => $SettingName2,
1324    IsValid                => 1,
1325    UserModificationActive => 0,
1326    EffectiveValue         => 'Modified1',
1327    ExclusiveLockGUID      => $ExclusiveLockGUID2,
1328    UserID                 => 1,
1329);
1330
1331my %DefaultSettingVersionGetLast2 = $SysConfigDBObject->DefaultSettingVersionGetLast(
1332    DefaultID => $DefaultSettingID2,
1333);
1334$Self->True(
1335    \%DefaultSettingVersionGetLast2,
1336    'DefaultSettingVersionGetLast get version for default.',
1337);
1338
1339my $DefaultSettingVersionID2 = $DefaultSettingVersionGetLast2{DefaultVersionID};
1340
1341my $ModifiedVersionID2 = $SysConfigDBObject->ModifiedSettingVersionAdd(
1342    DefaultVersionID       => $DefaultSettingVersionID2,
1343    Name                   => $SettingName2,
1344    IsValid                => 1,
1345    UserModificationActive => 0,
1346    EffectiveValue         => 'Modified1',
1347    DeploymentTimeStamp    => '2015-12-12 12:00:00',
1348    UserID                 => 1,
1349);
1350
1351$ModifiedVersionID2 = $SysConfigDBObject->ModifiedSettingVersionAdd(
1352    DefaultVersionID       => $DefaultSettingVersionID2,
1353    Name                   => $SettingName2,
1354    IsValid                => 1,
1355    UserModificationActive => 0,
1356    EffectiveValue         => 'Modified2',
1357    DeploymentTimeStamp    => '2015-12-12 12:00:00',
1358    UserID                 => 1,
1359);
1360
1361my %ModifiedSettingVersion2 = $SysConfigDBObject->ModifiedSettingVersionGetLast(
1362    Name => $SettingName2,
1363);
1364
1365my @List = $SysConfigDBObject->ModifiedSettingVersionListGetLast();
1366
1367$Self->IsDeeply(
1368    \@List,
1369    [ \%ModifiedSettingVersion, \%ModifiedSettingVersion2 ],
1370    "ModifiedSettingVersionListGetLast()"
1371);
1372
1373@Tests = (
1374    {
1375        Name   => 'Missing Name',
1376        Config => {},
1377    },
1378    {
1379        Name   => 'Wrong Name',
1380        Config => {
1381            Name => -1,
1382        },
1383    },
1384);
1385
1386for my $Test (@Tests) {
1387
1388    my %ModifiedSettingVersion = $SysConfigDBObject->ModifiedSettingVersionGetLast( %{ $Test->{Config} } );
1389
1390    $Self->IsDeeply(
1391        \%ModifiedSettingVersion,
1392        {},
1393        "$Test->{Name} ModifiedSettingVersionGetLast()",
1394    );
1395}
1396
13971;
1398