8
8
use Drupal \FunctionalJavascriptTests \PerformanceTestBase ;
9
9
use Drupal \Tests \PerformanceData ;
10
10
use Drupal \node \NodeInterface ;
11
+ use Drupal \user \UserInterface ;
11
12
12
13
/**
13
14
* Tests the performance of basic functionality in the standard profile.
@@ -29,6 +30,11 @@ class StandardPerformanceTest extends PerformanceTestBase {
29
30
*/
30
31
protected $ profile = 'standard ' ;
31
32
33
+ /**
34
+ * The user account created during testing.
35
+ */
36
+ protected ?UserInterface $ user = NULL ;
37
+
32
38
/**
33
39
* {@inheritdoc}
34
40
*/
@@ -43,10 +49,19 @@ protected function setUp(): void {
43
49
user_role_grant_permissions ('anonymous ' , ['access user profiles ' ]);
44
50
}
45
51
52
+ /**
53
+ * Tests performance of the standard profile.
54
+ */
55
+ public function testStandardPerformance (): void {
56
+ $ this ->testAnonymous ();
57
+ $ this ->testLogin ();
58
+ $ this ->testLoginBlock ();
59
+ }
60
+
46
61
/**
47
62
* Tests performance for anonymous users.
48
63
*/
49
- public function testAnonymous (): void {
64
+ protected function testAnonymous (): void {
50
65
// Request the front page, then immediately clear all object caches, so that
51
66
// aggregates and image styles are created on disk but otherwise caches are
52
67
// empty.
@@ -146,9 +161,9 @@ public function testAnonymous(): void {
146
161
$ this ->assertSame (0 , $ performance_data ->getCacheTagInvalidationCount ());
147
162
148
163
// Test user profile page.
149
- $ user = $ this ->drupalCreateUser ();
150
- $ performance_data = $ this ->collectPerformanceData (function () use ( $ user ) {
151
- $ this ->drupalGet ('user/ ' . $ user ->id ());
164
+ $ this -> user = $ this ->drupalCreateUser ();
165
+ $ performance_data = $ this ->collectPerformanceData (function () {
166
+ $ this ->drupalGet ('user/ ' . $ this -> user ->id ());
152
167
}, 'standardUserPage ' );
153
168
$ this ->assertNoJavaScript ($ performance_data );
154
169
$ this ->assertSame (1 , $ performance_data ->getStylesheetCount ());
@@ -182,23 +197,22 @@ public function testAnonymous(): void {
182
197
/**
183
198
* Tests the performance of logging in.
184
199
*/
185
- public function testLogin (): void {
200
+ protected function testLogin (): void {
186
201
// Create a user and log them in to warm all caches. Manually submit the
187
202
// form so that we repeat the same steps when recording performance data. Do
188
203
// this twice so that any caches which take two requests to warm are also
189
204
// covered.
190
- $ account = $ this ->drupalCreateUser ();
191
205
foreach (range (0 , 1 ) as $ index ) {
192
206
$ this ->drupalGet ('node ' );
193
207
$ this ->drupalGet ('user/login ' );
194
- $ this ->submitLoginForm ($ account );
208
+ $ this ->submitLoginForm ($ this -> user );
195
209
$ this ->drupalLogout ();
196
210
}
197
211
198
212
$ this ->drupalGet ('node ' );
199
213
$ this ->drupalGet ('user/login ' );
200
- $ performance_data = $ this ->collectPerformanceData (function () use ( $ account ) {
201
- $ this ->submitLoginForm ($ account );
214
+ $ performance_data = $ this ->collectPerformanceData (function () {
215
+ $ this ->submitLoginForm ($ this -> user );
202
216
}, 'standardLogin ' );
203
217
204
218
$ expected_queries = [
@@ -228,30 +242,29 @@ public function testLogin(): void {
228
242
$ this ->assertSame (1 , $ performance_data ->getCacheTagChecksumCount ());
229
243
$ this ->assertSame (23 , $ performance_data ->getCacheTagIsValidCount ());
230
244
$ this ->assertSame (0 , $ performance_data ->getCacheTagInvalidationCount ());
245
+ $ this ->drupalLogout ();
231
246
}
232
247
233
248
/**
234
249
* Tests the performance of logging in via the user login block.
235
250
*/
236
- public function testLoginBlock (): void {
251
+ protected function testLoginBlock (): void {
237
252
$ this ->drupalPlaceBlock ('user_login_block ' );
238
- // Create a user and log them in to warm all caches. Manually submit the
239
- // form so that we repeat the same steps when recording performance data. Do
240
- // this twice so that any caches which take two requests to warm are also
241
- // covered.
242
- $ account = $ this ->drupalCreateUser ();
253
+ // Log the user in in to warm all caches. Manually submit the form so that
254
+ // we repeat the same steps when recording performance data. Do this twice
255
+ // so that any caches which take two requests to warm are also covered.
243
256
244
257
foreach (range (0 , 1 ) as $ index ) {
245
258
$ this ->drupalGet ('node ' );
246
259
$ this ->assertSession ()->responseContains ('Password ' );
247
- $ this ->submitLoginForm ($ account );
260
+ $ this ->submitLoginForm ($ this -> user );
248
261
$ this ->drupalLogout ();
249
262
}
250
263
251
264
$ this ->drupalGet ('node ' );
252
265
$ this ->assertSession ()->responseContains ('Password ' );
253
- $ performance_data = $ this ->collectPerformanceData (function () use ( $ account ) {
254
- $ this ->submitLoginForm ($ account );
266
+ $ performance_data = $ this ->collectPerformanceData (function () {
267
+ $ this ->submitLoginForm ($ this -> user );
255
268
}, 'standardBlockLogin ' );
256
269
257
270
$ expected_queries = [
0 commit comments