|
4 | 4 |
|
5 | 5 | use function Tests\{asAdmin, asAuthor, asEditor}; |
6 | 6 |
|
7 | | -const SA_DEFAULT_SCRIPT = 'src="https://scripts.simpleanalyticscdn.com/latest.js"></script>'; |
8 | | -const SA_INACTIVE_ADMIN_NOTICE = '<!-- Simple Analytics: Not logging requests from admins -->'; |
9 | | -const SA_INACTIVE_ADMIN_SCRIPT = 'src="http://localhost:8100/wp-content/plugins/simpleanalytics/resources/js/inactive.js"'; |
| 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 | 10 |
|
11 | 11 | it('can be activated', function () { |
12 | 12 | asAdmin() |
|
19 | 19 | }); |
20 | 20 |
|
21 | 21 | it('adds a script by default', function () { |
22 | | - $homePage = visit('http://localhost:8100'); |
23 | | - expect($homePage->content())->toContain(SA_DEFAULT_SCRIPT); |
| 22 | + visit('http://localhost:8100')->assertPresent(SA_DEFAULT_SCRIPT_SELECTOR); |
24 | 23 | }); |
25 | 24 |
|
26 | 25 | it('adds inactive script for authenticated users by default', function () { |
27 | | - $homePage = asAdmin()->navigate('http://localhost:8100'); |
28 | | - |
29 | | - expect($homePage->content()) |
30 | | - ->toContain(SA_INACTIVE_ADMIN_NOTICE) |
31 | | - ->toContain(SA_INACTIVE_ADMIN_SCRIPT); |
| 26 | + asAdmin() |
| 27 | + ->navigate('http://localhost:8100') |
| 28 | + ->assertPresent('script[url="http://localhost:8100/wp-content/plugins/simpleanalytics/resources/js/inactive.js"]') |
| 29 | + ->assertSourceHas(SA_INACTIVE_ADMIN_COMMENT); |
32 | 30 | }); |
33 | 31 |
|
34 | 32 | it('adds a script with ignored pages', function () { |
|
38 | 36 | ->click('Save Changes') |
39 | 37 | ->assertValue('simpleanalytics_ignore_pages', '/vouchers'); |
40 | 38 |
|
41 | | - expect(visit('http://localhost:8100')->content())->toContain('data-ignore-pages="/vouchers"'); |
| 39 | + visit('http://localhost:8100')->assertSourceHas('data-ignore-pages="/vouchers"'); |
42 | 40 | }); |
43 | 41 |
|
44 | 42 | it('adds inactive script for selected user roles', function () { |
45 | | - $admin = asAdmin(); |
46 | | - |
47 | | - $admin->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules') |
| 43 | + $admin = asAdmin()->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules') |
48 | 44 | ->check('simpleanalytics_exclude_user_roles-editor') |
49 | 45 | ->check('simpleanalytics_exclude_user_roles-author') |
50 | 46 | ->click('Save Changes') |
51 | 47 | ->assertChecked('simpleanalytics_exclude_user_roles-editor') |
52 | 48 | ->assertChecked('simpleanalytics_exclude_user_roles-author'); |
53 | 49 |
|
54 | | - expect($admin->navigate('http://localhost:8100')->content()) |
55 | | - ->toContain(SA_DEFAULT_SCRIPT); |
| 50 | + $admin->navigate('http://localhost:8100') |
| 51 | + ->assertPresent(SA_DEFAULT_SCRIPT_SELECTOR); |
56 | 52 |
|
57 | | - expect(asEditor()->navigate('http://localhost:8100')->content()) |
58 | | - ->toContain(SA_INACTIVE_ADMIN_NOTICE) |
59 | | - ->toContain(SA_INACTIVE_ADMIN_SCRIPT); |
| 53 | + asAuthor()->navigate('http://localhost:8100') |
| 54 | + ->assertPresent(SA_INACTIVE_ADMIN_SCRIPT_SELECTOR) |
| 55 | + ->assertSourceHas(SA_INACTIVE_ADMIN_COMMENT); |
60 | 56 |
|
61 | | - expect(asAuthor()->navigate('http://localhost:8100')->content()) |
62 | | - ->toContain(SA_INACTIVE_ADMIN_NOTICE) |
63 | | - ->toContain(SA_INACTIVE_ADMIN_SCRIPT); |
| 57 | + asEditor()->navigate('http://localhost:8100') |
| 58 | + ->assertPresent(SA_INACTIVE_ADMIN_SCRIPT_SELECTOR) |
| 59 | + ->assertSourceHas(SA_INACTIVE_ADMIN_COMMENT); |
64 | 60 | }); |
65 | 61 |
|
66 | 62 | it('adds a script with a custom domain name', function () { |
|
70 | 66 | ->click('Save Changes') |
71 | 67 | ->assertValue('simpleanalytics_custom_domain', 'mydomain.com'); |
72 | 68 |
|
73 | | - $script = str_replace('scripts.simpleanalyticscdn.com', 'mydomain.com', SA_DEFAULT_SCRIPT); |
74 | | - |
75 | | - expect(visit('http://localhost:8100')->content())->toContain($script); |
| 69 | + visit('http://localhost:8100')->assertPresent('script[src="https://mydomain.com/latest.js"]'); |
76 | 70 | }); |
0 commit comments