You are here

core.test in Twitter 7.5

Functional tests for the Twitter module.

File

tests/core.test
View source
<?php

/**
 * @file
 * Functional tests for the Twitter module.
 */
class TwitterTest extends DrupalWebTestCase {

  /*'
   * The getInfo() method provides information about the test. In order for the
   * test to be run, the getInfo() method needs to be implemented.
   */
  public static function getInfo() {
    return array(
      'name' => t('Main'),
      'description' => t('Tests main module features such as adding accounts or loading tweets.'),
      'group' => t('Twitter'),
    );
  }

  /**
   * Prepares the testing environment.
   */
  function setUp() {
    parent::setUp('twitter', 'views', 'twitter_mock');
  }

  /**
   * Tests account addition without Oauth module activated.
   */
  public function testAccountAdditionNoOauth() {

    // Create a user.
    $this->user = $this
      ->drupalCreateUser(array(
      'add twitter accounts',
      'add authenticated twitter accounts',
    ));
    $this
      ->drupalLogin($this->user);

    // The path to the user account's Twitter page.
    $url = 'user/' . $this->user->uid . '/edit/twitter';

    // Before the global account is created, verify that accounts may not be
    // added yet.
    variable_set('twitter_consumer_key', '');
    variable_set('twitter_consumer_secret', '');
    $this
      ->drupalGet($url);
    $this
      ->assertText(t('You need to authenticate at least one Twitter account in order to use the Twitter API.'));

    // Set some mock auth strings.
    variable_set('twitter_consumer_key', 'twitter_consumer_key');
    variable_set('twitter_consumer_secret', 'twitter_consumer_secret');

    // Verify the Twitter user page loads correctly.
    $this
      ->drupalGet($url);
    $this
      ->assertText(t('Add Twitter accounts'));

    // Verify the "add account" button exists after providing mock auth strings.
    $this
      ->drupalGet($url);
    $this
      ->assertText(t('Authenticated accounts can post, sign in and pull mentions'));

    /**
     * Need to fix the twitter_mock system so that these work again.
     */

    // // Add an account.
    // $edit = array(
    //   'screen_name' => 'drupal',
    // );
    // $this->drupalPost($url, $edit, t('Go to Twitter to add an authenticated account'));
    // $this->assertLink('drupal', 0, t('Twitter account was added successfully'));
    // // Load tweets.
    // twitter_cron();
    // $this->drupalGet('user/' . $this->user->uid . '/tweets');
    // $elements = $this->xpath('//div[contains(@class, "view-tweets")]/div/table');
    // $this->assertTrue(count($elements), 'Tweets were loaded successfully.');
    // // Delete the Twitter account.
    // $url = 'user/' . $this->user->uid . '/edit/twitter';
    // $edit = array(
    //   'accounts[0][delete]' => 1,
    // );
    // $this->drupalPost($url, $edit, t('Save changes'));
    // $this->assertText(t('The Twitter account was deleted.'));
  }

}

Classes

Namesort descending Description
TwitterTest @file Functional tests for the Twitter module.