PHPUnit
|
Public Member Functions | |
__construct ($tablePrefix, array $additionalTablePrefixes=array()) | |
createRecord ($tableName, array $recordData=array()) | |
createFrontEndPage ($parentId=0, array $recordData=array()) | |
createSystemFolder ($parentId=0, array $recordData=array()) | |
createContentElement ($pageId=0, array $recordData=array()) | |
createTemplate ($pageId, array $recordData=array()) | |
createFrontEndUserGroup (array $recordData=array()) | |
createFrontEndUser ($frontEndUserGroups= '', array $recordData=array()) | |
createAndLoginFrontEndUser ($frontEndUserGroups= '', array $recordData=array()) | |
createBackEndUser (array $recordData=array()) | |
createBackEndUserGroup (array $recordData=array()) | |
changeRecord ($tableName, $uid, array $recordData) | |
deleteRecord ($tableName, $uid) | |
createRelation ($tableName, $uidLocal, $uidForeign, $sorting=0) | |
createRelationAndUpdateCounter ($tableName, $uidLocal, $uidForeign, $columnName) | |
removeRelation ($tableName, $uidLocal, $uidForeign) | |
createDummyFile ($fileName= 'test.txt', $content= '') | |
createDummyZipArchive ($fileName= 'test.zip', array $filesToAddToArchive=array()) | |
deleteDummyFile ($fileName) | |
createDummyFolder ($folderName) | |
deleteDummyFolder ($folderName) | |
setUploadFolderPath ($absolutePath) | |
getUploadFolderPath () | |
getPathRelativeToUploadDirectory ($absolutePath) | |
getUniqueFileOrFolderPath ($path) | |
discardFakeFrontEnd () | |
hasFakeFrontEnd () | |
loginFrontEndUser ($userId) | |
logoutFrontEndUser () | |
isLoggedIn () | |
getDummyColumnName ($tableName) | |
countRecords ($tableName, $whereClause= '') | |
existsRecord ($tableName, $whereClause= '') | |
existsRecordWithUid ($tableName, $uid) | |
existsExactlyOneRecord ($tableName, $whereClause= '') | |
resetAutoIncrement ($tableName) | |
resetAutoIncrementLazily ($tableName) | |
setResetAutoIncrementThreshold ($threshold) | |
getAutoIncrement ($tableName) | |
getListOfOwnAllowedTableNames () | |
getListOfAdditionalAllowedTableNames () | |
markTableAsDirty ($tableNames) | |
getListOfDirtyTables () | |
getListOfDirtySystemTables () | |
getRelationSorting ($tableName, $uidLocal) | |
increaseRelationCounter ($tableName, $uid, $fieldName) | |
checkForZipArchive () | |
purgeHooks () | |
Protected Member Functions | |
getCurrentTypo3Version () | |
createRecordWithoutTableNameChecks ($tableName, array $recordData) | |
createGeneralPageRecord ($documentType, $parentId, array $recordData) | |
cleanUpTableSet ($useSystemTables, $performDeepCleanUp) | |
deleteAllDummyFoldersAndFiles () | |
addToDummyFileList ($uniqueFileName) | |
createDummyUploadFolder () | |
suppressFrontEndCookies () | |
createListOfOwnAllowedTables () | |
createListOfAdditionalAllowedTables () | |
isOwnTableNameAllowed ($tableName) | |
isAdditionalTableNameAllowed ($tableName) | |
isSystemTableNameAllowed ($tableName) | |
isNoneSystemTableNameAllowed ($tableName) | |
isTableNameAllowed ($tableName) | |
getMaximumUidFromTable ($tableName) | |
getHooks () | |
Protected Attributes | |
$tablePrefix = '' | |
$additionalTablePrefixes = array() | |
$ownAllowedTables = array() | |
$additionalAllowedTables = array() | |
$allowedSystemTables | |
$dirtyTables = array() | |
$dirtySystemTables = array() | |
$relationSorting = array() | |
$resetAutoIncrementThreshold = 100 | |
$dummyFiles = array() | |
$dummyFolders = array() | |
$uploadFolderPath = '' | |
$hasFakeFrontEnd = FALSE | |
Static Protected Attributes | |
static | $fileNameProcessor = NULL |
static | $hooks = array() |
static | $hooksHaveBeenRetrieved = FALSE |
Tx_Phpunit_Framework::__construct | ( | $ | tablePrefix, |
array $ | additionalTablePrefixes = array() |
||
) |
The constructor for this class.
This testing framework can be instantiated for one extension at a time. Example: In your testcase, you'll have something similar to this line of code: $this->fixture = new Tx_Phpunit_Framework('tx_seminars'); The parameter you provide is the prefix of the table names of that particular extension. Like this, we ensure that the testing framework creates and deletes records only on table with this prefix.
If you need dummy records on tables of multiple extensions, you'll have to instantiate the testing frame work multiple times (once per extension).
string | $tablePrefix | the table name prefix of the extension for which this instance of the testing framework should be used |
array | $additionalTablePrefixes | the additional table name prefixes of the extensions for which this instance of the testing framework should be used, may be empty |
Tx_Phpunit_Framework::addToDummyFileList | ( | $ | uniqueFileName | ) | [protected] |
Adds a file name to $this->dummyFiles.
string | $uniqueFileName | file name to add, must be the unique name of a dummy file, must not be empty |
Tx_Phpunit_Framework::changeRecord | ( | $ | tableName, |
$ | uid, | ||
array $ | recordData | ||
) |
Changes an existing dummy record and stores the new data for this record. Only fields that get new values in $recordData will be changed, everything else will stay untouched.
The array with the new recordData must contain at least one entry, but must not contain a new UID for the record. If you need to change the UID, you have to create a new record!
string | $tableName | the name of the table, must not be empty |
integer | $uid | the UID of the record to change, must not be empty |
array | $recordData | associative array containing key => value pairs for those fields of the record that need to be changed, must not be empty |
Checks whether the ZIPArchive class is provided by the PHP installation.
Note: This function can be used to mark tests as skipped if this class is not available but required for a test to pass succesfully.
t3lib_exception | if the PHP installation does not provide ZIPArchive |
Tx_Phpunit_Framework::cleanUpTableSet | ( | $ | useSystemTables, |
$ | performDeepCleanUp | ||
) | [protected] |
Deletes a set of records that have been added through this framework for a set of tables (either the test tables or the allowed system tables). For this, all records with the "is_dummy_record" flag set to 1 will be deleted from all tables that have been used within this instance of the testing framework.
If you set $performDeepCleanUp to TRUE, it will go through ALL tables to which the current instance of the testing framework has access. Please consider well, whether you want to do this as it's a huge performance issue.
boolean | $useSystemTables | whether to clean up the system tables (TRUE) or the non-system test tables (FALSE) |
boolean | $performDeepCleanUp | whether a deep clean up should be performed |
Tx_Phpunit_Framework::countRecords | ( | $ | tableName, |
$ | whereClause = '' |
||
) |
Counts the dummy records in the table given by the first parameter $tableName that match a given WHERE clause.
string | $tableName | the name of the table to query, must not be empty |
string | $whereClause | the WHERE part of the query, may be empty (all records will be counted in that case) |
Tx_Phpunit_Framework::createAndLoginFrontEndUser | ( | $ | frontEndUserGroups = '' , |
array $ | recordData = array() |
||
) |
Creates and logs in an FE user.
string | $frontEndUserGroups | comma-separated list of UIDs of the user groups to which the new user belongs, each must be > 0, may contain spaces; if empty a new front-end user group is created |
array | $recordData | associative array that contains the data to save in the new user record, may be empty, but must not contain the keys "uid" or "usergroup" |
Tx_Phpunit_Framework::createBackEndUser | ( | array $ | recordData = array() | ) |
Creates a BE user record.
array | $recordData | associative array that contains the data to save in the new user record, may be empty, but must not contain the key "uid" |
Tx_Phpunit_Framework::createBackEndUserGroup | ( | array $ | recordData = array() | ) |
Creates a BE user group.
array | $recordData | associative array that contains the data to save in the new user group record, may be empty, but must not contain the key "uid" |
Tx_Phpunit_Framework::createContentElement | ( | $ | pageId = 0 , |
array $ | recordData = array() |
||
) |
Creates a FE content element on the page with the UID given by the first parameter $pageId.
Created content elements are text elements by default, but the content element's type can be overwritten by setting the key 'CType' in the parameter $recordData.
integer | $pageId | UID of the page on which the content element should be created |
array | $recordData | associative array that contains the data to save in the content element, may be empty, but must not contain the keys "uid" or "pid" |
Tx_Phpunit_Framework::createDummyFile | ( | $ | fileName = 'test.txt' , |
$ | content = '' |
||
) |
Creates an empty dummy file with a unique file name in the calling extension's upload directory.
string | $fileName | path of the dummy file to create, relative to the calling extension's upload directory, must not be empty |
string | $content | string content for the file to create, may be empty |
Tx_Phpunit_Framework::createDummyFolder | ( | $ | folderName | ) |
Creates a dummy folder with a unique folder name in the calling extension's upload directory.
string | $folderName | name of the dummy folder to create relative to $this->uploadFolderPath, must not be empty |
Tx_Phpunit_Framework::createDummyUploadFolder | ( | ) | [protected] |
Creates the upload folder if it does not exist yet.
Tx_Phpunit_Framework::createDummyZipArchive | ( | $ | fileName = 'test.zip' , |
array $ | filesToAddToArchive = array() |
||
) |
Creates a dummy ZIP archive with a unique file name in the calling extension's upload directory.
string | $fileName | path of the dummy ZIP archive to create, relative to the calling extension's upload directory, must not be empty |
array | $filesToAddToArchive | Absolute paths of the files to add to the ZIP archive. Note that the archives directory structure will be relative to the upload folder path, so only files within this folder or in sub-folders of this folder can be added. The provided array may be empty, but as ZIP archives cannot be empty, a content-less dummy text file will be added to the archive then. |
t3lib_exception | if the PHP installation does not provide ZIPArchive |
Tx_Phpunit_Framework::createFrontEndPage | ( | $ | parentId = 0 , |
array $ | recordData = array() |
||
) |
Creates a front-end page on the page with the UID given by the first parameter $parentId.
integer | $parentId | UID of the page on which the page should be created |
array | $recordData | associative array that contains the data to save in the new page, may be empty, but must not contain the keys "uid", "pid" or "doktype" |
Tx_Phpunit_Framework::createFrontEndUser | ( | $ | frontEndUserGroups = '' , |
array $ | recordData = array() |
||
) |
Creates a FE user record.
string | $frontEndUserGroups | comma-separated list of UIDs of the user groups to which the new user belongs, each must be > 0, may contain spaces, if empty a new FE user group will be created |
array | $recordData | associative array that contains the data to save in the new user record, may be empty, but must not contain the keys "uid" or "usergroup" |
Tx_Phpunit_Framework::createFrontEndUserGroup | ( | array $ | recordData = array() | ) |
Creates a FE user group.
array | $recordData | associative array that contains the data to save in the new user group record, may be empty, but must not contain the key "uid" |
Tx_Phpunit_Framework::createGeneralPageRecord | ( | $ | documentType, |
$ | parentId, | ||
array $ | recordData | ||
) | [protected] |
Creates a page record with the document type given by the first parameter $documentType.
The record will be created on the page with the UID given by the second parameter $parentId.
integer | $documentType | document type of the record to create, must be > 0 |
integer | $parentId | UID of the page on which the record should be created |
array | $recordData | associative array that contains the data to save in the record, may be empty, but must not contain the keys "uid", "pid" or "doktype" |
Tx_Phpunit_Framework::createListOfAdditionalAllowedTables | ( | ) | [protected] |
Generates a list of additional allowed tables to which this instance of the testing framework has access to create/remove test records.
The generated list is based on the list of all tables that TYPO3 can access (which will be all tables in this database), filtered by the prefixes of additional extensions.
The array with the allowed table names is written directly to $this->additionalAllowedTables.
Tx_Phpunit_Framework::createListOfOwnAllowedTables | ( | ) | [protected] |
Generates a list of allowed tables to which this instance of the testing framework has access to create/remove test records.
The generated list is based on the list of all tables that TYPO3 can access (which will be all tables in this database), filtered by prefix of the extension to test.
The array with the allowed table names is written directly to $this->ownAllowedTables.
Tx_Phpunit_Framework::createRecord | ( | $ | tableName, |
array $ | recordData = array() |
||
) |
Creates a new dummy record for unit tests.
If no record data for the new array is given, an empty record will be created. It will only contain a valid UID and the "is_dummy_record" flag will be set to 1.
Should there be any problem creating the record (wrong table name or a problem with the database), 0 instead of a valid UID will be returned.
string | $tableName | the name of the table on which the record should be created, must not be empty |
array | $recordData | associative array that contains the data to save in the new record, may be empty, but must not contain the key "uid" |
Tx_Phpunit_Framework::createRecordWithoutTableNameChecks | ( | $ | tableName, |
array $ | recordData | ||
) | [protected] |
Creates a new dummy record for unit tests without checks for the table name.
If no record data for the new array is given, an empty record will be created. It will only contain a valid UID and the "is_dummy_record" flag will be set to 1.
Should there be any problem creating the record (wrong table name or a problem with the database), 0 instead of a valid UID will be returned.
string | $tableName | the name of the table on which the record should be created, must not be empty |
array | $recordData | associative array that contains the data to save in the new record, may be empty, but must not contain the key "uid" |
Tx_Phpunit_Framework::createRelation | ( | $ | tableName, |
$ | uidLocal, | ||
$ | uidForeign, | ||
$ | sorting = 0 |
||
) |
Creates a relation between two records on different tables (so called m:n relation).
string | $tableName | name of the m:n table to which the record should be added, must not be empty |
integer | $uidLocal | UID of the local table, must be > 0 |
integer | $uidForeign | UID of the foreign table, must be > 0 |
integer | $sorting | sorting value of the relation, the default value is 0, which enables automatic sorting, a value >= 0 overwrites the automatic sorting |
Tx_Phpunit_Framework::createRelationAndUpdateCounter | ( | $ | tableName, |
$ | uidLocal, | ||
$ | uidForeign, | ||
$ | columnName | ||
) |
Creates a relation between two records based on the rules defined in TCA regarding the relation.
string | $tableName | name of the table from which a relation should be created, must not be empty |
integer | $uidLocal | UID of the record in the local table, must be > 0 |
integer | $uidForeign | UID of the record in the foreign table, must be > 0 |
string | $columnName | name of the column in which the relation counter should be updated, must not be empty |
Tx_Phpunit_Framework::createSystemFolder | ( | $ | parentId = 0 , |
array $ | recordData = array() |
||
) |
Creates a system folder on the page with the UID given by the first parameter $parentId.
integer | $parentId | UID of the page on which the system folder should be created |
array | $recordData | associative array that contains the data to save in the new page, may be empty, but must not contain the keys "uid", "pid" or "doktype" |
Tx_Phpunit_Framework::createTemplate | ( | $ | pageId, |
array $ | recordData = array() |
||
) |
Creates a template on the page with the UID given by the first parameter $pageId.
integer | $pageId | UID of the page on which the template should be created, must be > 0 |
array | $recordData | associative array that contains the data to save in the new template, may be empty, but must not contain the keys "uid" or "pid" |
Tx_Phpunit_Framework::deleteAllDummyFoldersAndFiles | ( | ) | [protected] |
Deletes all dummy files and folders.
Tx_Phpunit_Framework::deleteDummyFile | ( | $ | fileName | ) |
Deletes the dummy file specified by the first parameter $fileName.
string | $fileName | the path to the file to delete relative to $this->uploadFolderPath, must not be empty |
Tx_Phpunit_Framework::deleteDummyFolder | ( | $ | folderName | ) |
Deletes the dummy folder specified in the first parameter $folderName. The folder must be empty (no files or subfolders).
string | $folderName | the path to the folder to delete relative to $this->uploadFolderPath, must not be empty |
Tx_Phpunit_Framework::deleteRecord | ( | $ | tableName, |
$ | uid | ||
) |
Deletes a dummy record from the database.
Important: Only dummy records from non-system tables can be deleted with this method. Should there for any reason exist a real record with that UID, it won't be deleted.
string | $tableName | name of the table from which the record should be deleted, must not be empty |
integer | $uid | UID of the record to delete, must be > 0 |
Discards the fake front end.
This function nulls out $GLOBALS['TSFE'] and $GLOBALS['TT']. In addition, any logged-in front-end user will be logged out.
The page record for the current front end will _not_ be deleted by this function, though.
If no fake front end has been created, this function does nothing.
Tx_Phpunit_Framework::existsExactlyOneRecord | ( | $ | tableName, |
$ | whereClause = '' |
||
) |
Checks whether there is exactly one dummy record in the table given by the first parameter $tableName that matches a given WHERE clause.
string | $tableName | the name of the table to query, must not be empty |
string | $whereClause | the WHERE part of the query, may be empty (all records will be counted in that case) |
Tx_Phpunit_Framework::existsRecord | ( | $ | tableName, |
$ | whereClause = '' |
||
) |
Checks whether there are any dummy records in the table given by the first parameter $tableName that match a given WHERE clause.
string | $tableName | the name of the table to query, must not be empty |
string | $whereClause | the WHERE part of the query, may be empty (all records will be counted in that case) |
Tx_Phpunit_Framework::existsRecordWithUid | ( | $ | tableName, |
$ | uid | ||
) |
Checks whether there is a dummy record in the table given by the first parameter $tableName that has the given UID.
string | $tableName | the name of the table to query, must not be empty |
integer | $uid | the UID of the record to look up, must be > 0 |
Tx_Phpunit_Framework::getAutoIncrement | ( | $ | tableName | ) |
Reads the current auto increment value for a given table.
This function is only valid for tables that actually have an auto increment value.
string | $tableName | the name of the table for which the auto increment value should be retrieved, must not be empty |
Tx_Phpunit_Framework::getCurrentTypo3Version | ( | ) | [protected] |
Computes the current TYPO3 version and returns it.
Tx_Phpunit_Framework::getDummyColumnName | ( | $ | tableName | ) |
Returns the name of the column that marks a record as a dummy record.
On most tables this is "is_dummy_record", but on system tables like "pages" or "fe_users", the column is called "tx_phpunit_dummy_record".
On additional tables, the column is built using $this->tablePrefix as prefix e.g. "tx_seminars_is_dummy_record" if $this->tablePrefix = "tx_seminars".
string | $tableName | the table name to look up, must not be empty |
Tx_Phpunit_Framework::getHooks | ( | ) | [protected] |
Gets all hooks for this class.
Returns the list of additional allowed table names.
Returns the list of system tables that contain dummy records from testing. These tables are called "dirty tables" as they need to be cleaned up.
Returns the list of tables that contain dummy records from testing. These tables are called "dirty tables" as they need to be cleaned up.
Returns the list of allowed table names.
Tx_Phpunit_Framework::getMaximumUidFromTable | ( | $ | tableName | ) | [protected] |
Reads the highest UID for a database table.
This function may only be called after that the provided table name has been checked to be non-empty, valid and pointing to an existing database table that has the "uid" column.
string | $tableName | the name of an existing table that has the "uid" column |
Tx_Phpunit_Framework::getPathRelativeToUploadDirectory | ( | $ | absolutePath | ) |
Returns the path relative to the calling extension's upload directory for a path given in the first parameter $absolutePath.
string | $absolutePath | the absolute path to process, must be within the calling extension's upload directory, must not be empty |
Tx_Phpunit_Framework::getRelationSorting | ( | $ | tableName, |
$ | uidLocal | ||
) |
Returns the next sorting value of the relation table which should be used.
TODO: This function doesn't take already existing relations in the database - which were created without using the testing framework - into account. So you always should create new dummy records and create a relation between these two dummy records, so you're sure there aren't already relations for a local UID in the database.
string | $tableName | the relation table, must not be empty |
integer | $uidLocal | UID of the local table, must be > 0 |
Returns a unique absolut path of a file or folder.
string | $path | the path of a file or folder relative to the calling extension's upload directory, must not be empty |
Returns the absolute path to the upload folder of the extension to test.
Returns whether this testing framework instance has a fake front end.
Tx_Phpunit_Framework::increaseRelationCounter | ( | $ | tableName, |
$ | uid, | ||
$ | fieldName | ||
) |
Updates an integer field of a database table by one. This is mainly needed for counting up the relation counter when creating a database relation.
The field to update must be of type integer.
string | $tableName | name of the table, must not be empty |
integer | $uid | the UID of the record to modify, must be > 0 |
string | $fieldName | the field name of the field to modify, must not be empty |
Tx_Phpunit_Framework::isAdditionalTableNameAllowed | ( | $ | tableName | ) | [protected] |
Checks whether the given table name is in the list of additional allowed tables for this instance of the testing framework.
string | $tableName | the name of the table to check, must not be empty |
Checks whether a FE user is logged in.
t3lib_exception | if no front end has been created |
Tx_Phpunit_Framework::isNoneSystemTableNameAllowed | ( | $ | tableName | ) | [protected] |
Checks whether the given table name is in the list of allowed tables or additional allowed tables for this instance of the testing framework.
string | $tableName | the name of the table to check, must not be empty |
Tx_Phpunit_Framework::isOwnTableNameAllowed | ( | $ | tableName | ) | [protected] |
Checks whether the given table name is in the list of allowed tables for this instance of the testing framework.
string | $tableName | the name of the table to check, must not be empty |
Tx_Phpunit_Framework::isSystemTableNameAllowed | ( | $ | tableName | ) | [protected] |
Checks whether the given table name is in the list of allowed system tables for this instance of the testing framework.
string | $tableName | the name of the table to check, must not be empty |
Tx_Phpunit_Framework::isTableNameAllowed | ( | $ | tableName | ) | [protected] |
Checks whether the given table name is in the list of allowed tables, additional allowed tables or allowed system tables.
string | $tableName | the name of the table to check, must not be empty |
Tx_Phpunit_Framework::loginFrontEndUser | ( | $ | userId | ) |
Fakes that a front-end user has logged in.
If a front-end user currently is logged in, he/she will be logged out first.
Note: To set the logged-in users group data properly, the front-end user and his groups must actually exist in the database.
integer | $userId | UID of the FE user, must not necessarily exist in the database, must be > 0 |
t3lib_exception | if no front end has been created |
Logs out the current front-end user.
If no front-end user is logged in, this function does nothing.
t3lib_exception | if no front end has been created |
Tx_Phpunit_Framework::markTableAsDirty | ( | $ | tableNames | ) |
Puts one or multiple table names on the list of dirty tables (which represents a list of tables that were used for testing and contain dummy records and thus are called "dirty" until the next clean up).
string | $tableNames | the table name or a comma-separated list of table names to put on the list of dirty tables, must not be empty |
Purges the cached hooks.
Tx_Phpunit_Framework::removeRelation | ( | $ | tableName, |
$ | uidLocal, | ||
$ | uidForeign | ||
) |
Deletes a dummy relation from an m:n table in the database.
Important: Only dummy records can be deleted with this method. Should there for any reason exist a real record with that combination of local and foreign UID, it won't be deleted!
string | $tableName | name of the table from which the record should be deleted, must not be empty |
integer | $uidLocal | UID on the local table, must be > 0 |
integer | $uidForeign | UID on the foreign table, must be > 0 |
Tx_Phpunit_Framework::resetAutoIncrement | ( | $ | tableName | ) |
Eagerly resets the auto increment value for a given table to the highest existing UID + 1.
string | $tableName | the name of the table on which we're going to reset the auto increment entry, must not be empty |
Tx_Phpunit_Framework::resetAutoIncrementLazily | ( | $ | tableName | ) |
Resets the auto increment value for a given table to the highest existing UID + 1 if the current auto increment value is higher than a certain threshold over the current maximum UID.
The threshold is 100 by default and can be set using setResetAutoIncrementThreshold.
string | $tableName | the name of the table on which we're going to reset the auto increment entry, must not be empty |
Tx_Phpunit_Framework::setResetAutoIncrementThreshold | ( | $ | threshold | ) |
Sets the threshold for resetAutoIncrementLazily.
integer | $threshold | threshold, must be > 0 |
Tx_Phpunit_Framework::setUploadFolderPath | ( | $ | absolutePath | ) |
Sets the upload folder path.
string | $absolutePath | absolute path to the folder where to work on during the tests, can be either an existing folder which will be cleaned up after the tests or a path of a folder to be created as soon as it is needed and deleted during cleanUp, must end with a trailing slash |
t3lib_exception | if there are dummy files within the current upload folder as these files could not be deleted if the upload folder path has changed |
Tx_Phpunit_Framework::suppressFrontEndCookies | ( | ) | [protected] |
Makes sure that no FE login cookies will be sent.
Tx_Phpunit_Framework::$allowedSystemTables [protected] |
array( 'be_users', 'fe_groups', 'fe_users', 'pages', 'sys_template', 'tt_content', 'be_groups' )