Skip to content

Commit baf678c

Browse files
committed
wip
1 parent a86a7cb commit baf678c

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
3737
env:
3838
WP_VERSION: ${{ matrix.wordpress }}
39-
WP_SITE_URL: http://127.0.0.1:8100
39+
WP_SITE_URL: http://localhost:8100
4040
WP_DB_NAME: wordpress
4141
WP_DB_USER: root
4242
WP_DB_PASS: root
@@ -104,7 +104,7 @@ jobs:
104104
105105
- name: Start PHP server
106106
run: |
107-
php -S 127.0.0.1:8100 -t wordpress > /dev/null 2>&1 & until curl -sSf http://127.0.0.1:8100 > /dev/null; do sleep 0.2; done
107+
php -S localhost:8100 -t wordpress > /dev/null 2>&1 & until curl -sSf http://localhost:8100 > /dev/null; do sleep 0.2; done
108108
109109
- name: Install pnpm
110110
uses: pnpm/action-setup@v4

tests/Browser/PluginSettingsTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44

55
use function Tests\asAdmin;
66

7-
const DEFAULT_SA_NOTICE = '<!-- Simple Analytics: Not logging requests from admins -->';
7+
const SA_ADMIN_NOTICE = '<!-- Simple Analytics: Not logging requests from admins -->';
8+
const SA_DEFAULT_SCRIPT = '<script type="text/javascript" src="https://scripts.simpleanalyticscdn.com/latest.js"></script>';
9+
const WP_PLUGIN_ROW_SELECTOR = 'tr[data-slug="simpleanalytics"]';
10+
const WP_ACTIVATE_PLUGIN_SELECTOR = '#activate-simpleanalytics';
811

9-
test('Sign in as admin and activate the plugin', function () {
10-
$page = asAdmin();
12+
it('can be activated', function () {
13+
asAdmin()
14+
->navigate('http://localhost:8100/wp-admin/plugins.php')
15+
->assertPresent(WP_PLUGIN_ROW_SELECTOR)
16+
->click(WP_ACTIVATE_PLUGIN_SELECTOR);
17+
});
1118

12-
$page->navigate('http://127.0.0.1:8100/wp-admin/plugins.php')->screenshot();
13-
$page->assertSee('Simple Analytics Official');
19+
it('adds a script by default', function () {
20+
$homePage = visit('http://localhost:8100');
21+
expect($homePage->content())->toContain(SA_DEFAULT_SCRIPT);
22+
});
1423

15-
$page2 = visit('http://127.0.0.1:8100');//->screenshot();
16-
expect($page2->content())->not->toContain(DEFAULT_SA_NOTICE);
24+
it('adds a comment when an authenticated user visits', function () {
25+
$homePage = asAdmin()->navigate('http://localhost:8100');
26+
expect($homePage->content())->toContain(SA_ADMIN_NOTICE);
27+
$homePage->assertNoConsoleLogs();
1728
});

tests/Pest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,9 @@
4343

4444
function asAdmin()
4545
{
46-
$page = visit('http://127.0.0.1:8100/wp-admin');
47-
48-
$page->fill('user_login', 'admin');
49-
$page->fill('user_pass', 'admin');
50-
$page->press('wp-submit');
51-
$page->assertUrlIs('http://127.0.0.1:8100/wp-admin');
52-
53-
return $page;
46+
return visit('http://localhost:8100/wp-admin')
47+
->fill('user_login', 'admin')
48+
->fill('user_pass', 'admin')
49+
->press('wp-submit')
50+
->assertUrlIs('http://localhost:8100/wp-admin');
5451
}

0 commit comments

Comments
 (0)