Projet

Général

Profil

Paste
Télécharger (22,3 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / piwik / piwik.test @ 5136ce55

1
<?php
2

    
3
/**
4
 * @file
5
 * Test file for Piwik module.
6
 */
7
class PiwikBasicTest extends DrupalWebTestCase {
8

    
9
  /**
10
   * User without permissions to edit snippets.
11
   *
12
   * @var \StdClass
13
   */
14
  protected $noSnippetUser;
15

    
16
  public static function getInfo() {
17
    return array(
18
      'name' => t('Piwik basic tests'),
19
      'description' => t('Test basic functionality of Piwik module.'),
20
      'group' => 'Piwik',
21
    );
22
  }
23

    
24
  function setUp() {
25
    parent::setUp('piwik');
26

    
27
    $permissions = array(
28
      'access administration pages',
29
      'administer piwik',
30
    );
31

    
32
    // User to set up piwik.
33
    $this->noSnippetUser = $this->drupalCreateUser($permissions);
34
    $permissions[] = 'add JS snippets for piwik';
35
    $this->admin_user = $this->drupalCreateUser($permissions);
36
    $this->drupalLogin($this->admin_user);
37
  }
38

    
39
  function testPiwikConfiguration() {
40
    // Check for setting page's presence.
41
    $this->drupalGet('admin/config/system/piwik');
42
    $this->assertRaw(t('Piwik site ID'), '[testPiwikConfiguration]: Settings page displayed.');
43

    
44
    // Check for account code validation.
45
    $edit['piwik_site_id'] = $this->randomName(2);
46
    $this->drupalPost('admin/config/system/piwik', $edit, 'Save configuration');
47
    $this->assertRaw(t('A valid Piwik site ID is an integer only.'), '[testPiwikConfiguration]: Invalid Piwik site ID number validated.');
48

    
49
    // User should have access to code snippets.
50
    $this->assertFieldByName('piwik_codesnippet_before');
51
    $this->assertFieldByName('piwik_codesnippet_after');
52
    $this->assertNoFieldByXPath("//textarea[@name='piwik_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
53
    $this->assertNoFieldByXPath("//textarea[@name='piwik_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is enabled.');
54

    
55
    // Login as user without JS permissions.
56
    $this->drupalLogin($this->noSnippetUser);
57
    $this->drupalGet('admin/config/system/piwik');
58

    
59
    // User should *not* have access to snippets, but create fields.
60
    $this->assertFieldByName('piwik_codesnippet_before');
61
    $this->assertFieldByName('piwik_codesnippet_after');
62
    $this->assertFieldByXPath("//textarea[@name='piwik_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is disabled.');
63
    $this->assertFieldByXPath("//textarea[@name='piwik_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is disabled.');
64
  }
65

    
66
  function testPiwikPageVisibility() {
67
    $ua_code = '1';
68
    variable_set('piwik_site_id', $ua_code);
69
    variable_get('piwik_url_http', 'http://example.com/piwik/');
70
    variable_get('piwik_url_https', 'https://example.com/piwik/');
71

    
72
    // Show tracking on "every page except the listed pages".
73
    variable_set('piwik_visibility_pages', 0);
74
    // Disable tracking one "admin*" pages only.
75
    variable_set('piwik_pages', "admin\nadmin/*");
76
    // Enable tracking only for authenticated users only.
77
    variable_set('piwik_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
78

    
79
    // Check tracking code visibility.
80
    $this->drupalGet('');
81
    $this->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed for authenticated users.');
82

    
83
    // Test whether tracking code is not included on pages to omit.
84
    $this->drupalGet('admin');
85
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is not displayed on admin page.');
86
    $this->drupalGet('admin/config/system/piwik');
87
    // Checking for tracking code URI here, as $ua_code is displayed in the form.
88
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is not displayed on admin subpage.');
89

    
90
    // Test whether tracking code display is properly flipped.
91
    variable_set('piwik_visibility_pages', 1);
92
    $this->drupalGet('admin');
93
    $this->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed on admin page.');
94
    $this->drupalGet('admin/config/system/piwik');
95
    // Checking for tracking code URI here, as $ua_code is displayed in the form.
96
    $this->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed on admin subpage.');
97
    $this->drupalGet('');
98
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is NOT displayed on front page.');
99

    
100
    // Test whether tracking code is not display for anonymous.
101
    $this->drupalLogout();
102
    $this->drupalGet('');
103
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is NOT displayed for anonymous.');
104

    
105
    // Switch back to every page except the listed pages.
106
    variable_set('piwik_visibility_pages', 0);
107
    // Enable tracking code for all user roles.
108
    variable_set('piwik_roles', array());
109

    
110
    // Test whether 403 forbidden tracking code is shown if user has no access.
111
    $this->drupalGet('admin');
112
    $this->assertRaw('"403/URL = "', '[testPiwikPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
113

    
114
    // Test whether 404 not found tracking code is shown on non-existent pages.
115
    $this->drupalGet($this->randomName(64));
116
    $this->assertRaw('"404/URL = "', '[testPiwikPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
117
  }
118

    
119
  function testPiwikTrackingCode() {
120
    $ua_code = '2';
121
    variable_set('piwik_site_id', $ua_code);
122
    variable_get('piwik_url_http', 'http://example.com/piwik/');
123
    variable_get('piwik_url_https', 'https://example.com/piwik/');
124

    
125
    // Show tracking code on every page except the listed pages.
126
    variable_set('piwik_visibility_pages', 0);
127
    // Enable tracking code for all user roles.
128
    variable_set('piwik_roles', array());
129

    
130
    /* Sample JS code as added to page:
131
    <script type="text/javascript">
132
    var _paq = _paq || [];
133
    (function(){
134
        var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}" : "http://{$PIWIK_URL}");
135
        _paq.push(['setSiteId', {$IDSITE}]);
136
        _paq.push(['setTrackerUrl', u+'piwik.php']);
137
        _paq.push(['trackPageView']);
138
        var d=document,
139
            g=d.createElement('script'),
140
            s=d.getElementsByTagName('script')[0];
141
            g.type='text/javascript';
142
            g.defer=true;
143
            g.async=true;
144
            g.src=u+'piwik.js';
145
            s.parentNode.insertBefore(g,s);
146
    })();
147
    </script>
148
    */
149

    
150
    // Test whether tracking code uses latest JS.
151
    variable_set('piwik_cache', 0);
152
    $this->drupalGet('');
153
    $this->assertRaw('u+"piwik.php"', '[testPiwikTrackingCode]: Latest tracking code used.');
154

    
155
    // Test if tracking of User ID is enabled.
156
    variable_set('piwik_trackuserid', 1);
157
    $this->drupalGet('');
158
    $this->assertRaw('_paq.push(["setUserId", ', '[testPiwikTrackingCode]: Tracking code for User ID is enabled.');
159

    
160
    // Test if tracking of User ID is disabled.
161
    variable_set('piwik_trackuserid', 0);
162
    $this->drupalGet('');
163
    $this->assertNoRaw('_paq.push(["setUserId", ', '[testPiwikTrackingCode]: Tracking code for User ID is disabled.');
164

    
165
    // Test whether single domain tracking is active.
166
    $this->drupalGet('');
167
    $this->assertNoRaw('_paq.push(["setCookieDomain"', '[testPiwikTrackingCode]: Single domain tracking is active.');
168

    
169
    // Enable "One domain with multiple subdomains".
170
    variable_set('piwik_domain_mode', 1);
171
    $this->drupalGet('');
172

    
173
    // Test may run on localhost, an ipaddress or real domain name.
174
    // TODO: Workaround to run tests successfully. This feature cannot tested reliable.
175
    global $cookie_domain;
176
    if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
177
      $this->assertRaw('_paq.push(["setCookieDomain"', '[testPiwikTrackingCode]: One domain with multiple subdomains is active on real host.');
178
    }
179
    else {
180
      // Special cases, Localhost and IP addresses don't show 'setCookieDomain'.
181
      $this->assertNoRaw('_paq.push(["setCookieDomain"', '[testPiwikTrackingCode]: One domain with multiple subdomains may be active on localhost (test result is not reliable).');
182
    }
183

    
184
    // Test whether the BEFORE and AFTER code is added to the tracker.
185
    variable_set('piwik_codesnippet_before', '_paq.push(["setLinkTrackingTimer", 250]);');
186
    variable_set('piwik_codesnippet_after', '_paq.push(["t2.setSiteId", 2]);_gaq.push(["t2.trackPageView"]);');
187
    $this->drupalGet('');
188
    $this->assertRaw('setLinkTrackingTimer', '[testPiwikTrackingCode]: Before codesnippet has been found with "setLinkTrackingTimer" set.');
189
    $this->assertRaw('t2.trackPageView', '[testPiwikTrackingCode]: After codesnippet with "t2" tracker has been found.');
190
  }
191

    
192
}
193

    
194
class PiwikCustomVariablesTest extends DrupalWebTestCase {
195

    
196
  public static function getInfo() {
197
    return array(
198
      'name' => t('Piwik Custom Variables tests'),
199
      'description' => t('Test custom variables functionality of Piwik module.'),
200
      'group' => 'Piwik',
201
      'dependencies' => array('token'),
202
    );
203
  }
204

    
205
  function setUp() {
206
    parent::setUp('piwik', 'token');
207

    
208
    $permissions = array(
209
      'access administration pages',
210
      'administer piwik',
211
    );
212

    
213
    // User to set up piwik.
214
    $this->admin_user = $this->drupalCreateUser($permissions);
215
  }
216

    
217
  function testPiwikCustomVariables() {
218
    $ua_code = '3';
219
    variable_set('piwik_site_id', $ua_code);
220

    
221
    // Basic test if the feature works.
222
    $custom_vars = array(
223
      'slots' => array(
224
        1 => array(
225
          'slot' => 1,
226
          'name' => 'Foo 1',
227
          'value' => 'Bar 1',
228
          'scope' => 3,
229
        ),
230
        2 => array(
231
          'slot' => 2,
232
          'name' => 'Foo 2',
233
          'value' => 'Bar 2',
234
          'scope' => 2,
235
        ),
236
        3 => array(
237
          'slot' => 3,
238
          'name' => 'Foo 3',
239
          'value' => 'Bar 3',
240
          'scope' => 3,
241
        ),
242
        4 => array(
243
          'slot' => 4,
244
          'name' => 'Foo 4',
245
          'value' => 'Bar 4',
246
          'scope' => 2,
247
        ),
248
        5 => array(
249
          'slot' => 5,
250
          'name' => 'Foo 5',
251
          'value' => 'Bar 5',
252
          'scope' => 1,
253
        ),
254
      )
255
    );
256
    variable_set('piwik_custom_var', $custom_vars);
257
    $this->drupalGet('');
258

    
259
    foreach ($custom_vars['slots'] as $slot) {
260
      $this->assertRaw("_paq.push(['setCustomVariable', " . $slot['slot'] . ", \"" . $slot['name'] . "\", \"" . $slot['value'] . "\", " . $slot['scope'] . "]);", '[testPiwikCustomVariables]: setCustomVariable ' . $slot['slot'] . ' is shown.');
261
    }
262

    
263
    // Test whether tokens are replaced in custom variable names.
264
    $site_slogan = $this->randomName(16);
265
    variable_set('site_slogan', $site_slogan);
266

    
267
    $custom_vars = array(
268
      'slots' => array(
269
        1 => array(
270
          'slot' => 1,
271
          'name' => 'Name: [site:slogan]',
272
          'value' => 'Value: [site:slogan]',
273
          'scope' => 3,
274
        ),
275
        2 => array(
276
          'slot' => 2,
277
          'name' => '',
278
          'value' => $this->randomName(16),
279
          'scope' => 1,
280
        ),
281
        3 => array(
282
          'slot' => 3,
283
          'name' => $this->randomName(16),
284
          'value' => '',
285
          'scope' => 2,
286
        ),
287
        4 => array(
288
          'slot' => 4,
289
          'name' => '',
290
          'value' => '',
291
          'scope' => 3,
292
        ),
293
        5 => array(
294
          'slot' => 5,
295
          'name' => '',
296
          'value' => '',
297
          'scope' => 3,
298
        ),
299
      )
300
    );
301
    variable_set('piwik_custom_var', $custom_vars);
302
    $this->verbose('<pre>' . print_r($custom_vars, TRUE) . '</pre>');
303

    
304
    $this->drupalGet('');
305
    $this->assertRaw("_paq.push(['setCustomVariable', 1, \"Name: $site_slogan\", \"Value: $site_slogan\", 3]", '[testPiwikCustomVariables]: Tokens have been replaced in custom variable.');
306
    $this->assertNoRaw("_paq.push(['setCustomVariable', 2,", '[testPiwikCustomVariables]: Value with empty name is not shown.');
307
    $this->assertNoRaw("_paq.push(['setCustomVariable', 3,", '[testPiwikCustomVariables]: Name with empty value is not shown.');
308
    $this->assertNoRaw("_paq.push(['setCustomVariable', 4,", '[testPiwikCustomVariables]: Empty name and value is not shown.');
309
    $this->assertNoRaw("_paq.push(['setCustomVariable', 5,", '[testPiwikCustomVariables]: Empty name and value is not shown.');
310
  }
311
}
312

    
313
class PiwikStatusMessagesTest extends DrupalWebTestCase {
314

    
315
  public static function getInfo() {
316
    return array(
317
      'name' => 'Piwik status messages tests',
318
      'description' => 'Test status messages functionality of Piwik module.',
319
      'group' => 'Piwik',
320
    );
321
  }
322

    
323
  function setUp() {
324
    parent::setUp('piwik');
325

    
326
    $permissions = array(
327
      'access administration pages',
328
      'administer piwik',
329
    );
330

    
331
    // User to set up piwik.
332
    $this->admin_user = $this->drupalCreateUser($permissions);
333
  }
334

    
335
  function testPiwikStatusMessages() {
336
    $ua_code = '1';
337
    variable_set('piwik_site_id', $ua_code);
338

    
339
    // Enable logging of errors only.
340
    variable_set('piwik_trackmessages', array('error' => 'error'));
341

    
342
    $this->drupalPost('user/login', array(), t('Log in'));
343
    $this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Username field is required."]);', '[testPiwikStatusMessages]: trackEvent "Username field is required." is shown.');
344
    $this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Password field is required."]);', '[testPiwikStatusMessages]: trackEvent "Password field is required." is shown.');
345

    
346
    // @todo: investigate why drupal_set_message() fails.
347
    //drupal_set_message('Example status message.', 'status');
348
    //drupal_set_message('Example warning message.', 'warning');
349
    //drupal_set_message('Example error message.', 'error');
350
    //drupal_set_message('Example error <em>message</em> with html tags and <a href="http://example.com/">link</a>.', 'error');
351
    //$this->drupalGet('');
352
    //$this->assertNoRaw('_paq.push(["trackEvent", "Messages", "Status message", "Example status message."]);', '[testPiwikStatusMessages]: Example status message is not enabled for tracking.');
353
    //$this->assertNoRaw('_paq.push(["trackEvent", "Messages", "Warning message", "Example warning message."]);', '[testPiwikStatusMessages]: Example warning message is not enabled for tracking.');
354
    //$this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Example error message."]);', '[testPiwikStatusMessages]: Example error message is shown.');
355
    //$this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Example error message with html tags and link."]);', '[testPiwikStatusMessages]: HTML has been stripped successful from Example error message with html tags and link.');
356
  }
357
}
358

    
359
class PiwikRolesTest extends DrupalWebTestCase {
360

    
361
  public static function getInfo() {
362
    return array(
363
      'name' => t('Piwik role tests'),
364
      'description' => t('Test roles functionality of Piwik module.'),
365
      'group' => 'Piwik',
366
    );
367
  }
368

    
369
  function setUp() {
370
    parent::setUp('piwik');
371

    
372
    $permissions = array(
373
      'access administration pages',
374
      'administer piwik',
375
    );
376

    
377
    // User to set up piwik.
378
    $this->admin_user = $this->drupalCreateUser($permissions);
379
  }
380

    
381
  function testPiwikRolesTracking() {
382
    $ua_code = '1';
383
    variable_set('piwik_site_id', $ua_code);
384
    variable_get('piwik_url_http', 'http://example.com/piwik/');
385
    variable_get('piwik_url_https', 'https://example.com/piwik/');
386

    
387
    // Test if the default settings are working as expected.
388

    
389
    // Add to the selected roles only.
390
    variable_set('piwik_visibility_roles', 0);
391
    // Enable tracking for all users.
392
    variable_set('piwik_roles', array());
393

    
394
    // Check tracking code visibility.
395
    $this->drupalGet('');
396
    $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed for anonymous users on frontpage with default settings.');
397
    $this->drupalGet('admin');
398
    $this->assertRaw('"403/URL = "', '[testPiwikRoleVisibility]: 403 Forbidden tracking code is displayed for anonymous users in admin section with default settings.');
399

    
400
    $this->drupalLogin($this->admin_user);
401

    
402
    $this->drupalGet('');
403
    $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed for authenticated users on frontpage with default settings.');
404
    $this->drupalGet('admin');
405
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed for authenticated users in admin section with default settings.');
406

    
407
    // Test if the non-default settings are working as expected.
408

    
409
    // Enable tracking only for authenticated users.
410
    variable_set('piwik_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
411

    
412
    $this->drupalGet('');
413
    $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed for authenticated users only on frontpage.');
414

    
415
    $this->drupalLogout();
416
    $this->drupalGet('');
417
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed for anonymous users on frontpage.');
418

    
419
    // Add to every role except the selected ones.
420
    variable_set('piwik_visibility_roles', 1);
421
    // Enable tracking for all users.
422
    variable_set('piwik_roles', array());
423

    
424
    // Check tracking code visibility.
425
    $this->drupalGet('');
426
    $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is added to every role and displayed for anonymous users.');
427
    $this->drupalGet('admin');
428
    $this->assertRaw('"403/URL = "', '[testPiwikRoleVisibility]: 403 Forbidden tracking code is shown for anonymous users if every role except the selected ones is selected.');
429

    
430
    $this->drupalLogin($this->admin_user);
431

    
432
    $this->drupalGet('');
433
    $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is added to every role and displayed on frontpage for authenticated users.');
434
    $this->drupalGet('admin');
435
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is added to every role and NOT displayed in admin section for authenticated users.');
436

    
437
    // Disable tracking for authenticated users.
438
    variable_set('piwik_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
439

    
440
    $this->drupalGet('');
441
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed on frontpage for excluded authenticated users.');
442
    $this->drupalGet('admin');
443
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed in admin section for excluded authenticated users.');
444

    
445
    $this->drupalLogout();
446
    $this->drupalGet('');
447
    $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed on frontpage for included anonymous users.');
448
  }
449

    
450
}
451

    
452
class PiwikPhpFilterTest extends DrupalWebTestCase {
453

    
454
  public static function getInfo() {
455
    return array(
456
      'name' => 'Piwik php filter tests',
457
      'description' => 'Test php filter functionality of Piwik module.',
458
      'group' => 'Piwik',
459
    );
460
  }
461

    
462
  function setUp() {
463
    parent::setUp('piwik', 'php');
464

    
465
    // Administrator with all permissions.
466
    $permissions_admin_user = array(
467
      'access administration pages',
468
      'administer piwik',
469
      'use PHP for tracking visibility',
470
    );
471
    $this->admin_user = $this->drupalCreateUser($permissions_admin_user);
472

    
473
    // Administrator who cannot configure tracking visibility with PHP.
474
    $permissions_delegated_admin_user = array(
475
      'access administration pages',
476
      'administer piwik',
477
    );
478
    $this->delegated_admin_user = $this->drupalCreateUser($permissions_delegated_admin_user);
479
  }
480

    
481
  function testPiwikPhpFilter() {
482
    $ua_code = '1';
483
    $this->drupalLogin($this->admin_user);
484

    
485
    $edit = array();
486
    $edit['piwik_site_id'] = $ua_code;
487
    $edit['piwik_url_http'] = 'http://example.com/piwik/';
488
    $edit['piwik_url_https'] = 'https://example.com/piwik/';
489
    $edit['piwik_url_skiperror'] = TRUE; // Required for testing only.
490
    $edit['piwik_visibility_pages'] = 2;
491
    $edit['piwik_pages'] = '<?php return 0; ?>';
492
    $this->drupalPost('admin/config/system/piwik', $edit, t('Save configuration'));
493

    
494
    // Compare saved setting with posted setting.
495
    $piwik_pages = variable_get('piwik_pages', $this->randomName(8));
496
    $this->assertEqual('<?php return 0; ?>', $piwik_pages, '[testPiwikPhpFilter]: PHP code snippet is intact.');
497

    
498
    // Check tracking code visibility.
499
    variable_set('piwik_pages', '<?php return TRUE; ?>');
500
    $this->drupalGet('');
501
    $this->assertRaw('u+"piwik.php"', '[testPiwikPhpFilter]: Tracking is displayed on frontpage page.');
502
    $this->drupalGet('admin');
503
    $this->assertRaw('u+"piwik.php"', '[testPiwikPhpFilter]: Tracking is displayed on admin page.');
504

    
505
    variable_set('piwik_pages', '<?php return FALSE; ?>');
506
    $this->drupalGet('');
507
    $this->assertNoRaw('u+"piwik.php"', '[testPiwikPhpFilter]: Tracking is not displayed on frontpage page.');
508

    
509
    // Test administration form.
510
    variable_set('piwik_pages', '<?php return TRUE; ?>');
511
    $this->drupalGet('admin/config/system/piwik');
512
    $this->assertRaw(t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'), '[testPiwikPhpFilter]: Permission to administer PHP for tracking visibility.');
513
    $this->assertRaw(check_plain('<?php return TRUE; ?>'), '[testPiwikPhpFilter]: PHP code snippted is displayed.');
514

    
515
    // Login the delegated user and check if fields are visible.
516
    $this->drupalLogin($this->delegated_admin_user);
517
    $this->drupalGet('admin/config/system/piwik');
518
    $this->assertNoRaw(t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'), '[testPiwikPhpFilter]: No permission to administer PHP for tracking visibility.');
519
    $this->assertNoRaw(check_plain('<?php return TRUE; ?>'), '[testPiwikPhpFilter]: No permission to view PHP code snippted.');
520

    
521
    // Set a different value and verify that this is still the same after the post.
522
    variable_set('piwik_pages', '<?php return 0; ?>');
523

    
524
    $edit = array();
525
    $edit['piwik_site_id'] = $ua_code;
526
    $edit['piwik_url_http'] = 'http://example.com/piwik/';
527
    $edit['piwik_url_https'] = 'https://example.com/piwik/';
528
    $edit['piwik_url_skiperror'] = TRUE; // Required for testing only.
529
    $this->drupalPost('admin/config/system/piwik', $edit, t('Save configuration'));
530

    
531
    // Compare saved setting with posted setting.
532
    $piwik_visibility_pages = variable_get('piwik_visibility_pages', 0);
533
    $piwik_pages = variable_get('piwik_pages', $this->randomName(8));
534
    $this->assertEqual(2, $piwik_visibility_pages, '[testPiwikPhpFilter]: Pages on which this PHP code returns TRUE is selected.');
535
    $this->assertEqual('<?php return 0; ?>', $piwik_pages, '[testPiwikPhpFilter]: PHP code snippet is intact.');
536
  }
537

    
538
}