Projet

Général

Profil

Paste
Télécharger (13,1 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / addthis / addthis.test @ a5572547

1
<?php
2

    
3
/**
4
 * @file
5
 * Tests for the AddThis-module.
6
 */
7

    
8
class AddThisFunctionalityTestCase extends DrupalWebTestCase {
9

    
10
  private $user;
11

    
12
  public function setUp() {
13
    parent::setUp(AddThis::MODULE_NAME);
14
    $this->createAndLoginUser();
15
  }
16

    
17
  public static function getInfo() {
18
    return array(
19
      'name' => 'AddThis: Functionality tests',
20
      'description' => 'Functionality tests for the AddThis-module.',
21
      'group' => 'AddThis',
22
    );
23
  }
24

    
25
  public function testFunctionality() {
26
    $this->addThisShouldProvideHelp();
27

    
28
    $this->addThisShouldDefineField();
29

    
30
    $this->addThisShouldDefineBlock();
31

    
32
    $this->addThisShouldBeAbleToBeUsedAsField();
33

    
34
    $this->addThisSystemSettingsShouldBeAbleToBeSaved();
35
  }
36

    
37
  private function addThisShouldProvideHelp() {
38
    $helpText = module_invoke(AddThis::MODULE_NAME, 'help', 'admin/help#addthis', NULL);
39
    $this->assertTrue(TestHelper::stringContains($helpText, t('About')), 'AddThis-module should provide help.');
40
  }
41

    
42
  private function addThisShouldDefineField() {
43
    $fieldInfo = module_invoke(AddThis::MODULE_NAME, 'field_info');
44
    $this->assertTrue(is_array($fieldInfo), t('AddThis-module should define a field.'));
45
  }
46

    
47
  private function addThisShouldDefineBlock() {
48
    $blockInfo = module_invoke(AddThis::MODULE_NAME, 'block_info');
49
    $this->assertTrue(is_array($blockInfo), t('AddThis-module should define a block.'));
50
  }
51

    
52
  private function addThisShouldBeAbleToBeUsedAsField() {
53
    $edit = array();
54
    $label = TestHelper::generateRandomLowercaseString();
55
    $edit["fields[_add_new_field][label]"] = $label;
56
    $edit["fields[_add_new_field][field_name]"] = $label;
57
    $edit["fields[_add_new_field][type]"] = AddThis::FIELD_TYPE;
58
    $edit["fields[_add_new_field][widget_type]"] = AddThis::WIDGET_TYPE;
59

    
60
    $this->drupalPost('admin/structure/types/manage/article/fields', $edit, t('Save'));
61

    
62
    $this->assertText($label, 'AddThis-module should be able to be added as a field.');
63

    
64
    $this->addThisShouldNotHaveConfigurableFieldLevelSettings($label);
65

    
66
    $this->drupalGet('admin/structure/types/manage/article/display');
67
  }
68

    
69
  private function addThisShouldNotHaveConfigurableFieldLevelSettings($label) {
70
    $this->assertText(t("@name has no field settings.", array('@name' => $label)),
71
                     'AddThis-module should not have configurable field level settings.');
72
  }
73

    
74
  private function addThisSystemSettingsShouldBeAbleToBeSaved() {
75
    $edit_basic = array();
76

    
77
    // Basic settings
78
    $profileId = TestHelper::generateRandomLowercaseString();
79
    $edit_basic[AddThis::PROFILE_ID_KEY] = $profileId;
80

    
81
    $uiDelay = 400;
82
    $edit_basic[AddThis::UI_DELAY_KEY] = $uiDelay;
83

    
84
    $uiHeaderBackgroundColor = '#000000';
85
    $edit_basic[AddThis::UI_HEADER_BACKGROUND_COLOR_KEY] = $uiHeaderBackgroundColor;
86

    
87
    $uiHeaderColor = '#ffffff';
88
    $edit_basic[AddThis::UI_HEADER_COLOR_KEY] = $uiHeaderColor;
89

    
90
    $coBrand = TestHelper::generateRandomLowercaseString();
91
    $edit_basic[AddThis::CO_BRAND_KEY] = $coBrand;
92

    
93
    $edit_basic[AddThis::COMPLIANT_508_KEY] = TRUE;
94

    
95
    $edit_basic[AddThis::CLICKBACK_TRACKING_ENABLED_KEY] = TRUE;
96

    
97
    // Can only be tested with Google Analytics module installed.
98
    //$edit_basic[AddThis::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY] = TRUE;
99

    
100
    //$edit_basic[AddThis::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY] = TRUE;
101

    
102
    $edit_basic[AddThis::ADDRESSBOOK_ENABLED_KEY] = TRUE;
103

    
104
    $edit_basic[AddThis::CLICK_TO_OPEN_COMPACT_MENU_ENABLED_KEY] = TRUE;
105

    
106
    $edit_basic[AddThis::OPEN_WINDOWS_ENABLED_KEY] = TRUE;
107

    
108
    $edit_basic[AddThis::STANDARD_CSS_ENABLED_KEY] = TRUE;
109

    
110
    $serviceName = '2linkme';
111
    $edit_basic["addthis_enabled_services[$serviceName]"] = $serviceName;
112

    
113
    $this->drupalPost('admin/config/user-interface/addthis', $edit_basic, t('Save configuration'));
114

    
115
    $this->assertText(t('The configuration options have been saved.'), 'AddThis system settings should be able to be saved.');
116

    
117
    $this->addThisProfileIdShouldBeAbleToBeSaved($profileId);
118

    
119
    $this->addThisUiDelayShouldBeAbleToBeSaved($uiDelay);
120

    
121
    $this->addThisUiHeaderBackgroundColorShouldBeAbleToBeSaved($uiHeaderBackgroundColor);
122

    
123
    $this->addThisUiHeaderColorShouldBeAbleToBeSaved($uiHeaderColor);
124

    
125
    $this->addThisCoBrandShouldBeAbleToBeSaved($coBrand);
126

    
127
    $this->addThis508CompliantSettingShouldBeAbleToBeSaved();
128

    
129
    $this->addThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved();
130

    
131
    // Can only be tested with Google Analytics module installed.
132
    //$this->addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved();
133

    
134
    //$this->addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved();
135

    
136
    $this->addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved();
137

    
138
    $this->addThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved();
139

    
140
    $this->addThisStandardCssEnabledSettingShouldBeAbleToBeSaved();
141

    
142
    $this->addThisEnabledServicesShouldBeAbleToBeSaved($serviceName);
143

    
144
    // Advanced configuration
145
    $edit_basic = array();
146

    
147
    $servicesCssUrl = AddThis::DEFAULT_SERVICES_CSS_URL;
148
    $edit_basic[AddThis::SERVICES_CSS_URL_KEY] = $servicesCssUrl;
149

    
150
    $servicesJsonUrl = AddThis::DEFAULT_SERVICES_JSON_URL;
151
    $edit_basic[AddThis::SERVICES_JSON_URL_KEY] = $servicesJsonUrl;
152

    
153
    $widgetJsUrl = AddThis::DEFAULT_WIDGET_JS_URL;
154
    $edit_basic[AddThis::WIDGET_JS_URL_KEY] = $widgetJsUrl;
155

    
156
    $edit_basic[AddThis::CUSTOM_CONFIGURATION_CODE_ENABLED_KEY] = TRUE;
157

    
158
    $customConfigurationCode = TestHelper::generateRandomLowercaseString();
159
    $edit_basic[AddThis::CUSTOM_CONFIGURATION_CODE_KEY] = $customConfigurationCode;
160

    
161
    $this->drupalPost('admin/config/user-interface/addthis/advanced', $edit_basic, t('Save configuration'));
162

    
163
    $this->addThisServicesCssUrlShouldBeAbleToBeSaved($servicesCssUrl);
164

    
165
    $this->addThisServicesJsonUrlShouldBeAbleToBeSaved($servicesJsonUrl);
166

    
167
    $this->addThisWidgetJsUrlShouldBeAbleToBeSaved($widgetJsUrl);
168

    
169
    $this->addThisCustomConfigurationCodeEnabledSettingShouldBeAbleToBeSaved();
170
  }
171

    
172
  private function addThisProfileIdShouldBeAbleToBeSaved($profileId) {
173
    $this->assertFieldByName(AddThis::PROFILE_ID_KEY, $profileId, 
174
                             'AddThis profile ID should be able to be saved.');
175
  }
176

    
177
  private function addThisServicesCssUrlShouldBeAbleToBeSaved($servicesCssUrl) {
178
    $this->assertFieldByName(AddThis::SERVICES_CSS_URL_KEY, $servicesCssUrl,
179
                             'AddThis services stylesheet URL should be able to be saved.');
180
  }
181

    
182
  private function addThisServicesJsonUrlShouldBeAbleToBeSaved($servicesJsonUrl) {
183
    $this->assertFieldByName(AddThis::SERVICES_JSON_URL_KEY, $servicesJsonUrl,
184
                             'AddThis services json URL should be able to be saved.');
185
  }
186

    
187
  private function addThisWidgetJsUrlShouldBeAbleToBeSaved($widgetJsUrl) {
188
    $this->assertFieldByName(AddThis::WIDGET_JS_URL_KEY, $widgetJsUrl,
189
                             'AddThis javascript widget URL should be able to be saved.');
190
  }
191

    
192
  private function addThis508CompliantSettingShouldBeAbleToBeSaved() {
193
    $this->assertFieldChecked('edit-addthis-508-compliant',
194
                              'AddThis 508 compliant setting should be able to be saved.');
195
  }
196

    
197
  private function addThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved() {
198
    $this->assertFieldChecked('edit-addthis-clickback-tracking-enabled',
199
                              'AddThis clickback tracking enabled setting should be able to be saved.');
200
  }
201

    
202
  private function addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved() {
203
    $this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled',
204
                              'AddThis Google Analytics tracking enabled setting should be able to be saved.');
205
  }
206

    
207
  private function addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved() {
208
    $this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled',
209
                              'AddThis Google Analytics social tracking enabled setting should be able to be saved.');
210
  }
211

    
212
  private function addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved() {
213
    $this->assertFieldChecked('edit-addthis-click-to-open-compact-menu-enabled',
214
                              'AddThis click to open compact menu setting should be able to be saved.');
215
  }
216

    
217
  private function addThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved() {
218
    $this->assertFieldChecked('edit-addthis-open-windows-enabled',
219
                              'AddThis open windows setting should be able to be saved.');
220
  }
221

    
222
  private function addThisStandardCssEnabledSettingShouldBeAbleToBeSaved() {
223
    $this->assertFieldChecked('edit-addthis-open-windows-enabled',
224
                              'AddThis open windows setting should be able to be saved.');
225
  }
226

    
227
  private function addThisFacebookLikeEnabledSettingShouldBeAbleToBeSaved() {
228
    $this->assertFieldChecked('edit-addthis-facebook-like-enabled',
229
                              'AddThis Facebook Like enabled setting should be able to be saved.');
230
  }
231

    
232
  private function addThisAddressbookEnabledSettingShouldBeAbleToBeSaved() {
233
    $this->assertFieldChecked('edit-addthis-addressbook-enabled',
234
                              'AddThis addressbook enabled setting should be able to be saved.');
235
  }
236

    
237
  private function addThisCustomConfigurationCodeEnabledSettingShouldBeAbleToBeSaved() {
238
    $this->assertFieldChecked('edit-addthis-custom-configuration-code-enabled',
239
                              'AddThis custom configuration code enabled setting should be able to be saved.');
240
  }
241

    
242
  private function addThisCustomConfigurationCodeShouldBeAbleToBeSaved($customConfigurationCode) {
243
    $this->assertFieldByName(AddThis::CUSTOM_CONFIGURATION_CODE_KEY, $customConfigurationCode,
244
                             'AddThis custom configuration code should be able to be saved.');
245
  }
246

    
247
  private function addThisUiHeaderColorShouldBeAbleToBeSaved($uiHeaderColor) {
248
    $this->assertFieldByName(AddThis::UI_HEADER_COLOR_KEY, $uiHeaderColor,
249
                             'AddThis UI header color should be able to be saved.');
250
  }
251

    
252
  private function addThisUiDelayShouldBeAbleToBeSaved($uiDelay) {
253
    $this->assertFieldByName(AddThis::UI_DELAY_KEY, $uiDelay,
254
                             'AddThis UI delay should be able to be saved.');
255
  }
256

    
257
  private function addThisUiHeaderBackgroundColorShouldBeAbleToBeSaved($uiHeaderBackgroundColor) {
258
    $this->assertFieldByName(AddThis::UI_HEADER_BACKGROUND_COLOR_KEY, $uiHeaderBackgroundColor,
259
                             'AddThis UI header background color should be able to be saved.');
260
  }
261

    
262
  private function addThisCoBrandShouldBeAbleToBeSaved($coBrand) {
263
    $this->assertFieldByName(AddThis::CO_BRAND_KEY, $coBrand,
264
                             'AddThis co-brand should be able to be saved.');
265
  }
266

    
267
  private function addThisEnabledServicesShouldBeAbleToBeSaved($serviceName) {
268
    $this->assertFieldChecked('edit-addthis-enabled-services-' . $serviceName,
269
                              'AddThis enabled services should be able to be saved.');
270
  }
271

    
272
  private function createAndLoginUser() {
273
    $this->user = $this->createAdminUser();
274
    $this->drupalLogin($this->user);
275
  }
276

    
277
  private function createAdminUser() {
278
    return $this->drupalCreateUser(
279
      array(
280
        AddThis::PERMISSION_ADMINISTER_ADDTHIS,
281
        AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS,
282
        'administer blocks',
283
        'administer content types',
284
        'administer nodes'
285
      )
286
    );
287
  }
288
}
289

    
290
class AddThisPermissionsTestCase extends DrupalWebTestCase {
291

    
292
  public function setUp() {
293
    parent::setUp(AddThis::MODULE_NAME);
294
  }
295

    
296
  public static function getInfo() {
297
    return array(
298
      'name' => 'AddThis: Permission tests',
299
      'description' => 'Permission tests for the AddThis-module.',
300
      'group' => 'AddThis',
301
    );
302
  }
303

    
304
  public function testUserWithoutAdministerAddThisPermissionShouldNotBeAllowedToAccessAddThisSystemSettings() {
305
    $this->drupalLogin($this->createAdminUserWithoutAddThisAdministrationPermission());
306
    $this->drupalGet('admin/config/system/addthis');
307
    $this->assertRaw(t('Access denied'),
308
                     'A user without administer addthis permission should not be able to access AddThis system settings.');
309
  }
310

    
311
  public function testUserWithoutAdministerAdvancedAddThisPermissionShouldNotBeAllowedToAccessAdvancedAddThisSystemSettings() {
312
    $this->drupalLogin($this->createAdminUserWithoutAdvancedAddThisAdministrationPermission());
313
    $this->drupalGet('admin/config/system/addthis');
314
    $this->assertNoRaw(t('Advanced settings'),
315
                       'A user without administer advanced addthis permission should not be able to access advanced AddThis system settings.');
316
  }
317

    
318
  private function createAdminUserWithoutAddThisAdministrationPermission() {
319
    return $this->drupalCreateUser(array('administer content types'));
320
  }
321

    
322
  private function createAdminUserWithoutAdvancedAddThisAdministrationPermission() {
323
    return $this->drupalCreateUser(array('administer content types', AddThis::PERMISSION_ADMINISTER_ADDTHIS));
324
  }
325
}
326

    
327
class TestHelper {
328

    
329
  public static function stringContains($string, $contains) {
330
    return strpos($string, $contains) !== FALSE;
331
  }
332

    
333
  public static function generateRandomLowercaseString() {
334
    return drupal_strtolower(DrupalWebTestCase::randomName());
335
  }
336
}