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
16$Kernel::OM->ObjectParamAdd(
17    'Kernel::System::UnitTest::Helper' => {
18        RestoreDatabase => 1,
19    },
20);
21my $Helper = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
22
23my @FrameworkVersionParts = split /\./, $Kernel::OM->Get('Kernel::Config')->Get('Version');
24my $FrameworkVersion      = $FrameworkVersionParts[0];
25
26my @Tests = (
27    {
28        Name           => 'No Repositories',
29        ConfigSet      => {},
30        Success        => 1,
31        ExpectedResult => {},
32    },
33    {
34        Name      => 'No ITSM Repositories',
35        ConfigSet => {
36            'http://otrs.com' => 'Test Repository',
37        },
38        Success        => 1,
39        ExpectedResult => {
40            'http://otrs.com' => 'Test Repository',
41        },
42    },
43    {
44        Name      => 'ITSM 33 Repository',
45        ConfigSet => {
46            'http://otrs.com'                               => 'Test Repository',
47            'http://ftp.otrs.org/pub/otrs/itsm/packages33/' => 'OTRS::ITSM 3.3 Master',
48        },
49        Success        => 1,
50        ExpectedResult => {
51            'http://otrs.com'                                              => 'Test Repository',
52            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
53        },
54    },
55    {
56        Name      => 'ITSM 33 and 4 Repository',
57        ConfigSet => {
58            'http://otrs.com'                               => 'Test Repository',
59            'http://ftp.otrs.org/pub/otrs/itsm/packages33/' => 'OTRS::ITSM 3.3 Master',
60            'http://ftp.otrs.org/pub/otrs/itsm/packages4/'  => 'OTRS::ITSM 4 Master',
61        },
62        Success        => 1,
63        ExpectedResult => {
64            'http://otrs.com'                                              => 'Test Repository',
65            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
66        },
67    },
68    {
69        Name      => 'ITSM 33 4 and 5 Repository',
70        ConfigSet => {
71            'http://otrs.com'                               => 'Test Repository',
72            'http://ftp.otrs.org/pub/otrs/itsm/packages33/' => 'OTRS::ITSM 3.3 Master',
73            'http://ftp.otrs.org/pub/otrs/itsm/packages4/'  => 'OTRS::ITSM 4 Master',
74            'http://ftp.otrs.org/pub/otrs/itsm/packages5/'  => 'OTRS::ITSM 5 Master',
75        },
76        Success        => 1,
77        ExpectedResult => {
78            'http://otrs.com'                                              => 'Test Repository',
79            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
80        },
81    },
82    {
83        Name      => 'ITSM 6 Repository',
84        ConfigSet => {
85            'http://otrs.com'                              => 'Test Repository',
86            'http://ftp.otrs.org/pub/otrs/itsm/packages6/' => 'OTRS::ITSM 6 Master',
87        },
88        Success        => 1,
89        ExpectedResult => {
90            'http://otrs.com'                                              => 'Test Repository',
91            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
92        },
93    },
94);
95
96my $ConfigObject    = $Kernel::OM->Get('Kernel::Config');
97my $ConfigKey       = 'Package::RepositoryList';
98my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');
99
100for my $Test (@Tests) {
101    if ( $Test->{ConfigSet} ) {
102        my $Success = $ConfigObject->Set(
103            Key   => $ConfigKey,
104            Value => $Test->{ConfigSet},
105        );
106        $Self->True(
107            $Success,
108            "$Test->{Name} configuration set in run time",
109        );
110
111        my $ExclusiveLockGUID = $SysConfigObject->SettingLock(
112            Name   => $ConfigKey,
113            Force  => 1,
114            UserID => 1,
115        );
116
117        my %Result = $SysConfigObject->SettingUpdate(
118            Name              => $ConfigKey,
119            IsValid           => 1,
120            EffectiveValue    => $Test->{ConfigSet},
121            ExclusiveLockGUID => $ExclusiveLockGUID,
122            UserID            => 1,
123        );
124        $Self->True(
125            $Result{Success},
126            "$Test->{Name} configuration set in DB",
127        );
128    }
129
130    my $UpgradeSuccess = $Kernel::OM->Create('scripts::DBUpdateTo6::MigratePackageRepositoryConfiguration')->Run(
131        ContinueOnModified => 1,
132    );
133    $Self->Is(
134        $UpgradeSuccess,
135        $Test->{Success},
136        "$Test->{Name} Upgrade Package Repository result",
137    );
138
139    my %Setting = $SysConfigObject->SettingGet(
140        Name   => $ConfigKey,
141        UserID => 1,
142    );
143
144    $Self->IsDeeply(
145        $Setting{EffectiveValue},
146        $Test->{ExpectedResult},
147        "$Test->{Name} $ConfigKey value",
148    );
149}
150
1511;
152