function TokenExampleTestCase::testInterface

Test interface.

File

token_example/token_example.test, line 40

Class

TokenExampleTestCase
Functional tests for the Token Example module.

Code

public function testInterface() {
    $filtered_id = db_query("SELECT format FROM {filter_format} WHERE name = 'Filtered HTML'")->fetchField();
    $default_format_id = filter_default_format($this->webUser);
    $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->webUser->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 . ')');
}