function MenuAttributesNodeTestCase::testMenuNodeFormWidget in Menu Attributes 7
Test creating, editing, deleting menu links via node form widget.
File
- ./
menu_attributes.test, line 180 - Functionality tests for Menu attributes.
Class
- MenuAttributesNodeTestCase
- Test menu attributes settings for nodes.
Code
function testMenuNodeFormWidget() {
// Enable Navigation menu as available menu.
$edit = array(
'menu_options[navigation]' => 1,
);
$this
->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
// Change default parent item to Navigation menu, so we can assert more
// easily.
$edit = array(
'menu_parent' => 'navigation:0',
);
$this
->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
// Create a node.
$node_title = $this
->randomName();
$language = LANGUAGE_NONE;
$edit = array(
"title" => $node_title,
"body[{$language}][0][value]" => $this
->randomString(),
);
$this
->drupalPost('node/add/page', $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($node_title);
// Assert that there is no link for the node.
$this
->drupalGet('');
$this
->assertNoLink($node_title);
// Edit the node, enable the menu link setting, but skip the link title.
$edit = array(
'menu[enabled]' => 1,
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Assert that there is no link for the node.
$this
->drupalGet('');
$this
->assertNoLink($node_title);
// Edit the node and create a menu link with attributes.
$edit = array(
'menu[enabled]' => 1,
'menu[link_title]' => $node_title,
'menu[weight]' => 17,
'menu[options][attributes][title]' => $this->menu_attributes_new['title'],
'menu[options][attributes][id]' => $this->menu_attributes_new['id'],
'menu[options][attributes][name]' => $this->menu_attributes_new['name'],
'menu[options][attributes][rel]' => $this->menu_attributes_new['rel'],
'menu[options][attributes][class]' => $this->menu_attributes_new['class'],
'menu[options][attributes][style]' => $this->menu_attributes_new['style'],
'menu[options][attributes][target]' => $this->menu_attributes_new['target'],
'menu[options][attributes][accesskey]' => $this->menu_attributes_new['accesskey'],
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Assert that the link exists.
$this
->drupalGet('');
$this
->assertLink($node_title);
// Assert that the link attributes exist.
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertMenuAttributes('menu[options][attributes]', 'new');
// Edit the node again and change the menu link attributes.
$edit = array(
'menu[enabled]' => 1,
'menu[link_title]' => $node_title,
'menu[weight]' => 17,
'menu[options][attributes][title]' => $this->menu_attributes_edit['title'],
'menu[options][attributes][id]' => $this->menu_attributes_edit['id'],
'menu[options][attributes][name]' => $this->menu_attributes_edit['name'],
'menu[options][attributes][rel]' => $this->menu_attributes_edit['rel'],
'menu[options][attributes][class]' => $this->menu_attributes_edit['class'],
'menu[options][attributes][style]' => $this->menu_attributes_edit['style'],
'menu[options][attributes][target]' => $this->menu_attributes_edit['target'],
'menu[options][attributes][accesskey]' => $this->menu_attributes_edit['accesskey'],
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Assert that the link attributes exist.
$this
->drupalGet('node/' . $node->nid . '/edit');
$this
->assertMenuAttributes('menu[options][attributes]', 'edit');
// Edit the node and remove the menu link.
$edit = array(
'menu[enabled]' => FALSE,
);
$this
->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Assert that there is no link for the node.
$this
->drupalGet('');
$this
->assertNoLink($node_title);
}