You are here

function FlagLinkTypeConfirmTestCase::testFlag in Flag 7.3

Test usage of the flag confirm form.

File

tests/flag.test, line 849
Tests for the Flag module.

Class

FlagLinkTypeConfirmTestCase
Test the 'confirm form' link type.

Code

function testFlag() {

  // Look at our node.
  $this
    ->drupalGet('node/' . $this->nid);
  $flag_short_label = strip_tags($this->flag_data['flag_short']);
  $this
    ->assertRaw($this->flag_data['flag_short'], 'The flag text, including HTML, appears on the page.');

  // assertLink() appears to have interesting problems dealing with an A
  // element which contains other tags. However, the xpath it uses appears to
  // be fine with being given just the portion of the link text that comes
  // before the interior tag.
  // Fortunately, there will be no other text on the page that matches 'Flag'.
  $this
    ->assertLink('Flag', 0, 'The flag link appears on the page.');

  // Click the link to flag the node.
  // clickLink() has the same problem, as it uses the same xpath expression as
  // assertLink().
  $this
    ->clickLink('Flag');
  $this
    ->assertUrl('flag/confirm/flag/test_flag/' . $this->nid, array(
    'query' => array(
      'destination' => 'node/' . $this->nid,
    ),
  ), 'On confirm flagging form page.');
  $this
    ->assertText($this->flag_data['flag_confirmation'], 'The flag confirmation text appears as the confirmation page title.');
  $this
    ->assertPattern('@<input [^>]* value="' . $flag_short_label . '" [^>]*>@', 'The flag text, excluding HTML, is shown in the button.');

  // Click the button to confirm the flagging.
  $this
    ->drupalPost(NULL, array(), $flag_short_label);
  $this
    ->assertText($this->flag_data['flag_message'], 'The flag message appears once the item has been flagged.');
  $this
    ->assertLink($this->flag_data['unflag_short'], 0, 'The unflag link appears once the item has been flagged.');

  // Reset the static cache before we get data from it.
  drupal_static_reset('flag_get_user_flags');
  $this
    ->assertTrue($this->flag
    ->is_flagged($this->nid, $this->flag_unflag_user->uid), "The node is recorded as flagged by the user.");

  // Click the link to unflag the node.
  $this
    ->clickLink($this->flag_data['unflag_short']);
  $this
    ->assertUrl('flag/confirm/unflag/test_flag/' . $this->nid, array(
    'query' => array(
      'destination' => 'node/' . $this->nid,
    ),
  ), t('On confirm unflagging form page.'));
  $this
    ->assertText($this->flag_data['unflag_confirmation'], 'The unflag confirmation text appears as the confirmation page title.');

  // Click the button to confirm the flagging.
  $this
    ->drupalPost(NULL, array(), $this->flag_data['unflag_short']);
  $this
    ->assertText($this->flag_data['unflag_message'], 'The unflag message appears once the item has been flagged.');

  // Reset the static cache before we get data from it.
  drupal_static_reset('flag_get_user_flags');
  $this
    ->assertFalse($this->flag
    ->is_flagged($this->nid, $this->flag_unflag_user->uid), "The node is recorded as not flagged by the user.");
}