Merge multiple functional tests together to reduce test startup time #797

This commit is contained in:
Michael Stenta 2024-02-02 11:24:02 -05:00
parent 6abe3e73b0
commit b1d804dc76
9 changed files with 111 additions and 62 deletions

View File

@ -43,10 +43,18 @@ class SensorDataApiTest extends FarmBrowserTestBase {
$this->asset->save(); $this->asset->save();
} }
/**
* Run all tests.
*/
public function testAll() {
$this->doTestApiGet();
$this->doTestApiPost();
}
/** /**
* Test API GET requests. * Test API GET requests.
*/ */
public function testApiGet() { public function doTestApiGet() {
// Build the path. // Build the path.
$uri = $this->buildPath($this->asset); $uri = $this->buildPath($this->asset);
@ -82,7 +90,7 @@ class SensorDataApiTest extends FarmBrowserTestBase {
/** /**
* Test API POST requests. * Test API POST requests.
*/ */
public function testApiPost() { public function doTestApiPost() {
// Build the path. // Build the path.
$uri = $this->buildPath($this->asset); $uri = $this->buildPath($this->asset);

View File

@ -27,6 +27,14 @@ class EntryPointTest extends FarmBrowserTestBase {
'views', 'views',
]; ];
/**
* Run all tests.
*/
public function testAll() {
$this->doTestEntryPoint();
$this->doTestFarmMeta();
}
/** /**
* Test GET to the entry point. * Test GET to the entry point.
* *
@ -41,7 +49,7 @@ class EntryPointTest extends FarmBrowserTestBase {
* *
* @see \Drupal\Tests\jsonapi\Functional\EntryPointTest * @see \Drupal\Tests\jsonapi\Functional\EntryPointTest
*/ */
public function testEntryPoint() { public function doTestEntryPoint() {
$request_options = []; $request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json'; $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$response = $this->request('GET', Url::fromUri('base://api'), $request_options); $response = $this->request('GET', Url::fromUri('base://api'), $request_options);
@ -73,7 +81,7 @@ class EntryPointTest extends FarmBrowserTestBase {
/** /**
* Test that the meta.farm data is correct. * Test that the meta.farm data is correct.
*/ */
public function testFarmMeta() { public function doTestFarmMeta() {
$request_options = []; $request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json'; $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$response = $this->request('GET', Url::fromUri('base://api'), $request_options); $response = $this->request('GET', Url::fromUri('base://api'), $request_options);

View File

@ -14,10 +14,23 @@ class AssetCRUDTest extends AssetTestBase {
use StringTranslationTrait; 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. * Fields are displayed correctly.
*/ */
public function testFieldsVisibility() { public function doTestFieldsVisibility() {
$this->drupalGet('asset/add/default'); $this->drupalGet('asset/add/default');
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$assert_session->statusCodeEquals(200); $assert_session->statusCodeEquals(200);
@ -32,7 +45,7 @@ class AssetCRUDTest extends AssetTestBase {
/** /**
* Create asset entity. * Create asset entity.
*/ */
public function testCreateAsset() { public function doTestCreateAsset() {
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$name = $this->randomMachineName(); $name = $this->randomMachineName();
$edit = [ $edit = [
@ -59,7 +72,7 @@ class AssetCRUDTest extends AssetTestBase {
/** /**
* Display asset entity. * Display asset entity.
*/ */
public function testViewAsset() { public function doTestViewAsset() {
$edit = [ $edit = [
'name' => $this->randomMachineName(), 'name' => $this->randomMachineName(),
'created' => \Drupal::time()->getRequestTime(), 'created' => \Drupal::time()->getRequestTime(),
@ -77,7 +90,7 @@ class AssetCRUDTest extends AssetTestBase {
/** /**
* Edit asset entity. * Edit asset entity.
*/ */
public function testEditAsset() { public function doTestEditAsset() {
$asset = $this->createAssetEntity(); $asset = $this->createAssetEntity();
$asset->save(); $asset->save();
@ -92,7 +105,7 @@ class AssetCRUDTest extends AssetTestBase {
/** /**
* Delete asset entity. * Delete asset entity.
*/ */
public function testDeleteAsset() { public function doTestDeleteAsset() {
$asset = $this->createAssetEntity(); $asset = $this->createAssetEntity();
$asset->save(); $asset->save();
@ -111,7 +124,7 @@ class AssetCRUDTest extends AssetTestBase {
/** /**
* Asset archiving. * Asset archiving.
*/ */
public function testArchiveAsset() { public function doTestArchiveAsset() {
$asset = $this->createAssetEntity(); $asset = $this->createAssetEntity();
$asset->save(); $asset->save();
@ -141,7 +154,7 @@ class AssetCRUDTest extends AssetTestBase {
/** /**
* Asset archiving/unarchiving via timestamp. * Asset archiving/unarchiving via timestamp.
*/ */
public function testArchiveAssetViaTimestamp() { public function doTestArchiveAssetViaTimestamp() {
$asset = $this->createAssetEntity(); $asset = $this->createAssetEntity();
$asset->save(); $asset->save();

View File

@ -59,10 +59,18 @@ class FarmEntityBundleFieldTest extends FarmBrowserTestBase {
$this->moduleInstaller = $this->container->get('module_installer'); $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. * 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. // Install the farm_entity_contrib_test module.
$result = $this->moduleInstaller->install(['farm_entity_contrib_test'], TRUE); $result = $this->moduleInstaller->install(['farm_entity_contrib_test'], TRUE);
@ -105,7 +113,7 @@ class FarmEntityBundleFieldTest extends FarmBrowserTestBase {
/** /**
* Test that bundle fields can be reused across bundles. * 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 // Test that database tables exist after uninstalling a bundle with
// a field storage definition used by other bundles. // a field storage definition used by other bundles.

View File

@ -29,10 +29,18 @@ class UserLoginTest extends FarmBrowserTestBase {
'farm_login', 'farm_login',
]; ];
/**
* Run all tests.
*/
public function testAll() {
$this->doTestValidLoginWithDestination();
$this->doTestPerUserLoginFloodControl();
}
/** /**
* Tests login with destination. * Tests login with destination.
*/ */
public function testValidLoginWithDestination() { public function doTestValidLoginWithDestination() {
// 1. Test for correct text in the login form. // 1. Test for correct text in the login form.
$this->drupalGet('user/login'); $this->drupalGet('user/login');
@ -79,7 +87,7 @@ class UserLoginTest extends FarmBrowserTestBase {
* *
* @see UserLoginTest::testPerUserLoginFloodControl() * @see UserLoginTest::testPerUserLoginFloodControl()
*/ */
public function testPerUserLoginFloodControl() { public function doTestPerUserLoginFloodControl() {
$this->config('user.flood') $this->config('user.flood')
// Set a high global limit out so that it is not relevant in the test. // Set a high global limit out so that it is not relevant in the test.
->set('ip_limit', 4000) ->set('ip_limit', 4000)

View File

@ -14,10 +14,23 @@ class PlanCRUDTest extends PlanTestBase {
use StringTranslationTrait; 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. * Fields are displayed correctly.
*/ */
public function testFieldsVisibility() { public function doTestFieldsVisibility() {
$this->drupalGet('plan/add/default'); $this->drupalGet('plan/add/default');
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$assert_session->statusCodeEquals(200); $assert_session->statusCodeEquals(200);
@ -32,7 +45,7 @@ class PlanCRUDTest extends PlanTestBase {
/** /**
* Create plan entity. * Create plan entity.
*/ */
public function testCreatePlan() { public function doTestCreatePlan() {
$assert_session = $this->assertSession(); $assert_session = $this->assertSession();
$name = $this->randomMachineName(); $name = $this->randomMachineName();
$edit = [ $edit = [
@ -59,7 +72,7 @@ class PlanCRUDTest extends PlanTestBase {
/** /**
* Display plan entity. * Display plan entity.
*/ */
public function testViewPlan() { public function doTestViewPlan() {
$edit = [ $edit = [
'name' => $this->randomMachineName(), 'name' => $this->randomMachineName(),
'created' => \Drupal::time()->getRequestTime(), 'created' => \Drupal::time()->getRequestTime(),
@ -77,7 +90,7 @@ class PlanCRUDTest extends PlanTestBase {
/** /**
* Edit plan entity. * Edit plan entity.
*/ */
public function testEditPlan() { public function doTestEditPlan() {
$plan = $this->createPlanEntity(); $plan = $this->createPlanEntity();
$plan->save(); $plan->save();
@ -93,7 +106,7 @@ class PlanCRUDTest extends PlanTestBase {
/** /**
* Delete plan entity. * Delete plan entity.
*/ */
public function testDeletePlan() { public function doTestDeletePlan() {
$plan = $this->createPlanEntity(); $plan = $this->createPlanEntity();
$plan->save(); $plan->save();
@ -112,7 +125,7 @@ class PlanCRUDTest extends PlanTestBase {
/** /**
* Plan archiving. * Plan archiving.
*/ */
public function testArchivePlan() { public function doTestArchivePlan() {
$plan = $this->createPlanEntity(); $plan = $this->createPlanEntity();
$plan->save(); $plan->save();
@ -142,7 +155,7 @@ class PlanCRUDTest extends PlanTestBase {
/** /**
* Plan archiving/unarchiving via timestamp. * Plan archiving/unarchiving via timestamp.
*/ */
public function testArchivePlanViaTimestamp() { public function doTestArchivePlanViaTimestamp() {
$plan = $this->createPlanEntity(); $plan = $this->createPlanEntity();
$plan->save(); $plan->save();

View File

@ -37,10 +37,18 @@ class DashboardTest extends FarmBrowserTestBase {
$this->drupalLogin($this->user); $this->drupalLogin($this->user);
} }
/**
* Run all tests.
*/
public function testAll() {
$this->doTestDashboardBlock();
$this->doTestDashboardView();
}
/** /**
* Test that custom blocks are added to the dashboard. * Test that custom blocks are added to the dashboard.
*/ */
public function testDashboardBlock() { public function doTestDashboardBlock() {
$this->drupalGet('/dashboard'); $this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
@ -51,7 +59,7 @@ class DashboardTest extends FarmBrowserTestBase {
/** /**
* Test that custom views are added to the dashboard. * Test that custom views are added to the dashboard.
*/ */
public function testDashboardView() { public function doTestDashboardView() {
$this->drupalGet('/dashboard'); $this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);

View File

@ -66,23 +66,27 @@ class DashboardTasksTest extends FarmBrowserTestBase {
} }
/** /**
* 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->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200); $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('Upcoming tasks');
$this->assertSession()->pageTextNotContains('Late tasks');
// Grant the user permission to view any log. // Grant the user permission to view any log.
$this->user->addRole($this->role); $this->user->addRole($this->role);
$this->user->save(); $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->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Upcoming tasks'); $this->assertSession()->pageTextContains('Upcoming tasks');
$this->assertSession()->pageTextContains('Late tasks');
// Assert that the log is not displayed. // Assert that the log is not displayed.
$this->assertSession()->pageTextContains('No logs found.'); $this->assertSession()->pageTextContains('No logs found.');
@ -92,48 +96,19 @@ class DashboardTasksTest extends FarmBrowserTestBase {
$this->log->timestamp = \Drupal::time()->getCurrentTime() + 86400; $this->log->timestamp = \Drupal::time()->getCurrentTime() + 86400;
$this->log->save(); $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. // Assert that the log is displayed.
$this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($this->log->label()); $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.');
// Mark the log as pending in the past. // Mark the log as pending in the past.
$this->log->status = 'pending'; $this->log->status = 'pending';
$this->log->timestamp = \Drupal::time()->getCurrentTime() - 86400; $this->log->timestamp = \Drupal::time()->getCurrentTime() - 86400;
$this->log->save(); $this->log->save();
// Assert that the upcoming tasks view is added. // Assert that the log is displayed.
$this->drupalGet('/dashboard'); $this->drupalGet('/dashboard');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Late tasks');
// Assert that the log is displayed.
$this->assertSession()->pageTextContains($this->log->label()); $this->assertSession()->pageTextContains($this->log->label());
} }

View File

@ -87,10 +87,18 @@ class TaxonomyTermTasksTest extends FarmBrowserTestBase {
])->save(); ])->save();
} }
/**
* Run all tests.
*/
public function testAll() {
$this->doTestTaxonomyTermAssetTaskTabsAppear();
$this->doTestTaxonomyTermAssetViews();
}
/** /**
* Test that the asset view task links appear on taxonomy term pages. * Test that the asset view task links appear on taxonomy term pages.
*/ */
public function testTaxonomyTermAssetTaskTabsAppear() { public function doTestTaxonomyTermAssetTaskTabsAppear() {
$fava_term_url = 'taxonomy/term/' . $this->favaPlantType->id(); $fava_term_url = 'taxonomy/term/' . $this->favaPlantType->id();
$this->drupalGet($fava_term_url); $this->drupalGet($fava_term_url);
@ -131,7 +139,7 @@ class TaxonomyTermTasksTest extends FarmBrowserTestBase {
/** /**
* Test that the views of assets for terms show the correct assets. * Test that the views of assets for terms show the correct assets.
*/ */
public function testTaxonomyTermAssetViews() { public function doTestTaxonomyTermAssetViews() {
$fava_term_url = 'taxonomy/term/' . $this->favaPlantType->id(); $fava_term_url = 'taxonomy/term/' . $this->favaPlantType->id();
$this->drupalGet("$fava_term_url/assets/all"); $this->drupalGet("$fava_term_url/assets/all");