Skip to content

Commit 28920e2

Browse files
committed
Add Feedback tests
1 parent a2ca582 commit 28920e2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

projects/packages/forms/tests/php/contact-form/Feedback_Test.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,4 +1773,43 @@ public function test_has_field_type_legacy_feedback() {
17731773
$this->assertTrue( $response->has_field_type( 'consent' ), 'Legacy feedback should report consent field exists' );
17741774
$this->assertFalse( $response->has_consent(), 'Legacy consent should default to false (no)' );
17751775
}
1776+
1777+
public function test_get_field_by_id_and_value_by_id_new_submission() {
1778+
$form_id = Utility::get_form_id();
1779+
$_post_data = Utility::get_post_request(
1780+
array(
1781+
'name' => 'John Doe',
1782+
'email' => '[email protected]',
1783+
'message' => 'Hello!',
1784+
),
1785+
'g' . $form_id
1786+
);
1787+
1788+
$form = new Contact_Form(
1789+
array(
1790+
'title' => 'Test Form',
1791+
'description' => 'This is a test form.',
1792+
),
1793+
"[contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Message' type='textarea' required='1'/]"
1794+
);
1795+
1796+
$response = Feedback::from_submission( $_post_data, $form );
1797+
$field_ids = $form->get_field_ids();
1798+
$email_id = $field_ids['email'];
1799+
1800+
$this->assertNotEmpty( $email_id );
1801+
$this->assertEquals( '[email protected]', $response->get_field_value_by_id( $email_id ) );
1802+
1803+
$field = $response->get_field_by_id( $email_id );
1804+
$this->assertInstanceOf( Feedback_Field::class, $field );
1805+
$this->assertEquals( $email_id, $field->get_form_field_id() );
1806+
}
1807+
1808+
public function test_get_field_by_id_and_value_by_id_legacy() {
1809+
$post_id = Utility::create_legacy_feedback( array() );
1810+
$response = Feedback::get( $post_id );
1811+
1812+
$this->assertSame( '', $response->get_field_value_by_id( 'email' ) );
1813+
$this->assertNull( $response->get_field_by_id( 'email' ) );
1814+
}
17761815
}

0 commit comments

Comments
 (0)