TokenExampleTestCase

  1. examples
    1. 6 token_example/token_example.test
    2. 7 token_example/token_example.test
    3. 8 token_example/token_example.test

Hierarchy

Properties

NameDescription
TokenExampleTestCase::$web_user

Functions & methods

NameDescription
TokenExampleTestCase::getInfo
TokenExampleTestCase::setUp
TokenExampleTestCase::testInterface

File

token_example/token_example.test, line 8
Test cases for Testing the token example module.

View source
class TokenExampleTestCase extends DrupalWebTestCase {
  protected $web_user;

  public static function getInfo() {
    return array(
      'name' => 'Token example functionality', 
      'description' => 'Verify the token example interface.', 
      'group' => 'Examples', 
      'dependencies' => array('token'),
    );
  }

  function setUp() {
    parent::setUp('token_example');
    $this->web_user = $this->drupalCreateUser();
    $this->drupalLogin($this->web_user);
  }

  function testInterface() {
    $filtered_id = db_query("SELECT format FROM {filter_format} WHERE name = 'Filtered HTML'")->fetchField();
    $default_format_id = filter_default_format($this->web_user);

    $this->drupalGet('examples/token');
    $this->assertNoFieldByName('node');
    $this->assertNoFieldByName('user');

    $edit = array(
      'text' => 'User [current-user:name] is trying the token example!',
    );
    $this->drupalPost(NULL, $edit, t('Submit'));
    $this->assertText('User ' . $this->web_user->name . ' is trying the token example!');

    // Create a node and then make the 'Plain text' text format the default.
    $node = $this->drupalCreateNode(array('title' => 'Example node', 'status' => NODE_PUBLISHED));
    db_update('filter_format')
      ->fields(array('weight' => -10))
      ->condition('name', 'Plain text')
      ->execute();

    $this->drupalGet('examples/token');

    $edit = array(
      'text' => 'Would you like to view the [node:type-name] [node:title] with text format [node:body-format] (ID [node:body-format:id])?', 
      'node' => $node->nid,
    );
    $this->drupalPost(NULL, $edit, t('Submit'));
    $this->assertText('Would you like to view the Basic page Example node with text format Filtered HTML (ID ' . $filtered_id . ')?');

    $edit = array(
      'text' => 'Your default text format is [default-format:name] (ID [default-format:id]).',
    );
    $this->drupalPost(NULL, $edit, t('Submit'));
    $this->assertText('Your default text format is Filtered HTML (ID ' . $default_format_id . ')');
  }
}
Login or register to post comments