|
3 | 3 | require_once dirname( __FILE__ ) . '/IntegrationTestCase.php'; |
4 | 4 |
|
5 | 5 | 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 | | - |
17 | 6 | protected function get_enabled_sizes() { |
18 | 7 | return array_map( function( $checkbox ) { |
19 | 8 | return $checkbox->getAttribute( 'name' ); |
20 | 9 | }, $this->find_all( 'input[type=checkbox][checked][name^=tinypng_sizes]' ) ); |
21 | 10 | } |
22 | 11 |
|
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 | | - |
192 | 12 | public function test_settings_should_allow_key_reset() { |
193 | 13 | $this->find( '#tinypng_api_key_name' )->clear()->sendKeys( 'John' ); |
194 | 14 | $this->find( '#tinypng_api_key_email' )->clear()->sendKeys( 'john@example.com' ); |
|
0 commit comments