function ContentCrudTestCase::assertSchemaMatchesTables in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6 tests/content.crud.test \ContentCrudTestCase::assertSchemaMatchesTables()
- 6.2 tests/content.crud.test \ContentCrudTestCase::assertSchemaMatchesTables()
Checks that the database itself and the reported database schema match the expected columns for the given tables.
Parameters
$tables An array containing the key 'per_field' and/or the key 'per_type'.: These keys should have array values with table names as the keys (without the 'content_' / 'content_type_' prefix) These keys should have either NULL value to indicate the table should be absent, or array values containing column names. The column names can themselves be arrays, in which case the contents of the array are treated as column names and prefixed with the array key.
For example, if called with the following as an argument: array( 'per_field' => array( 'st_f1' => array('delta', 'field_f1' => array('value, 'format')), 'st_f2' => NULL, // no content_field_f2 table ), 'per_type' => array( 'st_t1' => array('field_f2' => array('value'), 'field_f3' => array('value', 'format')), 'st_t2' => array(), // only 'nid' and 'vid' columns 'st_t3' => NULL, // no content_type_t3 table ), ) Then the database and schema will be checked to ensure that: content_st_f1 table contains fields nid, vid, delta, field_f1_value, field_f1_format content_st_f2 table is absent content_type_st_t1 table contains fields nid, vid, field_f2_value, field_f3_value, field_f3_format content_type_st_t2 table contains fields nid, vid content_type_st_t3 table is absent
3 calls to ContentCrudTestCase::assertSchemaMatchesTables()
File
- tests/
content.crud.test, line 59
Class
- ContentCrudTestCase
- Base class for CCK CRUD tests. Defines many helper functions useful for writing CCK CRUD tests.
Code
function assertSchemaMatchesTables($tables) {
$groups = array(
'per_field' => 'content_',
'per_type' => 'content_type_',
);
foreach ($groups as $group => $table_prefix) {
if (isset($tables[$group])) {
foreach ($tables[$group] as $entity => $columns) {
if (isset($columns)) {
$db_columns = array(
'nid',
'vid',
);
foreach ($columns as $prefix => $items) {
if (is_array($items)) {
foreach ($items as $item) {
$db_columns[] = $prefix . '_' . $item;
}
}
else {
$db_columns[] = $items;
}
}
$this
->_assertSchemaMatches($table_prefix . $entity, $db_columns);
}
else {
$this
->_assertTableNotExists($table_prefix . $entity);
}
}
}
}
}