You are here

public function MemCacheRealWorldCase::testMenu in Memcache API and Integration 7

Test if the menu module caching acts as expected.

The menu module clears the affected menu if an menu item is changed using wildcards.

File

tests/memcache.test, line 805
Test cases for the memcache cache backend.

Class

MemCacheRealWorldCase
Test some real world cache scenarios with default modules.

Code

public function testMenu() {

  // Create and login user.
  $account = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer blocks',
    'administer menu',
    'create article content',
  ));
  $this
    ->drupalLogin($account);

  // Add Menu Link to test with.
  $item = $this
    ->addMenuLink();
  $original_title = $item['link_title'];

  // Check if menu link is displayed.
  $this
    ->drupalGet('');
  $this
    ->assertText($original_title, 'Menu item displayed in frontend');

  // Change menu item multiple times and check if the change is reflected.
  for ($i = 0; $i < 3; $i++) {

    // Edit menu link.
    $edit = array();
    $edit['link_title'] = $this
      ->randomName(16);
    $this
      ->drupalPost("admin/structure/menu/item/{$item['mlid']}/edit", $edit, t('Save'));
    if (!$this
      ->assertResponse(200)) {

      // One fail is enough.
      break;
    }

    // Verify edited menu link.
    if (!$this
      ->drupalGet('admin/structure/menu/manage/' . $item['menu_name'])) {

      // One fail is enough.
      break;
    }
    $this
      ->assertText($edit['link_title'], 'Menu link was edited');
    $this
      ->drupalGet('');
    if (!$this
      ->assertText($edit['link_title'], 'Change is reflected in frontend')) {

      // One fail is enough.
      break;
    }
  }
}