View source
<?php
namespace Drupal\Tests\menu_link_weight\FunctionalJavascript;
class MenuLinkWeightNodeJavascriptTest extends MenuLinkWeightJavascriptTestBase {
public function testMenuFunctionality() {
$node1_title = $this
->randomMachineName();
$edit = array(
'title[0][value]' => $node1_title,
);
$this
->drupalPostForm("node/add/{$this->nodeType}", $edit, t('Save'));
$this
->drupalGet('');
$this
->assertSession()
->linkNotExists($node1_title);
$node1_edit_url = $this
->drupalGetNodeByTitle($node1_title)
->toUrl('edit-form');
$edit = array(
'menu[enabled]' => 1,
'menu[title]' => '',
);
$this
->drupalPostForm($node1_edit_url, $edit, 'Save');
$this
->drupalGet('');
$this
->assertSession()
->linkNotExists($node1_title);
$this
->drupalGet($node1_edit_url);
$this
->assertSession()
->hiddenFieldExists('menu[db_weights][node.add_page]')
->setValue(-49);
$this
->assertSession()
->hiddenFieldExists('menu[db_weights][filter.tips_all]')
->setValue(-48);
$edit = array(
'menu[enabled]' => TRUE,
'menu[title]' => $node1_title,
'menu[menu_link_weight][node.add_page][weight]' => '-50',
'menu[menu_link_weight][link_current][weight]' => '-49',
'menu[menu_link_weight][filter.tips_all][weight]' => '-48',
);
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertSession()
->pageTextNotContains('The menu link weights have been changed by another user, please try again.');
$this
->drupalGet('');
$this
->assertSession()
->linkExists($node1_title);
$links = $this->contentMenuLinkStorage
->loadByProperties([
'title' => $node1_title,
]);
$link1_id = reset($links)
->getPluginId();
$this
->assertLinkWeight('node.add_page', -50);
$this
->assertLinkWeight($link1_id, -49);
$this
->assertLinkWeight('filter.tips_all', -48);
$this
->drupalGet($node1_edit_url);
$this
->assertSession()
->pageTextContains('(provided menu link)');
$this
->assertSession()
->pageTextContains('Change the weight of the links within the Tools menu');
$option = $this
->assertSession()
->optionExists('edit-menu-menu-link-weight-link-current-weight', -49);
$this
->assertTrue($option
->hasAttribute('selected'));
$select_xpath = $this
->cssSelectToXpath('[data-drupal-selector="edit-menu-menu-parent"]');
$this
->getSession()
->getDriver()
->selectOption($select_xpath, 'tools:node.add_page');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->assertSession()
->pageTextContains('Change the weight of the links within the Add content menu');
$node2_title = $this
->randomMachineName();
$edit = array(
'title[0][value]' => $node2_title,
'menu[enabled]' => TRUE,
'menu[title]' => $node2_title,
'menu[menu_link_weight][' . $link1_id . '][weight]' => '-50',
'menu[menu_link_weight][filter.tips_all][weight]' => '-49',
'menu[menu_link_weight][link_current][weight]' => '-48',
'menu[menu_link_weight][node.add_page][weight]' => '-47',
);
$this
->drupalPostForm("node/add/{$this->nodeType}", $edit, t('Save'));
$this
->drupalGet('');
$this
->assertSession()
->linkExists($node2_title);
$links = $this->contentMenuLinkStorage
->loadByProperties([
'title' => $node2_title,
]);
$link2_id = reset($links)
->getPluginId();
$this
->assertLinkWeight($link1_id, -50);
$this
->assertLinkWeight('filter.tips_all', -49);
$this
->assertLinkWeight($link2_id, -48);
$this
->assertLinkWeight('node.add_page', -47);
$node2_edit_url = $this
->drupalGetNodeByTitle($node2_title)
->toUrl('edit-form');
$this
->drupalGet($node2_edit_url);
$this
->assertSession()
->pageTextContains('(provided menu link)');
$option = $this
->assertSession()
->optionExists('edit-menu-menu-link-weight-link-current-weight', -48);
$this
->assertTrue($option
->hasAttribute('selected'));
$node3_title = $this
->randomMachineName();
$edit = array(
'title[0][value]' => $node3_title,
'menu[enabled]' => TRUE,
'menu[title]' => $node3_title,
);
$this
->drupalPostForm("node/add/{$this->nodeType}", $edit, t('Save'));
$this
->drupalGet('');
$this
->assertSession()
->linkExists($node3_title);
$links = $this->contentMenuLinkStorage
->loadByProperties([
'title' => $node3_title,
]);
$link3_id = reset($links)
->getPluginId();
$this
->assertLinkWeight($link3_id, -50);
$this
->assertLinkWeight($link1_id, -49);
$this
->assertLinkWeight('filter.tips_all', -48);
$this
->assertLinkWeight($link2_id, -47);
$this
->assertLinkWeight('node.add_page', -46);
$this->moduleInstaller
->install(array(
'menu_link_weight_test',
));
$this->state
->set('menu_link_weight_test_parent_value', 'tools:');
$this->state
->set('menu_link_weight_test_relative_position', 'above_' . $link2_id);
$node4_title = $this
->randomMachineName();
$edit = array(
'title[0][value]' => $node4_title,
'menu[enabled]' => TRUE,
'menu[title]' => $node4_title,
);
$this
->drupalPostForm("node/add/{$this->nodeType}", $edit, t('Save'));
$this
->drupalGet('');
$this
->assertSession()
->linkExists($node4_title);
$links = $this->contentMenuLinkStorage
->loadByProperties([
'title' => $node4_title,
]);
$link4_id = reset($links)
->getPluginId();
$this
->assertLinkWeight($link3_id, -50);
$this
->assertLinkWeight($link1_id, -49);
$this
->assertLinkWeight('filter.tips_all', -48);
$this
->assertLinkWeight($link4_id, -47);
$this
->assertLinkWeight($link2_id, -46);
$this
->assertLinkWeight('node.add_page', -45);
$this->state
->set('menu_link_weight_test_relative_position', 'below_' . $link2_id);
$node5_title = $this
->randomMachineName();
$edit = array(
'title[0][value]' => $node5_title,
'menu[enabled]' => 1,
'menu[title]' => $node5_title,
);
$this
->drupalPostForm("node/add/{$this->nodeType}", $edit, t('Save'));
$links = $this->contentMenuLinkStorage
->loadByProperties([
'title' => $node5_title,
]);
$link5_id = reset($links)
->getPluginId();
$this
->assertLinkWeight($link3_id, -50);
$this
->assertLinkWeight($link1_id, -49);
$this
->assertLinkWeight('filter.tips_all', -48);
$this
->assertLinkWeight($link4_id, -47);
$this
->assertLinkWeight($link2_id, -46);
$this
->assertLinkWeight($link5_id, -45);
$this
->assertLinkWeight('node.add_page', -44);
}
}