| 1 |
<?php |
| 2 |
require '/wordpress/wp-load.php'; |
| 3 |
|
| 4 |
// Minimal two-field form: a text field exercised by the spec, and a |
| 5 |
// select field whose choices the controller must NOT clobber on |
| 6 |
// label-only saves. WPForms stores the form post_content as JSON; the |
| 7 |
// post id and the form's internal `id` must match (WPForms renders by |
| 8 |
// post id + reads attributes by internal id). |
| 9 |
$formId = wp_insert_post([ |
| 10 |
'post_type' => 'wpforms', |
| 11 |
'post_status' => 'publish', |
| 12 |
'post_title' => 'QE Test Form', |
| 13 |
'post_content' => '', |
| 14 |
]); |
| 15 |
|
| 16 |
$formJson = [ |
| 17 |
'id' => (string) $formId, |
| 18 |
'field_id' => '5', |
| 19 |
'fields' => [ |
| 20 |
'1' => [ |
| 21 |
'id' => '1', |
| 22 |
'type' => 'text', |
| 23 |
'label' => 'Original Name Label', |
| 24 |
'placeholder' => 'Original placeholder', |
| 25 |
'description' => 'Original description', |
| 26 |
'required' => '1', |
| 27 |
'size' => 'medium', |
| 28 |
], |
| 29 |
'2' => [ |
| 30 |
'id' => '2', |
| 31 |
'type' => 'select', |
| 32 |
'label' => 'Preferred contact', |
| 33 |
'choices' => [ |
| 34 |
'1' => ['label' => 'Email', 'value' => 'email'], |
| 35 |
'2' => ['label' => 'Phone', 'value' => 'phone'], |
| 36 |
], |
| 37 |
'size' => 'medium', |
| 38 |
], |
| 39 |
], |
| 40 |
'settings' => [ |
| 41 |
'form_title' => 'QE Test Form', |
| 42 |
'form_desc' => '', |
| 43 |
'submit_text' => 'Submit', |
| 44 |
'submit_text_processing' => 'Sending…', |
| 45 |
], |
| 46 |
]; |
| 47 |
|
| 48 |
wp_update_post([ |
| 49 |
'ID' => $formId, |
| 50 |
'post_content' => wp_slash(wp_json_encode($formJson)), |
| 51 |
]); |
| 52 |
|
| 53 |
$content = "<!-- wp:heading -->\n" |
| 54 |
. '<h2 class="wp-block-heading">QE WPForms home.</h2>' |
| 55 |
. "\n<!-- /wp:heading -->\n\n" |
| 56 |
. '<!-- wp:wpforms/form-selector {"formId":"' . (int) $formId . '"} /-->'; |
| 57 |
|
| 58 |
$pageId = wp_insert_post([ |
| 59 |
'post_type' => 'page', |
| 60 |
'post_status' => 'publish', |
| 61 |
'post_title' => 'QE WPForms Home', |
| 62 |
'post_content' => $content, |
| 63 |
]); |
| 64 |
|
| 65 |
update_option('show_on_front', 'page'); |
| 66 |
update_option('page_on_front', $pageId); |
| 67 |
|
| 68 |
// Surface the form post id to the spec without an extra REST call. The |
| 69 |
// form-selector block embeds it in the rendered <form id> attribute, |
| 70 |
// but pinning it as a meta-tag keeps the assertion robust against |
| 71 |
// WPForms version changes. |
| 72 |
update_option('extendify_qe_test_form_id', (int) $formId); |
| 73 |
|