- Patch #292790 by mr.baileys: menu machine-name validation error.
							parent
							
								
									de97864969
								
							
						
					
					
						commit
						d3de6c8171
					
				| 
						 | 
					@ -539,10 +539,11 @@ function menu_edit_menu_validate($form, &$form_state) {
 | 
				
			||||||
  if (preg_match('/[^a-z0-9-]/', $item['menu_name'])) {
 | 
					  if (preg_match('/[^a-z0-9-]/', $item['menu_name'])) {
 | 
				
			||||||
    form_set_error('menu_name', t('The menu name may only consist of lowercase letters, numbers, and hyphens.'));
 | 
					    form_set_error('menu_name', t('The menu name may only consist of lowercase letters, numbers, and hyphens.'));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  if ($form['#insert']) {
 | 
				
			||||||
    if (strlen($item['menu_name']) > MENU_MAX_MENU_NAME_LENGTH_UI) {
 | 
					    if (strlen($item['menu_name']) > MENU_MAX_MENU_NAME_LENGTH_UI) {
 | 
				
			||||||
      form_set_error('menu_name', format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."));
 | 
					      form_set_error('menu_name', format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  if ($form['#insert']) {
 | 
					
 | 
				
			||||||
    // We will add 'menu-' to the menu name to help avoid name-space conflicts.
 | 
					    // We will add 'menu-' to the menu name to help avoid name-space conflicts.
 | 
				
			||||||
    $item['menu_name'] = 'menu-' . $item['menu_name'];
 | 
					    $item['menu_name'] = 'menu-' . $item['menu_name'];
 | 
				
			||||||
    $custom_exists = db_query('SELECT menu_name FROM {menu_custom} WHERE menu_name = :menu', array(':menu' => $item['menu_name']))->fetchField();
 | 
					    $custom_exists = db_query('SELECT menu_name FROM {menu_custom} WHERE menu_name = :menu', array(':menu' => $item['menu_name']))->fetchField();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,8 +95,10 @@ class MenuTestCase extends DrupalWebTestCase {
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  function addCustomMenu() {
 | 
					  function addCustomMenu() {
 | 
				
			||||||
    // Add custom menu.
 | 
					    // Add custom menu.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Try adding a menu using a menu_name that is too long.
 | 
				
			||||||
    $this->drupalGet('admin/build/menu/add');
 | 
					    $this->drupalGet('admin/build/menu/add');
 | 
				
			||||||
    $menu_name = substr(md5($this->randomName(16)), 0, 20);
 | 
					    $menu_name = substr(md5($this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI + 1);
 | 
				
			||||||
    $title = $this->randomName(16);
 | 
					    $title = $this->randomName(16);
 | 
				
			||||||
    $edit = array (
 | 
					    $edit = array (
 | 
				
			||||||
      'menu_name' => $menu_name,
 | 
					      'menu_name' => $menu_name,
 | 
				
			||||||
| 
						 | 
					@ -104,6 +106,17 @@ class MenuTestCase extends DrupalWebTestCase {
 | 
				
			||||||
      'title' =>  $title,
 | 
					      'title' =>  $title,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
    $this->drupalPost('admin/build/menu/add', $edit, t('Save'));
 | 
					    $this->drupalPost('admin/build/menu/add', $edit, t('Save'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Verify that using a menu_name that is too long results in a validation message.
 | 
				
			||||||
 | 
					    $this->assertText(format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."), t('Validation failed when menu name is too long.'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Change the menu_name so it no longer exceeds the maximum length.
 | 
				
			||||||
 | 
					    $menu_name = substr(md5($this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI);
 | 
				
			||||||
 | 
					    $edit['menu_name'] = $menu_name;
 | 
				
			||||||
 | 
					    $this->drupalPost('admin/build/menu/add', $edit, t('Save'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Verify that no validation error is given for menu_name length.
 | 
				
			||||||
 | 
					    $this->assertNoText(format_plural(MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."), t('Validation failed when menu name is too long.'));
 | 
				
			||||||
    // Unlike most other modules, there is no confirmation message displayed.
 | 
					    // Unlike most other modules, there is no confirmation message displayed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $this->drupalGet('admin/build/menu');
 | 
					    $this->drupalGet('admin/build/menu');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue