View source
<?php
namespace Drupal\Tests\sharethis\Functional;
use Drupal\Tests\node\Functional\NodeTestBase;
class SharethisBlockTest extends NodeTestBase {
protected $defaultTheme = 'classy';
public static $modules = [
'node',
'system_test',
'block',
'user',
'sharethis',
'menu_ui',
];
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer blocks',
'administer site configuration',
'access administration pages',
'administer sharethis',
'administer nodes',
]);
$this
->drupalLogin($admin_user);
}
public function testSharethisBlock() {
$edit['location'] = 'block';
$this
->drupalPostForm('admin/config/services/sharethis', $edit, t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
\Drupal::service('theme_installer')
->install([
'bartik',
'seven',
'stark',
]);
$theme_settings = $this
->config('system.theme');
foreach ([
'bartik',
'seven',
'stark',
] as $theme) {
$this
->drupalGet('admin/structure/block/list/' . $theme);
$block = [];
$block['id'] = strtolower($this
->randomMachineName());
$block['theme'] = $theme;
$block['region'] = 'content';
$this
->drupalPostForm('admin/structure/block/add/sharethis_block', $block, t('Save block'));
$this
->assertText(t('The block configuration has been saved.'));
$theme_settings
->set('default', $theme)
->save();
$this
->drupalGet('');
$result = $this
->xpath('//div[@class=:class]', [
':class' => 'sharethis-wrapper',
]);
$this
->assertEqual(count($result), 1, 'Sharethis links found');
}
}
}