Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions classes/controllers/FrmAbilitiesFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,13 @@ public static function execute_create_form( $input ) {
$form['options'] = array_merge( $stored, self::sanitize_option_values( $input['options'] ) );
}

if ( ! isset( $input['options']['antispam'] ) ) {
// The builder turns anti-spam on for every new form, while the plain
// default is off. Only a caller who sets it explicitly keeps it off.
$form['options'] = isset( $form['options'] ) && is_array( $form['options'] ) ? $form['options'] : array();
$form['options']['antispam'] = 1;
}

if ( empty( $input['form_key'] ) && ! empty( $input['name'] ) ) {
// The builder derives the form key from the form name whenever the
// name is set, in FrmFormsController::update_form_name(). It cannot
Expand All @@ -586,6 +593,11 @@ public static function execute_create_form( $input ) {

$new_form = FrmForm::getOne( $form_id );

if ( empty( $input['is_template'] ) && empty( $input['parent_form_id'] ) ) {
// Same default notification the builder adds to a new form.
FrmFormsController::create_default_email_action( $new_form );
}

if ( ! empty( $input['fields'] ) && is_array( $input['fields'] ) ) {
foreach ( $input['fields'] as $field ) {
// Share create-field's pipeline so inline fields get the same
Expand Down
3 changes: 2 additions & 1 deletion classes/controllers/FrmFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ public static function list_form() {
* Create the default email action
*
* @since 2.02.11
* @since x.x Changed from private to public.
*
* @param int|object $form
*
* @return void
*/
private static function create_default_email_action( $form ) {
public static function create_default_email_action( $form ) {
FrmForm::maybe_get_form( $form );

if ( ! is_object( $form ) ) {
Expand Down
76 changes: 76 additions & 0 deletions tests/phpunit/forms/test_FrmAbilitiesFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertNotWPError()


The method you are trying to call is not defined, which can result in a fatal error.


$form = FrmForm::getOne( $created['id'] );
$this->assertSame( 1, (int) ( $form->options['antispam'] ?? 0 ), 'Anti-spam should be on by default.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertCount( 1, FrmFormAction::get_action_for_form( $created['id'], 'email' ), 'The default email action should be created.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertCount()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @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 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertNotWPError()


The method you are trying to call is not defined, which can result in a fatal error.


$form = FrmForm::getOne( $created['id'] );
$this->assertSame( 0, (int) ( $form->options['antispam'] ?? 1 ), 'An explicit antispam of 0 should be kept.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @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 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertNotWPError()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertCount( 0, FrmFormAction::get_action_for_form( $template['id'], 'email' ), 'A template should not get an email action.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertCount()


The method you are trying to call is not defined, which can result in a fatal error.


$parent = $this->execute( 'create-form', array( 'name' => 'Parent Form' ) );
$this->assertNotWPError( $parent );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertNotWPError()


The method you are trying to call is not defined, which can result in a fatal error.


$child = $this->execute(
'create-form',
array(
'name' => 'Child Form',
'parent_form_id' => $parent['id'],
)
);
$this->assertNotWPError( $child );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertNotWPError()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertCount( 0, FrmFormAction::get_action_for_form( $child['id'], 'email' ), 'A child form should not get an email action.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertCount()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @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 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertNotWPError()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertCount( 0, FrmFormAction::get_action_for_form( $created['id'], 'email' ), 'The filter should be able to stop the default email action.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmAbilitiesFormsController::assertCount()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* 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
Expand Down
Loading