TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Testbase Class Reference

Public Member Functions

 __construct ()
 
 enableDisplayErrors ()
 
 defineBaseConstants ()
 
 defineSitePath ()
 
 defineOriginalRootPath ()
 
 defineTypo3ModeBe ()
 
 setTypo3TestingContext ()
 
 createDirectory ($directory)
 
 recentTestInstanceExists ($instancePath)
 
 removeOldInstanceIfExists ($instancePath)
 
 createLastRunTextfile ($instancePath)
 
 setUpInstanceCoreLinks ($instancePath)
 
 linkTestExtensionsToInstance ($instancePath, array $extensionPaths)
 
 linkPathsInTestInstance ($instancePath, array $pathsToLinkInTestInstance)
 
 getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration ()
 
 testDatabaseNameIsNotTooLong ($originalDatabaseName, array $configuration)
 
 setUpLocalConfiguration ($instancePath, array $configuration, array $overruleConfiguration)
 
 setUpPackageStates ($instancePath, array $defaultCoreExtensionsToLoad, array $additionalCoreExtensionsToLoad, array $testExtensionPaths)
 
 setUpTestDatabase ($databaseName, $originalDatabaseName)
 
 setUpBasicTypo3Bootstrap ($instancePath)
 
 initializeTestDatabaseAndTruncateTables ()
 
 loadExtensionTables ()
 
 createDatabaseStructure ()
 

Protected Member Functions

 getWebRoot ()
 
 exitWithMessage ($message)
 
 writeFile ($file, $content)
 

Detailed Description

This is a helper class used by unit, functional and acceptance test environment builders. It contains methods to create test environments.

This class is for internal use only and may change wihtout further notice.

Use the classes "UnitTestCase", "FunctionalTestCase" or "AcceptanceCoreEnvironment" to indirectly benefit from this class in own extensions.

Definition at line 36 of file Testbase.php.

Constructor & Destructor Documentation

__construct ( )

This class must be called in CLI environment as a security measure against path disclosures and other stuff. Check this within constructor to make sure this check can't be circumvented.

Definition at line 43 of file Testbase.php.

Member Function Documentation

createDatabaseStructure ( )

Create tables and import static rows. For functional and acceptance tests.

Returns
void

Definition at line 574 of file Testbase.php.

References GeneralUtility\makeInstance().

createDirectory (   $directory)

Creates directories, recursively if required.

Parameters
string$directoryAbsolute path to directories to create
Returns
void
Exceptions
Exception

Definition at line 152 of file Testbase.php.

createLastRunTextfile (   $instancePath)

Create last_run.txt file within instance path containing timestamp of "now". Used in functional tests to reuse an instance for multiple tests in one test case.

Parameters
string$instancePathAbsolute path to test instance
Returns
void

Definition at line 209 of file Testbase.php.

defineBaseConstants ( )

Defines a list of basic constants that are used by GeneralUtility and other helpers during tests setup. Those are sanitized in SystemEnvironmentBuilder to be not defined again.

Returns
void
See also
SystemEnvironmentBuilder::defineBaseConstants()

Definition at line 69 of file Testbase.php.

defineOriginalRootPath ( )

Defines the constant ORIGINAL_ROOT for the path to the original TYPO3 document root. For functional / acceptance tests only If ORIGINAL_ROOT already is defined, this method is a no-op.

Returns
void

Definition at line 114 of file Testbase.php.

References Testbase\exitWithMessage(), and Testbase\getWebRoot().

defineSitePath ( )

Defines the PATH_site and PATH_thisScript constant and sets $_SERVER['SCRIPT_NAME']. For unit tests only

Returns
void

Definition at line 96 of file Testbase.php.

References Testbase\exitWithMessage(), and Testbase\getWebRoot().

defineTypo3ModeBe ( )

Define TYPO3_MODE to BE

Returns
void

Definition at line 130 of file Testbase.php.

enableDisplayErrors ( )

Makes sure error messages during the tests get displayed no matter what is set in php.ini.

Returns
void

Definition at line 56 of file Testbase.php.

exitWithMessage (   $message)
protected

Send http headers, echo out a text message and exit with error code

Parameters
string$message

Definition at line 667 of file Testbase.php.

Referenced by Testbase\defineOriginalRootPath(), and Testbase\defineSitePath().

getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration ( )

Database settings for functional and acceptance tests can be either set by environment variables (recommended), or from an existing LocalConfiguration as fallback. The method fetches these.

An unique name will be added to the database name later.

Exceptions
Exception
Returns
array [DB][host], [DB][username], ...

Definition at line 311 of file Testbase.php.

getWebRoot ( )
protected

Returns the absolute path the TYPO3 document root. This is the "original" document root, not the "instance" root for functional / acceptance tests.

Returns
string the TYPO3 document root using Unix path separators

Definition at line 652 of file Testbase.php.

Referenced by Testbase\defineOriginalRootPath(), and Testbase\defineSitePath().

initializeTestDatabaseAndTruncateTables ( )

Truncate all tables. For functional and acceptance tests.

Exceptions
Exception
Returns
void

Definition at line 544 of file Testbase.php.

References ConnectionPool\DEFAULT_CONNECTION_NAME, Bootstrap\getInstance(), and GeneralUtility\makeInstance().

linkPathsInTestInstance (   $instancePath,
array  $pathsToLinkInTestInstance 
)

Link paths inside the test instance, e.g. from a fixture fileadmin subfolder to the test instance fileadmin folder. For functional and acceptance tests.

Parameters
string$instancePathAbsolute path to test instance
array$pathsToLinkInTestInstanceContains paths as array of source => destination in key => value pairs of folders relative to test instance root
Exceptions
Exceptionif a source path could not be found and on failing creating the symlink
Returns
void

Definition at line 280 of file Testbase.php.

linkTestExtensionsToInstance (   $instancePath,
array  $extensionPaths 
)

Link test extensions to the typo3conf/ext folder of the instance. For functional and acceptance tests.

Parameters
string$instancePathAbsolute path to test instance
array$extensionPathsContains paths to extensions relative to document root
Exceptions
Exception
Returns
void

Definition at line 249 of file Testbase.php.

loadExtensionTables ( )

Load ext_tables.php files. For functional and acceptance tests.

Returns
void

Definition at line 563 of file Testbase.php.

References Bootstrap\getInstance().

recentTestInstanceExists (   $instancePath)

Checks whether given test instance exists in path and is younger than some minutes. Used in functional tests

Parameters
string$instancePathAbsolute path to test instance
Returns
bool

Definition at line 171 of file Testbase.php.

removeOldInstanceIfExists (   $instancePath)

Remove test instance folder structure if it exists. This may happen if a functional test before threw a fatal or is too old

Parameters
string$instancePathAbsolute path to test instance
Returns
void
Exceptions
Exception

Definition at line 189 of file Testbase.php.

References GeneralUtility\rmdir().

setTypo3TestingContext ( )

Sets the environment variable TYPO3_CONTEXT to testing.

Returns
void

Definition at line 140 of file Testbase.php.

setUpBasicTypo3Bootstrap (   $instancePath)

Bootstrap basic TYPO3. This bootstraps TYPO3 far enough to initialize database afterwards. For functional and acceptance tests.

Parameters
string$instancePathAbsolute path to test instance
Returns
void

Definition at line 520 of file Testbase.php.

References Bootstrap\getInstance().

setUpInstanceCoreLinks (   $instancePath)

Link TYPO3 CMS core from "parent" instance. For functional and acceptance tests.

Parameters
string$instancePathAbsolute path to test instance
Exceptions
Exception
Returns
void

Definition at line 223 of file Testbase.php.

setUpLocalConfiguration (   $instancePath,
array  $configuration,
array  $overruleConfiguration 
)

Create LocalConfiguration.php file of the test instance. For functional and acceptance tests.

Parameters
string$instancePathAbsolute path to test instance
array$configurationBase configuration array
array$overruleConfigurationOverrule factory and base configuration
Exceptions
Exception
Returns
void

Definition at line 395 of file Testbase.php.

References ArrayUtility\arrayExport(), ArrayUtility\mergeRecursiveWithOverrule(), and Testbase\writeFile().

setUpPackageStates (   $instancePath,
array  $defaultCoreExtensionsToLoad,
array  $additionalCoreExtensionsToLoad,
array  $testExtensionPaths 
)

Compile typo3conf/PackageStates.php containing default packages like core, a test specific list of additional core extensions, and a list of test extensions. For functional and acceptance tests.

Parameters
string$instancePathAbsolute path to test instance
array$defaultCoreExtensionsToLoadDefault list of core extensions to load
array$additionalCoreExtensionsToLoadAdditional core extensions to load
array$testExtensionPathsPaths to extensions relative to document root
Exceptions
Exception

Definition at line 427 of file Testbase.php.

References ArrayUtility\arrayExport(), and Testbase\writeFile().

setUpTestDatabase (   $databaseName,
  $originalDatabaseName 
)

Create a low level connection to dbms, without selecting the target database. Drop existing database if it exists and create a new one.

Parameters
string$databaseNameDatabase name of this test instance
string$originalDatabaseNameOriginal database name before suffix was added
Exceptions
TYPO3
Returns
void

Definition at line 484 of file Testbase.php.

References $GLOBALS, and Bootstrap\getInstance().

testDatabaseNameIsNotTooLong (   $originalDatabaseName,
array  $configuration 
)

Maximum length of database names is 64 chars in mysql. Test this is not exceeded after a suffix has been added.

Parameters
string$originalDatabaseNameBase name of the database
array$configuration"LocalConfiguration" array with DB settings
Exceptions
Exception

Definition at line 370 of file Testbase.php.

writeFile (   $file,
  $content 
)
protected

Writes $content to the file $file. This is a simplified version of GeneralUtility::writeFile that does not fix permissions.

Parameters
string$fileFilepath to write to
string$contentContent to write
Returns
bool TRUE if the file was successfully opened and written to.

Definition at line 681 of file Testbase.php.

Referenced by Testbase\setUpLocalConfiguration(), and Testbase\setUpPackageStates().