Repository navigation
Give create-form the builder's defaults: anti-spam on and an email action #3600
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
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 |
|---|---|---|
|
|
@@ -174,6 +174,82 @@ public function test_create_form_applies_submitted_options() { | |
| $this->assertSame( 'Send it', $form->options['submit_value'] ?? null, 'A submitted option should be applied, not dropped to its default.' ); | ||
| } | ||
|
|
||
| /** | ||
| * The builder turns anti-spam on and adds the default email action to every | ||
| * new form, so a form made through the ability has to match. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_create_form_defaults_to_antispam_and_one_email_action() { | ||
| $created = $this->execute( 'create-form', array( 'name' => 'Form With Defaults' ) ); | ||
|
|
||
| $this->assertNotWPError( $created ); | ||
|
|
||
| $form = FrmForm::getOne( $created['id'] ); | ||
| $this->assertSame( 1, (int) ( $form->options['antispam'] ?? 0 ), 'Anti-spam should be on by default.' ); | ||
|
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->assertCount( 1, FrmFormAction::get_action_for_form( $created['id'], 'email' ), 'The default email action should be created.' ); | ||
|
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.
|
||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function test_create_form_keeps_antispam_off_when_the_caller_turns_it_off() { | ||
| $created = $this->execute( | ||
| 'create-form', | ||
| array( | ||
| 'name' => 'Form Without Antispam', | ||
| 'options' => array( 'antispam' => 0 ), | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertNotWPError( $created ); | ||
|
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.
|
||
|
|
||
| $form = FrmForm::getOne( $created['id'] ); | ||
| $this->assertSame( 0, (int) ( $form->options['antispam'] ?? 1 ), 'An explicit antispam of 0 should be kept.' ); | ||
|
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.
|
||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function test_create_form_skips_the_email_action_for_templates_and_child_forms() { | ||
| $template = $this->execute( | ||
| 'create-form', | ||
| array( | ||
| 'name' => 'Template Form', | ||
| 'is_template' => 1, | ||
| ) | ||
| ); | ||
| $this->assertNotWPError( $template ); | ||
|
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->assertCount( 0, FrmFormAction::get_action_for_form( $template['id'], 'email' ), 'A template should not get an email action.' ); | ||
|
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.
|
||
|
|
||
| $parent = $this->execute( 'create-form', array( 'name' => 'Parent Form' ) ); | ||
| $this->assertNotWPError( $parent ); | ||
|
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.
|
||
|
|
||
| $child = $this->execute( | ||
| 'create-form', | ||
| array( | ||
| 'name' => 'Child Form', | ||
| 'parent_form_id' => $parent['id'], | ||
| ) | ||
| ); | ||
| $this->assertNotWPError( $child ); | ||
|
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->assertCount( 0, FrmFormAction::get_action_for_form( $child['id'], 'email' ), 'A child form should not get an email action.' ); | ||
|
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.
|
||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
| public function test_create_form_respects_the_default_email_action_filter() { | ||
| add_filter( 'frm_create_default_email_action', '__return_false' ); | ||
|
|
||
| $created = $this->execute( 'create-form', array( 'name' => 'Form With Filter' ) ); | ||
|
|
||
| remove_filter( 'frm_create_default_email_action', '__return_false' ); | ||
|
|
||
| $this->assertNotWPError( $created ); | ||
|
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->assertCount( 0, FrmFormAction::get_action_for_form( $created['id'], 'email' ), 'The filter should be able to stop the default email action.' ); | ||
|
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.
|
||
| } | ||
|
|
||
| /** | ||
| * A partial options update has to merge over what is stored, not replace | ||
| * it outright, or every option left out of the request would reset to | ||
|
|
||
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.
The method you are trying to call is not defined, which can result in a fatal error.