Kernel::Test::Role::Environment::HandlesSystemConfiguration

NAME

Kernel::Test::Role::Environment::HandlesSystemConfiguration – role to manipulate the system configuration for tests.

PUBLIC INTERFACE

GetHome()

shortcut method to get the current OTRS home directory.

    my $Home = $Self->GetHome();

GetConfigSetting()

shortcut method to get the value of a config setting.

    my $Home = $Self->GetConfigSetting('My::Setting');

GetTestHTTPHostname()

returns a host name for HTTP based tests, possibly including the port.

ConfigSettingChange()

temporarily change a configuration setting system wide to another value, both in the current ConfigObject and also in the system configuration on disk.

This will be reset at the end of the test.

Please note that this will not work correctly in clustered environments.

    $Self->ConfigSettingChange(
        Valid => 1,            # (optional) enable or disable setting
        Key   => 'MySetting',  # setting name
        Value => { ... } ,     # setting value
    );

ConfigSettingsChange()

Call ConfigSettingChange() on all given config setting changes.

    $Self->ConfigSettingsChange(
        {
            Valid => 1,                 # (optional) enable or disable setting
            Key   => 'MySetting',       # setting name
            Value => { ... } ,          # setting value
        },
        {
            Valid => 1,                 # (optional) enable or disable setting
            Key   => 'AnotherSetting',  # setting name
            Value => { ... } ,          # setting value
        }
    );

CustomCodeActivate()

Temporarily include custom code in the system. For example, you may use this to redefine a subroutine from another class. This change will persist for remainder of the test.

All code will be removed when the test object is destroyed.

Please note that this will not work correctly in clustered environments.

    $Self->CustomCodeActivate(
        Identifier => 'AdminPackageManager' . $RandomID,   # (optional) Code identifier to include in file name
        Code => q^
sub Kernel::Config::Files::ZZZZUnitTestAdminPackageManager${RandomID}::Load {} # no-op, avoid warning logs

use Kernel::System::MojoUserAgent; package Kernel::System::MojoUserAgent; use Mojo::Transaction::HTTP;

use strict; use warnings; { no warnings 'redefine'; sub post { my \$Transaction = Mojo::Transaction::HTTP->new(); \$Transaction->res()->code(200)->body('{"Success":1,"Results":{"PackageManagement":[{"Operation":"PackageVerify","Data":{"Test":"not_verified","TestIncompatible":"not_verified"},"Success":"1"}]},"ErrorMessage":""}'); return \$Transaction; }; } 1; ^, );

_CustomFileCleanup()

removes all custom files from ConfigSettingChange() and CustomCodeActivate().

EditYAML

gets a YAML string, and a perl hash, changes the value, returns a YAML string undef if replacement not happened, logs error if YAML invalid. Be careful this method has limited functionality It handles for the time being only ToReplace as HashRef at the first key level. If you try something not implemented you get the original input and a log message

  $NewYamlString = $Self->EditYAML( YAMLIn =>'some string', ToReplace => {} );
Scroll to Top