File: RebuildConfigBug14910.t

package info (click to toggle)
znuny 6.5.18-1
  • links: PTS
  • area: non-free
  • in suites: forky, sid
  • size: 205,344 kB
  • sloc: perl: 1,038,694; xml: 74,551; javascript: 65,276; sql: 23,574; sh: 417; makefile: 63
file content (162 lines) | stat: -rw-r--r-- 5,073 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# --
# Copyright (C) 2001-2021 OTRS AG, https://otrs.com/
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --

## no critic (Modules::RequireExplicitPackage)
use strict;
use warnings;
use utf8;

use Kernel::System::VariableCheck qw( IsHashRefWithData );

use vars (qw($Self));

$Kernel::OM->ObjectParamAdd(
    'Kernel::System::UnitTest::Helper' => {
        RestoreDatabase => 1,
    },
);

my $ConfigurationDeploy = sub {
    my %Param = @_;

    # Remove remains of previous runs to ensure proper testing.
    $Kernel::OM->ObjectsDiscard(
        Objects => ['Kernel::System::SysConfig'],
    );
    delete $INC{'Kernel/Config/Files/ZZZAAuto.pm'};

    my $SysConfigObject = $Kernel::OM->Get('Kernel::System::SysConfig');

    my $ConfigurationXML2DBOk = $SysConfigObject->ConfigurationXML2DB(
        UserID  => 1,
        Force   => 1,
        CleanUp => 1,
    );
    $Self->True(
        $ConfigurationXML2DBOk,
        'Succcessfully converted configuration',
    );

    my %DeploymentResult = $SysConfigObject->ConfigurationDeploy(
        Comments    => "Configuration Rebuild",
        AllSettings => 1,
        UserID      => 1,
        Force       => 1,
    );
    $Self->Is(
        $DeploymentResult{Success} ? 1 : 0,
        $Param{Success},
        $Param{Success} ? 'Succcessfully deployed configuration' : 'Unsuccessful configuration deployment',
    );
};

my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $MainObject   = $Kernel::OM->Get('Kernel::System::Main');
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');

# Create file whose existence will be validated.
my $TestFileLocation = $ConfigObject->Get('Home') . '/var/tmp/UnitTest' . $HelperObject->GetRandomNumber();
my $TestFileContent  = 'UnitTest';
my $TestFileWriteOk  = $MainObject->FileWrite(
    Location => $TestFileLocation,
    Content  => \$TestFileContent,
);
$Self->True(
    $TestFileWriteOk,
    'Succcessfully wrote test file',
);

# Prepare two new file-type config settings.
my $ValidSettingXML = <<EOF,
<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="2.0" init="Framework">
    <Setting Name="Test1" Required="1" Valid="1">
        <Description Translatable="1">Test 1.</Description>
        <Navigation>Core::Ticket</Navigation>
        <Value>
            <Item ValueType="File">$TestFileLocation</Item>
        </Value>
    </Setting>
    <Setting Name="Test2" Required="1" Valid="1">
        <Description Translatable="1">Test 2.</Description>
        <Navigation>Core::Ticket</Navigation>
        <Value>
            <Item ValueType="File">$TestFileLocation</Item>
        </Value>
    </Setting>
</otrs_config>
EOF

    my $ConfigFileLocation
    = $ConfigObject->Get('Home') . '/Kernel/Config/Files/XML/UnitTest' . $HelperObject->GetRandomNumber() . '.xml';
my $ConfigFileWriteOk = $MainObject->FileWrite(
    Location => $ConfigFileLocation,
    Content  => \$ValidSettingXML,
);
$Self->True(
    $ConfigFileWriteOk,
    'Succcessfully wrote configuration file',
);

# Verify successful deployment.
$ConfigurationDeploy->( Success => 1 );

# Remove file and verify failed deployment.
my $TestFileDeleteOk = $MainObject->FileDelete(
    Location => $TestFileLocation,
);
$Self->True(
    $TestFileDeleteOk,
    'Succcessfully removed test file',
);

$ConfigurationDeploy->( Success => 0 );

# Add override file with correct configuration (implicitly by using helper object).
$HelperObject->ConfigSettingChange(
    Valid => 1,
    Key   => 'Test1',
    Value => $ConfigObject->Get('Home') . '/Kernel/System/UnitTest/Helper.pm',    # This should always exist.
);
$HelperObject->ConfigSettingChange(
    Valid => 1,
    Key   => 'Test2',
    Value => $ConfigObject->Get('Home') . '/Kernel/System/UnitTest/Helper.pm',    # This should always exist.
);

# Discard SysConfig object to ensure clean state. Then delete ZZZAAuto.pm to force regeneration.
my $ZZZAAutoFileDeleteOk = $MainObject->FileDelete(
    Location => $ConfigObject->Get('Home') . '/Kernel/Config/Files/ZZZAAuto.pm',
);
$Self->True(
    $ZZZAAutoFileDeleteOk,
    'Succcessfully removed ZZZAAuto.pm',
);

# During the next deployment there will be two requests to OverriddenFileNameGet().
# The first one takes the current database state as no ZZZAAuto.pm exists, the second one uses the cached values.
$ConfigurationDeploy->( Success => 1 );

# Run deployment again.
# Now the first request to OverriddenFileNameGet() will use ZZZAAuto.pm (which was regenerated by previous deployment)
#   and the second one the cached values.
$ConfigurationDeploy->( Success => 1 );

# Cleanup config file, deploy and verify result.
my $ConfigFileDeleteOk = $MainObject->FileDelete(
    Location => $ConfigFileLocation,
);
$Self->True(
    $ConfigFileDeleteOk,
    'Succcessfully removed configuration file',
);

$ConfigurationDeploy->( Success => 1 );

1;