You are here

sharemessage.shariff.test in Share Message 7

ShareMessage shariff integration tests.

File

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

/**
 * @file
 * ShareMessage shariff integration tests.
 */

/**
 * Tests the shariff integration.
 */
class ShareMessageShariffTestCase extends ShareMessageTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'ShareMessage Shariff',
      'description' => 'Checks the shariff integration',
      'group' => 'ShareMessage',
      'dependences' => array(
        'shariff',
      ),
    );
  }

  /**
   * Tests the shariff integration.
   */
  public function testShariffIntegration() {

    // Enable and configure shariff.
    module_enable([
      'shariff',
    ]);
    $this
      ->resetAll();
    $default_settings = array(
      'sharemessage_default_type' => 'shariff',
      'sharemessage_twitter_user' => 'MDSystems_CH',
    );
    $this
      ->drupalPost('admin/config/services/sharemessage/settings', $default_settings, t('Save configuration'));
    $shariff_settings = array(
      'shariff_services[mail]' => TRUE,
      'shariff_services[whatsapp]' => TRUE,
    );
    $this
      ->drupalPost('admin/config/services/shariff', $shariff_settings, t('Save configuration'));

    // Create another sharemessage that will be exposed as block.
    $this
      ->drupalGet('admin/config/services/sharemessage/add');
    $sharemessage = array(
      'label' => 'ShareMessage Test Label',
      'name' => 'sharemessage_test_label',
      'sharemessage_title[en][0][value]' => 'Short example title',
      'sharemessage_long[en][0][value]' => 'Long example description',
      'sharemessage_short[en][0][value]' => 'Short example description',
      'sharemessage_image_url[und][0][value]' => '/path/to/share-image.jpg',
      'block' => 1,
    );
    $this
      ->drupalPost(NULL, $sharemessage, t('Save share message'));
    $this
      ->assertText(t('Message @label saved.', array(
      '@label' => $sharemessage['label'],
    )));

    // Go to block section and enable block to be visible
    // on content region.
    $this
      ->drupalGet('admin/structure/block');
    $this
      ->assertRaw($sharemessage['label'], t($sharemessage['label'] . ' block exists.'));
    $edit = array(
      'blocks[sharemessage_' . $sharemessage['name'] . '][region]' => 'content',
    );
    $this
      ->drupalPost('admin/structure/block', $edit, t('Save blocks'));

    // Ensure that shariff is shown correctly and addthis is not loaded.
    $this
      ->drupalGet('<front>');
    $this
      ->assertNoRaw('addthis');
    $this
      ->assertRaw('class="shariff"');
    $this
      ->assertRaw('data-services="[&quot;twitter&quot;,&quot;facebook&quot;,&quot;whatsapp&quot;,&quot;mail&quot;]"');
    $this
      ->assertRaw('data-twitter-via="MDSystems_CH"');
    $this
      ->assertRaw('data-mail-subject="Short example title"');
    $this
      ->assertRaw('data-mail-body="Long example description"');
    $this
      ->assertRaw('data-media-url="/path/to/share-image.jpg"');

    // Do not assert the full URL, as this is not working on testbot, just make
    // sure it is there and absolute.
    $this
      ->assertRaw('data-url="http');

    // $this->assertRaw('data-url="' . $this->getAbsoluteUrl('node') . '"');
    // Uncomment when https://www.drupal.org/project/shariff/issues/2969264 is
    // committed and released.
    // $this->assertRaw('data-title="Short example description"');
  }

}

Classes

Namesort descending Description
ShareMessageShariffTestCase Tests the shariff integration.