web_user = $this->drupalCreateUser(); $this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer content types', 'access content', 'access administration pages')); variable_set('clean_url', 0); } protected function assertNoFieldCheckedByName($name, $message = '') { $elements = $this->xpath('//input[@name=:name]', array(':name' => $name)); return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : t('Checkbox field @name is not checked.', array('@name' => $name)), t('Browser')); } protected function assertFieldCheckedByName($name, $message = '') { $elements = $this->xpath('//input[@name=:name]', array(':name' => $name)); return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : t('Checkbox field @name is checked.', array('@name' => $name)), t('Browser')); } function assertNameFormat($name_components, $type, $object, $format, $expected, array $options = array()) { $this->assertNameFormats($name_components, $type, $object, array($format => $expected), $options); } function assertNameFormats($name_components, $type, $object, array $names, array $options = array()) { foreach ($names as $format => $expected) { $value = name_format($name_components, $format, array('object' => $object, 'type' => $type)); $this->assertIdentical($value, $expected, t("Name value for '@name' was '@actual', expected value '@expected'. Components were: %components", array('@name' => $format, '@actual' => $value, '@expected' => $expected, '%components' => implode(' ', $name_components)))); } } } class NameUnitTestCase extends NameTestHelper { public static function getInfo() { return array( 'name' => 'Name unit tests', 'description' => 'Test basic, low-level name functions.', 'group' => 'Name', ); } /** * Test name_format(). */ public function testGetInvalidTokens() { $names = array( 'given' => array( 'components' => array('given' => 'John'), 'tests' => array( // Test that only the given name creates a entry 't' => '', // Title 'g' => 'John', // Given name '\g' => 'g', // Escaped letter 'm' => '', // Middle name(s) 'f' => '', // Family name 'c' => '', // Credentials 's' => '', // Generational suffix 'x' => 'J', // First letter given 'y' => '', // First letter middle 'z' => '', // First letter family 'e' => 'John', // Either the given or family name. Given name is given preference 'E' => 'John', // Either the given or family name. Family name is given preference // Combination test 'g f' => 'John ', // Using a single space 'gif' => 'John ', // Separator 1 'gjf' => 'John, ', // Separator 2 'gkf' => 'John', // Separator 3 'f g' => ' John', 'fig' => ' John', 'fjg' => ', John', 'fkg' => 'John', 't g t' => ' John ', 'tigit' => ' John ', 'tjgjt' => ', John, ', 'tkgkt' => 'John', // Modifier entries 'Lg' => 'john', // lowercase 'Ug' => 'JOHN', // uppercase 'Fg' => 'John', // first letter to uppercase 'Gg' => 'John', // first letter of all words to uppercase 'LF(g)' => 'John', // lowercase, first letter to uppercase 'LG(g)' => 'John', // lowercase, first letter of all words to uppercase 'LFg' => 'John', // lowercase, first letter to uppercase 'LGg' => 'John', // lowercase, first letter of all words to uppercase 'Tg' => 'John', // Trims whitespace around the next token 'Sg' => 'John', // check_plain // Conditional entries '(((g)))' => 'John', // brackets '(g))()(' => 'John)(', // brackets - mismatched 'g+ f' => 'John', // Insert the token if both the surrounding tokens are not empty 'g= f' => 'John', // Insert the token, if and only if the next token after it is not empty 'g^ f' => 'John ', // Skip the token, if and only if the next token after it is not empty 's|c|g|m|f|t' => 'John', // Uses only the first one. 'g|f' => 'John', // Uses the previous token unless empty, otherwise it uses this token // Real world examples 'L(t= g= m= f= s=,(= c))' => ' john', // Full name with a comma-space before credentials 'TS(LF(t= g= m= f= s)=,(= c))' => 'john', // Full name with a comma-space before credentials. ucfirst does not work on a whitespace 'L(t+ g+ m+ f+ s+,(= c))' => 'john', // Full name with a comma-space before credentials 'TS(LF(t+ g+ m+ f+ s)+,(= c))' => 'John', // Full name with a comma-space before credentials ), ), 'full' => array( 'components' => array( 'title' => 'MR.', 'given' => 'JoHn', 'middle' => 'pEter', 'family' => 'dOE', 'generational' => 'sR', 'credentials' => 'b.Sc, pHd', ), //MR. JoHn pEter dOE sR b.Sc, pHd 'tests' => array( // Test that only the given name creates a entry 't' => 'MR.', // Title 'g' => 'JoHn', // Given name 'm' => 'pEter', // Middle name(s) 'f' => 'dOE', // Family name 'c' => 'b.Sc, pHd', // Credentials 's' => 'sR', // Generational suffix 'x' => 'J', // First letter given 'y' => 'p', // First letter middle 'z' => 'd', // First letter family 'e' => 'JoHn', // Either the given or family name. Given name is given preference 'E' => 'dOE', // Either the given or family name. Family name is given preference // Combination test 'g f' => 'JoHn dOE', // Using a single space 'gif' => 'JoHn dOE', // Separator 1 'gjf' => 'JoHn, dOE', // Separator 2 'gkf' => 'JoHndOE', // Separator 3 'f g' => 'dOE JoHn', 'fig' => 'dOE JoHn', 'fjg' => 'dOE, JoHn', 'fkg' => 'dOEJoHn', 't g t' => 'MR. JoHn MR.', 'tigit' => 'MR. JoHn MR.', 'tjgjt' => 'MR., JoHn, MR.', 'tkgkt' => 'MR.JoHnMR.', // Modifier entries 'L(t g m f s c)' => 'mr. john peter doe sr b.sc, phd', // lowercase 'U(t g m f s c)' => 'MR. JOHN PETER DOE SR B.SC, PHD', // uppercase 'F(t g m f s c)' => 'MR. JoHn pEter dOE sR b.Sc, pHd', // first letter to uppercase 'G(t g m f s c)' => 'MR. JoHn PEter DOE SR B.Sc, PHd', // first letter of all words to uppercase 'LF(t g m f s c)' => 'Mr. john peter doe sr b.sc, phd', // first letter to uppercase 'LG(t g m f s c)' => 'Mr. John Peter Doe Sr B.sc, Phd', // first letter of all words to uppercase 'T(t g m f s c)' => 'MR. JoHn pEter dOE sR b.Sc, pHd', // Trims whitespace around the next token 'S(t g m f s c)' => 'MR. JoHn pEter dOE sR b.Sc, pHd', // check_plain // Conditional entries '(((t g m f s c)))' => 'MR. JoHn pEter dOE sR b.Sc, pHd', // brackets '(t g m f s c))()(' => 'MR. JoHn pEter dOE sR b.Sc, pHd)(', // brackets - mismatched 't= g= m= f= s= c' => 'MR. JoHn pEter dOE sR b.Sc, pHd', // Insert the token, if and only if the next token after it is not empty 'g|m|f' => 'JoHn', // Uses the previous token unless empty, otherwise it uses this token 'm|f|g' => 'pEter', // Uses the previous token unless empty, otherwise it uses this token 's|c|g|m|f|t' => 'sR', // Uses only the first one. // Real world examples 'L(t= g= m= f= s=,(= c))' => 'mr. john peter doe sr, b.sc, phd', // Full name with a comma-space before credentials 'TS(LG(t= g= m= f= s)=,LG(= c))' => 'Mr. John Peter Doe Sr, B.sc, Phd', // Full name with a comma-space before credentials ), ), ); /* // Placeholders for token support insertion on the [object / key | entity / bundle]. '1' => t('Token placeholder 1'), '2' => t('Token placeholder 2'), '3' => t('Token placeholder 3'), '4' => t('Token placeholder 4'), '5' => t('Token placeholder 5'), '6' => t('Token placeholder 6'), '7' => t('Token placeholder 7'), '8' => t('Token placeholder 8'), '9' => t('Token placeholder 9'), */ foreach ($names as $title => $info) { $this->assertNameFormats($info['components'], NULL, NULL, $info['tests']); } } } /** * Tests for the admin settings and custom format page. */ class Name_AdminTestCase extends NameTestHelper { public static function getInfo() { return array( 'name' => 'Admin Setting Pages', 'description' => 'Various tests on the admin area settings.' , 'group' => 'Name', ); } /** * The most basic test. This should only fail if there is a change to the * Drupal API. */ function testAdminSettings() { global $base_path; // Default settings and system settings. $this->drupalLogin($this->admin_user); // The default installed formats. $this->drupalGet('admin/config/regional/name'); $row_template = array( 'title href' => '//tr[@id="name-id"]/td[1]/a/@href', 'title' => '//tr[@id="name-id"]/td[1]/a', 'machine' => '//tr[@id="name-id"]/td[2]', 'code' => '//tr[@id="name-id"]/td[3]', 'formatted' => '//tr[@id="name-id"]/td[4]', 'edit' => '//tr[@id="name-id"]/td[5]/a', 'edit link' => '//tr[@id="name-id"]/td[5]/a/@href', 'delete' => '//tr[@id="name-id"]/td[5]/a', 'delete link' => '//tr[@id="name-id"]/td[5]/a/@href', ); $all_values = array( 0 => array( 'title href' => $base_path . '?q=admin/config/regional/name/settings', 'title' => t('Default'), 'machine' => 'default', 'code' => '((((t+ig)+im)+if)+is)+jc', 'formatted' => 'Mr Joe John Peter Mark Doe Jnr., B.Sc., Ph.D. JOAN SUE DOE Prince ', ), 1 => array( 'title href' => $base_path . '?q=admin/config/regional/name/1', 'title' => t('Full'), 'machine' => 'full', 'code' => '((((t+ig)+im)+if)+is)+jc', 'formatted' => 'Mr Joe John Peter Mark Doe Jnr., B.Sc., Ph.D. JOAN SUE DOE Prince ', 'edit' => t('Edit'), 'edit link' => $base_path . '?q=admin/config/regional/name/1', 'delete' => t('Delete'), 'delete link' => $base_path . '?q=admin/config/regional/name/1/delete', ), 2 => array( 'title href' => $base_path . '?q=admin/config/regional/name/2', 'title' => t('Given'), 'machine' => 'given', 'code' => 'g', 'formatted' => 'Joe JOAN Prince ', 'edit' => t('Edit'), 'edit link' => $base_path . '?q=admin/config/regional/name/2', 'delete' => t('Delete'), 'delete link' => $base_path . '?q=admin/config/regional/name/2/delete', ), 3 => array( 'title href' => $base_path . '?q=admin/config/regional/name/3', 'title' => t('Family'), 'machine' => 'family', 'code' => 'f', 'formatted' => 'Doe DOE ', 'edit link' => $base_path . '?q=admin/config/regional/name/3', 'delete link' => $base_path . '?q=admin/config/regional/name/3/delete', ), 4 => array( 'title href' => $base_path . '?q=admin/config/regional/name/4', 'title' => t('Title Family'), 'machine' => 'formal', 'code' => 't+if', 'formatted' => 'Mr Doe DOE ', 'edit link' => $base_path . '?q=admin/config/regional/name/4', 'delete link' => $base_path . '?q=admin/config/regional/name/4/delete', ), 5 => array( 'title href' => $base_path . '?q=admin/config/regional/name/5', 'title' => t('Given Family'), 'machine' => 'short_full', 'code' => 'g+if', 'formatted' => 'Joe Doe JOAN DOE Prince ', 'edit link' => $base_path . '?q=admin/config/regional/name/5', 'delete link' => $base_path . '?q=admin/config/regional/name/5/delete', ), ); foreach ($all_values as $id => $row) { foreach ($row as $cell_code => $value) { $xpath = str_replace('name-id', 'name-'. $id, $row_template[$cell_code]); $raw_xpath = $this->xpath($xpath); if (!is_array($raw_xpath)) { $results = '__MISSING__'; } elseif ($cell_code == 'delete' || $cell_code == 'delete link') { $results = $raw_xpath[1]; } else { $results = current($raw_xpath); } $this->assertEqual($results, $value, "Testing {$cell_code} on row {$id} using '{$xpath}' and expecting '". check_plain($value) ."', got '". check_plain($results) ."'."); } } $raw_xpath = $this->xpath('//tr[@id="name-0"]/td[5]/a'); $results = $raw_xpath ? current($raw_xpath) : '__MISSING__'; $this->assertEqual($results, t('Edit'), "Testing edit on row 0 using '//tr[@id=\"name-id\"]/td[1]/a' and expecting 'Edit', got '{$results}'."); $raw_xpath = $this->xpath('//tr[@id="name-0"]/td[5]/a/@href'); $results = $raw_xpath ? current($raw_xpath) : '__MISSING__'; $this->assertEqual($results, $base_path . '?q=admin/config/regional/name/settings', "Testing edit link on row 0 using '//tr[@id=\"name-id\"]/td[1]/a/@href' and expecting $base_path . '?q=admin/config/regional/name/settings', got '{$results}'."); $this->drupalGet('admin/config/regional/name/settings'); // Fieldset rendering check $this->assertRaw('Format string help
', 'Testing the help fieldgroup'); $default_values = array( 'name_settings[default_format]' => 't+ig+im+if+is+kc', 'name_settings[sep1]' => ' ', 'name_settings[sep2]' => ', ', 'name_settings[sep3]' => '', ); foreach ($default_values as $name => $value) { $this->assertField($name, $value); } // ID example $this->assertFieldById('edit-name-settings-sep1', ' ', t('Sep 3 default value.')); $post_values = $default_values; $post_values['name_settings[default_format]'] = ''; $this->drupalPost('admin/config/regional/name/settings', $post_values, t('Save configuration')); $this->assertText(t('Default format field is required.')); $post_values['name_settings[default_format]'] = ' '; $this->drupalPost('admin/config/regional/name/settings', $post_values, t('Save configuration')); $this->assertText(t('Default format field is required.')); $test_values = array( 'name_settings[default_format]' => 'c+ks+if+im+ig+t', 'name_settings[sep1]' => '~', 'name_settings[sep2]' => '^', 'name_settings[sep3]' => '-', ); $this->drupalPost('admin/config/regional/name/settings', $test_values, t('Save configuration')); $this->assertText(t('The configuration options have been saved.')); foreach ($test_values as $name => $value) { $this->assertField($name, $value); } // The default installed formats and the updated default format. $this->drupalGet('admin/config/regional/name'); $xpath = '//tr[@id="name-0"]/td[3]'; $this->assertEqual(current($this->xpath($xpath)), 'c+ks+if+im+ig+t', 'Default is equal to set default.'); $this->drupalGet('admin/config/regional/name/add'); $this->assertRaw('Format string help
', 'Testing the help fieldgroup'); $values = array('name' => '', 'machine_name' => '', 'format' => ''); $this->drupalPost('admin/config/regional/name/add', $values, t('Save')); foreach (array(t('Name'), t('Machine-readable name'), t('Format')) as $title) { $this->assertText(t('!field field is required', array('!field' => $title))); } $values = array('name' => 'given', 'machine_name' => '1234567890abcdefghijklmnopqrstuvwxyz_', 'format' => 'a'); $this->drupalPost('admin/config/regional/name/add', $values, t('Save')); $this->assertText(t('The name you have chosen is already in use.')); $this->assertNoText(t('!field field is required', array('!field' => t('Format')))); $this->assertNoText(t('!field field is required', array('!field' => t('Machine-readable name')))); $values = array('name' => 'given', 'machine_name' => '%&*(', 'format' => 'a'); $this->drupalPost('admin/config/regional/name/add', $values, t('Save')); $this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.')); $values = array('name' => 'given', 'machine_name' => 'given', 'format' => 'a'); $this->drupalPost('admin/config/regional/name/add', $values, t('Save')); $this->assertText(t('The machine-readable name you have chosen is already in use.')); $values = array('name' => 'given', 'machine_name' => 'default', 'format' => 'a'); $this->drupalPost('admin/config/regional/name/add', $values, t('Save')); $this->assertText(t('The machine-readable name you have chosen is reserved.')); $values = array('name' => 'Test', 'machine_name' => 'test', 'format' => 'abc'); $this->drupalPost('admin/config/regional/name/add', $values, t('Save')); $this->assertText(t('Custom format Test has been created.')); $new_rows = array( 6 => array( 'title href' => $base_path . '?q=admin/config/regional/name/6', 'title' => 'Test', 'machine' => 'test', 'code' => 'abc', 'formatted' => 'abB.Sc., Ph.D. ab ab ', 'edit link' => $base_path . '?q=admin/config/regional/name/6', 'delete link' => $base_path . '?q=admin/config/regional/name/6/delete', ), ); foreach ($new_rows as $id => $row) { foreach ($row as $cell_code => $value) { $xpath = str_replace('name-id', 'name-'. $id, $row_template[$cell_code]); $raw_xpath = $this->xpath($xpath); if (!is_array($raw_xpath)) { $results = '__MISSING__'; } elseif ($cell_code == 'delete' || $cell_code == 'delete link') { $results = count($raw_xpath) > 1 ? $raw_xpath[1] : '__MISSING__'; } else { $results = current($raw_xpath); } $this->assertEqual($results, $value, "Testing {$cell_code} on row {$id} using '{$xpath}' and expecting '{$value}', got '{$results}'."); } } $values = array('name' => 'new name', 'machine_name' => 'bob', 'format' => 'f+g'); $this->drupalPost('admin/config/regional/name/6', $values, t('Save')); $this->assertText(t('Custom format new name has been updated.')); $new_rows = array( 6 => array( 'title' => $values['name'], 'machine' => $values['machine_name'], 'code' => $values['format'], ), ); foreach ($new_rows as $id => $row) { foreach ($row as $cell_code => $value) { $xpath = str_replace('name-id', 'name-'. $id, $row_template[$cell_code]); $raw_xpath = $this->xpath($xpath); if (!is_array($raw_xpath)) { $results = '__MISSING__'; } elseif ($cell_code == 'delete' || $cell_code == 'delete link') { $results = count($raw_xpath) > 1 ? $raw_xpath[1] : '__MISSING__'; } else { $results = current($raw_xpath); } $this->assertEqual($results, $value, "Testing {$cell_code} on row {$id} using '{$xpath}' and expecting '{$value}', got '{$results}'."); } } $this->drupalGet('admin/config/regional/name/60'); $this->assertText(t('The custom format could not be found.')); $this->drupalGet('admin/config/regional/name/60/delete'); $this->assertText(t('The custom format could not be found.')); $this->drupalPost('admin/config/regional/name/4', array(), t('Delete')); $this->assertText(t('Are you sure you want to delete the custom format !title ("t+if")?', array('!title' => check_plain(t('Title Family'))))); $this->drupalPost(NULL, array('confirm' => 1), t('Delete')); $this->assertText(t('The custom name format !title was deleted.', array('!title' => check_plain('Title Family')))); } } /** * Tests for the admin settings and custom format page. */ class Name_FieldTestCase extends NameTestHelper { public static function getInfo() { return array( 'name' => 'Node Name Field', 'description' => 'Various tests on creating a name field on a node.' , 'group' => 'Name', ); } /** * The most basic test. This should only fail if there is a change to the * Drupal API. */ function testFieldEntry() { $this->drupalLogin($this->admin_user); $new_name_field = array( 'fields[_add_new_field][label]' => 'Test name', 'fields[_add_new_field][field_name]' => 'name_test', 'fields[_add_new_field][type]' => 'name', 'fields[_add_new_field][widget_type]' => 'name_widget', ); $this->drupalPost('admin/structure/types/manage/page/fields', $new_name_field, t('Save')); // Required test. $field_settings = array(); foreach ($this->name_getFieldSettings() as $key => $value) { $field_settings[$key] = ''; } foreach ($this->name_getFieldSettingsCheckboxes() as $key => $value) { $field_settings[$key] = FALSE; } $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test/field-settings', $field_settings, t('Save field settings')); $n = _name_translations(); $required_messages = array( t('Label for !field field is required.', array('!field' => $n['title'])), t('Label for !field field is required.', array('!field' => $n['given'])), t('Label for !field field is required.', array('!field' => $n['middle'])), t('Label for !field field is required.', array('!field' => $n['family'])), t('Label for !field field is required.', array('!field' => $n['generational'])), t('Label for !field field is required.', array('!field' => $n['credentials'])), t('Maximum length for !field field is required.', array('!field' => $n['title'])), t('Maximum length for !field field is required.', array('!field' => $n['given'])), t('Maximum length for !field field is required.', array('!field' => $n['middle'])), t('Maximum length for !field field is required.', array('!field' => $n['family'])), t('Maximum length for !field field is required.', array('!field' => $n['generational'])), t('Maximum length for !field field is required.', array('!field' => $n['credentials'])), t('!field options field is required.', array('!field' => $n['title'])), t('!field options field is required.', array('!field' => $n['generational'])), t('!field field is required.', array('!field' => t('Components'))), t('!field must have one of the following components: !components', array('!field' => t('Components'), '!components' => check_plain(implode(', ', array($n['given'], $n['family']))))), t('!field field is required.', array('!field' => t('Minimum components'))), t('!field must have one of the following components: !components', array('!field' => t('Minimum components'), '!components' => check_plain(implode(', ', array($n['given'], $n['family']))))), ); foreach ($required_messages as $message) { $this->assertText($message); } $field_settings = array( 'field[settings][components][title]' => FALSE, 'field[settings][components][given]' => TRUE, 'field[settings][components][middle]' => FALSE, 'field[settings][components][family]' => TRUE, 'field[settings][components][generational]' => FALSE, 'field[settings][components][credentials]' => FALSE, 'field[settings][minimum_components][title]' => TRUE, 'field[settings][minimum_components][given]' => FALSE, 'field[settings][minimum_components][middle]' => FALSE, 'field[settings][minimum_components][family]' => FALSE, 'field[settings][minimum_components][generational]' => TRUE, 'field[settings][minimum_components][credentials]' => TRUE, 'field[settings][max_length][title]' => 0, 'field[settings][max_length][given]' => -456, 'field[settings][max_length][middle]' => 'asdf', 'field[settings][max_length][family]' => 3454, 'field[settings][max_length][generational]' => 4.5, 'field[settings][max_length][credentials]' => 'NULL', 'field[settings][title_options]' => "-- --\nMr.\nMrs.\nMiss\nMs.\nDr.\nProf.\n[vocabulary:machine]", 'field[settings][generational_options]' => "-- --\nJr.\nSr.\nI\nII\nIII\nIV\nV\nVI\nVII\nVIII\nIX\nX\n[vocabulary:123]", ); $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test/field-settings', $field_settings, t('Save field settings')); $required_messages = array( t('!components can not be selected for !label when they are not selected for !label2.', array('!label' => t('Minimum components'), '!label2' => t('Components'), '!components' => check_plain(implode(', ', array($n['title'], $n['generational'], $n['credentials']))))), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['title'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['given'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['middle'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['family'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['generational'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['credentials'])), t('!field must have one of the following components: !components', array('!field' => t('Minimum components'), '!components' => check_plain(implode(', ', array($n['given'], $n['family']))))), t("The vocabulary 'machine' in !field could not be found.", array('!field' => t('!title options', array('!title' => $n['title'])))), t("The vocabulary '123' in !field could not be found.", array('!field' => t('!generational options', array('!generational' => $n['generational'])))), ); foreach ($required_messages as $message) { $this->assertText($message); } // Make sure option lengths do not exceed the title lengths $field_settings = array( 'field[settings][max_length][title]' => 5, 'field[settings][max_length][generational]' => 3, 'field[settings][title_options]' => "Aaaaa.\n-- --\nMr.\nMrs.\nBbbbbbbb\nMiss\nMs.\nDr.\nProf.\nCcccc.", 'field[settings][generational_options]' => "AAAA\n-- --\nJr.\nSr.\nI\nII\nIII\nIV\nV\nVI\nVII\nVIII\nIX\nX\nBBBB", ); $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test/field-settings', $field_settings, t('Save field settings')); $required_messages = array( t('The following options exceed the maximun allowed !field length: Aaaaa., Bbbbbbbb, Ccccc.', array('!field' => t('!title options', array('!title' => $n['title'])))), t('The following options exceed the maximun allowed !field length: AAAA, VIII, BBBB', array('!field' => t('!generational options', array('!generational' => $n['generational'])))), ); foreach ($required_messages as $message) { $this->assertText($message); } // Make sure option have at least one valid option. $field_settings = array( 'field[settings][title_options]' => " \n-- --\n ", 'field[settings][generational_options]' => " \n-- --\n ", ); $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test/field-settings', $field_settings, t('Save field settings')); $required_messages = array( t('!field are required.', array('!field' => t('!title options', array('!title' => $n['title'])))), t('!field are required.', array('!field' => t('!generational options', array('!generational' => $n['generational'])))), ); foreach ($required_messages as $message) { $this->assertText($message); } // Make sure option have at least one valid only have one default value. $field_settings = array( 'field[settings][title_options]' => "-- --\nMr.\nMrs.\nMiss\n-- Bob\nDr.\nProf.", 'field[settings][generational_options]' => "-- --\nJr.\nSr.\nI\nII\nIII\nIV\nV\nVI\n--", ); $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test/field-settings', $field_settings, t('Save field settings')); $required_messages = array( t('!field can only have one blank value assigned to it.', array('!field' => t('!title options', array('!title' => $n['title'])))), t('!field can only have one blank value assigned to it.', array('!field' => t('!generational options', array('!generational' => $n['generational'])))), ); foreach ($required_messages as $message) { $this->assertText($message); } // Save the field again with the default values $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test/field-settings', $this->name_getFieldSettings(), t('Save field settings')); $this->assertText(t('Updated field Test name field settings.')); // Now the widget settings... // First, check that field validation is working... cut n paste from above test $field_settings = array( 'field[settings][components][title]' => FALSE, 'field[settings][components][given]' => TRUE, 'field[settings][components][middle]' => FALSE, 'field[settings][components][family]' => TRUE, 'field[settings][components][generational]' => FALSE, 'field[settings][components][credentials]' => FALSE, 'field[settings][minimum_components][title]' => TRUE, 'field[settings][minimum_components][given]' => FALSE, 'field[settings][minimum_components][middle]' => FALSE, 'field[settings][minimum_components][family]' => FALSE, 'field[settings][minimum_components][generational]' => TRUE, 'field[settings][minimum_components][credentials]' => TRUE, 'field[settings][max_length][title]' => 0, 'field[settings][max_length][given]' => -456, 'field[settings][max_length][middle]' => 'asdf', 'field[settings][max_length][family]' => 3454, 'field[settings][max_length][generational]' => 4.5, 'field[settings][max_length][credentials]' => 'NULL', 'field[settings][title_options]' => "-- --\nMr.\nMrs.\nMiss\nMs.\nDr.\nProf.\n[vocabulary:machine]", 'field[settings][generational_options]' => "-- --\nJr.\nSr.\nI\nII\nIII\nIV\nV\nVI\nVII\nVIII\nIX\nX\n[vocabulary:123]", ); $this->drupalPost('admin/structure/types/manage/page/fields/field_name_test', $field_settings, t('Save settings')); $required_messages = array( t('!components can not be selected for !label when they are not selected for !label2.', array('!label' => t('Minimum components'), '!label2' => t('Components'), '!components' => check_plain(implode(', ', array($n['title'], $n['generational'], $n['credentials']))))), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['title'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['given'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['middle'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['family'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['generational'])), t('!field must be a positive integer between 1 and 255.', array('!field' => $n['credentials'])), t('!field must have one of the following components: !components', array('!field' => t('Minimum components'), '!components' => check_plain(implode(', ', array($n['given'], $n['family']))))), t("The vocabulary 'machine' in !field could not be found.", array('!field' => t('!title options', array('!title' => $n['title'])))), t("The vocabulary '123' in !field could not be found.", array('!field' => t('!generational options', array('!generational' => $n['generational'])))), ); foreach ($required_messages as $message) { $this->assertText($message); } $widget_settings = array( 'instance[settings][title_display][title]' => 'description', // title, description, none 'instance[settings][title_display][given]' => 'description', 'instance[settings][title_display][middle]' => 'description', 'instance[settings][title_display][family]' => 'description', 'instance[settings][title_display][generational]' => 'description', 'instance[settings][title_display][credentials]' => 'description', 'instance[settings][size][title]' => 6, 'instance[settings][size][given]' => 20, 'instance[settings][size][middle]' => 20, 'instance[settings][size][family]' => 20, 'instance[settings][size][generational]' => 5, 'instance[settings][size][credentials]' => 35, 'instance[settings][inline_css][title]' => '', 'instance[settings][inline_css][given]' => '', 'instance[settings][inline_css][middle]' => '', 'instance[settings][inline_css][family]' => '', 'instance[settings][inline_css][generational]' => '', 'instance[settings][inline_css][credentials]' => '', ); $this->drupalGet('admin/structure/types/manage/page/fields/field_name_test'); foreach ($widget_settings as $name => $value) { $this->assertFieldByName($name, $value); } } function name_getFieldSettings() { $field_settings = array( 'field[settings][components][title]' => TRUE, 'field[settings][components][given]' => TRUE, 'field[settings][components][middle]' => TRUE, 'field[settings][components][family]' => TRUE, 'field[settings][components][generational]' => TRUE, 'field[settings][components][credentials]' => TRUE, 'field[settings][minimum_components][title]' => FALSE, 'field[settings][minimum_components][given]' => TRUE, 'field[settings][minimum_components][middle]' => FALSE, 'field[settings][minimum_components][family]' => TRUE, 'field[settings][minimum_components][generational]' => FALSE, 'field[settings][minimum_components][credentials]' => FALSE, 'field[settings][max_length][title]' => 31, 'field[settings][max_length][given]' => 63, 'field[settings][max_length][middle]' => 127, 'field[settings][max_length][family]' => 63, 'field[settings][max_length][generational]' => 15, 'field[settings][max_length][credentials]' => 255, 'field[settings][labels][title]' => t('Title'), 'field[settings][labels][given]' => t('Given'), 'field[settings][labels][middle]' => t('Middle name(s)'), 'field[settings][labels][family]' => t('Family'), 'field[settings][labels][generational]' => t('Generational'), 'field[settings][labels][credentials]' => t('Credentials'), 'field[settings][sort_options][title]' => TRUE, 'field[settings][sort_options][generational]' => FALSE, 'field[settings][title_options]' => "-- --\nMr.\nMrs.\nMiss\nMs.\nDr.\nProf.", 'field[settings][generational_options]' => "-- --\nJr.\nSr.\nI\nII\nIII\nIV\nV\nVI\nVII\nVIII\nIX\nX", ); return $field_settings; } function name_getFieldSettingsCheckboxes() { $field_settings = array( 'field[settings][components][title]' => TRUE, 'field[settings][components][given]' => TRUE, 'field[settings][components][middle]' => TRUE, 'field[settings][components][family]' => TRUE, 'field[settings][components][generational]' => TRUE, 'field[settings][components][credentials]' => TRUE, 'field[settings][minimum_components][title]' => FALSE, 'field[settings][minimum_components][given]' => TRUE, 'field[settings][minimum_components][middle]' => FALSE, 'field[settings][minimum_components][family]' => TRUE, 'field[settings][minimum_components][generational]' => FALSE, 'field[settings][minimum_components][credentials]' => FALSE, 'field[settings][sort_options][title]' => TRUE, 'field[settings][sort_options][generational]' => FALSE, ); return $field_settings; } }