You are here

class MemCacheRealWorldCase in Memcache API and Integration 7

Test some real world cache scenarios with default modules.

Please make sure you've set the proper memcache settings in the settings.php. Looks like I've not chance to change the cache settings to what's needed by this test.

Hierarchy

Expanded class hierarchy of MemCacheRealWorldCase

File

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

View source
class MemCacheRealWorldCase extends MemcacheTestCase {
  protected $profile = 'standard';
  protected $default_bin = 'cache_menu';
  public static function getInfo() {
    return array(
      'name' => 'Real world cache tests',
      'description' => 'Test some real world cache scenarios.',
      'group' => 'Memcache',
    );
  }

  /**
   * @see MemcacheTestCase::setUp()
   */
  public function setUp() {
    parent::setUp('menu');
  }

  /**
   * Test if the menu module caching acts as expected.
   *
   * The menu module clears the affected menu if an menu item is changed using
   * wildcards.
   */
  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;
      }
    }
  }

  /**
   * Adds a menu link.
   *
   * @see MenuTestCase::addMenuLink()
   */
  public function addMenuLink($plid = 0, $link = '<front>', $menu_name = 'main-menu') {

    // View add menu link page.
    $this
      ->drupalGet("admin/structure/menu/manage/{$menu_name}/add");
    $this
      ->assertResponse(200);
    $title = '!OriginalLink_' . $this
      ->randomName(16);
    $edit = array(
      'link_path' => $link,
      'link_title' => $title,
      'description' => '',
      // Use this to disable the menu and test.
      'enabled' => TRUE,
      // Setting this to true should test whether it works when we do the
      // std_user tests.
      'expanded' => TRUE,
      'parent' => $menu_name . ':' . $plid,
      'weight' => '0',
    );

    // Add menu link.
    $this
      ->drupalPost(NULL, $edit, t('Save'));
    $this
      ->assertResponse(200);

    // Unlike most other modules, there is no confirmation message displayed.
    $this
      ->assertText($title, 'Menu link was added');
    $item = db_query('SELECT * FROM {menu_links} WHERE link_title = :title', array(
      ':title' => $title,
    ))
      ->fetchAssoc();
    return $item;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemCacheRealWorldCase::$default_bin protected property
MemCacheRealWorldCase::$profile protected property
MemCacheRealWorldCase::addMenuLink public function Adds a menu link.
MemCacheRealWorldCase::getInfo public static function
MemCacheRealWorldCase::setUp public function
MemCacheRealWorldCase::testMenu public function Test if the menu module caching acts as expected.