You are here

function FlagTestCase::testFlagAdmin in Flag 7.2

Same name and namespace in other branches
  1. 6.2 tests/flag.test \FlagTestCase::testFlagAdmin()
  2. 6 tests/flag.test \FlagTestCase::testFlagAdmin()

Create a flag through the UI and ensure that it is saved properly.

File

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

Class

FlagTestCase
@file Tests for the Flag module.

Code

function testFlagAdmin() {

  // Add a new flag using the UI.
  $edit = array(
    'name' => strtolower($this
      ->randomName()),
    'title' => $this
      ->randomName(),
    'flag_short' => 'flag short [node:nid]',
    'flag_long' => 'flag long [node:nid]',
    'flag_message' => 'flag message [node:nid]',
    'unflag_short' => 'unflag short [node:nid]',
    'unflag_long' => 'unflag long [node:nid]',
    'unflag_message' => 'unflag message [node:nid]',
    'roles[flag][2]' => TRUE,
    'roles[unflag][2]' => TRUE,
    'types[article]' => FALSE,
    'types[page]' => TRUE,
    'show_on_teaser' => FALSE,
    'show_on_page' => FALSE,
    'show_on_form' => FALSE,
    'link_type' => 'toggle',
  );
  $saved = $edit;
  $saved['roles'] = array(
    'flag' => array(
      2,
    ),
    'unflag' => array(
      2,
    ),
  );
  $saved['types'] = array(
    'page',
  );
  unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]']);
  $this
    ->drupalPost(FLAG_ADMIN_PATH . '/add/node/' . $edit['name'], $edit, t('Save flag'));
  flag_get_flags(NULL, NULL, NULL, TRUE);
  $flag = flag_get_flag($edit['name']);

  // Check that the flag object is in the database.
  $this
    ->assertTrue($flag != FALSE, t('Flag object found in database'));

  // Check each individual property of the flag and make sure it was set.
  foreach ($saved as $property => $value) {
    $this
      ->assertEqual($flag->{$property}, $value, t('Flag property %property properly saved.', array(
      '%property' => $property,
    )));
  }

  // Edit the flag through the UI.
  $edit = array(
    'name' => strtolower($this
      ->randomName()),
    'title' => $this
      ->randomName(),
    'flag_short' => 'flag 2 short [node:nid]',
    'flag_long' => 'flag 2 long [node:nid]',
    'flag_message' => 'flag 2 message [node:nid]',
    'unflag_short' => 'unflag 2 short [node:nid]',
    'unflag_long' => 'unflag 2 long [node:nid]',
    'unflag_message' => 'unflag 2 message [node:nid]',
    'roles[flag][2]' => TRUE,
    'roles[unflag][2]' => TRUE,
    'types[article]' => TRUE,
    'types[page]' => FALSE,
    'show_on_teaser' => TRUE,
    'show_on_page' => TRUE,
    'show_on_form' => TRUE,
    'link_type' => 'normal',
  );
  $saved = $edit;
  $saved['roles'] = array(
    'flag' => array(
      2,
    ),
    'unflag' => array(
      2,
    ),
  );
  $saved['types'] = array(
    'article',
  );
  unset($saved['roles[flag][2]'], $saved['roles[unflag][2]'], $saved['types[article]'], $saved['types[page]']);
  $this
    ->drupalPost(FLAG_ADMIN_PATH . '/manage/' . $flag->name, $edit, t('Save flag'));
  flag_get_flags(NULL, NULL, NULL, TRUE);
  $flag = flag_get_flag($edit['name']);

  // Check that the flag object is in the database.
  $this
    ->assertTrue($flag != FALSE, t('Flag object found in database'));

  // Check each individual property of the flag and make sure it was set.
  foreach ($saved as $property => $value) {
    $this
      ->assertEqual($flag->{$property}, $value, t('Flag property %property properly saved.', array(
      '%property' => $property,
    )));
  }

  // Delete the flag through the UI.
  $this
    ->drupalPost(FLAG_ADMIN_PATH . '/manage/' . $flag->name . '/delete', array(), t('Delete'));
  flag_get_flags(NULL, NULL, NULL, TRUE);
  $this
    ->assertFalse(flag_get_flag($flag->name), t('Flag successfully deleted.'));
}