Skip to content

Commit 873043a

Browse files
committed
wip
1 parent 6b5c935 commit 873043a

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

tests/Browser/PluginSettingsTest.php

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use function Tests\{asAdmin, asAuthor, asEditor};
66

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 -->';
1010

1111
it('can be activated', function () {
1212
asAdmin()
@@ -19,16 +19,14 @@
1919
});
2020

2121
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);
2423
});
2524

2625
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);
3230
});
3331

3432
it('adds a script with ignored pages', function () {
@@ -38,29 +36,27 @@
3836
->click('Save Changes')
3937
->assertValue('simpleanalytics_ignore_pages', '/vouchers');
4038

41-
expect(visit('http://localhost:8100')->content())->toContain('data-ignore-pages="/vouchers"');
39+
visit('http://localhost:8100')->assertSourceHas('data-ignore-pages="/vouchers"');
4240
});
4341

4442
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')
4844
->check('simpleanalytics_exclude_user_roles-editor')
4945
->check('simpleanalytics_exclude_user_roles-author')
5046
->click('Save Changes')
5147
->assertChecked('simpleanalytics_exclude_user_roles-editor')
5248
->assertChecked('simpleanalytics_exclude_user_roles-author');
5349

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);
5652

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);
6056

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);
6460
});
6561

6662
it('adds a script with a custom domain name', function () {
@@ -70,7 +66,5 @@
7066
->click('Save Changes')
7167
->assertValue('simpleanalytics_custom_domain', 'mydomain.com');
7268

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"]');
7670
});

0 commit comments

Comments
 (0)