You are here

word_link.test in Word Link 7.2

Tests for the Word Link module.

File

tests/word_link.test
View source
<?php

/**
 * @file
 * Tests for the Word Link module.
 */

/**
 * Base class for Word Link web test cases.
 */
class WordLinkWebTestCase extends DrupalWebTestCase {
  protected $privilegedUser;

  /**
   * Declare test.
   */
  public static function getInfo() {
    return array(
      'name' => 'Word Link',
      'description' => 'Test word link functional.',
      'group' => 'Word Link',
    );
  }

  /**
   * Prepare for test.
   */
  public function setUp() {
    parent::setUp(array(
      'word_link',
    ));

    // Create and log in our privileged user.
    $this->privilegedUser = $this
      ->drupalCreateUser(array(
      'view word link',
      'create word link',
      'edit word link',
      'delete word link',
    ));
    $this
      ->drupalLogin($this->privilegedUser);
  }

  /**
   * Tests creation and editing of a word.
   */
  public function testWordLinkCreate() {

    // Create word to edit.
    $edit = array(
      'word[text]' => $this
        ->randomName(8),
      'word[weight]' => 0,
      'word[url]' => 'http://drupal.org',
      'word[class]' => $this
        ->randomName(8),
    );
    $this
      ->drupalPost('admin/config/content/word-link/add', $edit, t('Save'));
    $this
      ->assertRaw(t('Word %text has been @action.', array(
      '%text' => $edit['word[text]'],
      '@action' => 'created',
    )));
    $words = word_link_load_all();
    $word = (array) current($words);
    unset($word['text_lower']);
    $word['text'] = $this
      ->randomName(8);
    foreach ($word as $delta => $value) {
      $edit['word[' . $delta . ']'] = $value;
    }
    $this
      ->drupalPost('admin/config/content/word-link/edit/' . $word['id'], $edit, t('Save'));
    $this
      ->assertRaw(t('Word %text has been @action.', array(
      '%text' => $word['text'],
      '@action' => 'updated',
    )));
    $this
      ->drupalGet('admin/config/content/word-link/delete/' . $word['id']);
    $this
      ->assertRaw(t('Are you sure you want to delete %title?', array(
      '%title' => $word['text'],
    )));
    $this
      ->drupalPost('admin/config/content/word-link/delete/' . $word['id'], array(), t('Delete'));
    $this
      ->assertRaw(t('Word %text has been deleted.', array(
      '%text' => $word['text'],
    )));
  }

}

Classes

Namesort descending Description
WordLinkWebTestCase Base class for Word Link web test cases.