public function BlockAttributesTestCase::getBlockAttributesTestingData in Block Attributes 7
Build a complete data set of attribute values to perform the tests.
Returns an array containing test values for every single attribute field. This array can then be passed to either the Block admin config form to update Block's configuration or to assert values upon Block display. Default values can be provided to the function for initializing test data, which is particularly useful for testing the Block Attributes configuration form.
Parameters
array $defaults: An array containing default values to initialize the test dataset.
4 calls to BlockAttributesTestCase::getBlockAttributesTestingData()
- BlockAttributesAdminConfigTestCase::testAdminConfigForm in ./
block_attributes.test - Create a block based on default settings and test disabling attributes.
- BlockAttributesMenuBlockTestCase::testMenuBlockDisplayAttributes in ./
block_attributes.test - Create, update and display a Menu Block to ensure attributes are found.
- BlockAttributesPermissionTestCase::testPermission in ./
block_attributes.test - Ensure Block Attributes fields only appear with the right permissions.
- BlockAttributesTestCase::assertUpdateDisplayBlockAttributes in ./
block_attributes.test - Update Block Attributes and assert whether they are found when displayed.
File
- ./
block_attributes.test, line 76 - Test the Block Attributes module.
Class
- BlockAttributesTestCase
- Provides common functionality for the Block Attributes test classes.
Code
public function getBlockAttributesTestingData($defaults = NULL) {
// Different styles for different scopes. Unfortunately, styles, can't be
// randomly generated, so we can use sample/example styles.
$testing_styles = array(
BLOCK_ATTRIBUTES_BLOCK => "font-weight: bold;text-decoration: underline;",
BLOCK_ATTRIBUTES_TITLE => "font-size: 11px; font-weight: normal;",
BLOCK_ATTRIBUTES_CONTENT => "text-align: center;",
);
// Get block attributes scopes ready for looping.
$scopes = array(
BLOCK_ATTRIBUTES_BLOCK,
BLOCK_ATTRIBUTES_TITLE,
BLOCK_ATTRIBUTES_CONTENT,
);
// Our Block title needs a value to test the Title level attributes.
// If default values are provided, title should be initialized outside.
if (empty($defaults)) {
$block_attributes['title'] = $this
->randomName(8);
}
// Access Key is a Block level attribute, test with a random string.
// Special characters, such as > or ' create problems with xpath, so in
// this test we use alphanumeric characters exclusively, not randomString.
$block_attributes[BLOCK_ATTRIBUTES_BLOCK . '[accesskey]'] = empty($defaults['block_attributes_accesskey_default']) ? $this
->randomName(1) : $defaults['block_attributes_accesskey_default'];
// Loop through all attributes to fill $block_attributes with all values.
foreach ($scopes as $scope) {
// Align: Test with a random alignment (not empty).
$block_attributes[$scope . '[align]'] = empty($defaults['block_attributes_align_default']) ? array_rand(array(
'left' => t('Left'),
'right' => t('Right'),
'center' => t('Center'),
'justify' => t('Justify'),
)) : $defaults['block_attributes_align_default'];
// Class: Test with three random class names.
$block_attributes[$scope . '[class]'] = empty($defaults['block_attributes_class_default']) ? implode(' ', array(
$this
->randomName(8),
$this
->randomName(8),
$this
->randomName(8),
)) : $defaults['block_attributes_class_default'];
// ID: Test with a random CSS ID.
$block_attributes[$scope . '[id]'] = empty($defaults['block_attributes_id_default']) ? $this
->randomName(8) : $defaults['block_attributes_id_default'];
// Style: Test Block level CSS styles.
$block_attributes[$scope . '[style]'] = empty($defaults['block_attributes_style_default']) ? $testing_styles[$scope] : $defaults['block_attributes_style_default'];
// Title: Test with a random title.
$block_attributes[$scope . '[title]'] = empty($defaults['block_attributes_title_default']) ? $this
->randomName(8) : $defaults['block_attributes_title_default'];
}
// The CSS Class is not a Block Content level attribute.
unset($block_attributes[BLOCK_ATTRIBUTES_CONTENT . '[class]']);
return $block_attributes;
}