Skip to content

Commit

Permalink
VATEAM-88658: Script to add Digital Forms test data (#19025)
Browse files Browse the repository at this point in the history
* WIP: Create digital form script

* Add steps

* Rename exit_if_wrong_env
  • Loading branch information
derekhouck authored and ryguyk committed Sep 3, 2024
1 parent 24e69b5 commit af73e95
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
68 changes: 68 additions & 0 deletions scripts/content/digital-forms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* @file
* Creates Digital Form test data for local and Tugboat environments.
*
* !!!! DO NOT RUN ON PROD !!!!
*/

use Drupal\node\Entity\Node;
use Drupal\paragraphs\Entity\Paragraph;

require_once __DIR__ . '/script-library.php';

run();

/**
* Executes the script.
*/
function run() {
$env = getenv('CMS_ENVIRONMENT_TYPE') ?: 'ci';
exit_if_not_local_or_tugboat($env);

create_digital_form();
}

/**
* Creates a Digital Form with hard-coded values.
*/
function create_digital_form() {
$digital_form = Node::create([
'type' => 'digital_form',
'title' => 'Script Generated Digital Form',
'field_va_form_number' => '123456789',
'field_omb_number' => '1234-5678',
'moderation_state' => 'published',
]);
$digital_form->field_chapters->appendItem(create_step());
$digital_form
->field_chapters
->appendItem(create_step('Step without Date of Birth', FALSE));
save_node_revision($digital_form, 'Created by the content script', TRUE);
}

/**
* Creates a Digital Form Step.
*
* For now, this only creates the Name and Date of Birth step.
* That will change as more patterns are added.
*
* @param string $title
* The step title.
* @param bool $includeDob
* Should the step include the date of birth field?
*
* @return \Drupal\paragraphs\Entity\Paragraph
* The created Step.
*/
function create_step(
string $title = 'Script Generated Step',
bool $includeDob = TRUE,
): Paragraph {
return Paragraph::create([
'type' => 'digital_form_name_and_date_of_bi',
'field_title' => $title,
'field_include_date_of_birth' => $includeDob,
]);
}
15 changes: 14 additions & 1 deletion scripts/content/script-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Drupal\user\UserStorageInterface;
use Psr\Log\LogLevel;

const CMS_MIGRATOR_ID = 1317;
const CMS_MIGRATOR_ID = 1317; // phpcs:ignore

/**
* Log a message to stdout.
Expand All @@ -46,6 +46,19 @@ function entity_type_manager(): EntityTypeManagerInterface {
return $entity_type_manager;
}

/**
* Exit if script is run in an environment other than local or tugboat.
*
* @param string $env
* The CMS environment.
*/
function exit_if_not_local_or_tugboat(string $env) {
if ($env !== 'local' && $env !== 'tugboat') {
echo "This script can only be run on local or Tugboat environments.\n";
exit();
}
}

/**
* Get the node storage.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
function run() {
$env = getenv('CMS_ENVIRONMENT_TYPE') ?: 'ci';
if ($env !== 'local' && $env !== 'tugboat') {
echo "This script can only be run on local or Tugboat environments.\n";
exit();
}
exit_if_not_local_or_tugboat($env);
process_csv_file(__DIR__ . '/VACMS-17969-vba-test-data-source-services.csv',
'create_vba_facility_service_node');
process_csv_file(__DIR__ . '/VACMS-17969-vba-test-data-source-facilities.csv',
Expand Down

0 comments on commit af73e95

Please sign in to comment.