piwik.test 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <?php
  2. /**
  3. * @file
  4. * Test file for Piwik module.
  5. */
  6. class PiwikBasicTest extends DrupalWebTestCase {
  7. /**
  8. * User without permissions to edit snippets.
  9. *
  10. * @var \StdClass
  11. */
  12. protected $noSnippetUser;
  13. public static function getInfo() {
  14. return array(
  15. 'name' => t('Piwik basic tests'),
  16. 'description' => t('Test basic functionality of Piwik module.'),
  17. 'group' => 'Piwik',
  18. );
  19. }
  20. function setUp() {
  21. parent::setUp('piwik');
  22. $permissions = array(
  23. 'access administration pages',
  24. 'administer piwik',
  25. );
  26. // User to set up piwik.
  27. $this->noSnippetUser = $this->drupalCreateUser($permissions);
  28. $permissions[] = 'add JS snippets for piwik';
  29. $this->admin_user = $this->drupalCreateUser($permissions);
  30. $this->drupalLogin($this->admin_user);
  31. }
  32. function testPiwikConfiguration() {
  33. // Check for setting page's presence.
  34. $this->drupalGet('admin/config/system/piwik');
  35. $this->assertRaw(t('Piwik site ID'), '[testPiwikConfiguration]: Settings page displayed.');
  36. // Check for account code validation.
  37. $edit['piwik_site_id'] = $this->randomName(2);
  38. $this->drupalPost('admin/config/system/piwik', $edit, 'Save configuration');
  39. $this->assertRaw(t('A valid Piwik site ID is an integer only.'), '[testPiwikConfiguration]: Invalid Piwik site ID number validated.');
  40. // User should have access to code snippets.
  41. $this->assertFieldByName('piwik_codesnippet_before');
  42. $this->assertFieldByName('piwik_codesnippet_after');
  43. $this->assertNoFieldByXPath("//textarea[@name='piwik_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is enabled.');
  44. $this->assertNoFieldByXPath("//textarea[@name='piwik_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is enabled.');
  45. // Login as user without JS permissions.
  46. $this->drupalLogin($this->noSnippetUser);
  47. $this->drupalGet('admin/config/system/piwik');
  48. // User should *not* have access to snippets, but create fields.
  49. $this->assertFieldByName('piwik_codesnippet_before');
  50. $this->assertFieldByName('piwik_codesnippet_after');
  51. $this->assertFieldByXPath("//textarea[@name='piwik_codesnippet_before' and @disabled='disabled']", NULL, '"Code snippet (before)" is disabled.');
  52. $this->assertFieldByXPath("//textarea[@name='piwik_codesnippet_after' and @disabled='disabled']", NULL, '"Code snippet (after)" is disabled.');
  53. }
  54. function testPiwikPageVisibility() {
  55. $ua_code = '1';
  56. variable_set('piwik_site_id', $ua_code);
  57. variable_get('piwik_url_http', 'http://example.com/piwik/');
  58. variable_get('piwik_url_https', 'https://example.com/piwik/');
  59. // Show tracking on "every page except the listed pages".
  60. variable_set('piwik_visibility_pages', 0);
  61. // Disable tracking one "admin*" pages only.
  62. variable_set('piwik_pages', "admin\nadmin/*");
  63. // Enable tracking only for authenticated users only.
  64. variable_set('piwik_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
  65. // Check tracking code visibility.
  66. $this->drupalGet('');
  67. $this->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed for authenticated users.');
  68. // Test whether tracking code is not included on pages to omit.
  69. $this->drupalGet('admin');
  70. $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is not displayed on admin page.');
  71. $this->drupalGet('admin/config/system/piwik');
  72. // Checking for tracking code URI here, as $ua_code is displayed in the form.
  73. $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is not displayed on admin subpage.');
  74. // Test whether tracking code display is properly flipped.
  75. variable_set('piwik_visibility_pages', 1);
  76. $this->drupalGet('admin');
  77. $this->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed on admin page.');
  78. $this->drupalGet('admin/config/system/piwik');
  79. // Checking for tracking code URI here, as $ua_code is displayed in the form.
  80. $this->assertRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is displayed on admin subpage.');
  81. $this->drupalGet('');
  82. $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is NOT displayed on front page.');
  83. // Test whether tracking code is not display for anonymous.
  84. $this->drupalLogout();
  85. $this->drupalGet('');
  86. $this->assertNoRaw('u+"piwik.php"', '[testPiwikPageVisibility]: Tracking code is NOT displayed for anonymous.');
  87. // Switch back to every page except the listed pages.
  88. variable_set('piwik_visibility_pages', 0);
  89. // Enable tracking code for all user roles.
  90. variable_set('piwik_roles', array());
  91. // Test whether 403 forbidden tracking code is shown if user has no access.
  92. $this->drupalGet('admin');
  93. $this->assertRaw('"403/URL = "', '[testPiwikPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
  94. // Test whether 404 not found tracking code is shown on non-existent pages.
  95. $this->drupalGet($this->randomName(64));
  96. $this->assertRaw('"404/URL = "', '[testPiwikPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
  97. }
  98. function testPiwikTrackingCode() {
  99. $ua_code = '2';
  100. variable_set('piwik_site_id', $ua_code);
  101. variable_get('piwik_url_http', 'http://example.com/piwik/');
  102. variable_get('piwik_url_https', 'https://example.com/piwik/');
  103. // Show tracking code on every page except the listed pages.
  104. variable_set('piwik_visibility_pages', 0);
  105. // Enable tracking code for all user roles.
  106. variable_set('piwik_roles', array());
  107. /* Sample JS code as added to page:
  108. <script type="text/javascript">
  109. var _paq = _paq || [];
  110. (function(){
  111. var u=(("https:" == document.location.protocol) ? "https://{$PIWIK_URL}" : "http://{$PIWIK_URL}");
  112. _paq.push(['setSiteId', {$IDSITE}]);
  113. _paq.push(['setTrackerUrl', u+'piwik.php']);
  114. _paq.push(['trackPageView']);
  115. var d=document,
  116. g=d.createElement('script'),
  117. s=d.getElementsByTagName('script')[0];
  118. g.type='text/javascript';
  119. g.defer=true;
  120. g.async=true;
  121. g.src=u+'piwik.js';
  122. s.parentNode.insertBefore(g,s);
  123. })();
  124. </script>
  125. */
  126. // Test whether tracking code uses latest JS.
  127. variable_set('piwik_cache', 0);
  128. $this->drupalGet('');
  129. $this->assertRaw('u+"piwik.php"', '[testPiwikTrackingCode]: Latest tracking code used.');
  130. // Test if tracking of User ID is enabled.
  131. variable_set('piwik_trackuserid', 1);
  132. $this->drupalGet('');
  133. $this->assertRaw('_paq.push(["setUserId", ', '[testPiwikTrackingCode]: Tracking code for User ID is enabled.');
  134. // Test if tracking of User ID is disabled.
  135. variable_set('piwik_trackuserid', 0);
  136. $this->drupalGet('');
  137. $this->assertNoRaw('_paq.push(["setUserId", ', '[testPiwikTrackingCode]: Tracking code for User ID is disabled.');
  138. // Test whether single domain tracking is active.
  139. $this->drupalGet('');
  140. $this->assertNoRaw('_paq.push(["setCookieDomain"', '[testPiwikTrackingCode]: Single domain tracking is active.');
  141. // Enable "One domain with multiple subdomains".
  142. variable_set('piwik_domain_mode', 1);
  143. $this->drupalGet('');
  144. // Test may run on localhost, an ipaddress or real domain name.
  145. // TODO: Workaround to run tests successfully. This feature cannot tested reliable.
  146. global $cookie_domain;
  147. if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
  148. $this->assertRaw('_paq.push(["setCookieDomain"', '[testPiwikTrackingCode]: One domain with multiple subdomains is active on real host.');
  149. }
  150. else {
  151. // Special cases, Localhost and IP addresses don't show 'setCookieDomain'.
  152. $this->assertNoRaw('_paq.push(["setCookieDomain"', '[testPiwikTrackingCode]: One domain with multiple subdomains may be active on localhost (test result is not reliable).');
  153. }
  154. // Test whether the BEFORE and AFTER code is added to the tracker.
  155. variable_set('piwik_codesnippet_before', '_paq.push(["setLinkTrackingTimer", 250]);');
  156. variable_set('piwik_codesnippet_after', '_paq.push(["t2.setSiteId", 2]);_gaq.push(["t2.trackPageView"]);');
  157. $this->drupalGet('');
  158. $this->assertRaw('setLinkTrackingTimer', '[testPiwikTrackingCode]: Before codesnippet has been found with "setLinkTrackingTimer" set.');
  159. $this->assertRaw('t2.trackPageView', '[testPiwikTrackingCode]: After codesnippet with "t2" tracker has been found.');
  160. }
  161. }
  162. class PiwikCustomVariablesTest extends DrupalWebTestCase {
  163. public static function getInfo() {
  164. return array(
  165. 'name' => t('Piwik Custom Variables tests'),
  166. 'description' => t('Test custom variables functionality of Piwik module.'),
  167. 'group' => 'Piwik',
  168. 'dependencies' => array('token'),
  169. );
  170. }
  171. function setUp() {
  172. parent::setUp('piwik', 'token');
  173. $permissions = array(
  174. 'access administration pages',
  175. 'administer piwik',
  176. );
  177. // User to set up piwik.
  178. $this->admin_user = $this->drupalCreateUser($permissions);
  179. }
  180. function testPiwikCustomVariables() {
  181. $ua_code = '3';
  182. variable_set('piwik_site_id', $ua_code);
  183. // Basic test if the feature works.
  184. $custom_vars = array(
  185. 'slots' => array(
  186. 1 => array(
  187. 'slot' => 1,
  188. 'name' => 'Foo 1',
  189. 'value' => 'Bar 1',
  190. 'scope' => 3,
  191. ),
  192. 2 => array(
  193. 'slot' => 2,
  194. 'name' => 'Foo 2',
  195. 'value' => 'Bar 2',
  196. 'scope' => 2,
  197. ),
  198. 3 => array(
  199. 'slot' => 3,
  200. 'name' => 'Foo 3',
  201. 'value' => 'Bar 3',
  202. 'scope' => 3,
  203. ),
  204. 4 => array(
  205. 'slot' => 4,
  206. 'name' => 'Foo 4',
  207. 'value' => 'Bar 4',
  208. 'scope' => 2,
  209. ),
  210. 5 => array(
  211. 'slot' => 5,
  212. 'name' => 'Foo 5',
  213. 'value' => 'Bar 5',
  214. 'scope' => 1,
  215. ),
  216. )
  217. );
  218. variable_set('piwik_custom_var', $custom_vars);
  219. $this->drupalGet('');
  220. foreach ($custom_vars['slots'] as $slot) {
  221. $this->assertRaw("_paq.push(['setCustomVariable', " . $slot['slot'] . ", \"" . $slot['name'] . "\", \"" . $slot['value'] . "\", " . $slot['scope'] . "]);", '[testPiwikCustomVariables]: setCustomVariable ' . $slot['slot'] . ' is shown.');
  222. }
  223. // Test whether tokens are replaced in custom variable names.
  224. $site_slogan = $this->randomName(16);
  225. variable_set('site_slogan', $site_slogan);
  226. $custom_vars = array(
  227. 'slots' => array(
  228. 1 => array(
  229. 'slot' => 1,
  230. 'name' => 'Name: [site:slogan]',
  231. 'value' => 'Value: [site:slogan]',
  232. 'scope' => 3,
  233. ),
  234. 2 => array(
  235. 'slot' => 2,
  236. 'name' => '',
  237. 'value' => $this->randomName(16),
  238. 'scope' => 1,
  239. ),
  240. 3 => array(
  241. 'slot' => 3,
  242. 'name' => $this->randomName(16),
  243. 'value' => '',
  244. 'scope' => 2,
  245. ),
  246. 4 => array(
  247. 'slot' => 4,
  248. 'name' => '',
  249. 'value' => '',
  250. 'scope' => 3,
  251. ),
  252. 5 => array(
  253. 'slot' => 5,
  254. 'name' => '',
  255. 'value' => '',
  256. 'scope' => 3,
  257. ),
  258. )
  259. );
  260. variable_set('piwik_custom_var', $custom_vars);
  261. $this->verbose('<pre>' . print_r($custom_vars, TRUE) . '</pre>');
  262. $this->drupalGet('');
  263. $this->assertRaw("_paq.push(['setCustomVariable', 1, \"Name: $site_slogan\", \"Value: $site_slogan\", 3]", '[testPiwikCustomVariables]: Tokens have been replaced in custom variable.');
  264. $this->assertNoRaw("_paq.push(['setCustomVariable', 2,", '[testPiwikCustomVariables]: Value with empty name is not shown.');
  265. $this->assertNoRaw("_paq.push(['setCustomVariable', 3,", '[testPiwikCustomVariables]: Name with empty value is not shown.');
  266. $this->assertNoRaw("_paq.push(['setCustomVariable', 4,", '[testPiwikCustomVariables]: Empty name and value is not shown.');
  267. $this->assertNoRaw("_paq.push(['setCustomVariable', 5,", '[testPiwikCustomVariables]: Empty name and value is not shown.');
  268. }
  269. }
  270. class PiwikStatusMessagesTest extends DrupalWebTestCase {
  271. public static function getInfo() {
  272. return array(
  273. 'name' => 'Piwik status messages tests',
  274. 'description' => 'Test status messages functionality of Piwik module.',
  275. 'group' => 'Piwik',
  276. );
  277. }
  278. function setUp() {
  279. parent::setUp('piwik');
  280. $permissions = array(
  281. 'access administration pages',
  282. 'administer piwik',
  283. );
  284. // User to set up piwik.
  285. $this->admin_user = $this->drupalCreateUser($permissions);
  286. }
  287. function testPiwikStatusMessages() {
  288. $ua_code = '1';
  289. variable_set('piwik_site_id', $ua_code);
  290. // Enable logging of errors only.
  291. variable_set('piwik_trackmessages', array('error' => 'error'));
  292. $this->drupalPost('user/login', array(), t('Log in'));
  293. $this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Username field is required."]);', '[testPiwikStatusMessages]: trackEvent "Username field is required." is shown.');
  294. $this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Password field is required."]);', '[testPiwikStatusMessages]: trackEvent "Password field is required." is shown.');
  295. // @todo: investigate why drupal_set_message() fails.
  296. //drupal_set_message('Example status message.', 'status');
  297. //drupal_set_message('Example warning message.', 'warning');
  298. //drupal_set_message('Example error message.', 'error');
  299. //drupal_set_message('Example error <em>message</em> with html tags and <a href="http://example.com/">link</a>.', 'error');
  300. //$this->drupalGet('');
  301. //$this->assertNoRaw('_paq.push(["trackEvent", "Messages", "Status message", "Example status message."]);', '[testPiwikStatusMessages]: Example status message is not enabled for tracking.');
  302. //$this->assertNoRaw('_paq.push(["trackEvent", "Messages", "Warning message", "Example warning message."]);', '[testPiwikStatusMessages]: Example warning message is not enabled for tracking.');
  303. //$this->assertRaw('_paq.push(["trackEvent", "Messages", "Error message", "Example error message."]);', '[testPiwikStatusMessages]: Example error message is shown.');
  304. //$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.');
  305. }
  306. }
  307. class PiwikRolesTest extends DrupalWebTestCase {
  308. public static function getInfo() {
  309. return array(
  310. 'name' => t('Piwik role tests'),
  311. 'description' => t('Test roles functionality of Piwik module.'),
  312. 'group' => 'Piwik',
  313. );
  314. }
  315. function setUp() {
  316. parent::setUp('piwik');
  317. $permissions = array(
  318. 'access administration pages',
  319. 'administer piwik',
  320. );
  321. // User to set up piwik.
  322. $this->admin_user = $this->drupalCreateUser($permissions);
  323. }
  324. function testPiwikRolesTracking() {
  325. $ua_code = '1';
  326. variable_set('piwik_site_id', $ua_code);
  327. variable_get('piwik_url_http', 'http://example.com/piwik/');
  328. variable_get('piwik_url_https', 'https://example.com/piwik/');
  329. // Test if the default settings are working as expected.
  330. // Add to the selected roles only.
  331. variable_set('piwik_visibility_roles', 0);
  332. // Enable tracking for all users.
  333. variable_set('piwik_roles', array());
  334. // Check tracking code visibility.
  335. $this->drupalGet('');
  336. $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed for anonymous users on frontpage with default settings.');
  337. $this->drupalGet('admin');
  338. $this->assertRaw('"403/URL = "', '[testPiwikRoleVisibility]: 403 Forbidden tracking code is displayed for anonymous users in admin section with default settings.');
  339. $this->drupalLogin($this->admin_user);
  340. $this->drupalGet('');
  341. $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed for authenticated users on frontpage with default settings.');
  342. $this->drupalGet('admin');
  343. $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed for authenticated users in admin section with default settings.');
  344. // Test if the non-default settings are working as expected.
  345. // Enable tracking only for authenticated users.
  346. variable_set('piwik_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
  347. $this->drupalGet('');
  348. $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed for authenticated users only on frontpage.');
  349. $this->drupalLogout();
  350. $this->drupalGet('');
  351. $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed for anonymous users on frontpage.');
  352. // Add to every role except the selected ones.
  353. variable_set('piwik_visibility_roles', 1);
  354. // Enable tracking for all users.
  355. variable_set('piwik_roles', array());
  356. // Check tracking code visibility.
  357. $this->drupalGet('');
  358. $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is added to every role and displayed for anonymous users.');
  359. $this->drupalGet('admin');
  360. $this->assertRaw('"403/URL = "', '[testPiwikRoleVisibility]: 403 Forbidden tracking code is shown for anonymous users if every role except the selected ones is selected.');
  361. $this->drupalLogin($this->admin_user);
  362. $this->drupalGet('');
  363. $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is added to every role and displayed on frontpage for authenticated users.');
  364. $this->drupalGet('admin');
  365. $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is added to every role and NOT displayed in admin section for authenticated users.');
  366. // Disable tracking for authenticated users.
  367. variable_set('piwik_roles', array(DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
  368. $this->drupalGet('');
  369. $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed on frontpage for excluded authenticated users.');
  370. $this->drupalGet('admin');
  371. $this->assertNoRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is NOT displayed in admin section for excluded authenticated users.');
  372. $this->drupalLogout();
  373. $this->drupalGet('');
  374. $this->assertRaw('u+"piwik.php"', '[testPiwikRoleVisibility]: Tracking code is displayed on frontpage for included anonymous users.');
  375. }
  376. }
  377. class PiwikPhpFilterTest extends DrupalWebTestCase {
  378. public static function getInfo() {
  379. return array(
  380. 'name' => 'Piwik php filter tests',
  381. 'description' => 'Test php filter functionality of Piwik module.',
  382. 'group' => 'Piwik',
  383. );
  384. }
  385. function setUp() {
  386. parent::setUp('piwik', 'php');
  387. // Administrator with all permissions.
  388. $permissions_admin_user = array(
  389. 'access administration pages',
  390. 'administer piwik',
  391. 'use PHP for tracking visibility',
  392. );
  393. $this->admin_user = $this->drupalCreateUser($permissions_admin_user);
  394. // Administrator who cannot configure tracking visibility with PHP.
  395. $permissions_delegated_admin_user = array(
  396. 'access administration pages',
  397. 'administer piwik',
  398. );
  399. $this->delegated_admin_user = $this->drupalCreateUser($permissions_delegated_admin_user);
  400. }
  401. function testPiwikPhpFilter() {
  402. $ua_code = '1';
  403. $this->drupalLogin($this->admin_user);
  404. $edit = array();
  405. $edit['piwik_site_id'] = $ua_code;
  406. $edit['piwik_url_http'] = 'http://example.com/piwik/';
  407. $edit['piwik_url_https'] = 'https://example.com/piwik/';
  408. $edit['piwik_url_skiperror'] = TRUE; // Required for testing only.
  409. $edit['piwik_visibility_pages'] = 2;
  410. $edit['piwik_pages'] = '<?php return 0; ?>';
  411. $this->drupalPost('admin/config/system/piwik', $edit, t('Save configuration'));
  412. // Compare saved setting with posted setting.
  413. $piwik_pages = variable_get('piwik_pages', $this->randomName(8));
  414. $this->assertEqual('<?php return 0; ?>', $piwik_pages, '[testPiwikPhpFilter]: PHP code snippet is intact.');
  415. // Check tracking code visibility.
  416. variable_set('piwik_pages', '<?php return TRUE; ?>');
  417. $this->drupalGet('');
  418. $this->assertRaw('u+"piwik.php"', '[testPiwikPhpFilter]: Tracking is displayed on frontpage page.');
  419. $this->drupalGet('admin');
  420. $this->assertRaw('u+"piwik.php"', '[testPiwikPhpFilter]: Tracking is displayed on admin page.');
  421. variable_set('piwik_pages', '<?php return FALSE; ?>');
  422. $this->drupalGet('');
  423. $this->assertNoRaw('u+"piwik.php"', '[testPiwikPhpFilter]: Tracking is not displayed on frontpage page.');
  424. // Test administration form.
  425. variable_set('piwik_pages', '<?php return TRUE; ?>');
  426. $this->drupalGet('admin/config/system/piwik');
  427. $this->assertRaw(t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'), '[testPiwikPhpFilter]: Permission to administer PHP for tracking visibility.');
  428. $this->assertRaw(check_plain('<?php return TRUE; ?>'), '[testPiwikPhpFilter]: PHP code snippted is displayed.');
  429. // Login the delegated user and check if fields are visible.
  430. $this->drupalLogin($this->delegated_admin_user);
  431. $this->drupalGet('admin/config/system/piwik');
  432. $this->assertNoRaw(t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'), '[testPiwikPhpFilter]: No permission to administer PHP for tracking visibility.');
  433. $this->assertNoRaw(check_plain('<?php return TRUE; ?>'), '[testPiwikPhpFilter]: No permission to view PHP code snippted.');
  434. // Set a different value and verify that this is still the same after the post.
  435. variable_set('piwik_pages', '<?php return 0; ?>');
  436. $edit = array();
  437. $edit['piwik_site_id'] = $ua_code;
  438. $edit['piwik_url_http'] = 'http://example.com/piwik/';
  439. $edit['piwik_url_https'] = 'https://example.com/piwik/';
  440. $edit['piwik_url_skiperror'] = TRUE; // Required for testing only.
  441. $this->drupalPost('admin/config/system/piwik', $edit, t('Save configuration'));
  442. // Compare saved setting with posted setting.
  443. $piwik_visibility_pages = variable_get('piwik_visibility_pages', 0);
  444. $piwik_pages = variable_get('piwik_pages', $this->randomName(8));
  445. $this->assertEqual(2, $piwik_visibility_pages, '[testPiwikPhpFilter]: Pages on which this PHP code returns TRUE is selected.');
  446. $this->assertEqual('<?php return 0; ?>', $piwik_pages, '[testPiwikPhpFilter]: PHP code snippet is intact.');
  447. }
  448. }