Skip to content

Commit 76166a8

Browse files
committed
wip
1 parent 29ef711 commit 76166a8

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ jobs:
8787
--path=wordpress \
8888
--skip-email \
8989
--allow-root
90+
wp user create author author@localhost --role=author --user_pass=author
91+
wp user create editor editor@localhost --role=editor --user_pass=editor
92+
wp user create subscriber subscriber@localhost --role=subscriber --user_pass=subscriber
9093
9194
- name: Show current config values
9295
run: wp config list --path=wordpress --allow-root

tests/Browser/PluginSettingsTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Tests\Browser;
44

5-
use function Tests\asAdmin;
5+
use function Tests\{asAdmin, asAuthor, asEditor};
66

77
const SA_ADMIN_NOTICE = '<!-- Simple Analytics: Not logging requests from admins -->';
88
const SA_DEFAULT_SCRIPT = 'src="https://scripts.simpleanalyticscdn.com/latest.js"></script>';
@@ -20,13 +20,13 @@
2020

2121
it('adds a script by default', function () {
2222
$homePage = visit('http://localhost:8100');
23-
expect($homePage->content())->dump()->toContain(SA_DEFAULT_SCRIPT);
23+
expect($homePage->content())->toContain(SA_DEFAULT_SCRIPT);
2424
});
2525

26-
it('adds a comment when an authenticated user visits', function () {
26+
it('adds inactive script for authenticated users by default', function () {
2727
$homePage = asAdmin()->navigate('http://localhost:8100');
2828

29-
expect($homePage->content())->dump()
29+
expect($homePage->content())
3030
->toContain(SA_ADMIN_NOTICE)
3131
->toContain(SA_INACTIVE_ADMIN_SCRIPT);
3232
});
@@ -52,3 +52,21 @@
5252

5353
expect(visit('http://localhost:8100')->content())->toContain('data-ignore-pages="/vouchers"');
5454
});
55+
56+
it('adds inactive script for selected user roles', function () {
57+
asAdmin()
58+
->navigate('http://localhost:8100/wp-admin/options-general.php?page=simpleanalytics&tab=ignore-rules')
59+
->check('simpleanalytics_exclude_user_roles-editor')
60+
->check('simpleanalytics_exclude_user_roles-author')
61+
->click('Save Changes')
62+
->assertChecked('simpleanalytics_exclude_user_roles-editor')
63+
->assertChecked('simpleanalytics_exclude_user_roles-author');
64+
65+
expect(asEditor()->navigate('http://localhost:8100')->content())
66+
->toContain(SA_ADMIN_NOTICE)
67+
->toContain(SA_INACTIVE_ADMIN_SCRIPT);
68+
69+
expect(asAuthor()->navigate('http://localhost:8100')->content())
70+
->toContain(SA_ADMIN_NOTICE)
71+
->toContain(SA_INACTIVE_ADMIN_SCRIPT);
72+
});

tests/Pest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
|
1414
*/
1515

16+
use Pest\Browser\Api\Webpage;
17+
1618
pest()->extend(TestCase::class)->in('Feature');
1719

1820
/*
@@ -41,11 +43,26 @@
4143
|
4244
*/
4345

44-
function asAdmin()
46+
function asUser(string $login, string $password): Webpage
4547
{
4648
return visit('http://localhost:8100/wp-admin')
47-
->fill('user_login', 'admin')
48-
->fill('user_pass', 'admin')
49+
->fill('user_login', $login)
50+
->fill('user_pass', $password)
4951
->press('wp-submit')
5052
->assertUrlIs('http://localhost:8100/wp-admin');
5153
}
54+
55+
function asAdmin()
56+
{
57+
return asUser('admin', 'admin');
58+
}
59+
60+
function asAuthor()
61+
{
62+
return asUser('author', 'author');
63+
}
64+
65+
function asEditor()
66+
{
67+
return asUser('editor', 'editor');
68+
}

0 commit comments

Comments
 (0)