summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJani Palsamäki2011-06-17 10:06:50 (GMT)
committer Jani Palsamäki2011-06-17 10:06:50 (GMT)
commit87bc3b42cdebb717099842d1fbd1a1838c508e7f (patch)
tree168eb0edc15400566c942fe5e26036d642ed5287
parentd523e7b44b48f2a67673464da6491c0c76e72621 (diff)
- Enabled services can now be configured (global setting)
- Added tests - Added some check_plain()-calls
-rw-r--r--addthis.module2
-rw-r--r--addthis.test16
-rw-r--r--classes/AddThis.php25
-rw-r--r--classes/MarkupGenerator.php2
4 files changed, 40 insertions, 5 deletions
diff --git a/addthis.module b/addthis.module
index a15e408..4271d23 100644
--- a/addthis.module
+++ b/addthis.module
@@ -156,6 +156,7 @@ function addthis_field_formatter_settings_summary($field, $instance, $view_mode)
* Implements hook_field_formatter_view().
*/
function addthis_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
+ AddThis::addConfigurationOptionsJs();
$element = array();
foreach ($items as $delta => $item) {
@@ -163,7 +164,6 @@ function addthis_field_formatter_view($entity_type, $entity, $field, $instance,
$markup = AddThis::getWidgetMarkup($widgetType, $entity);
$element[$delta] = array('#markup' => $markup);
}
-
return $element;
}
diff --git a/addthis.test b/addthis.test
index 88225b6..03d873b 100644
--- a/addthis.test
+++ b/addthis.test
@@ -126,10 +126,24 @@ class AddThisFunctionalityTestCase extends DrupalWebTestCase {
$edit = array();
$profileId = TestHelper::generateRandomLowercaseString();
$edit[AddThis::PROFILE_ID_KEY] = $profileId;
+ $serviceName = '2linkme';
+ $edit["addthis_enabled_services[$serviceName]"] = $serviceName;
$this->drupalPost('admin/config/system/addthis', $edit, t('Save configuration'));
- $this->assertText(t('The configuration options have been saved.'));
+ $this->assertText(t('The configuration options have been saved.'), 'AddThis system settings should be able to be saved.');
+
+ $this->addThisProfileIdShouldBeAbleToBeSaved($profileId);
+
+ $this->addThisEnabledServicesShouldBeAbleToBeSaved($serviceName);
+ }
+
+ private function addThisProfileIdShouldBeAbleToBeSaved($profileId) {
+ $this->assertFieldByName(AddThis::PROFILE_ID_KEY, $profileId, 'AddThis profile ID should be able to be saved.');
+ }
+
+ private function addThisEnabledServicesShouldBeAbleToBeSaved($serviceName) {
+ $this->assertFieldChecked('edit-addthis-enabled-services-' . $serviceName, 'AddThis enabled services should be able to be saved.');
}
private function createAndLoginUser() {
diff --git a/classes/AddThis.php b/classes/AddThis.php
index b3c142b..d9fecc9 100644
--- a/classes/AddThis.php
+++ b/classes/AddThis.php
@@ -120,6 +120,27 @@ class AddThis {
drupal_add_css(self::getAdminCssFilePath(), 'file');
}
+ public static function addConfigurationOptionsJs() {
+ $enabledServices = self::getServiceNamesAsCommaSeparatedString();
+ drupal_add_js("var addthis_config = {services_compact: '"
+ . $enabledServices
+ . "more', services_expanded: '"
+ . $enabledServices
+ . "more'}", 'inline'
+ );
+ }
+
+ private static function getServiceNamesAsCommaSeparatedString() {
+ $enabledServiceNames = array_values(self::getEnabledServices());
+ $enabledServicesAsCommaSeparatedString = '';
+ foreach ($enabledServiceNames as $enabledServiceName) {
+ if ($enabledServiceName != '0') {
+ $enabledServicesAsCommaSeparatedString .= $enabledServiceName . ',';
+ }
+ }
+ return $enabledServicesAsCommaSeparatedString;
+ }
+
private static function getAdminCssFilePath() {
return drupal_get_path('module', self::MODULE_NAME) . '/' . self::ADMIN_CSS_FILE;
}
@@ -131,8 +152,8 @@ class AddThis {
$services = $json->decode(self::SERVICES_JSON_URL);
if ($services != NULL) {
foreach ($services['data'] AS $service) {
- $serviceCode = $service['code'];
- $serviceName = $service['name'];
+ $serviceCode = check_plain($service['code']);
+ $serviceName = check_plain($service['name']);
$rows[$serviceCode] = '<span class="addthis_service_icon icon_' . $serviceCode . '"></span> ' . $serviceName;
}
}
diff --git a/classes/MarkupGenerator.php b/classes/MarkupGenerator.php
index 3ff7e5a..084ce32 100644
--- a/classes/MarkupGenerator.php
+++ b/classes/MarkupGenerator.php
@@ -9,6 +9,6 @@
class MarkupGenerator {
public static function generateAttribute($name, $value) {
- return $name != NULL && $value != NULL ? $name . '="' . $value . '"' : '';
+ return $name != NULL && $value != NULL ? check_plain($name) . '="' . $value . '"' : '';
}
}