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
2 changes: 1 addition & 1 deletion classes/helpers/FrmFormsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ private static function field_has_top_label( $field, $form ) {
/**
* @param array|bool|int|object|string $form
*
* @return string
* @return int|string
*/
public static function get_form_style( $form ) {
$style = 1;
Expand Down
10 changes: 9 additions & 1 deletion mago.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ preset = "default"
use-tabs = true

[linter]
integrations = []
integrations = [ "wordpress", "phpunit" ]

[linter.rules]
ambiguous-function-call = { enabled = false }
Expand Down Expand Up @@ -64,6 +64,14 @@ tagged-todo = { enabled = false }
too-many-methods = { enabled = false }
too-many-properties = { enabled = false }
use-compound-assignment = { enabled = false } # Consider enabling this soon.
# PHPUnit Rules
assertion-style = { enabled = false }
# WordPress Rules
no-db-schema-change = { enabled = false }
no-direct-db-query = { enabled = false }
no-roles-as-capabilities = { enabled = false }
no-unescaped-output = { enabled = false }
use-wp-functions = { enabled = false }

[analyzer]
plugins = []
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/applications/test_FrmApplicationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function test_get_api_info() {

$business_hours = $applications[ $business_hours_id ];
$this->assertIsArray( $business_hours );
$this->assertEquals( 'business-hours-template', $business_hours['slug'] );
$this->assertSame( 'business-hours-template', $business_hours['slug'] );
$this->assertArrayHasKey( 'name', $business_hours );
$this->assertNotEmpty( $business_hours['name'] );
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/database/test_FrmMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_maybe_create_contact_form() {
// Check for auto contact form.
$form = FrmForm::getOne( 'contact-form' );
$this->assertNotEmpty( $form );
$this->assertEquals( $form->form_key, 'contact-form' );
$this->assertSame( $form->form_key, 'contact-form' );

// Make sure the form isn't recreated after delete
FrmForm::destroy( 'contact-form' );
Expand Down Expand Up @@ -363,7 +363,7 @@ public function test_migrate_from_12_to_current() {

$this->assertTrue( ! isset( $form->options['notification'] ), 'The migrated notification settings are not cleared from form.' );

$this->assertEquals( 1, count( $form_actions ), 'Old form settings are not converted to email action.' );
$this->assertSame( 1, count( $form_actions ), 'Old form settings are not converted to email action.' );

foreach ( $form_actions as $action ) {
$this->assertStringContainsString( 'emailto@test.com', $action->post_content['email_to'] );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/emails/test_FrmEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public function test_set_reply_to() {
$action->post_content['reply_to'] = '[' . $email_field_key . ']';
$email = new FrmEmail( $action, $entry, $this->contact_form );
$actual = $this->get_private_property( $email, 'reply_to' );
$this->assertEquals( 'fromemail@example.com', $actual );
$this->assertSame( 'fromemail@example.com', $actual );
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/emails/test_FrmEmailSummaryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function test_get_date_obj() {
);

$this->assertTrue( $date instanceof DateTime );
$this->assertEquals( $date->format( 'Y-m-d' ), '2023-08-13' );
$this->assertSame( $date->format( 'Y-m-d' ), '2023-08-13' );

$this->assertFalse(
$this->run_private_method(
Expand All @@ -36,7 +36,7 @@ public function test_get_date_obj() {
}

public function test_get_date_diff() {
$this->assertEquals(
$this->assertSame(
$this->run_private_method(
array( 'FrmEmailSummaryHelper', 'get_date_diff' ),
array( '2023-08-12', '2023-08-16' )
Expand Down Expand Up @@ -175,10 +175,10 @@ function ( $pre, $parsed_args, $url ) {

$recipients = 'test@example.com';
FrmEmailSummaryHelper::maybe_remove_recipients_from_api( $recipients );
$this->assertEquals( '', $recipients );
$this->assertSame( '', $recipients );

$recipients = 'test@example.com,recipient2@example.com';
FrmEmailSummaryHelper::maybe_remove_recipients_from_api( $recipients );
$this->assertEquals( 'recipient2@example.com', $recipients );
$this->assertSame( 'recipient2@example.com', $recipients );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function test_maybe_modify_ajax_error() {
),
)
);
$this->assertEquals(
$this->assertSame(
'<div class="frm_error my_custom_error_class" id="frm_error_field_modify_ajax_error_test_key">My custom error label: This field cannot be blank.</div>',
$this->maybe_modify_ajax_error( $error, $field_id, $form )
);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/entries/test_FrmEntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function test_delete_entry_after_save() {

$post = get_post( $post_id );
$this->assertNotEmpty( $post );
$this->assertEquals( 'publish', $post->post_status );
$this->assertSame( 'publish', $post->post_status );

$no_save_form = $this->create_form( array( 'no_save' => 1 ) );
$this->assertNotEmpty( $no_save_form->options['no_save'] );
Expand All @@ -31,7 +31,7 @@ public function test_delete_entry_after_save() {

$post = get_post( $created_post );
$this->assertNotEmpty( $post );
$this->assertEquals( 'publish', $post->post_status );
$this->assertSame( 'publish', $post->post_status );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/entries/test_FrmEntriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function test_display_value() {
$atts = array();
$display_value = FrmEntriesHelper::display_value( $value, $field, $atts );
$this->assertIsString( $display_value );
$this->assertEquals( 'Option 1, Option 2', $display_value );
$this->assertSame( 'Option 1, Option 2', $display_value );
}
}
6 changes: 3 additions & 3 deletions tests/phpunit/entries/test_FrmEntriesListHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function test_column_value() {

$column_value = $this->column_value( $item, 'description' );
$this->assertIsString( $column_value );
$this->assertEquals( 'Description field value', $column_value );
$this->assertSame( 'Description field value', $column_value );

$column_value = $this->column_value( $item, 'id' );
$this->assertEquals( 1, $column_value );
$this->assertSame( 1, $column_value );

$column_value = $this->column_value( $item, 'name' );
$this->assertEquals( 'My entry name', $column_value );
$this->assertSame( 'My entry name', $column_value );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/entries/test_FrmEntryFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public function test_flatten_array() {
);

$this->formatter = new FrmEntryFormatter( $atts );
$this->assertEquals( 'Option 1, Option 2, Option 3', $this->flatten_array( $values ) );
$this->assertSame( 'Option 1, Option 2, Option 3', $this->flatten_array( $values ) );

$atts['array_separator'] = '<br/>';
$this->formatter = new FrmEntryFormatter( $atts );
$this->assertEquals( 'Option 1<br/>Option 2<br/>Option 3', $this->flatten_array( $values ) );
$this->assertSame( 'Option 1<br/>Option 2<br/>Option 3', $this->flatten_array( $values ) );
}

private function flatten_array( $value ) {
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/entries/test_FrmEntryMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function test_update_entry_metas() {

$meta = FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id );

$this->assertEquals( 'Updated value by field ID', $meta );
$this->assertSame( 'Updated value by field ID', $meta );

// Test field key.
$field_key = FrmField::get_key_by_id( $field_id );
Expand All @@ -40,7 +40,7 @@ public function test_update_entry_metas() {

$meta = FrmEntryMeta::get_entry_meta_by_field( $entry_id, $field_id );

$this->assertEquals( 'Updated value by field key', $meta );
$this->assertSame( 'Updated value by field key', $meta );

// Test with an empty value. It should be null because the row should be deleted from the db.
$values = array(
Expand All @@ -59,11 +59,11 @@ public function test_update_entry_metas() {
public function test_should_join_fields_table() {
$where = 'fi.form_id=123';
$this->assertFalse( $this->run_private_method( array( 'FrmEntryMeta', 'should_join_fields_table' ), array( &$where ) ) );
$this->assertEquals( 'e.form_id=123', $where );
$this->assertSame( 'e.form_id=123', $where );

$where = 'fi.id=123 AND fi.form_id=456';
$this->assertTrue( $this->run_private_method( array( 'FrmEntryMeta', 'should_join_fields_table' ), array( &$where ) ) );
$this->assertEquals( 'fi.id=123 AND fi.form_id=456', $where );
$this->assertSame( 'fi.id=123 AND fi.form_id=456', $where );

$where = array(
'fi.id' => 123,
Expand Down
14 changes: 7 additions & 7 deletions tests/phpunit/entries/test_FrmEntryValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function test_validate() {
$this->assertIsArray( $errors );

$this->assertArrayHasKey( 'custom_error', $errors );
$this->assertEquals( 'Error message', $errors['custom_error'] );
$this->assertSame( 'Error message', $errors['custom_error'] );

remove_filter( 'frm_validate_entry', $add_a_custom_error );
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public function test_get_spam_check_user_info() {
$check = $this->get_spam_check_user_info( $values );
$this->assertTrue( empty( $check['user_ID'] ) );
$this->assertTrue( empty( $check['user_id'] ) );
$this->assertEquals( 'Some Guy', $check['comment_author'] );
$this->assertSame( 'Some Guy', $check['comment_author'] );
$this->assertEquals( $test_email, $check['comment_author_email'] );
$this->assertEquals( $test_url, $check['comment_author_url'] );

Expand Down Expand Up @@ -92,7 +92,7 @@ public function test_get_spam_check_user_info() {
$_POST['form_id'] = $form_id;
$this->run_private_method( array( 'FrmEntryValidate', 'prepare_values_for_spam_check' ), array( &$values ) );
$check = $this->get_spam_check_user_info( $values );
$this->assertEquals( 'John Doe', $check['comment_author'] );
$this->assertSame( 'John Doe', $check['comment_author'] );

// Test with repeater/embedded field.
$values['item_meta'][ $made_up_name_field_id ] = array(
Expand All @@ -109,9 +109,9 @@ public function test_get_spam_check_user_info() {
);

$check = $this->get_spam_check_user_info( $values );
$this->assertEquals( 'John Doe', $check['comment_author'] );
$this->assertEquals( 'johndoe@gmail.com', $check['comment_author_email'] );
$this->assertEquals( 'https://johndoe.com', $check['comment_author_url'] );
$this->assertSame( 'John Doe', $check['comment_author'] );
$this->assertSame( 'johndoe@gmail.com', $check['comment_author_email'] );
$this->assertSame( 'https://johndoe.com', $check['comment_author_url'] );

wp_set_current_user( 1 );
$user = wp_get_current_user();
Expand Down Expand Up @@ -193,7 +193,7 @@ public function test_get_all_form_ids_and_flatten_meta() {
$this->assertFalse( isset( $test_values['item_meta'][165] ) );
$this->assertEquals( $test_values['item_meta'][162], array( 'Option 2', 'Option 1' ) );
$this->assertEquals( $test_values['item_meta'][118], array( 'John Doe' ) );
$this->assertEquals( $test_values['item_meta'][1], 'John Doe' );
$this->assertSame( $test_values['item_meta'][1], 'John Doe' );
}

public function test_skip_adding_values_to_akismet() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/entries/test_FrmShortodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function test_get_shortcode_tag() {

$this->assertNotEmpty( $matches[0][0] );
$tag = FrmShortcodeHelper::get_shortcode_tag( $matches, 0, $args );
$this->assertEquals( '25', $tag );
$this->assertSame( '25', $tag );
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/entries/test_FrmTableHTMLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function test_remove_border() {
);

$html = '<div style="border-top:3px solid #eee;"></div>';
$this->assertEquals( $table_generator->remove_border( $html ), '<div style=""></div>' );
$this->assertSame( $table_generator->remove_border( $html ), '<div style=""></div>' );
$this->assertEquals( $table_generator->remove_border( $html, 'bottom' ), $html );

$html = '<div style="border-top:1px solid #eee;"></div>';
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/fields/test_FrmFieldCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function test_print_input_atts() {
);
$atts = ob_get_clean();

$this->assertEquals( $atts, ' placeholder="First placeholder" class="frm-custom-class" maxlength="10" data-attr="custom-attr" ' );
$this->assertSame( $atts, ' placeholder="First placeholder" class="frm-custom-class" maxlength="10" data-attr="custom-attr" ' );

$sub_field = array(
'name' => 'second',
Expand All @@ -283,7 +283,7 @@ public function test_print_input_atts() {
);
$atts = ob_get_clean();

$this->assertEquals( $atts, ' class="frm-class1 frm-class2 frm_optional" ' );
$this->assertSame( $atts, ' class="frm-class1 frm-class2 frm_optional" ' );

$sub_field = array(
'name' => 'forth',
Expand All @@ -299,7 +299,7 @@ public function test_print_input_atts() {
);
$atts = ob_get_clean();

$this->assertEquals( $atts, ' ' );
$this->assertSame( $atts, ' ' );
}

public function test_get_export_headings() {
Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/fields/test_FrmFieldGridHelper.php.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class test_FrmFieldGridHelper extends FrmUnitTest {
* @covers FrmFieldGridHelper::get_size_of_class
*/
public function test_get_size_of_class() {
$this->assertEquals( 1, $this->get_size_of_class( 'frm1' ) );
$this->assertEquals( 6, $this->get_size_of_class( 'frm6' ) );
$this->assertEquals( 8, $this->get_size_of_class( 'frm8' ) );
$this->assertEquals( 10, $this->get_size_of_class( 'frm10' ) );
$this->assertEquals( 12, $this->get_size_of_class( 'frm12' ) );
$this->assertEquals( 2, $this->get_size_of_class( 'frm_sixth' ) );
$this->assertEquals( 3, $this->get_size_of_class( 'frm_fourth' ) );
$this->assertEquals( 4, $this->get_size_of_class( 'frm_third' ) );
$this->assertEquals( 6, $this->get_size_of_class( 'frm_half' ) );
$this->assertEquals( 12, $this->get_size_of_class( 'frm_full' ) );
$this->assertSame( 1, $this->get_size_of_class( 'frm1' ) );
$this->assertSame( 6, $this->get_size_of_class( 'frm6' ) );
$this->assertSame( 8, $this->get_size_of_class( 'frm8' ) );
$this->assertSame( 10, $this->get_size_of_class( 'frm10' ) );
$this->assertSame( 12, $this->get_size_of_class( 'frm12' ) );
$this->assertSame( 2, $this->get_size_of_class( 'frm_sixth' ) );
$this->assertSame( 3, $this->get_size_of_class( 'frm_fourth' ) );
$this->assertSame( 4, $this->get_size_of_class( 'frm_third' ) );
$this->assertSame( 6, $this->get_size_of_class( 'frm_half' ) );
$this->assertSame( 12, $this->get_size_of_class( 'frm_full' ) );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/fields/test_FrmFieldNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class test_FrmFieldNumber extends FrmUnitTest {
public function test_check_value_is_valid_with_step() {
$number_field = new FrmFieldNumber();

$this->assertEquals( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9, 3 ) ) );
$this->assertEquals( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9.0, 3 ) ) );
$this->assertEquals( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9, 3.0 ) ) );
$this->assertEquals( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 68.93, 0.01 ) ) );
$this->assertEquals( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( '68.93', '0.01' ) ) );
$this->assertSame( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9, 3 ) ) );
$this->assertSame( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9.0, 3 ) ) );
$this->assertSame( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9, 3.0 ) ) );
$this->assertSame( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 68.93, 0.01 ) ) );
$this->assertSame( 0, $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( '68.93', '0.01' ) ) );

$this->assertEquals( array( 0, 3 ), $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 1, 3 ) ) );
$this->assertEquals( array( 8, 10 ), $this->run_private_method( array( $number_field, 'check_value_is_valid_with_step' ), array( 9, 2 ) ) );
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/fields/test_FrmFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ public function test_get_import_value() {

$checkbox = FrmFieldFactory::get_field_type( 'checkbox', $field );

$this->assertEquals( $checkbox->get_import_value( 'a,b' ), 'a,b' );
$this->assertSame( $checkbox->get_import_value( 'a,b' ), 'a,b' );
$this->assertEquals( $checkbox->get_import_value( 'a,c' ), array( 'a', 'c' ) );
$this->assertEquals( $checkbox->get_import_value( 'a,b,c' ), 'a,b,c' );
$this->assertSame( $checkbox->get_import_value( 'a,b,c' ), 'a,b,c' );
}

/**
Expand Down Expand Up @@ -315,7 +315,7 @@ public function test_prepare_field_html() {
$field_array = FrmFieldsHelper::setup_edit_vars( $field );
$field_object = FrmFieldFactory::get_field_type( 'text', $field_array );
$html = $field_object->prepare_field_html( $args );
$this->assertEquals( '', $html );
$this->assertSame( '', $html );

// Test a draft field on a preview page for a privileged user (the HTML should not be empty).
$this->reset_should_hide_draft_fields_flag();
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/fields/test_FrmFieldValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function test_number_validation() {
),
)
);
$this->assertEquals( 20, $field->field_options['maxnum'] );
$this->assertSame( 20, $field->field_options['maxnum'] );

$errors = $this->check_single_value( array( $field->id => '10.5' ) );
$this->assertFalse( isset( $errors[ 'field' . $field->id ] ), 'Number failed range validation ' . print_r( $errors, 1 ) );
Expand Down Expand Up @@ -357,7 +357,7 @@ public function test_is_akismet_enabled_for_user() {
),
)
);
$this->assertEquals( 'logged', $akismet_logged->options['akismet'] );
$this->assertSame( 'logged', $akismet_logged->options['akismet'] );

wp_set_current_user( 0 );
$this->assertFalse( is_user_logged_in() );
Expand Down
Loading
Loading