You are here

sharemessage.twitter.test in Share Message 7

ShareMessage twitter card tests.

File

tests/sharemessage.twitter.test
View source
<?php

/**
 * @file
 * ShareMessage twitter card tests.
 */

/**
 * Share message twitter card tests.
 */
class ShareMessageTwitterCardsTest extends ShareMessageTestCase {
  public static function getInfo() {
    return array(
      'name' => 'ShareMessage twitter cards',
      'description' => 'Verifies the output of ShareMessage twitter card meta tags.',
      'group' => 'ShareMessage',
    );
  }

  /**
   * Checks whether twitter card meta tags get rendered.
   */
  public function testShareMessageViewModes() {

    // Enable rendering of twitter cards meta tags.
    variable_set('sharemessage_add_twitter_card', TRUE);
    $user_name = $this
      ->randomName();
    variable_set('sharemessage_twitter_user', $user_name);

    // Create a share message in the UI.
    $this
      ->drupalGet('admin/config/services/sharemessage/add');
    $edit = array(
      'label' => 'ShareMessage Test Label',
      'name' => 'sharemessage_test_label',
      'sharemessage_title[en][0][value]' => 'ShareMessage Test Title',
      'sharemessage_long[en][0][value]' => 'ShareMessage Test Long Description',
      'sharemessage_short[en][0][value]' => 'ShareMessage Test Short Description',
      'sharemessage_image_url[und][0][value]' => 'http://www.example.com/drupal.jpg',
      'sharemessage_url[und][0][value]' => 'http://www.example.com',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save share message'));
    $this
      ->assertText(t('Message @label saved.', array(
      '@label' => $edit['label'],
    )), t('ShareMessage is successfully saved.'));

    // Display share message and verify the twitter card meta tags.
    $this
      ->drupalGet('sharemessage-test/1');
    $meta = '<meta name="twitter:card" content="summary_large_image" />';
    $this
      ->assertRaw($meta);
    $meta = '<meta name="twitter:site" content="' . $user_name . '" />';
    $this
      ->assertRaw($meta);
    $meta = '<meta name="twitter:description" content="' . $edit['sharemessage_long[en][0][value]'] . '" />';
    $this
      ->assertRaw($meta);
    $meta = '<meta name="twitter:image" content="' . $edit['sharemessage_image_url[und][0][value]'] . '" />';
    $this
      ->assertRaw($meta);
  }

}

Classes

Namesort descending Description
ShareMessageTwitterCardsTest Share message twitter card tests.