You are here

function FlagFlaggingCRUDTestCase::testFlaggingCreateException in Flag 7.3

Test throwing of exceptions with flagging_save().

File

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

Class

FlagFlaggingCRUDTestCase
Test CRUD operations on Flagging entities.

Code

function testFlaggingCreateException() {

  // Create an article node that we try to create a flagging entity for.
  $title = $this
    ->randomName(8);
  $node = array(
    'title' => $title,
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomName(32),
        ),
      ),
    ),
    'uid' => 1,
    'type' => 'article',
    'is_new' => TRUE,
  );
  $node = node_submit((object) $node);
  node_save($node);

  // Create test user who can't use this flag.
  $no_flag_user = $this
    ->drupalCreateUser(array());

  // Create a flagging entity with that tries to perform an flagging action
  // that is not permitted.
  $flagging = array(
    'fid' => $this->flag->fid,
    'entity_type' => 'node',
    'entity_id' => $node->nid,
    'uid' => $no_flag_user->uid,
  );
  $flagging = (object) $flagging;
  try {
    flagging_save($flagging);
    $this
      ->fail(t('Expected exception has not been thrown.'));
  } catch (Exception $e) {
    $this
      ->pass(t('Expected exception has been thrown.'));
  }
}