Skip to content

Commit 5fe79c0

Browse files
Replace more integration tests
1 parent 8a8b4e0 commit 5fe79c0

File tree

2 files changed

+118
-183
lines changed

2 files changed

+118
-183
lines changed

test/integration/SettingsIntegrationTest.php

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -3,192 +3,12 @@
33
require_once dirname( __FILE__ ) . '/IntegrationTestCase.php';
44

55
class SettingsIntegrationTest extends IntegrationTestCase {
6-
public function set_up() {
7-
parent::set_up();
8-
$this->visit( '/wp-admin/options-general.php?page=tinify' );
9-
}
10-
11-
public function tear_down() {
12-
parent::tear_down();
13-
clear_settings();
14-
clear_uploads();
15-
}
16-
176
protected function get_enabled_sizes() {
187
return array_map( function( $checkbox ) {
198
return $checkbox->getAttribute( 'name' );
209
}, $this->find_all( 'input[type=checkbox][checked][name^=tinypng_sizes]' ) );
2110
}
2211

23-
public function test_settings_should_contain_title() {
24-
$headings = array_map( function( $heading ) {
25-
return $heading->getText();
26-
}, $this->find_all( 'h1' ) );
27-
28-
$this->assertContains( 'TinyPNG - JPEG, PNG & WebP image compression', $headings );
29-
}
30-
31-
public function test_settings_should_show_notice_if_key_is_missing() {
32-
$this->assertStringEndsWith(
33-
'options-general.php?page=tinify',
34-
$this->find( '.error a' )->getAttribute( 'href' )
35-
);
36-
}
37-
38-
public function test_settings_should_not_show_notice_if_key_is_set() {
39-
$this->set_api_key( 'PNG123' );
40-
$this->refresh();
41-
42-
$this->assertEquals( 0, count( $this->find_all( '.error a' ) ) );
43-
}
44-
45-
public function test_settings_should_store_valid_api_key() {
46-
$this->find( '#tinypng_api_key' )->sendKeys( 'PNG123' );
47-
$this->find( 'button[data-tiny-action=update-key]' )->click();
48-
49-
$this->wait_for_text(
50-
'div.tiny-account-status p.status span',
51-
'Your account is connected'
52-
);
53-
54-
$this->refresh();
55-
56-
$this->assertEquals(
57-
'Your account is connected',
58-
$this->find( 'div.tiny-account-status p.status span' )->getText()
59-
);
60-
}
61-
62-
public function test_settings_should_not_store_invalid_api_key() {
63-
$this->find( '#tinypng_api_key' )->sendKeys( 'INVALID123' );
64-
$this->find( 'button[data-tiny-action=update-key]' )->click();
65-
66-
$this->wait_for_text(
67-
'div.tiny-account-status div.update p.message',
68-
'The key that you have entered is not valid'
69-
);
70-
71-
$this->refresh();
72-
73-
$this->assertEquals(
74-
'Register new account',
75-
$this->find( 'div.tiny-account-status h4' )->getText()
76-
);
77-
}
78-
79-
public function test_settings_should_allow_changing_api_key() {
80-
$this->find( '#tinypng_api_key' )->sendKeys( 'PNG123' );
81-
$this->find( 'button[data-tiny-action=update-key]' )->click();
82-
83-
$this->wait_for_text(
84-
'div.tiny-account-status p.status span',
85-
'Your account is connected'
86-
);
87-
88-
$this->find_link( 'Change API key' )->click();
89-
90-
$this->find( '#tinypng_api_key' )->sendKeys( 'JPG123' );
91-
$this->find( 'button[data-tiny-action=update-key]' )->click();
92-
93-
$this->wait_for_text(
94-
'div.tiny-account-status p.status span',
95-
'Your account is connected'
96-
);
97-
}
98-
99-
public function test_settings_should_show_upgrade_notice() {
100-
$this->find( '#tinypng_api_key' )->sendKeys( 'LIMIT123' );
101-
$this->find( 'button[data-tiny-action=update-key]' )->click();
102-
103-
$this->wait_for_text(
104-
'div.tiny-account-status p.status span',
105-
'Your account is connected'
106-
);
107-
108-
$this->assertEquals(
109-
'Upgrade account',
110-
$this->find( 'a.upgrade-account' )->getText()
111-
);
112-
}
113-
114-
public function test_settings_should_not_show_upgrade_notice_for_paying_users() {
115-
$this->find( '#tinypng_api_key' )->sendKeys( 'PAID123' );
116-
$this->find( 'button[data-tiny-action=update-key]' )->click();
117-
118-
$this->wait_for_text(
119-
'div.tiny-account-status p.status span',
120-
'Your account is connected'
121-
);
122-
123-
$this->assertEquals( 0, count( $this->find_all( 'a.upgrade-account' ) ) );
124-
}
125-
126-
public function test_settings_should_pre_fill_registration_form() {
127-
$this->assertEquals(
128-
'',
129-
$this->find( '#tinypng_api_key_name' )->getAttribute( 'value' )
130-
);
131-
132-
$this->assertEquals(
133-
'developers@voormedia.com',
134-
$this->find( '#tinypng_api_key_email' )->getAttribute( 'value' )
135-
);
136-
}
137-
138-
public function test_settings_should_not_send_registration_without_name() {
139-
$this->find( '#tinypng_api_key_name' )->clear();
140-
$this->find( '#tinypng_api_key_email' )->clear()->sendKeys( 'john@example.com' );
141-
$this->find( 'button[data-tiny-action=create-key]' )->click();
142-
143-
$this->wait_for_text(
144-
'div.tiny-account-status div.create p.message',
145-
'Please enter your name'
146-
);
147-
148-
$this->refresh();
149-
150-
$this->assertEquals(
151-
'Register new account',
152-
$this->find( 'div.tiny-account-status h4' )->getText()
153-
);
154-
}
155-
156-
public function test_settings_should_not_send_registration_without_email() {
157-
$this->find( '#tinypng_api_key_name' )->clear()->sendKeys( 'John' );
158-
$this->find( '#tinypng_api_key_email' )->clear();
159-
$this->find( 'button[data-tiny-action=create-key]' )->click();
160-
161-
$this->wait_for_text(
162-
'div.tiny-account-status div.create p.message',
163-
'Please enter your email address'
164-
);
165-
166-
$this->refresh();
167-
168-
$this->assertEquals(
169-
'Register new account',
170-
$this->find( 'div.tiny-account-status h4' )->getText()
171-
);
172-
}
173-
174-
public function test_settings_should_store_registration_key() {
175-
$this->find( '#tinypng_api_key_name' )->clear()->sendKeys( 'John' );
176-
$this->find( '#tinypng_api_key_email' )->clear()->sendKeys( 'john@example.com' );
177-
$this->find( 'button[data-tiny-action=create-key]' )->click();
178-
179-
$this->wait_for_text(
180-
'div.tiny-account-status p.status span',
181-
'An email has been sent to activate your account'
182-
);
183-
184-
$this->refresh();
185-
186-
$this->assertEquals(
187-
'An email has been sent to activate your account',
188-
$this->find( 'div.tiny-account-status p.status span' )->getText()
189-
);
190-
}
191-
19212
public function test_settings_should_allow_key_reset() {
19313
$this->find( '#tinypng_api_key_name' )->clear()->sendKeys( 'John' );
19414
$this->find( '#tinypng_api_key_email' )->clear()->sendKeys( 'john@example.com' );

test/integration/settings.spec.ts

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect, test } from '@playwright/test';
22

3+
test.describe.configure({ mode: 'serial' });
4+
35
test.describe('settings', () => {
46
test('can load settings page', async ({ page }) => {
57
await page.goto('/wp-admin/options-general.php?page=tinify');
@@ -11,17 +13,130 @@ test.describe('settings', () => {
1113
test('show notice if key is missing', async ({ page }) => {
1214
await page.goto('/wp-admin/options-general.php?page=tinify');
1315

14-
const hasRegistrationUrl = await page.getByText('Please register or provide an API key to start compressing images.').isVisible();
15-
expect(hasRegistrationUrl).toBe(true);
16+
await expect(page.getByText('Please register or provide an API key to start compressing images.')).toBeVisible();
1617
});
1718

18-
test('not show notice if key is set', async ({ page }) => {
19+
test('invalid keys should not be stored', async ({ page }) => {
20+
await page.goto('/wp-admin/options-general.php?page=tinify');
21+
22+
await page.locator('#tinypng_api_key').click();
23+
await page.locator('#tinypng_api_key').fill('INVALID123');
24+
await page.getByRole('button', { name: 'Save', exact: true }).click();
25+
26+
await expect(page.getByText('The key that you have entered is not valid')).toBeVisible();
27+
28+
await page.reload();
29+
30+
await expect(page.getByText('Register new account')).toBeVisible();
31+
});
32+
33+
test('store valid api key', async ({ page }) => {
1934
await page.goto('/wp-admin/options-general.php?page=tinify');
2035

2136
await page.locator('#tinypng_api_key').click();
2237
await page.locator('#tinypng_api_key').fill('PNG123');
2338
await page.getByRole('button', { name: 'Save', exact: true }).click();
2439

2540
await expect(page.getByText('Your account is connected')).toBeVisible();
41+
42+
await page.reload();
43+
44+
await expect(page.getByText('Your account is connected')).toBeVisible();
45+
});
46+
47+
test('not show notice if key is set', async ({ page }) => {
48+
await page.goto('/wp-admin/options-general.php?page=tinify');
49+
50+
await expect(page.getByText('Please register or provide an API key to start compressing images.')).not.toBeVisible();
51+
});
52+
53+
test('allow changing api key', async ({ page }) => {
54+
await page.goto('/wp-admin/options-general.php?page=tinify');
55+
56+
await page.getByText('Change API key').click();
57+
58+
await page.locator('#tinypng_api_key').click();
59+
await page.locator('#tinypng_api_key').fill('JPG123');
60+
await page.getByRole('button', { name: 'Save', exact: true }).click();
61+
62+
await expect(page.getByText('Your account is connected')).toBeVisible();
63+
});
64+
65+
test('show upgrade notice', async ({ page }) => {
66+
await page.goto('/wp-admin/options-general.php?page=tinify');
67+
68+
await page.getByText('Change API key').click();
69+
70+
await page.locator('#tinypng_api_key').click();
71+
await page.locator('#tinypng_api_key').fill('LIMIT123');
72+
await page.getByRole('button', { name: 'Save', exact: true }).click();
73+
74+
await expect(page.getByText('Upgrade account')).toBeVisible();
75+
});
76+
77+
test('not show upgrade notice for paid users', async ({ page }) => {
78+
await page.goto('/wp-admin/options-general.php?page=tinify');
79+
80+
await page.getByText('Change API key').click();
81+
82+
await page.locator('#tinypng_api_key').click();
83+
await page.locator('#tinypng_api_key').fill('PAID123');
84+
await page.getByRole('button', { name: 'Save', exact: true }).click();
85+
86+
87+
await expect(page.getByText('Upgrade account')).not.toBeVisible();
88+
89+
await page.getByText('Change API key').click();
90+
await page.locator('#tinypng_api_key').fill('');
91+
await page.getByRole('button', { name: 'Save', exact: true }).click();
92+
});
93+
94+
test('have prefilled registration form', async ({ page }) => {
95+
await page.goto('/wp-admin/options-general.php?page=tinify');
96+
97+
await expect(page.locator('#tinypng_api_key_name')).toHaveValue('');
98+
await expect(page.locator('#tinypng_api_key_email')).toHaveValue('wordpress@example.com');
99+
});
100+
101+
test('should not send registration without name', async ({ page }) => {
102+
await page.goto('/wp-admin/options-general.php?page=tinify');
103+
104+
await expect(page.locator('#tinypng_api_key_name')).toHaveValue('');
105+
await expect(page.locator('#tinypng_api_key_email')).toHaveValue('wordpress@example.com');
106+
await page.getByText('Register account').click();
107+
108+
await expect(page.getByText('Please enter your name')).toBeVisible();
109+
110+
await page.reload();
111+
112+
await expect(page.getByText('Register new account')).toBeVisible();
113+
});
114+
115+
test('should not send registration without email', async ({ page }) => {
116+
await page.goto('/wp-admin/options-general.php?page=tinify');
117+
118+
await page.locator('#tinypng_api_key_email').fill('');
119+
await page.locator('#tinypng_api_key_name').fill('John');
120+
await page.getByText('Register account').click();
121+
122+
await expect(page.getByText('Please enter your email address')).toBeVisible();
123+
124+
await page.reload();
125+
126+
await expect(page.getByText('Register new account')).toBeVisible();
127+
});
128+
129+
test('should store registration key', async ({ page }) => {
130+
await page.goto('/wp-admin/options-general.php?page=tinify');
131+
132+
await page.locator('#tinypng_api_key_name').fill('John');
133+
await page.locator('#tinypng_api_key_email').fill('john@example.com');
134+
await page.getByText('Register account').click();
135+
136+
await expect(page.getByText('An email has been sent to activate your account')).toBeVisible();
137+
138+
await page.reload();
139+
140+
await expect(page.getByText('An email has been sent to activate your account')).toBeVisible();
26141
});
27142
});

0 commit comments

Comments
 (0)