Kernel::Test::Role::Environment::ProvidesTestDatabase

NAME

Kernel::Test::Role::Environment::ProvidesTestDatabase – role to provide a separate test database.

ProvideTestDatabase()

Provide temporary database for the test. Please first define test database settings in Config.pm, i.e:

    $Self->{TestDatabase} = {
        DatabaseDSN  => 'DBI:mysql:database=otrs_test;host=127.0.0.1;',
        DatabaseUser => 'otrs_test',
        DatabasePw   => 'otrs_test',
    };

The method call will override global database configuration for duration of the test, i.e. temporary database will receive all calls sent over system DBObject.

All database contents will be automatically dropped at the end of the test.

    $Self->ProvideTestDatabase(
        DatabaseXMLString => $XML,      # (optional) OTRS database XML schema to execute
                                        # or
        DatabaseXMLFiles => [           # (optional) List of XML files to load and execute
            '/opt/otrs/scripts/database/otrs-schema.xml',
            '/opt/otrs/scripts/database/otrs-initial_insert.xml',
        ],
    );

This method returns 'undef' in case the test database is not configured. If it is configured, but the supplied XML cannot be read or executed, this method will die() to interrupt the test with an error.

GetDatabaseStructure()

returns a hash representation of the current database structure. This can be used if certain transformations in the database lead to identical / expected results.

Please note that the hash structure varies based on the used DB driver type.

    my $DatabaseStructureHashBefore = $Self->GetDatabaseStructure();

    ...     # perform some changes

    my $DatabaseStructureHashAfter  = $Self->GetDatabaseStructure();

    ...     # compare the hashes

TestDatabaseCleanup()

Clears the temporary database used in the test.

DatabaseXMLExecute()

Execute supplied XML against the current database. Content of supplied XML or XMLFilename parameter must be valid OTRS database XML schema.

    $Self->DatabaseXMLExecute(
        XML => $XML,     # OTRS database XML schema to execute
    );

Alternatively, it can also load an XML file to execute:

    $Self->DatabaseXMLExecute(
        XMLFile => '/path/to/file',  # OTRS database XML file to execute
    );
Scroll to Top