diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index 2e1725d..835bc74 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -307,6 +307,9 @@ function menu_edit_item($form, &$form_state, $type, $item, $menu) { '#access' => $item['mlid'], '#submit' => array('menu_item_delete_submit'), '#weight' => 10, + // Keep array('mlid') for passing mlid of the + // menu link item to delete confirmation form. + '#limit_validation_errors' => array(array('mlid')), ); } else { @@ -487,6 +490,9 @@ function menu_edit_menu($form, &$form_state, $type, $menu = array()) { '#value' => t('Delete'), '#access' => $type == 'edit' && !isset($system_menus[$menu['menu_name']]), '#submit' => array('menu_custom_delete_submit'), + // Keep array('menu_name') for passing menu_name of the + // menu item to delete confirmation form. + '#limit_validation_errors' => array(array('menu_name')), ); return $form; diff --git a/core/modules/menu/menu.test b/core/modules/menu/menu.test index e1f2aa9..84807d5 100644 --- a/core/modules/menu/menu.test +++ b/core/modules/menu/menu.test @@ -62,6 +62,21 @@ class MenuTestCase extends DrupalWebTestCase { // Delete custom menu. $this->deleteCustomMenu($this->menu); + // Delete menu submitting empty title on edit form. + // Check if validation permits to do this. + $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI); + $title = $this->randomName(16); + + $menu = array( + 'menu_name' => $menu_name, + 'title' => $title, + 'description' => 'Description text', + ); + menu_save($menu); + $edit = array('title' => ''); + $this->drupalPost('admin/structure/menu/manage/' . $menu_name . '/edit', $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Title'))), t('Delete menu on edit form with empty title.')); + // Modify and reset a standard menu link. $item = $this->getStandardMenuLink(); $old_title = $item['link_title']; @@ -74,6 +89,35 @@ class MenuTestCase extends DrupalWebTestCase { $saved_item = menu_link_load($item['mlid']); $this->assertEqual($description, $saved_item['options']['attributes']['title'], t('Saving an existing link updates the description (title attribute)')); $this->resetMenuLink($item, $old_title); + + // Delete link submitting empty title or path on edit form. + // Check if validation permits to do this. + // Login the user. + $this->drupalLogin($this->big_user); + // Create custom link to User menu. + $link_title = $this->randomName(); + $edit = array( + 'link_title' => $link_title, + 'link_path' => '', + ); + $this->drupalPost('admin/structure/menu/manage/user-menu/add', $edit, t('Save')); + // Select mlid of new created menu item. + $mlid = db_query("SELECT mlid FROM {menu_links} WHERE link_title = :link_title", array(':link_title' => $link_title))->fetchField(); + // Submit edit form with empty title. + $edit = array( + 'link_title' => '', + 'link_path' => '', + ); + $this->drupalPost('admin/structure/menu/item/' . $mlid . '/edit', $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Menu link title'))), t('Delete link on edit form with empty title.')); + + // Submit edit form with empty path. + $edit = array( + 'link_title' => $link_title, + 'link_path' => '', + ); + $this->drupalPost('admin/structure/menu/item/' . $mlid . '/edit', $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Path'))), t('Delete link on edit form with empty path.')); } /** diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 4e94b26..a0abea6 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -338,6 +338,9 @@ function node_form($form, &$form_state, $node) { '#value' => t('Delete'), '#weight' => 15, '#submit' => array('node_form_delete_submit'), + // Keep array('nid') for passing nid of the node + // to delete confirmation form + '#limit_validation_errors' => array(array('nid')), ); } // This form uses a button-level #submit handler for the form's main submit diff --git a/core/modules/node/node.test b/core/modules/node/node.test index 1dbcaf3..09c0734 100644 --- a/core/modules/node/node.test +++ b/core/modules/node/node.test @@ -413,6 +413,59 @@ class PageEditTestCase extends NodeWebTestCase { } } +/** + * Tests node deletion not triggering the whole form validation. + */ +class NodeDeleteTestCase extends NodeWebTestCase { + protected $web_user; + + public static function getInfo() { + return array( + 'name' => 'Node delete', + 'description' => 'Create a node and test node delete functionality.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(); + + $this->web_user = $this->drupalCreateUser(array( + 'edit own page content', 'create page content', 'delete own page content' + )); + } + + /** + * Check deleting node from edit form with empty title. + */ + function testNodeDeleteEmptyTitle() { + $this->drupalLogin($this->web_user); + + $langcode = LANGUAGE_NOT_SPECIFIED; + $title_key = "title"; + $body_key = "body[$langcode][0][value]"; + // Create node to delete. + $edit = array(); + $edit[$title_key] = $this->randomName(8); + $edit[$body_key] = $this->randomName(16); + $this->drupalPost('node/add/page', $edit, t('Save')); + + // Load created node. + $node = $this->drupalGetNodeByTitle($edit[$title_key]); + + // Delete the node through edit form. + $edit = array(); + $edit[$title_key] = ''; + $edit[$body_key] = $this->randomName(16); + // Use Delete button on edit form taking off the title. + $this->drupalPost("node/$node->nid/edit", $edit, t('Delete')); + + // Check that node edit form can be submitted + // with Delete button and empty title. + $this->assertNoText(t('!name field is required.', array('!name' => t('Title'))), t('Delete button works with empty title on edit form.')); + } +} + class PagePreviewTestCase extends NodeWebTestCase { public static function getInfo() { return array( diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc index 24921b8..1cb2943 100644 --- a/core/modules/path/path.admin.inc +++ b/core/modules/path/path.admin.inc @@ -182,6 +182,9 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali '#type' => 'submit', '#value' => t('Delete'), '#submit' => array('path_admin_form_delete_submit'), + // Keep array('pid') for passing pid of the + // url alias record to delete confirmation form. + '#limit_validation_errors' => array(array('pid')), ); } diff --git a/core/modules/path/path.test b/core/modules/path/path.test index d652654..df80908 100644 --- a/core/modules/path/path.test +++ b/core/modules/path/path.test @@ -131,6 +131,41 @@ class PathAliasTestCase extends PathTestCase { } /** + * Delete alias through alias edit form. + */ + function testDeleteAlias() { + // Create alias. + $alias = $this->randomName(); + $edit = array( + 'source' => '', + 'alias' => $alias, + ); + $this->drupalPost('admin/config/search/path/add', $edit, t('Save')); + + // Select pid of new created alias. + $query = db_select('url_alias'); + $query->addField('url_alias', 'pid'); + $query->condition('alias', $alias); + $pid = $query->execute()->fetchField(); + + // Delete submit with empty source field. + $edit = array( + 'source' => '', + 'alias' => $alias, + ); + $this->drupalPost('admin/config/search/path/edit/' . $pid, $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Existing system path'))), t('Delete alias on edit form with empty source field.')); + + // Delete submit with empty alias field. + $edit = array( + 'source' => '', + 'alias' => '', + ); + $this->drupalPost('admin/config/search/path/edit/' . $pid, $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Path alias'))), t('Delete alias on edit form with empty alias field.')); + } + + /** * Tests alias functionality through the node interfaces. */ function testNodeAlias() { diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index f7d4552..56cfa2d 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -959,6 +959,9 @@ function user_admin_role($form, $form_state, $role) { '#type' => 'submit', '#value' => t('Delete role'), '#submit' => array('user_admin_role_delete_submit'), + // Keep array('rid') for passing rid of the role + // to delete confirmation form + '#limit_validation_errors' => array(array('rid')), ); return $form; diff --git a/core/modules/user/user.test b/core/modules/user/user.test index 3a07e1c..6aa9492 100644 --- a/core/modules/user/user.test +++ b/core/modules/user/user.test @@ -1923,6 +1923,11 @@ class UserRoleAdminTestCase extends DrupalWebTestCase { $this->assertFalse(user_role_load_by_name($old_name), t('The role can no longer be retrieved from the database using its old name.')); $this->assertTrue(is_object(user_role_load_by_name($role_name)), t('The role can be retrieved from the database using its new name.')); + // Test submit edit role form with empty role name. + $edit = array('name' => ''); + $this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", $edit, t('Delete role')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Role name'))), t('Role can be deleted with empty name submitted to the form.')); + // Test deleting a role. $this->drupalPost("admin/people/permissions/roles/edit/{$role->rid}", NULL, t('Delete role')); $this->drupalPost(NULL, NULL, t('Delete'));