View source
<?php
namespace Drupal\Tests\sharemessage\Functional;
class ShareMessageSettingsTest extends ShareMessageTestBase {
public function testShareMessageSettings() {
$this
->drupalGet('admin/config/services/sharemessage/addthis-settings');
$default_settings = [
'default_services[]' => [
'facebook',
'facebook_like',
],
'default_additional_services' => FALSE,
'default_icon_style' => 'addthis_16x16_style',
];
$this
->drupalPostForm(NULL, $default_settings, t('Save configuration'));
$this
->drupalGet('admin/config/services/sharemessage/add');
$sharemessage = [
'label' => 'Share Message Test Label',
'id' => 'sharemessage_test_label',
'settings[override_default_settings]' => 1,
'settings[services][]' => [
'facebook',
],
'settings[additional_services]' => 1,
'settings[icon_style]' => 'addthis_32x32_style',
];
$this
->drupalPostForm(NULL, $sharemessage, t('Save'));
$this
->assertText(t('Share Message @label has been added.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('sharemessage-test/sharemessage_test_label');
$raw_html_services = '<a class="addthis_button_facebook_like"></a>';
$raw_html_additional_services = '<a class="addthis_button_compact"></a>';
$this
->assertNoRaw($raw_html_services, 'Facebook like button that is globally enabled is not displayed on the page, so that the global settings are overridden.');
$this
->assertRaw($raw_html_additional_services, 'Additional services button is displayed, so that the global settings are overridden.');
$this
->assertShareButtons($sharemessage, $sharemessage['settings[icon_style]'], TRUE);
$this
->drupalGet('admin/config/services/sharemessage/manage/' . $sharemessage['id']);
$edit = [
'settings[override_default_settings]' => FALSE,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText(t('Share Message @label has been updated.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('sharemessage-test/sharemessage_test_label');
$this
->assertRaw($raw_html_services, 'Facebook like button is displayed as it is globally configured.');
$this
->assertNoRaw($raw_html_additional_services, 'Additional services button is not displayed as it is globally configured.');
$this
->assertShareButtons($sharemessage, $default_settings['default_icon_style'], TRUE);
$this
->drupalGet('admin/config/services/sharemessage/sharrre-settings');
$this
->assertNoText('Either set the library locally (in /libraries/sharrre) and enable the libraries module or enter the remote URL on Sharrre settings page.');
$this
->assertNoLinkByHref('admin/config/services/sharemessage/sharrre-settings');
$settings_without_url = [
'default_services[]' => [
'googlePlus',
],
'library_url' => '',
];
$this
->drupalPostForm(NULL, $settings_without_url, t('Save configuration'));
$this
->assertText('The configuration options have been saved.');
$this
->assertText('Either set the library locally (in /libraries/sharrre) and enable the libraries module or enter the remote URL on Sharrre settings page.');
$this
->assertLinkByHref('admin/config/services/sharemessage/sharrre-settings');
$this
->drupalGet('admin/config/services/sharemessage/sharrre-settings');
$settings_with_wrong_url = [
'default_services[]' => [
'googlePlus',
],
'library_url' => 'test/sharrre.js',
];
$this
->drupalPostForm(NULL, $settings_with_wrong_url, t('Save configuration'));
$this
->assertText('The configuration options have been saved.');
$this
->assertText('The remote URL is unexpected. Please, provide the correct URL to the minimized version of the library found on Sharrre CDN.');
$default_settings = [
'default_services[]' => [
'googlePlus',
'facebook',
'twitter',
'linkedin',
'pinterest',
],
'library_url' => '//cdn.jsdelivr.net/sharrre/1.3.4/jquery.sharrre-1.3.4.min.js',
'shorter_total' => TRUE,
'enable_hover' => TRUE,
'enable_counter' => FALSE,
];
$this
->drupalPostForm(NULL, $default_settings, t('Save configuration'));
$this
->drupalGet('admin/config/services/sharemessage');
$this
->clickLink('Edit');
$sharemessage = [
'label' => 'Share Message Sharrre Test Label',
'plugin' => 'sharrre',
'title' => 'Sharrre',
'message_long' => 'Test long message',
'message_short' => 'Test short message',
];
$this
->drupalPostForm(NULL, $sharemessage, t('Save'));
$this
->assertText(t('Share Message @label has been updated.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('sharemessage-test/sharemessage_test_label');
$this
->assertRaw('"library_url":"\\/\\/cdn.jsdelivr.net\\/sharrre\\/1.3.4\\/jquery.sharrre-1.3.4.min.js"');
$this
->assertRaw('"googlePlus":"googlePlus","facebook":"facebook","twitter":"twitter","linkedin":"linkedin","pinterest":"pinterest"');
$this
->drupalGet('admin/config/services/sharemessage/sharrre-settings');
$settings_with_wrong_library_naming = [
'default_services[]' => [
'facebook',
],
'library_url' => '//cdn.jsdelivr.net/sharrre/1.3.4/jquery.sharrre.js',
];
$this
->drupalPostForm(NULL, $settings_with_wrong_library_naming, t('Save configuration'));
$this
->assertText('The configuration options have been saved.');
$this
->assertText('The naming of the library is unexpected. Double check that this is the real Sharrre library. The URL for the minimized version of the library can be found on Sharrre CDN.');
$settings_with_correct_library_naming = [
'default_services[]' => [
'facebook',
],
'library_url' => '//cdn.jsdelivr.net/sharrre/1.3.4/jquery.sharrre-10.130.1234.min.js',
];
$this
->drupalPostForm(NULL, $settings_with_correct_library_naming, t('Save configuration'));
$this
->assertText('The configuration options have been saved.');
$this
->assertNoText('The naming of the library is unexpected. Double check that this is the real Sharrre library. The URL for the minimized version of the library can be found on Sharrre CDN.');
$this
->drupalGet('/sharemessage/sharrre/counter', [
'query' => [
'url' => 'https://www.drupal.org/',
'type' => 'stumbleupon',
],
]);
$json_content = json_decode($this
->getSession()
->getPage()
->getContent(), TRUE);
$this
->assertTrue(isset($json_content['count']), 'stumbleupon count found and has a non-zero value: ' . $json_content['count']);
$this
->drupalGet('admin/config/services/sharemessage/socialshareprivacy-settings');
$default_settings = [
'services[]' => [
'gplus',
'twitter',
],
];
$this
->drupalPostForm(NULL, $default_settings, t('Save configuration'));
$this
->drupalGet('admin/config/services/sharemessage/add');
$sharemessage = [
'label' => 'Social Share Privacy Test Label',
'id' => 'socialshareprivacy_test_label',
'settings[override_default_settings]' => 1,
'settings[services][]' => [
'facebook',
],
'plugin' => 'socialshareprivacy',
];
$this
->drupalPostForm(NULL, $sharemessage, t('Save'));
$this
->assertText(t('Share Message @label has been added.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('sharemessage-test/socialshareprivacy_test_label');
$this
->assertRaw('"facebook":{"status":true');
$this
->drupalGet('admin/config/services/sharemessage/manage/' . $sharemessage['id']);
$edit = [
'settings[override_default_settings]' => FALSE,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText(t('Share Message @label has been updated.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('sharemessage-test/socialshareprivacy_test_label');
$this
->assertRaw('"gplus":{"status":true');
$this
->assertRaw('"twitter":{"status":true');
$this
->assertRaw('"facebook":{"status":false');
$this
->drupalGet('admin/config/services/sharemessage/sharemessage-settings');
$edit = [
'add_twitter_card' => TRUE,
'twitter_user' => 'fancy_twitter_name',
];
$this
->drupalPostForm(NULL, $edit, t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
$this
->assertFieldByName('add_twitter_card', TRUE);
$this
->assertFieldByName('twitter_user', 'fancy_twitter_name');
}
function testShareMessageDeleteCancel() {
$this
->drupalGet('admin/config/services/sharemessage/add');
$sharemessage = [
'label' => 'Share Message Test Label',
'id' => 'sharemessage_test_label',
'settings[override_default_settings]' => 1,
'settings[services][]' => [
'facebook',
],
'settings[additional_services]' => 1,
'settings[icon_style]' => 'addthis_32x32_style',
];
$this
->drupalPostForm(NULL, $sharemessage, t('Save'));
$this
->drupalGet('admin/config/services/sharemessage');
$this
->assertText($sharemessage['label'], 'Newly created sharemessage found.');
$this
->assertLink('Edit');
$this
->assertLink('Delete');
$this
->clickLink('Delete');
$this
->assertText(t('Are you sure you want to delete the share message @label?', [
'@label' => $sharemessage['label'],
]));
$this
->assertLink('Cancel');
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertText(t('The share message @label has been deleted.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('admin/config/services/sharemessage');
$this
->assertNoText($sharemessage['label'], 'Not found the deleted message.');
}
public function testShareMessageSpecialCharsEncoding() {
$this
->drupalGet('admin/config/services/sharemessage/add');
$sharemessage = [
'label' => 'Special characters encoding test',
'id' => 'sharemessage_test_special_chars',
'plugin' => 'addthis',
'title' => 'Inondations sur la Côte d\'Azur: «C’est apocalyptique, c’est Tchernobyl»',
'message_long' => 'Long description',
'message_short' => 'Short description',
];
$this
->drupalPostForm(NULL, $sharemessage, t('Save'));
$this
->assertText(t('Share Message @label has been added.', [
'@label' => $sharemessage['label'],
]));
$this
->drupalGet('sharemessage-test/sharemessage_test_special_chars');
$this
->assertOGTags('og:title', 'Inondations sur la Côte d'Azur: «C’est apocalyptique, c’est Tchernobyl»');
$this
->assertNoOGTags('og:title', 'Inondations sur la Côte d\'Azur: «C’est apocalyptique, c’est Tchernobyl»');
$this
->assertOGTags('og:url', $this
->getUrl());
$this
->assertOGTags('og:description', 'Long description');
$this
->assertOGTags('og:type', 'website');
$this
->drupalGet('admin/config/services/sharemessage/add');
$sharemessage2 = [
'label' => 'Special characters encoding test 2',
'id' => 'sharemessage_test_special_chars_2',
'plugin' => 'addthis',
'title' => 'This is a second test with quotes "',
'message_long' => 'Long description 2',
'message_short' => 'Short description 2',
];
$this
->drupalPostForm(NULL, $sharemessage2, t('Save'));
$this
->drupalGet('sharemessage-test/sharemessage_test_special_chars_2');
$this
->assertOGTags('og:title', 'This is a second test with quotes "');
$this
->assertNoOGTags('og:title', 'This is a second test with quotes "');
}
}