PHPUnit
PHPUnit TYPO3 extension
Static Public Member Functions | List of all members
Tx_Phpunit_Service_Database Class Reference

Static Public Member Functions

static enableQueryLogging ()
 
static enableFields ($tableName, $showHidden=-1, array $ignoreArray=array(), $noVersionPreview=FALSE)
 
static createRecursivePageList ($startPages, $recursionDepth=0)
 
static delete ($tableName, $whereClause)
 
static update ($tableName, $whereClause, array $fields)
 
static insert ($tableName, array $recordData)
 
static select ($fields, $tableNames, $whereClause= '', $groupBy= '', $orderBy= '', $limit= '')
 
static selectSingle ($fields, $tableNames, $whereClause= '', $groupBy= '', $orderBy= '', $offset=0)
 
static selectMultiple ($fieldNames, $tableNames, $whereClause= '', $groupBy= '', $orderBy= '', $limit= '')
 
static selectColumnForMultiple ($fieldName, $tableNames, $whereClause= '', $groupBy= '', $orderBy= '', $limit= '')
 
static count ($tableNames, $whereClause= '')
 
static existsRecord ($tableName, $whereClause= '')
 
static existsExactlyOneRecord ($tableName, $whereClause= '')
 
static existsRecordWithUid ($tableName, $uid, $additionalWhereClause= '')
 
static getAllTableNames ()
 
static existsTable ($tableName)
 
static getColumnsInTable ($tableName)
 
static getColumnDefinition ($tableName, $column)
 
static tableHasColumn ($tableName, $column)
 
static tableHasColumnUid ($tableName)
 
static getTcaForTable ($tableName)
 
static getDatabaseConnection ()
 

Member Function Documentation

static Tx_Phpunit_Service_Database::count (   $tableNames,
  $whereClause = '' 
)
static

Counts the number of matching records in the database for a particular WHERE clause.

Parameters
string$tableNamescomma-separated list of existing tables from which to count, can also be a JOIN, must not be empty
string$whereClauseWHERE clause, may be empty
Returns
int the number of matching records, will be >= 0
Exceptions
Tx_Phpunit_Exception_Databaseif an error has occurred
static Tx_Phpunit_Service_Database::createRecursivePageList (   $startPages,
  $recursionDepth = 0 
)
static

Recursively creates a comma-separated list of subpage UIDs from a list of pages. The result also includes the original pages. The maximum level of recursion can be limited: 0 = no recursion (the default value, will return $startPages), 1 = only direct child pages, ..., 250 = all descendants for all sane cases

Note: The returned page list is not sorted.

Parameters
string$startPagescomma-separated list of page UIDs to start from, must only contain numbers and commas, may be empty
int$recursionDepthmaximum depth of recursion, must be >= 0
Returns
string comma-separated list of subpage UIDs including the UIDs provided in $startPages, will be empty if $startPages is empty
Exceptions
InvalidArgumentException
static Tx_Phpunit_Service_Database::delete (   $tableName,
  $whereClause 
)
static

Executes a DELETE query.

Parameters
string$tableNamethe name of the table from which to delete, must not be empty
string$whereClausethe WHERE clause to select the records, may be empty
Returns
int the number of affected rows, might be 0
Exceptions
InvalidArgumentException
Tx_Phpunit_Exception_Databaseif an error has occurred
static Tx_Phpunit_Service_Database::enableFields (   $tableName,
  $showHidden = -1,
array  $ignoreArray = array(),
  $noVersionPreview = FALSE 
)
static

Wrapper function for ::enableFields() since it is no longer accessible statically.

Returns a part of a WHERE clause which will filter out records with start/end times or deleted/hidden/fe_groups fields set to values that should de-select them according to the current time, preview settings or user login. Is using the $TCA arrays "ctrl" part where the key "enablefields" determines for each table which of these features applies to that table.

Parameters
string$tableNametable name found in the $TCA array
int$showHiddenIf $showHidden is set (0/1), any hidden-fields in records are ignored. NOTICE: If you call this function, consider what to do with the show_hidden parameter.
array$ignoreArrayArray you can pass where keys can be "disabled", "starttime", "endtime", "fe_group" (keys from "enablefields" in TCA) and if set they will make sure that part of the clause is not added. Thus disables the specific part of the clause. For previewing etc.
bool$noVersionPreviewIf set, enableFields will be applied regardless of any versioning preview settings which might otherwise disable enableFields.
Returns
string the WHERE clause starting like " AND ...=... AND ...=..."
Exceptions
InvalidArgumentException
static Tx_Phpunit_Service_Database::enableQueryLogging ( )
static

Enables query logging in TYPO3's DB class.

Returns
void
static Tx_Phpunit_Service_Database::existsExactlyOneRecord (   $tableName,
  $whereClause = '' 
)
static

Checks whether there is exactly one record in the table given by the first parameter $tableName that matches a given WHERE clause.

Parameters
string$tableNamethe name of the table to query, must not be empty
string$whereClausethe WHERE part of the query, may be empty (all records will be counted in that case)
Returns
bool TRUE if there is exactly one matching record, FALSE otherwise
static Tx_Phpunit_Service_Database::existsRecord (   $tableName,
  $whereClause = '' 
)
static

Checks whether there are any records in the table given by the first parameter $tableName that match a given WHERE clause.

Parameters
string$tableNamethe name of the table to query, must not be empty
string$whereClausethe WHERE part of the query, may be empty (all records will be counted in that case)
Returns
bool TRUE if there is at least one matching record, FALSE otherwise
static Tx_Phpunit_Service_Database::existsRecordWithUid (   $tableName,
  $uid,
  $additionalWhereClause = '' 
)
static

Checks whether there is a record in the table given by the first parameter $tableName that has the given UID.

Important: This function also returns TRUE if there is a deleted or hidden record with that particular UID.

Parameters
string$tableNamethe name of the table to query, must not be empty
int$uidthe UID of the record to look up, must be > 0
string$additionalWhereClauseadditional WHERE clause to append, must either start with " AND" or be completely empty
Returns
bool TRUE if there is a matching record, FALSE otherwise
Exceptions
InvalidArgumentException
static Tx_Phpunit_Service_Database::existsTable (   $tableName)
static

Checks whether a database table exists.

Parameters
string$tableNamethe name of the table to check for, must not be empty
Returns
bool TRUE if the table $tableName exists, FALSE otherwise
Exceptions
InvalidArgumentException
static Tx_Phpunit_Service_Database::getAllTableNames ( )
static

Returns a list of all table names that are available in the current database.

Returns
string[] list of table names
static Tx_Phpunit_Service_Database::getColumnDefinition (   $tableName,
  $column 
)
static

Gets the column definition for a field in $tableName.

Parameters
string$tableNamethe name of the table for which the column names should be retrieved, must not be empty
string$columnthe name of the field of which to retrieve the definition, must not be empty
Returns
array the field definition for the field in $tableName, will not be empty
static Tx_Phpunit_Service_Database::getColumnsInTable (   $tableName)
static

Gets the column data for a table.

Parameters
string$tableNamethe name of the table for which the column names should be retrieved, must not be empty
Returns
array the column data for the table $tableName with the column names as keys and the SHOW COLUMNS field information (in an array) as values
static Tx_Phpunit_Service_Database::getDatabaseConnection ( )
static

Returns $GLOBALS['TYPO3_DB'].

Returns
DatabaseConnection
static Tx_Phpunit_Service_Database::getTcaForTable (   $tableName)
static

Returns the TCA for a certain table.

Parameters
string$tableNamethe table name to look up, must not be empty
Returns
array[] associative array with the TCA description for this table
Exceptions
BadMethodCallException
static Tx_Phpunit_Service_Database::insert (   $tableName,
array  $recordData 
)
static

Executes an INSERT query.

Parameters
string$tableNamethe name of the table in which the record should be created, must not be empty
array$recordDatakey/value pairs of the record to insert, must not be empty
Returns
int the UID of the created record, will be 0 if the table has no UID column
Exceptions
InvalidArgumentException
Tx_Phpunit_Exception_Databaseif an error has occurred
static Tx_Phpunit_Service_Database::select (   $fields,
  $tableNames,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $limit = '' 
)
static

Executes a SELECT query.

Parameters
string$fieldslist of fields to select, may be "*", must not be empty
string$tableNamescomma-separated list of tables from which to select, must not be empty
string$whereClauseWHERE clause, may be empty
string$groupByGROUP BY field(s), may be empty
string$orderByORDER BY field(s), may be empty
string$limitLIMIT value ([begin,]max), may be empty
Returns
MySQLi result object
Exceptions
InvalidArgumentException
Tx_Phpunit_Exception_Databaseif an error has occurred
static Tx_Phpunit_Service_Database::selectColumnForMultiple (   $fieldName,
  $tableNames,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $limit = '' 
)
static

Executes a SELECT query and returns one column from the result rows as a one-dimensional numeric array.

If there is more than one matching record, only one will be returned.

Parameters
string$fieldNamename of the field to select, must not be empty
string$tableNamescomma-separated list of tables from which to select, must not be empty
string$whereClauseWHERE clause, may be empty
string$groupByGROUP BY field(s), may be empty
string$orderByORDER BY field(s), may be empty
string$limitLIMIT value ([begin,]max), may be empty
Returns
string[] one column from the the query result rows, will be empty if there are no matching records
Exceptions
Tx_Phpunit_Exception_Databaseif an error has occurred
static Tx_Phpunit_Service_Database::selectMultiple (   $fieldNames,
  $tableNames,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $limit = '' 
)
static

Executes a SELECT query and returns the result rows as a two-dimensional associative array.

Parameters
string$fieldNameslist of fields to select, may be "*", must not be empty
string$tableNamescomma-separated list of tables from which to select, must not be empty
string$whereClauseWHERE clause, may be empty
string$groupByGROUP BY field(s), may be empty
string$orderByORDER BY field(s), may be empty
string$limitLIMIT value ([begin,]max), may be empty
Returns
array[] the query result rows, will be empty if there are no matching records
Exceptions
Tx_Phpunit_Exception_Databaseif an error has occurred
static Tx_Phpunit_Service_Database::selectSingle (   $fields,
  $tableNames,
  $whereClause = '',
  $groupBy = '',
  $orderBy = '',
  $offset = 0 
)
static

Executes a SELECT query and returns the single result row as an associative array.

If there is more than one matching record, only one will be returned.

Parameters
string$fieldslist of fields to select, may be "*", must not be empty
string$tableNamescomma-separated list of tables from which to select, must not be empty
string$whereClauseWHERE clause, may be empty
string$groupByGROUP BY field(s), may be empty
string$orderByORDER BY field(s), may be empty
int$offsetthe offset to start the result for, must be >= 0
Returns
string[] the single result row, will not be empty
Exceptions
Tx_Phpunit_Exception_EmptyQueryResultif there is no matching record
static Tx_Phpunit_Service_Database::tableHasColumn (   $tableName,
  $column 
)
static

Checks whether a table has a column with a particular name.

To get a boolean TRUE as result, the table must contain a column with the given name.

Parameters
string$tableNamethe name of the table to check, must not be empty
string$columnthe column name to check, must not be empty
Returns
bool TRUE if the column with the provided name exists, FALSE otherwise
static Tx_Phpunit_Service_Database::tableHasColumnUid (   $tableName)
static

Checks whether a table has a column "uid".

Parameters
string$tableNamethe name of the table to check, must not be empty
Returns
bool TRUE if a valid column was found, FALSE otherwise
static Tx_Phpunit_Service_Database::update (   $tableName,
  $whereClause,
array  $fields 
)
static

Executes an UPDATE query.

Parameters
string$tableNamethe name of the table to change, must not be empty
string$whereClausethe WHERE clause to select the records, may be empty
array$fieldskey/value pairs of the fields to change, may be empty
Returns
int the number of affected rows, might be 0
Exceptions
InvalidArgumentException
Tx_Phpunit_Exception_Databaseif an error has occurred

The documentation for this class was generated from the following file: