Skip to content

Commit

Permalink
Merge multiple functional tests together to reduce test startup time #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Feb 9, 2024
1 parent 6abe3e7 commit b1d804d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 61 deletions.
12 changes: 10 additions & 2 deletions modules/asset/sensor/tests/src/Functional/SensorDataApiTest.php
Expand Up @@ -43,10 +43,18 @@ protected function setUp(): void {
$this->asset->save();
}

/**
* Run all tests.
*/
public function testAll() {
$this->doTestApiGet();
$this->doTestApiPost();
}

/**
* Test API GET requests.
*/
public function testApiGet() {
public function doTestApiGet() {

// Build the path.
$uri = $this->buildPath($this->asset);
Expand Down Expand Up @@ -82,7 +90,7 @@ public function testApiGet() {
/**
* Test API POST requests.
*/
public function testApiPost() {
public function doTestApiPost() {

// Build the path.
$uri = $this->buildPath($this->asset);
Expand Down
12 changes: 10 additions & 2 deletions modules/core/api/tests/src/Functional/EntryPointTest.php
Expand Up @@ -27,6 +27,14 @@ class EntryPointTest extends FarmBrowserTestBase {
'views',
];

/**
* Run all tests.
*/
public function testAll() {
$this->doTestEntryPoint();
$this->doTestFarmMeta();
}

/**
* Test GET to the entry point.
*
Expand All @@ -41,7 +49,7 @@ class EntryPointTest extends FarmBrowserTestBase {
*
* @see \Drupal\Tests\jsonapi\Functional\EntryPointTest
*/
public function testEntryPoint() {
public function doTestEntryPoint() {
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$response = $this->request('GET', Url::fromUri('base://api'), $request_options);
Expand Down Expand Up @@ -73,7 +81,7 @@ public function testEntryPoint() {
/**
* Test that the meta.farm data is correct.
*/
public function testFarmMeta() {
public function doTestFarmMeta() {
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$response = $this->request('GET', Url::fromUri('base://api'), $request_options);
Expand Down
27 changes: 20 additions & 7 deletions modules/core/asset/tests/src/Functional/AssetCRUDTest.php
Expand Up @@ -14,10 +14,23 @@ class AssetCRUDTest extends AssetTestBase {

use StringTranslationTrait;

/**
* Run all tests.
*/
public function testAll() {
$this->doTestFieldsVisibility();
$this->doTestCreateAsset();
$this->doTestViewAsset();
$this->doTestEditAsset();
$this->doTestDeleteAsset();
$this->doTestArchiveAsset();
$this->doTestArchiveAssetViaTimestamp();
}

/**
* Fields are displayed correctly.
*/
public function testFieldsVisibility() {
public function doTestFieldsVisibility() {
$this->drupalGet('asset/add/default');
$assert_session = $this->assertSession();
$assert_session->statusCodeEquals(200);
Expand All @@ -32,7 +45,7 @@ public function testFieldsVisibility() {
/**
* Create asset entity.
*/
public function testCreateAsset() {
public function doTestCreateAsset() {
$assert_session = $this->assertSession();
$name = $this->randomMachineName();
$edit = [
Expand All @@ -59,7 +72,7 @@ public function testCreateAsset() {
/**
* Display asset entity.
*/
public function testViewAsset() {
public function doTestViewAsset() {
$edit = [
'name' => $this->randomMachineName(),
'created' => \Drupal::time()->getRequestTime(),
Expand All @@ -77,7 +90,7 @@ public function testViewAsset() {
/**
* Edit asset entity.
*/
public function testEditAsset() {
public function doTestEditAsset() {
$asset = $this->createAssetEntity();
$asset->save();

Expand All @@ -92,7 +105,7 @@ public function testEditAsset() {
/**
* Delete asset entity.
*/
public function testDeleteAsset() {
public function doTestDeleteAsset() {
$asset = $this->createAssetEntity();
$asset->save();

Expand All @@ -111,7 +124,7 @@ public function testDeleteAsset() {
/**
* Asset archiving.
*/
public function testArchiveAsset() {
public function doTestArchiveAsset() {
$asset = $this->createAssetEntity();
$asset->save();

Expand Down Expand Up @@ -141,7 +154,7 @@ public function testArchiveAsset() {
/**
* Asset archiving/unarchiving via timestamp.
*/
public function testArchiveAssetViaTimestamp() {
public function doTestArchiveAssetViaTimestamp() {
$asset = $this->createAssetEntity();
$asset->save();

Expand Down
Expand Up @@ -59,10 +59,18 @@ protected function setUp():void {
$this->moduleInstaller = $this->container->get('module_installer');
}

/**
* Run all tests.
*/
public function testAll() {
$this->doTestBundleFieldPostponedInstall();
$this->doTestBundlePluginModuleUninstallation();
}

/**
* Test installing the farm_entity_contrib_test module after farm_entity_test.
*/
public function testBundleFieldPostponedInstall() {
public function doTestBundleFieldPostponedInstall() {

// Install the farm_entity_contrib_test module.
$result = $this->moduleInstaller->install(['farm_entity_contrib_test'], TRUE);
Expand Down Expand Up @@ -105,7 +113,7 @@ public function testBundleFieldPostponedInstall() {
/**
* Test that bundle fields can be reused across bundles.
*/
public function testBundlePluginModuleUninstallation() {
public function doTestBundlePluginModuleUninstallation() {

// Test that database tables exist after uninstalling a bundle with
// a field storage definition used by other bundles.
Expand Down
12 changes: 10 additions & 2 deletions modules/core/login/tests/src/Functional/UserLoginTest.php
Expand Up @@ -29,10 +29,18 @@ class UserLoginTest extends FarmBrowserTestBase {
'farm_login',
];

/**
* Run all tests.
*/
public function testAll() {
$this->doTestValidLoginWithDestination();
$this->doTestPerUserLoginFloodControl();
}

/**
* Tests login with destination.
*/
public function testValidLoginWithDestination() {
public function doTestValidLoginWithDestination() {

// 1. Test for correct text in the login form.
$this->drupalGet('user/login');
Expand Down Expand Up @@ -79,7 +87,7 @@ public function testValidLoginWithDestination() {
*
* @see UserLoginTest::testPerUserLoginFloodControl()
*/
public function testPerUserLoginFloodControl() {
public function doTestPerUserLoginFloodControl() {
$this->config('user.flood')
// Set a high global limit out so that it is not relevant in the test.
->set('ip_limit', 4000)
Expand Down
27 changes: 20 additions & 7 deletions modules/core/plan/tests/src/Functional/PlanCRUDTest.php
Expand Up @@ -14,10 +14,23 @@ class PlanCRUDTest extends PlanTestBase {

use StringTranslationTrait;

/**
* Run all tests.
*/
public function testAll() {
$this->doTestFieldsVisibility();
$this->doTestCreatePlan();
$this->doTestViewPlan();
$this->doTestEditPlan();
$this->doTestDeletePlan();
$this->doTestArchivePlan();
$this->doTestArchivePlanViaTimestamp();
}

/**
* Fields are displayed correctly.
*/
public function testFieldsVisibility() {
public function doTestFieldsVisibility() {
$this->drupalGet('plan/add/default');
$assert_session = $this->assertSession();
$assert_session->statusCodeEquals(200);
Expand All @@ -32,7 +45,7 @@ public function testFieldsVisibility() {
/**
* Create plan entity.
*/
public function testCreatePlan() {
public function doTestCreatePlan() {
$assert_session = $this->assertSession();
$name = $this->randomMachineName();
$edit = [
Expand All @@ -59,7 +72,7 @@ public function testCreatePlan() {
/**
* Display plan entity.
*/
public function testViewPlan() {
public function doTestViewPlan() {
$edit = [
'name' => $this->randomMachineName(),
'created' => \Drupal::time()->getRequestTime(),
Expand All @@ -77,7 +90,7 @@ public function testViewPlan() {
/**
* Edit plan entity.
*/
public function testEditPlan() {
public function doTestEditPlan() {
$plan = $this->createPlanEntity();
$plan->save();

Expand All @@ -93,7 +106,7 @@ public function testEditPlan() {
/**
* Delete plan entity.
*/
public function testDeletePlan() {
public function doTestDeletePlan() {
$plan = $this->createPlanEntity();
$plan->save();

Expand All @@ -112,7 +125,7 @@ public function testDeletePlan() {
/**
* Plan archiving.
*/
public function testArchivePlan() {
public function doTestArchivePlan() {
$plan = $this->createPlanEntity();
$plan->save();

Expand Down Expand Up @@ -142,7 +155,7 @@ public function testArchivePlan() {
/**
* Plan archiving/unarchiving via timestamp.
*/
public function testArchivePlanViaTimestamp() {
public function doTestArchivePlanViaTimestamp() {
$plan = $this->createPlanEntity();
$plan->save();

Expand Down
12 changes: 10 additions & 2 deletions modules/core/ui/dashboard/tests/src/Functional/DashboardTest.php
Expand Up @@ -37,10 +37,18 @@ protected function setUp(): void {
$this->drupalLogin($this->user);
}

/**
* Run all tests.
*/
public function testAll() {
$this->doTestDashboardBlock();
$this->doTestDashboardView();
}

/**
* Test that custom blocks are added to the dashboard.
*/
public function testDashboardBlock() {
public function doTestDashboardBlock() {
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);

Expand All @@ -51,7 +59,7 @@ public function testDashboardBlock() {
/**
* Test that custom views are added to the dashboard.
*/
public function testDashboardView() {
public function doTestDashboardView() {
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);

Expand Down
45 changes: 10 additions & 35 deletions modules/core/ui/views/tests/src/Functional/DashboardTasksTest.php
Expand Up @@ -66,23 +66,27 @@ protected function setUp(): void {
}

/**
* Test the upcoming tasks view on the dashboard.
* Test the upcoming and late tasks views on the dashboard.
*/
public function testUpcomingTasks() {
public function testDashboardTasks() {

// Load the dashboard.
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);

// Assert that the upcoming tasks view was not added.
// Assert that the upcoming and late tasks views were not added.
$this->assertSession()->pageTextNotContains('Upcoming tasks');
$this->assertSession()->pageTextNotContains('Late tasks');

// Grant the user permission to view any log.
$this->user->addRole($this->role);
$this->user->save();

// Assert that the upcoming tasks view is added.
// Assert that the upcoming tasks and late tasks views are added.
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Upcoming tasks');
$this->assertSession()->pageTextContains('Late tasks');

// Assert that the log is not displayed.
$this->assertSession()->pageTextContains('No logs found.');
Expand All @@ -92,48 +96,19 @@ public function testUpcomingTasks() {
$this->log->timestamp = \Drupal::time()->getCurrentTime() + 86400;
$this->log->save();

// Assert that the upcoming tasks view is added.
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Upcoming tasks');

// Assert that the log is displayed.
$this->assertSession()->pageTextContains($this->log->label());
}

/**
* Test the late tasks view on the dashboard.
*/
public function testLateTasks() {
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);

// Assert that the upcoming tasks view was not added.
$this->assertSession()->pageTextNotContains('Late tasks');

// Grant the user permission to view any log.
$this->user->addRole($this->role);
$this->user->save();

// Assert that the upcoming tasks view is added.
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Late tasks');

// Assert that the log is not displayed.
$this->assertSession()->pageTextContains('No logs found.');
$this->assertSession()->pageTextContains($this->log->label());

// Mark the log as pending in the past.
$this->log->status = 'pending';
$this->log->timestamp = \Drupal::time()->getCurrentTime() - 86400;
$this->log->save();

// Assert that the upcoming tasks view is added.
// Assert that the log is displayed.
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Late tasks');

// Assert that the log is displayed.
$this->assertSession()->pageTextContains($this->log->label());
}

Expand Down

0 comments on commit b1d804d

Please sign in to comment.