From 0a7ee72300b317b290ae0ea75262f372653b7060 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Tue, 11 Jun 2024 12:12:19 -0400 Subject: [PATCH] wip --- farm_crop_plan.info.yml | 1 + .../artifacts}/export-crop-plan.csv | 0 .../artifacts}/import-crop-plan.csv | 0 .../artifacts}/update-crop-plan.csv | 0 .../farm_crop_plan_test.info.yml | 7 ++ tests/src/Functional/CropPlanTest.php | 2 +- tests/src/Kernel/CropPlanImportTest.php | 91 +++++++++++++++++++ tests/src/Kernel/CropPlanTest.php | 3 + 8 files changed, 103 insertions(+), 1 deletion(-) rename tests/{files => modules/farm_crop_plan_test/artifacts}/export-crop-plan.csv (100%) rename tests/{files => modules/farm_crop_plan_test/artifacts}/import-crop-plan.csv (100%) rename tests/{files => modules/farm_crop_plan_test/artifacts}/update-crop-plan.csv (100%) create mode 100644 tests/modules/farm_crop_plan_test/farm_crop_plan_test.info.yml create mode 100644 tests/src/Kernel/CropPlanImportTest.php diff --git a/farm_crop_plan.info.yml b/farm_crop_plan.info.yml index 34339e8..d70f535 100644 --- a/farm_crop_plan.info.yml +++ b/farm_crop_plan.info.yml @@ -12,4 +12,5 @@ dependencies: - farm_migrate - farm_plant - farm_season + - farm_seeding - plan diff --git a/tests/files/export-crop-plan.csv b/tests/modules/farm_crop_plan_test/artifacts/export-crop-plan.csv similarity index 100% rename from tests/files/export-crop-plan.csv rename to tests/modules/farm_crop_plan_test/artifacts/export-crop-plan.csv diff --git a/tests/files/import-crop-plan.csv b/tests/modules/farm_crop_plan_test/artifacts/import-crop-plan.csv similarity index 100% rename from tests/files/import-crop-plan.csv rename to tests/modules/farm_crop_plan_test/artifacts/import-crop-plan.csv diff --git a/tests/files/update-crop-plan.csv b/tests/modules/farm_crop_plan_test/artifacts/update-crop-plan.csv similarity index 100% rename from tests/files/update-crop-plan.csv rename to tests/modules/farm_crop_plan_test/artifacts/update-crop-plan.csv diff --git a/tests/modules/farm_crop_plan_test/farm_crop_plan_test.info.yml b/tests/modules/farm_crop_plan_test/farm_crop_plan_test.info.yml new file mode 100644 index 0000000..a605c3d --- /dev/null +++ b/tests/modules/farm_crop_plan_test/farm_crop_plan_test.info.yml @@ -0,0 +1,7 @@ +name: farmOS Crop Plan Test +description: Support module for CSV Crop Plan testing. +type: module +package: Testing +core_version_requirement: ^10 +dependencies: + - farm:farm_crop_plan diff --git a/tests/src/Functional/CropPlanTest.php b/tests/src/Functional/CropPlanTest.php index 6ace9ac..525e0ae 100644 --- a/tests/src/Functional/CropPlanTest.php +++ b/tests/src/Functional/CropPlanTest.php @@ -41,7 +41,7 @@ public function testCropPlanExport() { $this->assertSession()->statusCodeEquals(200); $this->assertSession()->responseHeaderContains('Content-Type', 'application/csv'); $this->assertSession()->responseHeaderContains('Content-Disposition', 'attachment; filename="crop-plan-1.csv'); - $expected = file_get_contents(__DIR__ . '/../../files/export-crop-plan.csv'); + $expected = file_get_contents(__DIR__ . '/../../artifacts/export-crop-plan.csv'); $this->assertEquals($expected, $output); } diff --git a/tests/src/Kernel/CropPlanImportTest.php b/tests/src/Kernel/CropPlanImportTest.php new file mode 100644 index 0000000..c6bf592 --- /dev/null +++ b/tests/src/Kernel/CropPlanImportTest.php @@ -0,0 +1,91 @@ +installEntitySchema('plan'); + $this->installEntitySchema('plan_record'); + $this->installConfig([ + 'farm_crop_plan', + 'farm_land', + 'farm_plant', + 'farm_plant_type', + 'farm_seeding', + 'farm_transplanting', + ]); + + // Set the private:// filesystem to use this module's artifacts directory. + $this->setSetting('file_private_path', \Drupal::service('extension.list.module')->getPath('farm_crop_plan_test') . '/artifacts'); + } + + /** + * Test crop plan import. + */ + public function testCropPlanImport() { + $this->importCsv('import-crop-plan.csv', 'crop_plan_records'); + $d=1; + } + + /** + * Test crop plan update. + */ + public function testCropPlanUpdate() { + $this->importCsv('import-crop-plan.csv', 'crop_plan_records'); + $d=1; + } + +} diff --git a/tests/src/Kernel/CropPlanTest.php b/tests/src/Kernel/CropPlanTest.php index 410679d..66beeda 100644 --- a/tests/src/Kernel/CropPlanTest.php +++ b/tests/src/Kernel/CropPlanTest.php @@ -24,6 +24,8 @@ class CropPlanTest extends MigrateTestBase { 'entity_reference_validators', 'farm_crop_plan', 'farm_entity', + 'farm_id_tag', + 'farm_import_csv', 'farm_field', 'farm_land', 'farm_location', @@ -44,6 +46,7 @@ class CropPlanTest extends MigrateTestBase { 'migrate_source_csv', 'options', 'plan', + 'quantity', 'state_machine', 'taxonomy', 'text',