|
7 | 7 | const SA_DEFAULT_SCRIPT_SELECTOR = 'script[src="https://scripts.simpleanalyticscdn.com/latest.js"]'; |
8 | 8 | const SA_INACTIVE_ADMIN_SCRIPT_SELECTOR = 'script[src="http://localhost:8100/wp-content/plugins/simpleanalytics/resources/js/inactive.js"]'; |
9 | 9 | const SA_INACTIVE_ADMIN_COMMENT = '<!-- Simple Analytics: Not logging requests from admins -->'; |
| 10 | +const SA_NOSCRIPT_SELECTOR = 'noscript img[src="https://queue.simpleanalyticscdn.com/noscript.gif"][alt=""][referrerpolicy="no-referrer-when-downgrade"]'; |
10 | 11 |
|
11 | 12 | it('can be activated', function () { |
12 | 13 | asAdmin() |
|
68 | 69 |
|
69 | 70 | visit('http://localhost:8100')->assertPresent('script[src="https://mydomain.com/latest.js"]'); |
70 | 71 | }); |
| 72 | + |
| 73 | +it('adds a script with collect do not track enabled', function () { |
| 74 | + asAdmin() |
| 75 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 76 | + ->check('simpleanalytics_collect_dnt') |
| 77 | + ->click('Save Changes') |
| 78 | + ->assertChecked('simpleanalytics_collect_dnt'); |
| 79 | + |
| 80 | + visit('http://localhost:8100')->assertSourceHas('data-collect-dnt="true"'); |
| 81 | +}); |
| 82 | + |
| 83 | +it('adds a script with hash mode enabled', function () { |
| 84 | + asAdmin() |
| 85 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 86 | + ->check('simpleanalytics_hash_mode') |
| 87 | + ->click('Save Changes') |
| 88 | + ->assertChecked('simpleanalytics_hash_mode'); |
| 89 | + |
| 90 | + visit('http://localhost:8100')->assertSourceHas('data-mode="hash"'); |
| 91 | +}); |
| 92 | + |
| 93 | +it('adds a script with manually collect page views enabled', function () { |
| 94 | + asAdmin() |
| 95 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 96 | + ->check('simpleanalytics_manual_collect') |
| 97 | + ->click('Save Changes') |
| 98 | + ->assertChecked('simpleanalytics_manual_collect'); |
| 99 | + |
| 100 | + visit('http://localhost:8100')->assertSourceHas('data-auto-collect="true"'); |
| 101 | +}); |
| 102 | + |
| 103 | +it('adds noscript tag when support no javascript mode is enabled', function () { |
| 104 | + asAdmin() |
| 105 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 106 | + ->check('simpleanalytics_noscript') |
| 107 | + ->click('Save Changes') |
| 108 | + ->assertChecked('simpleanalytics_noscript'); |
| 109 | + |
| 110 | + visit('http://localhost:8100')->assertPresent(SA_NOSCRIPT_SELECTOR); |
| 111 | +}); |
| 112 | + |
| 113 | +it('adds a script with onload callback', function () { |
| 114 | + asAdmin() |
| 115 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 116 | + ->fill('simpleanalytics_onload_callback', 'sa_event("My event")') |
| 117 | + ->click('Save Changes') |
| 118 | + ->assertValue('simpleanalytics_onload_callback', 'sa_event("My event")'); |
| 119 | + |
| 120 | + visit('http://localhost:8100')->assertSourceHas('data-onload="sa_event(\"My event\")"'); |
| 121 | +}); |
| 122 | + |
| 123 | +it('adds a script with overwrite domain name', function () { |
| 124 | + asAdmin() |
| 125 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 126 | + ->fill('simpleanalytics_hostname', 'example.com') |
| 127 | + ->click('Save Changes') |
| 128 | + ->assertValue('simpleanalytics_hostname', 'example.com'); |
| 129 | + |
| 130 | + visit('http://localhost:8100')->assertSourceHas('data-hostname="example.com"'); |
| 131 | +}); |
| 132 | + |
| 133 | +it('adds a script with global variable name', function () { |
| 134 | + asAdmin() |
| 135 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 136 | + ->fill('simpleanalytics_sa_global', 'ba_event') |
| 137 | + ->click('Save Changes') |
| 138 | + ->assertValue('simpleanalytics_sa_global', 'ba_event'); |
| 139 | + |
| 140 | + visit('http://localhost:8100')->assertSourceHas('data-sa-global="ba_event"'); |
| 141 | +}); |
| 142 | + |
| 143 | +it('adds automated events script when collect automated events is enabled', function () { |
| 144 | + asAdmin() |
| 145 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 146 | + ->check('simpleanalytics_automated_events') |
| 147 | + ->click('Save Changes') |
| 148 | + ->assertChecked('simpleanalytics_automated_events'); |
| 149 | + |
| 150 | + visit('http://localhost:8100')->assertPresent('script[src="https://scripts.simpleanalyticscdn.com/auto-events.js"]'); |
| 151 | +}); |
| 152 | + |
| 153 | +it('adds automated events script with auto collect downloads', function () { |
| 154 | + asAdmin() |
| 155 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 156 | + ->check('simpleanalytics_automated_events') |
| 157 | + ->fill('simpleanalytics_event_collect_downloads', 'outbound,emails,downloads') |
| 158 | + ->click('Save Changes') |
| 159 | + ->assertChecked('simpleanalytics_automated_events') |
| 160 | + ->assertValue('simpleanalytics_event_collect_downloads', 'outbound,emails,downloads'); |
| 161 | + |
| 162 | + visit('http://localhost:8100')->assertSourceHas('data-collect="outbound,emails,downloads"'); |
| 163 | +}); |
| 164 | + |
| 165 | +it('adds automated events script with download file extensions', function () { |
| 166 | + asAdmin() |
| 167 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 168 | + ->check('simpleanalytics_automated_events') |
| 169 | + ->fill('simpleanalytics_event_extensions', 'pdf,zip') |
| 170 | + ->click('Save Changes') |
| 171 | + ->assertChecked('simpleanalytics_automated_events') |
| 172 | + ->assertValue('simpleanalytics_event_extensions', 'pdf,zip'); |
| 173 | + |
| 174 | + visit('http://localhost:8100')->assertSourceHas('data-extensions="pdf,zip"'); |
| 175 | +}); |
| 176 | + |
| 177 | +it('adds automated events script with use titles of page enabled', function () { |
| 178 | + asAdmin() |
| 179 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 180 | + ->check('simpleanalytics_automated_events') |
| 181 | + ->check('simpleanalytics_event_use_title') |
| 182 | + ->click('Save Changes') |
| 183 | + ->assertChecked('simpleanalytics_automated_events') |
| 184 | + ->assertChecked('simpleanalytics_event_use_title'); |
| 185 | + |
| 186 | + visit('http://localhost:8100')->assertSourceHas('data-use-title'); |
| 187 | +}); |
| 188 | + |
| 189 | +it('adds automated events script with use full urls enabled', function () { |
| 190 | + asAdmin() |
| 191 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 192 | + ->check('simpleanalytics_automated_events') |
| 193 | + ->check('simpleanalytics_event_full_urls') |
| 194 | + ->click('Save Changes') |
| 195 | + ->assertChecked('simpleanalytics_automated_events') |
| 196 | + ->assertChecked('simpleanalytics_event_full_urls'); |
| 197 | + |
| 198 | + visit('http://localhost:8100')->assertSourceHas('data-full-urls'); |
| 199 | +}); |
| 200 | + |
| 201 | +it('adds automated events script with override global', function () { |
| 202 | + asAdmin() |
| 203 | + ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 204 | + ->check('simpleanalytics_automated_events') |
| 205 | + ->fill('simpleanalytics_event_sa_global', 'ba_event') |
| 206 | + ->click('Save Changes') |
| 207 | + ->assertChecked('simpleanalytics_automated_events') |
| 208 | + ->assertValue('simpleanalytics_event_sa_global', 'ba_event'); |
| 209 | + |
| 210 | + visit('http://localhost:8100')->assertSourceHas('data-sa-global="ba_event"'); |
| 211 | +}); |
0 commit comments