You are here

function SharerichTest::testBlock in Sharerich 7.2

Same name and namespace in other branches
  1. 7.3 tests/sharerich.test \SharerichTest::testBlock()

Test sharerich block.

File

tests/sharerich.test, line 133

Class

SharerichTest
Sharerich tests.

Code

function testBlock() {
  $this
    ->drupalLogin($this->adminUser);

  // Configure block.
  $edit = array(
    'regions[bartik]' => 'content',
    'regions[seven]' => 'content',
  );
  $this
    ->drupalPost('admin/structure/block/manage/sharerich/default_set/configure', $edit, t('Save block'));

  //$this->drupalPost('admin/config/development/performance', array(), t('Clear all caches'));

  // Create page.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'title' => 'Sharerich page',
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          $this
            ->randomName(64),
        ),
      ),
    ),
    'promote' => 1,
  ));

  // Visit node.
  $this
    ->drupalGet('node/' . $node->nid);
  $text = $this
    ->xpath('//div[@id="block-sharerich-default-set"]//h4/text()')[0];
  $this
    ->assertEqual($text, t('Share this'), 'The title of sharerich block is correct');

  //    $element = $this->xpath('//div[contains(@class, "sharerich-wrapper") and contains(@class, "sharerich-vertical") and contains(@class, "sharerich-sticky")]');
  //    $this->assertTrue(!empty($element), 'Found a sticky sharerich block');
  foreach ($this->services as $item) {
    $text = $this
      ->xpath('//div[@id="block-sharerich-default-set"]//div[@class="item-list"]//ul/li[contains(@class, "' . $item . '")]//span[@class="text"]/text()')[0];
    $this
      ->assertEqual($text, $item, t('The text of :item button is correct', array(
      ':item' => $item,
    )));
  }

  // Test that tokens were rendered correctly.
  $this
    ->assertElementByXPath('//div[@id="block-sharerich-default-set"]//ul/li[contains(@class, :li_class)]/a[contains(@href, :href)]', array(
    ':li_class' => 'email',
    ':href' => 'mailto:?subject=Sharerich%20page&body=http',
  ), "Email Tokens rendered correctly.");
  $this
    ->assertElementByXPath('//div[@id="block-sharerich-default-set"]//ul/li[contains(@class, :li_class)]/a[contains(@href, :href)]', array(
    ':li_class' => 'facebook',
    ':href' => 'https://www.facebook.com/sharer/sharer.php?u=http',
  ), "Facebook Tokens rendered correctly.");
  $this
    ->assertElementByXPath('//div[@id="block-sharerich-default-set"]//ul/li[contains(@class, :li_class)]/a[contains(@href, :href)]', array(
    ':li_class' => 'twitter',
    ':href' => 'https://twitter.com/intent/tweet?url=http',
  ), "Twitter Tokens rendered correctly.");
  $this
    ->assertElementByXPath('//div[@id="block-sharerich-default-set"]//li[contains(@class, :li_class)]/a[contains(@href, :href)]', array(
    ':li_class' => 'block-configure',
    ':href' => '/admin/structure/block/manage/sharerich/default_set/configure?destination=node/' . $node->nid,
  ), "Contextual links is correct.");
}