View source
<?php
if (!class_exists('Drupali18nTestCase')) {
return;
}
class I18nFieldPlaceholderTestCase extends Drupali18nTestCase {
public static function getInfo() {
return array(
'name' => t('Field placeholder translation'),
'group' => 'Field placeholder',
'description' => t('Field placeholder translation functions'),
);
}
function setUp() {
parent::setUp('i18n_field_placeholder');
parent::setUpLanguages();
$this->translator = $this
->drupalCreateUser(array(
'translate interface',
'translate user-defined strings',
));
$type_name = strtolower($this
->randomName(8)) . '_test';
$type = $this
->drupalCreateContentType(array(
'name' => $type_name,
'type' => $type_name,
));
$this->type = $type->type;
$this->hyphen_type = str_replace('_', '-', $this->type);
}
protected function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
$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]'];
$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.'));
$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.'));
$this
->drupalPost(NULL, $instance_edit, t('Save settings'));
$this
->assertRaw(t('Saved %label configuration.', array(
'%label' => $label,
)), t('Redirected to "Manage fields" page.'));
$this
->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}
public function testFieldPlaceholderTranslation() {
$field_name = drupal_strtolower($this
->randomName());
$label = $this
->randomName();
$placeholder = $this
->randomName();
$bundle_path1 = 'admin/structure/types/manage/' . $this->hyphen_type;
$edit = array(
'fields[_add_new_field][type]' => 'text',
'fields[_add_new_field][widget_type]' => 'text_textfield',
'fields[_add_new_field][label]' => $label,
'fields[_add_new_field][field_name]' => $field_name,
);
$instance_settings = array(
'instance[placeholder]' => $placeholder,
);
$this
->fieldUIAddNewField($bundle_path1, $edit, array(), $instance_settings);
$edit = array(
'groups[field]' => TRUE,
);
$this
->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
$label_translation = $this
->createStringTranslation('field', $label);
$placeholder_translation = $this
->createStringTranslation('field', $placeholder);
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('node/add/' . $this->hyphen_type);
$this
->assertText($label, 'Field label is not translated');
$this
->assertRaw('placeholder="' . $placeholder, 'Field description is not translated');
$this
->drupalGet($this->secondary_language . '/node/add/' . $this->hyphen_type);
$this
->assertText($label_translation[$this->secondary_language], 'Field label is translated');
$this
->assertRaw('placeholder="' . $placeholder_translation[$this->secondary_language], 'Field description is translated');
$edit = array(
'instance[use_title_as_placeholder]' => 1,
);
$this
->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/fields/field_' . $field_name, $edit, t('Save settings'));
$this
->drupalGet('node/add/' . $this->hyphen_type);
$this
->assertRaw('placeholder="' . $label, 'Field description is not translated');
$this
->drupalGet($this->secondary_language . '/node/add/' . $this->hyphen_type);
$this
->assertRaw('placeholder="' . $label_translation[$this->secondary_language], 'Field description is translated');
}
}