Skip to content

Commit 481d4c2

Browse files
committed
Issue #3463288 by catch: Consolidate test methods in StandardPerformanceTest
1 parent 8b8098a commit 481d4c2

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php

+31-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\FunctionalJavascriptTests\PerformanceTestBase;
99
use Drupal\Tests\PerformanceData;
1010
use Drupal\node\NodeInterface;
11+
use Drupal\user\UserInterface;
1112

1213
/**
1314
* Tests the performance of basic functionality in the standard profile.
@@ -29,6 +30,11 @@ class StandardPerformanceTest extends PerformanceTestBase {
2930
*/
3031
protected $profile = 'standard';
3132

33+
/**
34+
* The user account created during testing.
35+
*/
36+
protected ?UserInterface $user = NULL;
37+
3238
/**
3339
* {@inheritdoc}
3440
*/
@@ -43,10 +49,19 @@ protected function setUp(): void {
4349
user_role_grant_permissions('anonymous', ['access user profiles']);
4450
}
4551

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+
4661
/**
4762
* Tests performance for anonymous users.
4863
*/
49-
public function testAnonymous(): void {
64+
protected function testAnonymous(): void {
5065
// Request the front page, then immediately clear all object caches, so that
5166
// aggregates and image styles are created on disk but otherwise caches are
5267
// empty.
@@ -146,9 +161,9 @@ public function testAnonymous(): void {
146161
$this->assertSame(0, $performance_data->getCacheTagInvalidationCount());
147162

148163
// 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());
152167
}, 'standardUserPage');
153168
$this->assertNoJavaScript($performance_data);
154169
$this->assertSame(1, $performance_data->getStylesheetCount());
@@ -182,23 +197,22 @@ public function testAnonymous(): void {
182197
/**
183198
* Tests the performance of logging in.
184199
*/
185-
public function testLogin(): void {
200+
protected function testLogin(): void {
186201
// Create a user and log them in to warm all caches. Manually submit the
187202
// form so that we repeat the same steps when recording performance data. Do
188203
// this twice so that any caches which take two requests to warm are also
189204
// covered.
190-
$account = $this->drupalCreateUser();
191205
foreach (range(0, 1) as $index) {
192206
$this->drupalGet('node');
193207
$this->drupalGet('user/login');
194-
$this->submitLoginForm($account);
208+
$this->submitLoginForm($this->user);
195209
$this->drupalLogout();
196210
}
197211

198212
$this->drupalGet('node');
199213
$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);
202216
}, 'standardLogin');
203217

204218
$expected_queries = [
@@ -228,30 +242,29 @@ public function testLogin(): void {
228242
$this->assertSame(1, $performance_data->getCacheTagChecksumCount());
229243
$this->assertSame(23, $performance_data->getCacheTagIsValidCount());
230244
$this->assertSame(0, $performance_data->getCacheTagInvalidationCount());
245+
$this->drupalLogout();
231246
}
232247

233248
/**
234249
* Tests the performance of logging in via the user login block.
235250
*/
236-
public function testLoginBlock(): void {
251+
protected function testLoginBlock(): void {
237252
$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.
243256

244257
foreach (range(0, 1) as $index) {
245258
$this->drupalGet('node');
246259
$this->assertSession()->responseContains('Password');
247-
$this->submitLoginForm($account);
260+
$this->submitLoginForm($this->user);
248261
$this->drupalLogout();
249262
}
250263

251264
$this->drupalGet('node');
252265
$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);
255268
}, 'standardBlockLogin');
256269

257270
$expected_queries = [

0 commit comments

Comments
 (0)