<?php/** * @file * Tests for the AddThis-module. */classAddThisFunctionalityTestCaseextendsDrupalWebTestCase{private$user;publicfunctionsetUp(){parent::setUp(AddThis::MODULE_NAME);$this->createAndLoginUser();}publicfunctiongetInfo(){returnarray('name'=>'AddThis: Functionality tests','description'=>'Functionality tests for the AddThis-module.','group'=>'AddThis',);}publicfunctiontestFunctionality(){$this->addThisShouldProvideHelp();$this->addThisShouldDefineField();$this->addThisShouldDefineBlock();$this->addThisShouldBeAbleToBeUsedAsField();$this->addThisShouldBeAbleToBeUsedAsBlock();$this->addThisSystemSettingsShouldBeAbleToBeSaved();}privatefunctionaddThisShouldProvideHelp(){$helpText=module_invoke(AddThis::MODULE_NAME,'help','admin/help#addthis',NULL);$this->assertTrue(TestHelper::stringContains($helpText,t('About')),'AddThis-module should provide help.');}privatefunctionaddThisShouldDefineField(){$fieldInfo=module_invoke(AddThis::MODULE_NAME,'field_info');$this->assertTrue(is_array($fieldInfo),t('AddThis-module should define a field.'));}privatefunctionaddThisShouldDefineBlock(){$blockInfo=module_invoke(AddThis::MODULE_NAME,'block_info');$this->assertTrue(is_array($blockInfo),t('AddThis-module should define a block.'));}privatefunctionaddThisShouldBeAbleToBeUsedAsField(){$edit=array();$label=TestHelper::generateRandomLowercaseString();$edit["fields[_add_new_field][label]"]=$label;$edit["fields[_add_new_field][field_name]"]=$label;$edit["fields[_add_new_field][type]"]=AddThis::FIELD_TYPE;$edit["fields[_add_new_field][widget_type]"]=AddThis::WIDGET_TYPE;$this->drupalPost('admin/structure/types/manage/article/fields',$edit,t('Save'));$this->assertText($label,'AddThis-module should be able to be added as a field.');$this->addThisShouldNotHaveConfigurableFieldLevelSettings($label);$this->drupalGet('admin/structure/types/manage/article/display');$this->addThisShouldProvideWidgetTypeCompactButton();$this->addThisShouldProvideWidgetTypeDisabled();$this->addThisShouldProvideWidgetTypeLargeButton();$this->addThisShouldProvideWidgetTypeSharecount();$this->addThisShouldProvideWidgetTypeToolbox();}privatefunctionaddThisShouldNotHaveConfigurableFieldLevelSettings($label){$this->assertText(t("@name has no field settings.",array('@name'=>$label)),'AddThis-module should not have configurable field level settings.');}privatefunctionaddThisShouldProvideWidgetTypeCompactButton(){$this->assertText('Compact button','AddThis-module should provide widget type "Compact button"');}privatefunctionaddThisShouldProvideWidgetTypeDisabled(){$this->assertText('Disabled','AddThis-module should provide widget type "Disabled"');}privatefunctionaddThisShouldProvideWidgetTypeLargeButton(){$this->assertText('Large button','AddThis-module should provide widget type "Large button"');}privatefunctionaddThisShouldProvideWidgetTypeSharecount(){$this->assertText('Sharecount','AddThis-module should provide widget type "Sharecount"');}privatefunctionaddThisShouldProvideWidgetTypeToolbox(){$this->assertText('Toolbox','AddThis-module should provide widget type "Toolbox"');}privatefunctionaddThisShouldBeAbleToBeUsedAsBlock(){$this->drupalGet('admin/structure/block');$this->assertRaw(t('AddThis'),'AddThis should be able to be used as a block.');$this->addThisBlockSettingsShouldBeAbleToBeSaved();}privatefunctionaddThisBlockSettingsShouldBeAbleToBeSaved(){$edit=array();$edit[AddThis::BLOCK_WIDGET_TYPE_KEY]=AddThis::WIDGET_TYPE_COMPACT_BUTTON;$this->drupalPost('admin/structure/block/manage/addthis/addthis_block/configure',$edit,t('Save block'));$this->assertText(t('The block configuration has been saved.'),'AddThis block settings should be able to be saved.');}privatefunctionaddThisSystemSettingsShouldBeAbleToBeSaved(){$edit=array();$profileId=TestHelper::generateRandomLowercaseString();$edit[AddThis::PROFILE_ID_KEY]=$profileId;$servicesCssUrl=AddThis::DEFAULT_SERVICES_CSS_URL;$edit[AddThis::SERVICES_CSS_URL_KEY]=$servicesCssUrl;$servicesJsonUrl=AddThis::DEFAULT_SERVICES_JSON_URL;$edit[AddThis::SERVICES_JSON_URL_KEY]=$servicesJsonUrl;$widgetJsUrl=AddThis::DEFAULT_WIDGET_JS_URL;$edit[AddThis::WIDGET_JS_URL_KEY]=$widgetJsUrl;$uiDelay=400;$edit[AddThis::UI_DELAY_KEY]=$uiDelay;$uiHeaderBackgroundColor='#000000';$edit[AddThis::UI_HEADER_BACKGROUND_COLOR_KEY]=$uiHeaderBackgroundColor;$uiHeaderColor='#ffffff';$edit[AddThis::UI_HEADER_COLOR_KEY]=$uiHeaderColor;$coBrand=TestHelper::generateRandomLowercaseString();$edit[AddThis::CO_BRAND_KEY]=$coBrand;$edit[AddThis::LARGE_ICONS_ENABLED_KEY]=TRUE;$edit[AddThis::COMPLIANT_508_KEY]=TRUE;$edit[AddThis::CLICKBACK_TRACKING_ENABLED_KEY]=TRUE;$edit[AddThis::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY]=TRUE;$edit[AddThis::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY]=TRUE;$edit[AddThis::ADDRESSBOOK_ENABLED_KEY]=TRUE;$edit[AddThis::CLICK_TO_OPEN_COMPACT_MENU_ENABLED_KEY]=TRUE;$edit[AddThis::OPEN_WINDOWS_ENABLED_KEY]=TRUE;$edit[AddThis::STANDARD_CSS_ENABLED_KEY]=TRUE;$edit[AddThis::CUSTOM_CONFIGURATION_CODE_ENABLED_KEY]=TRUE;$customConfigurationCode=TestHelper::generateRandomLowercaseString();$edit[AddThis::CUSTOM_CONFIGURATION_CODE_KEY]=$customConfigurationCode;$serviceName='2linkme';$edit["addthis_enabled_services[$serviceName]"]=$serviceName;$this->drupalPost('admin/config/user-interface/addthis',$edit,t('Save configuration'));$this->assertText(t('The configuration options have been saved.'),'AddThis system settings should be able to be saved.');$this->addThisProfileIdShouldBeAbleToBeSaved($profileId);$this->addThisServicesCssUrlShouldBeAbleToBeSaved($servicesCssUrl);$this->addThisServicesJsonUrlShouldBeAbleToBeSaved($servicesJsonUrl);$this->addThisWidgetJsUrlShouldBeAbleToBeSaved($widgetJsUrl);$this->addThisUiDelayShouldBeAbleToBeSaved($uiDelay);$this->addThisUiHeaderBackgroundColorShouldBeAbleToBeSaved($uiHeaderBackgroundColor);$this->addThisUiHeaderColorShouldBeAbleToBeSaved($uiHeaderColor);$this->addThisCoBrandShouldBeAbleToBeSaved($coBrand);$this->addThisLargeToolboxIconsSettingShouldBeAbleToBeSaved();$this->addThis508CompliantSettingShouldBeAbleToBeSaved();$this->addThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved();$this->addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved();$this->addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved();$this->addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved();$this->addThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved();$this->addThisStandardCssEnabledSettingShouldBeAbleToBeSaved();$this->addThisEnabledServicesShouldBeAbleToBeSaved($serviceName);$this->addThisCustomConfigurationCodeEnabledSettingShouldBeAbleToBeSaved();}privatefunctionaddThisProfileIdShouldBeAbleToBeSaved($profileId){$this->assertFieldByName(AddThis::PROFILE_ID_KEY,$profileId,'AddThis profile ID should be able to be saved.');}privatefunctionaddThisServicesCssUrlShouldBeAbleToBeSaved($servicesCssUrl){$this->assertFieldByName(AddThis::SERVICES_CSS_URL_KEY,$servicesCssUrl,'AddThis services stylesheet URL should be able to be saved.');}privatefunctionaddThisServicesJsonUrlShouldBeAbleToBeSaved($servicesJsonUrl){$this->assertFieldByName(AddThis::SERVICES_JSON_URL_KEY,$servicesJsonUrl,'AddThis services json URL should be able to be saved.');}privatefunctionaddThisWidgetJsUrlShouldBeAbleToBeSaved($widgetJsUrl){$this->assertFieldByName(AddThis::WIDGET_JS_URL_KEY,$widgetJsUrl,'AddThis javascript widget URL should be able to be saved.');}privatefunctionaddThisLargeToolboxIconsSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-large-icons-enabled','AddThis large toolbox icons setting should be able to be saved.');}privatefunctionaddThis508CompliantSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-508-compliant','AddThis 508 compliant setting should be able to be saved.');}privatefunctionaddThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-clickback-tracking-enabled','AddThis clickback tracking enabled setting should be able to be saved.');}privatefunctionaddThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled','AddThis Google Analytics tracking enabled setting should be able to be saved.');}privatefunctionaddThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled','AddThis Google Analytics social tracking enabled setting should be able to be saved.');}privatefunctionaddThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-click-to-open-compact-menu-enabled','AddThis click to open compact menu setting should be able to be saved.');}privatefunctionaddThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-open-windows-enabled','AddThis open windows setting should be able to be saved.');}privatefunctionaddThisStandardCssEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-open-windows-enabled','AddThis open windows setting should be able to be saved.');}privatefunctionaddThisFacebookLikeEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-facebook-like-enabled','AddThis Facebook Like enabled setting should be able to be saved.');}privatefunctionaddThisGooglePlusOneEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-google-plus-one-enabled','AddThis Google +1 enabled setting should be able to be saved.');}privatefunctionaddThisTwitterEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-twitter-enabled','AddThis Twitter enabled setting should be able to be saved.');}privatefunctionaddThisAddressbookEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-addressbook-enabled','AddThis addressbook enabled setting should be able to be saved.');}privatefunctionaddThisNumberOfPreferredServicesShouldBeAbleToBeSaved($numberOfPreferredServices){$this->assertFieldByName(AddThis::NUMBER_OF_PREFERRED_SERVICES_KEY,$numberOfPreferredServices,'The number of preferred services should be able to be saved.');}privatefunctionaddThisCustomConfigurationCodeEnabledSettingShouldBeAbleToBeSaved(){$this->assertFieldChecked('edit-addthis-custom-configuration-code-enabled','AddThis custom configuration code enabled setting should be able to be saved.');}privatefunctionaddThisCustomConfigurationCodeShouldBeAbleToBeSaved($customConfigurationCode){$this->assertFieldByName(AddThis::CUSTOM_CONFIGURATION_CODE_KEY,$customConfigurationCode,'AddThis custom configuration code should be able to be saved.');}privatefunctionaddThisUiHeaderColorShouldBeAbleToBeSaved($uiHeaderColor){$this->assertFieldByName(AddThis::UI_HEADER_COLOR_KEY,$uiHeaderColor,'AddThis UI header color should be able to be saved.');}privatefunctionaddThisUiDelayShouldBeAbleToBeSaved($uiDelay){$this->assertFieldByName(AddThis::UI_DELAY_KEY,$uiDelay,'AddThis UI delay should be able to be saved.');}privatefunctionaddThisUiHeaderBackgroundColorShouldBeAbleToBeSaved($uiHeaderBackgroundColor){$this->assertFieldByName(AddThis::UI_HEADER_BACKGROUND_COLOR_KEY,$uiHeaderBackgroundColor,'AddThis UI header background color should be able to be saved.');}privatefunctionaddThisCoBrandShouldBeAbleToBeSaved($coBrand){$this->assertFieldByName(AddThis::CO_BRAND_KEY,$coBrand,'AddThis co-brand should be able to be saved.');}privatefunctionaddThisEnabledServicesShouldBeAbleToBeSaved($serviceName){$this->assertFieldChecked('edit-addthis-enabled-services-'.$serviceName,'AddThis enabled services should be able to be saved.');}privatefunctioncreateAndLoginUser(){$this->user=$this->createAdminUser();$this->drupalLogin($this->user);}privatefunctioncreateAdminUser(){return$this->drupalCreateUser(array(AddThis::PERMISSION_ADMINISTER_ADDTHIS,AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS,'administer blocks','administer content types','administer nodes'));}}classAddThisPermissionsTestCaseextendsDrupalWebTestCase{publicfunctionsetUp(){parent::setUp(AddThis::MODULE_NAME);}publicfunctiongetInfo(){returnarray('name'=>'AddThis: Permission tests','description'=>'Permission tests for the AddThis-module.','group'=>'AddThis',);}publicfunctiontestUserWithoutAdministerAddThisPermissionShouldNotBeAllowedToAccessAddThisSystemSettings(){$this->drupalLogin($this->createAdminUserWithoutAddThisAdministrationPermission());$this->drupalGet('admin/config/system/addthis');$this->assertRaw(t('Access denied'),'A user without administer addthis permission should not be able to access AddThis system settings.');}publicfunctiontestUserWithoutAdministerAdvancedAddThisPermissionShouldNotBeAllowedToAccessAdvancedAddThisSystemSettings(){$this->drupalLogin($this->createAdminUserWithoutAdvancedAddThisAdministrationPermission());$this->drupalGet('admin/config/system/addthis');$this->assertNoRaw(t('Advanced settings'),'A user without administer advanced addthis permission should not be able to access advanced AddThis system settings.');}privatefunctioncreateAdminUserWithoutAddThisAdministrationPermission(){return$this->drupalCreateUser(array('administer content types'));}privatefunctioncreateAdminUserWithoutAdvancedAddThisAdministrationPermission(){return$this->drupalCreateUser(array('administer content types',AddThis::PERMISSION_ADMINISTER_ADDTHIS));}}classTestHelper{publicstaticfunctionstringContains($string,$contains){returnstrpos($string,$contains)!==FALSE;}publicstaticfunctiongenerateRandomLowercaseString(){returndrupal_strtolower(DrupalWebTestCase::randomName());}}