You are here

public function ShareMessageTwitterCardsTest::testShareMessageViewModes in Share Message 7

Checks whether twitter card meta tags get rendered.

File

tests/sharemessage.twitter.test, line 24
ShareMessage twitter card tests.

Class

ShareMessageTwitterCardsTest
Share message twitter card tests.

Code

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);
}