Project

General

Profile

Paste
Download (12 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / addthis / tests / AddThisFunctionalityTestCase.test @ 2c8c2b87

1
<?php
2
/**
3
 * @file
4
 * Tests for the AddThis-module.
5
 */
6
class AddThisFunctionalityTestCase extends DrupalWebTestCase
7
{
8

    
9
    private $user;
10

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

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

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

    
30
        $this->addThisShouldDefineField();
31

    
32
        $this->addThisShouldDefineBlock();
33

    
34
        $this->addThisShouldBeAbleToBeUsedAsField();
35

    
36
        $this->addThisSystemSettingsShouldBeAbleToBeSaved();
37

    
38
        $this->addThisBlockSettingsPageShouldBeLoading();
39
    }
40

    
41
    private function addThisShouldProvideHelp()
42
    {
43
        $helpText = module_invoke(AddThis::MODULE_NAME, 'help', 'admin/help#addthis', NULL);
44
        $this->assertTrue(AddThisTestHelper::stringContains($helpText, t('About')), 'AddThis-module should provide help.');
45
    }
46

    
47
    private function addThisShouldDefineField()
48
    {
49
        $fieldInfo = module_invoke(AddThis::MODULE_NAME, 'field_info');
50
        $this->assertTrue(is_array($fieldInfo), t('AddThis-module should define a field.'));
51
    }
52

    
53
    private function addThisShouldDefineBlock()
54
    {
55
        $blockInfo = module_invoke(AddThis::MODULE_NAME, 'block_info');
56
        $this->assertTrue(is_array($blockInfo), t('AddThis-module should define a block.'));
57
    }
58

    
59
    private function addThisShouldBeAbleToBeUsedAsField()
60
    {
61
        $edit = array();
62
        $label = AddThisTestHelper::generateRandomLowercaseString();
63
        $edit["fields[_add_new_field][label]"] = $label;
64
        $edit["fields[_add_new_field][field_name]"] = $label;
65
        $edit["fields[_add_new_field][type]"] = AddThis::FIELD_TYPE;
66
        $edit["fields[_add_new_field][widget_type]"] = AddThis::WIDGET_TYPE;
67

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

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

    
72
        $this->addThisShouldNotHaveConfigurableFieldLevelSettings($label);
73

    
74
        $this->drupalGet('admin/structure/types/manage/article/display');
75
    }
76

    
77
    private function addThisShouldNotHaveConfigurableFieldLevelSettings($label)
78
    {
79
        $this->assertText(t("@name has no field settings.", array('@name' => $label)),
80
            'AddThis-module should not have configurable field level settings.');
81
    }
82

    
83
    private function addThisSystemSettingsShouldBeAbleToBeSaved()
84
    {
85
        $edit_basic = array();
86

    
87
        // Basic settings
88
        $profileId = AddThisTestHelper::generateRandomLowercaseString();
89
        $edit_basic[AddThis::PROFILE_ID_KEY] = $profileId;
90

    
91
        $uiDelay = 400;
92
        $edit_basic[AddThis::UI_DELAY_KEY] = $uiDelay;
93

    
94
        $uiHeaderBackgroundColor = '#000000';
95
        $edit_basic[AddThis::UI_HEADER_BACKGROUND_COLOR_KEY] = $uiHeaderBackgroundColor;
96

    
97
        $uiHeaderColor = '#ffffff';
98
        $edit_basic[AddThis::UI_HEADER_COLOR_KEY] = $uiHeaderColor;
99

    
100
        $coBrand = AddThisTestHelper::generateRandomLowercaseString();
101
        $edit_basic[AddThis::CO_BRAND_KEY] = $coBrand;
102

    
103
        $edit_basic[AddThis::COMPLIANT_508_KEY] = TRUE;
104

    
105
        $edit_basic[AddThis::CLICKBACK_TRACKING_ENABLED_KEY] = TRUE;
106

    
107
        // Can only be tested with Google Analytics module installed.
108
        //$edit_basic[AddThis::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY] = TRUE;
109

    
110
        //$edit_basic[AddThis::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY] = TRUE;
111

    
112
        $edit_basic[AddThis::ADDRESSBOOK_ENABLED_KEY] = TRUE;
113

    
114
        $edit_basic[AddThis::CLICK_TO_OPEN_COMPACT_MENU_ENABLED_KEY] = TRUE;
115

    
116
        $edit_basic[AddThis::OPEN_WINDOWS_ENABLED_KEY] = TRUE;
117

    
118
        $edit_basic[AddThis::STANDARD_CSS_ENABLED_KEY] = TRUE;
119

    
120
        $serviceName = '2linkme';
121
        $edit_basic["addthis_enabled_services[$serviceName]"] = $serviceName;
122

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

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

    
127
        $this->addThisProfileIdShouldBeAbleToBeSaved($profileId);
128

    
129
        $this->addThisUiDelayShouldBeAbleToBeSaved($uiDelay);
130

    
131
        $this->addThisUiHeaderBackgroundColorShouldBeAbleToBeSaved($uiHeaderBackgroundColor);
132

    
133
        $this->addThisUiHeaderColorShouldBeAbleToBeSaved($uiHeaderColor);
134

    
135
        $this->addThisCoBrandShouldBeAbleToBeSaved($coBrand);
136

    
137
        $this->addThis508CompliantSettingShouldBeAbleToBeSaved();
138

    
139
        $this->addThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved();
140

    
141
        // Can only be tested with Google Analytics module installed.
142
        //$this->addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved();
143

    
144
        //$this->addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved();
145

    
146
        $this->addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved();
147

    
148
        $this->addThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved();
149

    
150
        $this->addThisStandardCssEnabledSettingShouldBeAbleToBeSaved();
151

    
152
        $this->addThisEnabledServicesShouldBeAbleToBeSaved($serviceName);
153

    
154
        // Advanced configuration
155
        $edit_basic = array();
156

    
157
        $servicesCssUrl = AddThis::DEFAULT_SERVICES_CSS_URL;
158
        $edit_basic[AddThis::SERVICES_CSS_URL_KEY] = $servicesCssUrl;
159

    
160
        $servicesJsonUrl = AddThis::DEFAULT_SERVICES_JSON_URL;
161
        $edit_basic[AddThis::SERVICES_JSON_URL_KEY] = $servicesJsonUrl;
162

    
163
        $widgetJsUrl = AddThis::DEFAULT_WIDGET_JS_URL;
164
        $edit_basic[AddThis::WIDGET_JS_URL_KEY] = $widgetJsUrl;
165

    
166
        $edit_basic[AddThis::CUSTOM_CONFIGURATION_CODE_ENABLED_KEY] = TRUE;
167

    
168
        $customConfigurationCode = AddThisTestHelper::generateRandomLowercaseString();
169
        $edit_basic[AddThis::CUSTOM_CONFIGURATION_CODE_KEY] = $customConfigurationCode;
170

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

    
173
        $this->addThisServicesCssUrlShouldBeAbleToBeSaved($servicesCssUrl);
174

    
175
        $this->addThisServicesJsonUrlShouldBeAbleToBeSaved($servicesJsonUrl);
176

    
177
        $this->addThisWidgetJsUrlShouldBeAbleToBeSaved($widgetJsUrl);
178

    
179
        $this->addThisCustomConfigurationCodeEnabledSettingShouldBeAbleToBeSaved();
180
    }
181

    
182
    private function addThisProfileIdShouldBeAbleToBeSaved($profileId)
183
    {
184
        $this->assertFieldByName(AddThis::PROFILE_ID_KEY, $profileId,
185
            'AddThis profile ID should be able to be saved.');
186
    }
187

    
188
    private function addThisServicesCssUrlShouldBeAbleToBeSaved($servicesCssUrl)
189
    {
190
        $this->assertFieldByName(AddThis::SERVICES_CSS_URL_KEY, $servicesCssUrl,
191
            'AddThis services stylesheet URL should be able to be saved.');
192
    }
193

    
194
    private function addThisServicesJsonUrlShouldBeAbleToBeSaved($servicesJsonUrl)
195
    {
196
        $this->assertFieldByName(AddThis::SERVICES_JSON_URL_KEY, $servicesJsonUrl,
197
            'AddThis services json URL should be able to be saved.');
198
    }
199

    
200
    private function addThisWidgetJsUrlShouldBeAbleToBeSaved($widgetJsUrl)
201
    {
202
        $this->assertFieldByName(AddThis::WIDGET_JS_URL_KEY, $widgetJsUrl,
203
            'AddThis javascript widget URL should be able to be saved.');
204
    }
205

    
206
    private function addThis508CompliantSettingShouldBeAbleToBeSaved()
207
    {
208
        $this->assertFieldChecked('edit-addthis-508-compliant',
209
            'AddThis 508 compliant setting should be able to be saved.');
210
    }
211

    
212
    private function addThisClickbackTrackingEnabledSettingShouldBeAbleToBeSaved()
213
    {
214
        $this->assertFieldChecked('edit-addthis-clickback-tracking-enabled',
215
            'AddThis clickback tracking enabled setting should be able to be saved.');
216
    }
217

    
218
    private function addThisGoogleAnalyticsTrackingEnabledSettingShouldBeAbleToBeSaved()
219
    {
220
        $this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled',
221
            'AddThis Google Analytics tracking enabled setting should be able to be saved.');
222
    }
223

    
224
    private function addThisGoogleAnalyticsSocialTrackingEnabledSettingShouldBeAbleToBeSaved()
225
    {
226
        $this->assertFieldChecked('edit-addthis-google-analytics-tracking-enabled',
227
            'AddThis Google Analytics social tracking enabled setting should be able to be saved.');
228
    }
229

    
230
    private function addThisClickToOpenCompactMenuEnabledSettingShouldBeAbleToBeSaved()
231
    {
232
        $this->assertFieldChecked('edit-addthis-click-to-open-compact-menu-enabled',
233
            'AddThis click to open compact menu setting should be able to be saved.');
234
    }
235

    
236
    private function addThisOpenWindowsEnabledSettingShouldBeAbleToBeSaved()
237
    {
238
        $this->assertFieldChecked('edit-addthis-open-windows-enabled',
239
            'AddThis open windows setting should be able to be saved.');
240
    }
241

    
242
    private function addThisStandardCssEnabledSettingShouldBeAbleToBeSaved()
243
    {
244
        $this->assertFieldChecked('edit-addthis-open-windows-enabled',
245
            'AddThis open windows setting should be able to be saved.');
246
    }
247

    
248
    private function addThisFacebookLikeEnabledSettingShouldBeAbleToBeSaved()
249
    {
250
        $this->assertFieldChecked('edit-addthis-facebook-like-enabled',
251
            'AddThis Facebook Like enabled setting should be able to be saved.');
252
    }
253

    
254
    private function addThisAddressbookEnabledSettingShouldBeAbleToBeSaved()
255
    {
256
        $this->assertFieldChecked('edit-addthis-addressbook-enabled',
257
            'AddThis addressbook enabled setting should be able to be saved.');
258
    }
259

    
260
    private function addThisCustomConfigurationCodeEnabledSettingShouldBeAbleToBeSaved()
261
    {
262
        $this->assertFieldChecked('edit-addthis-custom-configuration-code-enabled',
263
            'AddThis custom configuration code enabled setting should be able to be saved.');
264
    }
265

    
266
    private function addThisCustomConfigurationCodeShouldBeAbleToBeSaved($customConfigurationCode)
267
    {
268
        $this->assertFieldByName(AddThis::CUSTOM_CONFIGURATION_CODE_KEY, $customConfigurationCode,
269
            'AddThis custom configuration code should be able to be saved.');
270
    }
271

    
272
    private function addThisUiHeaderColorShouldBeAbleToBeSaved($uiHeaderColor)
273
    {
274
        $this->assertFieldByName(AddThis::UI_HEADER_COLOR_KEY, $uiHeaderColor,
275
            'AddThis UI header color should be able to be saved.');
276
    }
277

    
278
    private function addThisUiDelayShouldBeAbleToBeSaved($uiDelay)
279
    {
280
        $this->assertFieldByName(AddThis::UI_DELAY_KEY, $uiDelay,
281
            'AddThis UI delay should be able to be saved.');
282
    }
283

    
284
    private function addThisUiHeaderBackgroundColorShouldBeAbleToBeSaved($uiHeaderBackgroundColor)
285
    {
286
        $this->assertFieldByName(AddThis::UI_HEADER_BACKGROUND_COLOR_KEY, $uiHeaderBackgroundColor,
287
            'AddThis UI header background color should be able to be saved.');
288
    }
289

    
290
    private function addThisCoBrandShouldBeAbleToBeSaved($coBrand)
291
    {
292
        $this->assertFieldByName(AddThis::CO_BRAND_KEY, $coBrand,
293
            'AddThis co-brand should be able to be saved.');
294
    }
295

    
296
    private function addThisEnabledServicesShouldBeAbleToBeSaved($serviceName)
297
    {
298
        $this->assertFieldChecked('edit-addthis-enabled-services-' . $serviceName,
299
            'AddThis enabled services should be able to be saved.');
300
    }
301

    
302
    private function createAndLoginUser()
303
    {
304
        $this->user = $this->createAdminUser();
305
        $this->drupalLogin($this->user);
306
    }
307

    
308
    private function addThisBlockSettingsPageShouldBeLoading()
309
    {
310
        $this->drupalGet('admin/structure/block/manage/addthis/addthis_block/configure');
311
        $this->assertNoPattern('|[Ff]atal|', 'No fatal error found.');
312
        $this->assertResponse(200);
313
    }
314

    
315
    private function createAdminUser()
316
    {
317
        return $this->drupalCreateUser(
318
            array(
319
                AddThis::PERMISSION_ADMINISTER_ADDTHIS,
320
                AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS,
321
                'administer blocks',
322
                'administer content types',
323
                'administer nodes'
324
            )
325
        );
326
    }
327
}