field_placeholder.test in Field placeholder 7
Same filename and directory in other branches
File that holds functional tests for Field placeholder module.
File
field_placeholder.testView source
<?php
/**
* @file
* File that holds functional tests for Field placeholder module.
*/
class FieldPlaceholderTestCase extends DrupalWebTestCase {
/**
* The getInfo() method provides information about the test.
*
* In order for the test to be run, the getInfo() method needs
* to be implemented.
*/
public static function getInfo() {
return array(
'name' => t('Field placeholder basic'),
'description' => t('Tests basic module functionality.'),
'group' => 'Field placeholder',
);
}
/**
* Prepares the testing environment.
*/
function setUp() {
// Enable minimum required modules.
parent::setUp('field_placeholder');
// Create user.
$this->privileged_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer content types',
));
$this
->drupalLogin($this->privileged_user);
// Create content type, with underscores.
$type_name = strtolower($this
->randomName(8)) . '_test';
$type = $this
->drupalCreateContentType(array(
'name' => $type_name,
'type' => $type_name,
));
$this->type = $type->type;
// Store a valid URL name, with hyphens instead of underscores.
$this->hyphen_type = str_replace('_', '-', $this->type);
}
/**
* Creates a new field through the Field UI.
*
* @param string $bundle_path
* Admin path of the bundle that the new field is to be attached to.
* @param string $initial_edit
* $edit parameter for drupalPost() on the first step ('Manage fields'
* screen).
* @param array $field_edit
* $edit parameter for drupalPost() on the second step ('Field settings'
* form).
* @param array $instance_edit
* $edit parameter for drupalPost() on the third step ('Instance settings'
* form).
*/
protected function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
// Use 'test_field' field type by default.
$initial_edit += array(
'fields[_add_new_field][type]' => 'test_field',
'fields[_add_new_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['fields[_add_new_field][label]'];
$field_name = $initial_edit['fields[_add_new_field][field_name]'];
// First step : 'Add new field' on the 'Manage fields' page.
$this
->drupalPost("{$bundle_path}/fields", $initial_edit, t('Save'));
$this
->assertRaw(t('These settings apply to the %label field everywhere it is used.', array(
'%label' => $label,
)), t('Field settings page was displayed.'));
// Second step : 'Field settings' form.
$this
->drupalPost(NULL, $field_edit, t('Save field settings'));
$this
->assertRaw(t('Updated field %label field settings.', array(
'%label' => $label,
)), t('Redirected to instance and widget settings page.'));
// Third step : 'Instance settings' form.
$this
->drupalPost(NULL, $instance_edit, t('Save settings'));
$this
->assertRaw(t('Saved %label configuration.', array(
'%label' => $label,
)), t('Redirected to "Manage fields" page.'));
// Check that the field appears in the overview form.
$this
->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}
/**
* Performs the basic tests.
*/
public function testPlaceholderBasic() {
$bundle_path1 = 'admin/structure/types/manage/' . $this->hyphen_type;
// Create a basic text field.
$edit = array(
'fields[_add_new_field][type]' => 'text',
'fields[_add_new_field][widget_type]' => 'text_textfield',
'fields[_add_new_field][label]' => 'Text',
'fields[_add_new_field][field_name]' => 'text',
);
$instance_settings = array(
'instance[placeholder]' => 'Textfield placeholder',
);
$this
->fieldUIAddNewField($bundle_path1, $edit, array(), $instance_settings);
// Create a long text field.
$edit = array(
'fields[_add_new_field][type]' => 'text_long',
'fields[_add_new_field][widget_type]' => 'text_textarea',
'fields[_add_new_field][label]' => 'Long text',
'fields[_add_new_field][field_name]' => 'longtext',
);
$instance_settings = array(
'instance[placeholder]' => 'Textarea placeholder',
);
$this
->fieldUIAddNewField($bundle_path1, $edit, array(), $instance_settings);
// Create a long text with summary field.
$edit = array(
'fields[_add_new_field][type]' => 'text_with_summary',
'fields[_add_new_field][widget_type]' => 'text_textarea_with_summary',
'fields[_add_new_field][label]' => 'Text with summary',
'fields[_add_new_field][field_name]' => 'summary',
);
$instance_settings = array(
'instance[placeholder]' => 'Summary placeholder',
'instance[settings][display_summary]' => 1,
);
$this
->fieldUIAddNewField($bundle_path1, $edit, array(), $instance_settings);
// Create an integer field.
$edit = array(
'fields[_add_new_field][type]' => 'number_integer',
'fields[_add_new_field][widget_type]' => 'number',
'fields[_add_new_field][label]' => 'Number',
'fields[_add_new_field][field_name]' => 'integer',
);
$instance_settings = array(
'instance[placeholder]' => 'Integer placeholder',
);
$this
->fieldUIAddNewField($bundle_path1, $edit, array(), $instance_settings);
// Go to node creation page.
$this
->drupalGet('node/add/' . $this->hyphen_type);
// Assertions.
$this
->assertRaw('placeholder="Textfield placeholder"', 'Text field placeholder displayed');
$this
->assertRaw('placeholder="Textarea placeholder"', 'Textarea field placeholder displayed');
$this
->assertRaw('placeholder="Summary placeholder"', 'Text with summary field placeholder displayed');
$this
->assertRaw('placeholder="Integer placeholder"', 'Integer field placeholder displayed');
}
}
Classes
Name | Description |
---|---|
FieldPlaceholderTestCase | @file File that holds functional tests for Field placeholder module. |