protected function PropertiesBaseTestCase::createCategory in Dynamic properties 7
Create a category with attributes through the administration interface, load and return it.
Parameters
$name: machine_name of category, a random name is generated when left empty.
$label: Label of the category, a random label is generated when left empty.
$attributes: An array of attributes, that is added to the category.
Return value
Loaded category object.
3 calls to PropertiesBaseTestCase::createCategory()
- PropertiesAdministrationTestCase::testEditCategory in ./
properties.test - Tests for creating and editing a category.
- PropertiesBaseTestCase::createProperties in ./
properties.test - Creates a given number of categories including attributes.
- PropertiesTemplateTestCase::testAdministration in properties_template/
properties_template.test - Creates two different categories, adds them to a template and checks if the data is correctly displayed and stored.
File
- ./
properties.test, line 115 - Contains tests for the properties.module
Class
- PropertiesBaseTestCase
- Base class for properties tests, provides helper methods.
Code
protected function createCategory($name = NULL, $label = NULL, $attributes = array()) {
$category = array(
'name' => empty($name) ? drupal_strtolower($this
->randomName(8)) : $name,
'label' => empty($label) ? $this
->randomName(20) : $label,
);
$this
->drupalPost('admin/config/content/properties/categories/add', $category, t('Add another attribute'));
for ($i = 0; $i < count($attributes); $i++) {
$newAttribute = array(
"attributes[{$i}][attribute]" => $attributes[$i]->name,
);
$this
->drupalPost(NULL, $newAttribute, t('Add another attribute'));
}
$this
->drupalPost(NULL, NULL, t('Save'));
$category_object = properties_category_load($category['name']);
$this
->assertEqual($category_object->label, $category['label']);
return $category_object;
}