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
23# Make sure repository root setting is set to default for duration of the test.
24my %Setting = $Kernel::OM->Get('Kernel::System::SysConfig')->SettingGet(
25    Name    => 'Package::RepositoryRoot',
26    Default => 1,
27);
28$Helper->ConfigSettingChange(
29    Valid => 1,
30    Key   => 'Package::RepositoryRoot',
31    Value => $Setting{DefaultValue},
32);
33
34my @FrameworkVersionParts = split /\./, $Kernel::OM->Get('Kernel::Config')->Get('Version');
35my $FrameworkVersion      = $FrameworkVersionParts[0];
36
37my @Tests = (
38    {
39        Name           => 'No Repositories',
40        ConfigSet      => {},
41        Success        => 1,
42        ExpectedResult => {
43            'http://ftp.otrs.org/pub/otrs/packages/' => 'OTRS Freebie Features'
44        },
45    },
46    {
47        Name      => 'No ITSM Repositories',
48        ConfigSet => {
49            'http://otrs.com' => 'Test Repository',
50        },
51        Success        => 1,
52        ExpectedResult => {
53            'http://ftp.otrs.org/pub/otrs/packages/' => 'OTRS Freebie Features',
54            'http://otrs.com'                        => 'Test Repository',
55        },
56    },
57    {
58        Name      => 'ITSM 33 Repository',
59        ConfigSet => {
60            'http://otrs.com'                               => 'Test Repository',
61            'http://ftp.otrs.org/pub/otrs/itsm/packages33/' => 'OTRS::ITSM 3.3 Master',
62        },
63        Success        => 1,
64        ExpectedResult => {
65            'http://ftp.otrs.org/pub/otrs/packages/'                       => 'OTRS Freebie Features',
66            'http://otrs.com'                                              => 'Test Repository',
67            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
68        },
69    },
70    {
71        Name      => 'ITSM 33 and 4 Repository',
72        ConfigSet => {
73            'http://otrs.com'                               => 'Test Repository',
74            'http://ftp.otrs.org/pub/otrs/itsm/packages33/' => 'OTRS::ITSM 3.3 Master',
75            'http://ftp.otrs.org/pub/otrs/itsm/packages4/'  => 'OTRS::ITSM 4 Master',
76        },
77        Success        => 1,
78        ExpectedResult => {
79            'http://ftp.otrs.org/pub/otrs/packages/'                       => 'OTRS Freebie Features',
80            'http://otrs.com'                                              => 'Test Repository',
81            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
82        },
83    },
84    {
85        Name      => 'ITSM 33 4 and 5 Repository',
86        ConfigSet => {
87            'http://otrs.com'                               => 'Test Repository',
88            'http://ftp.otrs.org/pub/otrs/itsm/packages33/' => 'OTRS::ITSM 3.3 Master',
89            'http://ftp.otrs.org/pub/otrs/itsm/packages4/'  => 'OTRS::ITSM 4 Master',
90            'http://ftp.otrs.org/pub/otrs/itsm/packages5/'  => 'OTRS::ITSM 5 Master',
91        },
92        Success        => 1,
93        ExpectedResult => {
94            'http://ftp.otrs.org/pub/otrs/packages/'                       => 'OTRS Freebie Features',
95            'http://otrs.com'                                              => 'Test Repository',
96            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
97        },
98    },
99    {
100        Name      => 'ITSM 6 Repository',
101        ConfigSet => {
102            'http://ftp.otrs.org/pub/otrs/packages/'                       => 'OTRS Freebie Features',
103            'http://otrs.com'                                              => 'Test Repository',
104            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
105        },
106        Success        => 1,
107        ExpectedResult => {
108            'http://ftp.otrs.org/pub/otrs/packages/'                       => 'OTRS Freebie Features',
109            'http://otrs.com'                                              => 'Test Repository',
110            "http://ftp.otrs.org/pub/otrs/itsm/packages$FrameworkVersion/" => "OTRS::ITSM $FrameworkVersion Master",
111        },
112    },
113);
114
115my $ConfigObject  = $Kernel::OM->Get('Kernel::Config');
116my $PackageObject = $Kernel::OM->Get('Kernel::System::Package');
117my $ConfigKey     = 'Package::RepositoryList';
118
119for my $Test (@Tests) {
120    if ( $Test->{ConfigSet} ) {
121        my $Success = $ConfigObject->Set(
122            Key   => $ConfigKey,
123            Value => $Test->{ConfigSet},
124        );
125        $Self->True(
126            $Success,
127            "$Test->{Name} configuration set in run time",
128        );
129    }
130
131    my %RepositoryList = $PackageObject->_ConfiguredRepositoryDefinitionGet();
132
133    $Self->IsDeeply(
134        \%RepositoryList,
135        $Test->{ExpectedResult},
136        "$Test->{Name} _ConfiguredRepositoryDefinitionGet()",
137    );
138}
139
1401;
141