You are here

function MenuModuleTestCase::testCreateCheckDelete in SimpleTest 6

1 method overrides MenuModuleTestCase::testCreateCheckDelete()
MenuModuleCustomMenuTest::testCreateCheckDelete in tests/menu_module.test

File

tests/menu_module.test, line 22

Class

MenuModuleTestCase

Code

function testCreateCheckDelete() {
  $web_user = $this
    ->drupalCreateUserRolePerm(array(
    'access content',
    'administer menu',
    'access administration pages',
  ));
  $this
    ->drupalLoginUser($web_user);
  $mlid1 = $this
    ->uiCreateLink();
  $mlid2 = $this
    ->uiCreateLink($mlid1);
  $link1 = menu_link_load($mlid1);
  $this
    ->assertTrue((bool) $link1, '1st link created and loaded');
  $link2 = menu_link_load($mlid2);
  $this
    ->assertTrue((bool) $link2, '2nd link created as child and loaded');

  // Check the structure in the DB of the two links.
  // In general, if $n = $link['depth'] then $link['p'. $n] == $link['mlid'] and $link['p'. ($n - 1)] == $link['plid'] (unless depth == 0).
  // All $link['p'. $n] for $n > depth must be 0.
  // We know link1 is at the top level, so $link1['deptj'] == 1 and $link1['plid'] == 0.
  // We know that the parent of link2 is link1, so $link2['plid'] == $link1['mlid'].
  // Both links were created in the avigation menu.
  $this
    ->assertTrue($link1['p2'] == 0 && $link1['p1'] == $mlid1 && $link1['plid'] == 0 && $link1['depth'] == 1 && $link1['has_children'], '1st link has correct data');
  $this
    ->assertTrue($link2['menu_name'] == 'navigation' && $link2['p2'] == $mlid2 && $link2['p1'] == $mlid1 && $link2['plid'] == $mlid1 && $link2['depth'] == 2, '2nd link has correct data');
  $this
    ->uiDeleteLink($mlid1);
  $this
    ->assertFalse(menu_link_load($mlid1), '1st link deleted');
  $link2 = menu_link_load($mlid2);
  $this
    ->assertTrue($link2['plid'] == 0, '2nd link re-parented');
  $this
    ->uiDeleteLink($mlid2);
  $this
    ->assertFalse(menu_link_load($mlid2), '2nd link link deleted');
}