|
4 | 4 |
|
5 | 5 | use function Tests\{asAdmin, asAuthor, asEditor}; |
6 | 6 |
|
7 | | -const SA_DEFAULT_SCRIPT_SELECTOR = 'script[src="https://scripts.simpleanalyticscdn.com/latest.js"]'; |
8 | | -const SA_INACTIVE_ADMIN_SCRIPT_SELECTOR = 'script[src="http://localhost:8100/wp-content/plugins/simpleanalytics/resources/js/inactive.js"]'; |
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"]'; |
| 7 | +const DEFAULT_SCRIPT_SELECTOR = 'script[src="https://scripts.simpleanalyticscdn.com/latest.js"]'; |
| 8 | +const INACTIVE_ADMIN_SCRIPT_SELECTOR = 'script[src="http://localhost:8100/wp-content/plugins/simpleanalytics/resources/js/inactive.js"]'; |
| 9 | +const INACTIVE_ADMIN_COMMENT = '<!-- Simple Analytics: Not logging requests from admins -->'; |
| 10 | +const NOSCRIPT_SELECTOR = 'noscript img[src="https://queue.simpleanalyticscdn.com/noscript.gif"][alt=""][referrerpolicy="no-referrer-when-downgrade"]'; |
11 | 11 |
|
12 | 12 | it('can be activated', function () { |
13 | 13 | asAdmin() |
|
20 | 20 | }); |
21 | 21 |
|
22 | 22 | it('adds a script by default', function () { |
23 | | - visit('http://localhost:8100')->assertPresent(SA_DEFAULT_SCRIPT_SELECTOR); |
| 23 | + visit('http://localhost:8100')->assertPresent(DEFAULT_SCRIPT_SELECTOR); |
24 | 24 | }); |
25 | 25 |
|
26 | 26 | it('adds inactive script for authenticated users by default', function () { |
27 | 27 | asAdmin() |
28 | 28 | ->navigate('http://localhost:8100') |
29 | 29 | ->assertPresent('script[src="http://localhost:8100/wp-content/plugins/simpleanalytics/resources/js/inactive.js"]') |
30 | | - ->assertSourceHas(SA_INACTIVE_ADMIN_COMMENT); |
| 30 | + ->assertSourceHas(INACTIVE_ADMIN_COMMENT); |
31 | 31 | }); |
32 | 32 |
|
33 | 33 | it('adds a script with ignored pages', function () { |
|
49 | 49 | ->assertChecked('simpleanalytics_exclude_user_roles-author'); |
50 | 50 |
|
51 | 51 | $admin->navigate('http://localhost:8100') |
52 | | - ->assertPresent(SA_DEFAULT_SCRIPT_SELECTOR); |
| 52 | + ->assertPresent(DEFAULT_SCRIPT_SELECTOR); |
53 | 53 |
|
54 | 54 | asAuthor()->navigate('http://localhost:8100') |
55 | | - ->assertPresent(SA_INACTIVE_ADMIN_SCRIPT_SELECTOR) |
56 | | - ->assertSourceHas(SA_INACTIVE_ADMIN_COMMENT); |
| 55 | + ->assertPresent(INACTIVE_ADMIN_SCRIPT_SELECTOR) |
| 56 | + ->assertSourceHas(INACTIVE_ADMIN_COMMENT); |
57 | 57 |
|
58 | 58 | asEditor()->navigate('http://localhost:8100') |
59 | | - ->assertPresent(SA_INACTIVE_ADMIN_SCRIPT_SELECTOR) |
60 | | - ->assertSourceHas(SA_INACTIVE_ADMIN_COMMENT); |
| 59 | + ->assertPresent(INACTIVE_ADMIN_SCRIPT_SELECTOR) |
| 60 | + ->assertSourceHas(INACTIVE_ADMIN_COMMENT); |
61 | 61 | }); |
62 | 62 |
|
63 | 63 | it('adds a script with a custom domain name', function () { |
|
71 | 71 | }); |
72 | 72 |
|
73 | 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') |
| 74 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
76 | 75 | ->check('simpleanalytics_collect_dnt') |
77 | 76 | ->click('Save Changes') |
78 | 77 | ->assertChecked('simpleanalytics_collect_dnt'); |
|
81 | 80 | }); |
82 | 81 |
|
83 | 82 | 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') |
| 83 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
86 | 84 | ->check('simpleanalytics_hash_mode') |
87 | 85 | ->click('Save Changes') |
88 | 86 | ->assertChecked('simpleanalytics_hash_mode'); |
|
91 | 89 | }); |
92 | 90 |
|
93 | 91 | 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') |
| 92 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
96 | 93 | ->check('simpleanalytics_manual_collect') |
97 | 94 | ->click('Save Changes') |
98 | 95 | ->assertChecked('simpleanalytics_manual_collect'); |
|
101 | 98 | }); |
102 | 99 |
|
103 | 100 | 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') |
| 101 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
106 | 102 | ->check('simpleanalytics_noscript') |
107 | 103 | ->click('Save Changes') |
108 | 104 | ->assertChecked('simpleanalytics_noscript'); |
109 | 105 |
|
110 | | - visit('http://localhost:8100')->assertPresent(SA_NOSCRIPT_SELECTOR); |
| 106 | + visit('http://localhost:8100')->assertPresent(NOSCRIPT_SELECTOR); |
111 | 107 | }); |
112 | 108 |
|
113 | 109 | it('adds a script with onload callback', function () { |
114 | | - asAdmin() |
115 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 110 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
116 | 111 | ->fill('simpleanalytics_onload_callback', 'sa_event("My event")') |
117 | 112 | ->click('Save Changes') |
118 | 113 | ->assertValue('simpleanalytics_onload_callback', 'sa_event("My event")'); |
|
121 | 116 | }); |
122 | 117 |
|
123 | 118 | it('adds a script with global variable name', function () { |
124 | | - asAdmin() |
125 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 119 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
126 | 120 | ->fill('simpleanalytics_sa_global', 'ba_event') |
127 | 121 | ->click('Save Changes') |
128 | 122 | ->assertValue('simpleanalytics_sa_global', 'ba_event'); |
|
131 | 125 | }); |
132 | 126 |
|
133 | 127 | it('adds automated events script when collect automated events is enabled', function () { |
134 | | - asAdmin() |
135 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 128 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
136 | 129 | ->check('simpleanalytics_automated_events') |
137 | 130 | ->click('Save Changes') |
138 | 131 | ->assertChecked('simpleanalytics_automated_events'); |
|
141 | 134 | }); |
142 | 135 |
|
143 | 136 | it('adds automated events script with auto collect downloads', function () { |
144 | | - asAdmin() |
145 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 137 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
146 | 138 | ->check('simpleanalytics_automated_events') |
147 | 139 | ->fill('simpleanalytics_event_collect_downloads', 'outbound,emails,downloads') |
148 | 140 | ->click('Save Changes') |
|
153 | 145 | }); |
154 | 146 |
|
155 | 147 | it('adds automated events script with download file extensions', function () { |
156 | | - asAdmin() |
157 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 148 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
158 | 149 | ->check('simpleanalytics_automated_events') |
159 | 150 | ->fill('simpleanalytics_event_extensions', 'pdf,zip') |
160 | 151 | ->click('Save Changes') |
|
165 | 156 | }); |
166 | 157 |
|
167 | 158 | it('adds automated events script with use titles of page enabled', function () { |
168 | | - asAdmin() |
169 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 159 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
170 | 160 | ->check('simpleanalytics_automated_events') |
171 | 161 | ->check('simpleanalytics_event_use_title') |
172 | 162 | ->click('Save Changes') |
|
177 | 167 | }); |
178 | 168 |
|
179 | 169 | it('adds automated events script with use full urls enabled', function () { |
180 | | - asAdmin() |
181 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 170 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
182 | 171 | ->check('simpleanalytics_automated_events') |
183 | 172 | ->check('simpleanalytics_event_full_urls') |
184 | 173 | ->click('Save Changes') |
|
189 | 178 | }); |
190 | 179 |
|
191 | 180 | it('adds automated events script with override global', function () { |
192 | | - asAdmin() |
193 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
| 181 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=events') |
194 | 182 | ->check('simpleanalytics_automated_events') |
195 | 183 | ->fill('simpleanalytics_event_sa_global', 'ba_event') |
196 | 184 | ->click('Save Changes') |
|
201 | 189 | }); |
202 | 190 |
|
203 | 191 | it('adds a script with overwrite domain name', function () { |
204 | | - asAdmin() |
205 | | - ->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
| 192 | + asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=advanced') |
206 | 193 | ->fill('simpleanalytics_hostname', 'example.com') |
207 | 194 | ->click('Save Changes') |
208 | 195 | ->assertValue('simpleanalytics_hostname', 'example.com'); |
|
0 commit comments