Repository navigation
Keep the Entry Key typed on an earlier page of a multi-page Add New #3609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
edb15d4
0767dcf
066b2d2
a4c0ead
609ba61
067ac4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,11 @@ | |
| #[\PHPUnit\Framework\Attributes\CoversClass( FrmEntriesHelper::class )] | ||
| class test_FrmEntriesHelper extends FrmUnitTest { | ||
|
|
||
| public function tearDown(): void { | ||
| unset( $_POST['item_key'] ); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| public function test_display_value() { | ||
| $value = serialize( array( 'Option 1', 'Option 2' ) ); | ||
| $field = $this->factory->field->create_and_get( | ||
|
|
@@ -22,4 +27,33 @@ public function test_display_value() { | |
| $this->assertIsString( $display_value ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $this->assertSame( 'Option 1, Option 2', $display_value ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
| * The Entry Key typed on one page of a multi-page form must survive to the next page. | ||
| */ | ||
| public function test_setup_new_vars_keeps_posted_item_key() { | ||
| $form_id = $this->factory->form->create(); | ||
| $this->factory->field->create( | ||
| array( | ||
| 'form_id' => $form_id, | ||
| 'type' => 'text', | ||
| ) | ||
| ); | ||
| $fields = FrmField::get_all_for_form( $form_id ); | ||
| $_POST['item_key'] = 'My Typed Key'; | ||
| $values = FrmEntriesHelper::setup_new_vars( $fields ); | ||
| $this->assertSame( 'my-typed-key', $values['item_key'] ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| $values = FrmEntriesHelper::setup_new_vars( $fields, '', true ); | ||
| $this->assertSame( '', $values['item_key'], 'A reset form must not carry the posted key.' ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 609ba61. The cleanup moved to tearDown(). |
||
| $_POST['item_key'] = array( 'x' ); | ||
| $values = FrmEntriesHelper::setup_new_vars( $fields ); | ||
| $this->assertSame( '', $values['item_key'], 'An array posted as the key must not reach the view.' ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| unset( $_POST['item_key'] ); | ||
|
|
||
| $values = FrmEntriesHelper::setup_new_vars( $fields ); | ||
| $this->assertSame( '', $values['item_key'] ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid call to a static method. This would lead to a run time error.