From db7fb1c2698ebbd63a128579d91b24e9be5780ca Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 4 Dec 2025 17:28:42 +0100 Subject: [PATCH 1/5] fix all tests and function --- .phpcs.xml.dist | 21 +- includes/admin/class-admin-options.php | 203 +++--- .../crm-library/class-crmlib-clientify.php | 43 +- includes/crm-library/class-crmlib-holded.php | 10 +- .../formscrm-library/class-contactform7.php | 44 +- includes/formscrm-library/class-elementor.php | 44 +- .../class-gravityforms-widget.php | 3 - .../formscrm-library/class-gravityforms.php | 74 +- .../formscrm-library/class-woocommerce.php | 37 +- includes/formscrm-library/class-wpforms.php | 44 +- includes/formscrm-library/elementor-ajax.php | 4 +- .../formscrm-library/helpers-functions.php | 40 +- includes/formscrm-library/loader.php | 13 +- phpstan.neon.dist | 25 - report.txt | 177 +++++ tests/README-TESTS.md | 4 +- tests/Unit/test-helpers-functions.php | 8 + tests/Unit/test-notifications.php | 4 +- tests/debugtest.php | 2 +- tests/phpstan-bootstrap.php | 646 ++++++++++++++++++ tests/test-email.php | 4 +- 21 files changed, 1032 insertions(+), 418 deletions(-) create mode 100644 report.txt diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 75713ac..024887a 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -30,12 +30,21 @@ - + + + + + + + + - + + + @@ -58,4 +67,12 @@ 0 + + + + 0 + + + 0 + diff --git a/includes/admin/class-admin-options.php b/includes/admin/class-admin-options.php index 89b1523..5e5a18a 100644 --- a/includes/admin/class-admin-options.php +++ b/includes/admin/class-admin-options.php @@ -6,8 +6,6 @@ * @author David Perez * @copyright 2019 Closemarketing * @version 1.0 - * - * phpcs:disable WordPress.Files.FileName.InvalidClassFileName */ defined( 'ABSPATH' ) || exit; @@ -30,8 +28,6 @@ * Handles admin settings page for FormsCRM plugin. */ class FORMSCRM_Admin { - // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- File name follows plugin convention. - /** * Construct of class */ @@ -166,43 +162,16 @@ public function create_admin_page() { * @return void */ public function settings_page() { - $source_shop_url = 'es' === strtok( get_locale(), '_' ) ? 'https://close.technology/' : 'https://close.technology/en/'; - $utm_source = '?utm_source=WordPress+Settings&utm_medium=plugin&utm_campaign=link'; - $slack_webhook_url = get_option( 'formscrm_slack_webhook_url', '' ); - ?> - -
- -

- - - - - -
- - - -

- ' . esc_html__( 'Learn how to create a Slack Webhook', 'formscrm' ) . ' →'; - ?> -

-
- -
- -
- -

- +
+ +

+ + + +
@@ -221,6 +190,20 @@ public function settings_page() {

+ + + +

+ ' . esc_html__( 'Learn how to create a Slack Webhook', 'formscrm' ) . ' →'; + ?> +

+
@@ -229,88 +212,88 @@ public function settings_page() {

    - 'Gravity' ), - array( 'label' => 'Elementor' ), - array( 'label' => 'ContactForm7' ), - array( 'label' => 'WooCommerce' ), - array( 'label' => 'WPForms' ), - ); + 'Gravity' ), + array( 'label' => 'Elementor' ), + array( 'label' => 'ContactForm7' ), + array( 'label' => 'WooCommerce' ), + array( 'label' => 'WPForms' ), + ); - foreach ( $forms_supported as $form ) { - echo '
  • '; - $slug = strtolower( $form['label'] ); - echo '' . esc_html( $form['label'] ) . '
    '; - echo '
  • '; - } - ?> + foreach ( $forms_supported as $form ) { + echo '
  • '; + $slug = strtolower( $form['label'] ); + echo '' . esc_html( $form['label'] ) . '
    '; + echo '
  • '; + } + ?>

    - 'Holded', - 'url' => false, - ), - array( - 'label' => 'Clientify', - 'url' => false, - ), - array( - 'label' => 'AcumbaMail', - 'url' => false, - ), - array( - 'label' => 'Odoo', - 'url' => true, - ), - array( - 'label' => 'Brevo', - 'url' => false, - ), - array( - 'label' => 'WHMCS', - 'url' => true, - ), - array( - 'label' => 'vTiger', - 'url' => true, - ), - array( - 'label' => 'Inmovilla', - 'url' => true, - ), - array( - 'label' => 'Pipedrive', - 'url' => true, - ), - array( - 'label' => 'SuiteCRM', - 'url' => true, - ), - array( - 'label' => 'FacturaDirecta', - 'url' => true, - ), - ); + 'Holded', + 'url' => false, + ), + array( + 'label' => 'Clientify', + 'url' => false, + ), + array( + 'label' => 'AcumbaMail', + 'url' => false, + ), + array( + 'label' => 'Odoo', + 'url' => true, + ), + array( + 'label' => 'Brevo', + 'url' => false, + ), + array( + 'label' => 'WHMCS', + 'url' => true, + ), + array( + 'label' => 'vTiger', + 'url' => true, + ), + array( + 'label' => 'Inmovilla', + 'url' => true, + ), + array( + 'label' => 'Pipedrive', + 'url' => true, + ), + array( + 'label' => 'SuiteCRM', + 'url' => true, + ), + array( + 'label' => 'FacturaDirecta', + 'url' => true, + ), + ); - foreach ( $crms_supported as $crm ) { - echo '
  • '; - $slug = strtolower( $crm['label'] ); - if ( isset( $crm['url'] ) && $crm['url'] ) { - $url = esc_url( $source_shop_url ) . 'wordpress-plugins/formscrm-' . $slug . '/' . esc_attr( $utm_source ); - echo ' '; - } - echo '' . esc_html( $crm['label'] ) . '
    '; + foreach ( $crms_supported as $crm ) { + echo '
  • '; + $slug = strtolower( $crm['label'] ); + if ( isset( $crm['url'] ) && $crm['url'] ) { + $url = esc_url( $source_shop_url ) . 'wordpress-plugins/formscrm-' . $slug . '/' . esc_attr( $utm_source ); + echo ' '; + } + echo '' . esc_html( $crm['label'] ) . '
    '; - if ( isset( $crm['url'] ) && $crm['url'] ) { - echo '
    '; - } - echo '
  • '; + if ( isset( $crm['url'] ) && $crm['url'] ) { + echo ''; } - ?> + echo ''; + } + ?>

diff --git a/includes/crm-library/class-crmlib-clientify.php b/includes/crm-library/class-crmlib-clientify.php index 6b27af7..aae8259 100644 --- a/includes/crm-library/class-crmlib-clientify.php +++ b/includes/crm-library/class-crmlib-clientify.php @@ -923,30 +923,29 @@ public function create_entry( $settings, $merge_vars ) { // Add tags to deal. if ( ! empty( $deal_tags ) ) { $deal_tags_raw = explode( ',', $deal_tags ); - if ( ! empty( $deal_tags_raw ) ) { - $deal_id = $result['data']['id']; - foreach ( $deal_tags_raw as $deal_tag ) { - $deal_tags_api = array( - 'name' => sanitize_text_field( $deal_tag ), - ); + $deal_id = $result['data']['id']; + + foreach ( $deal_tags_raw as $deal_tag ) { + $deal_tags_api = array( + 'name' => sanitize_text_field( $deal_tag ), + ); + + $result_tag = $this->request( 'deals/' . $deal_id . '/tags/', $deal_tags_api, $apikey ); - $result_tag = $this->request( 'deals/' . $deal_id . '/tags/', $deal_tags_api, $apikey ); - - if ( 'ok' !== $result_tag['status'] ) { - $result_deal_tag = sprintf( - /* translators: %s: Tag name */ - __( 'Tag %s not added to deal', 'formscrm' ), - $deal_tag, - ); - } else { - $result_deal_tag = sprintf( - /* translators: %s: Tag name */ - __( 'Tag %s added to deal', 'formscrm' ), - $deal_tag, - ); - } - $response_result['message'] .= ' ' . $result_deal_tag; + if ( 'ok' !== $result_tag['status'] ) { + $result_deal_tag = sprintf( + /* translators: %s: Tag name */ + __( 'Tag %s not added to deal', 'formscrm' ), + $deal_tag, + ); + } else { + $result_deal_tag = sprintf( + /* translators: %s: Tag name */ + __( 'Tag %s added to deal', 'formscrm' ), + $deal_tag, + ); } + $response_result['message'] .= ' ' . $result_deal_tag; } } diff --git a/includes/crm-library/class-crmlib-holded.php b/includes/crm-library/class-crmlib-holded.php index 34b8dc4..61635d0 100644 --- a/includes/crm-library/class-crmlib-holded.php +++ b/includes/crm-library/class-crmlib-holded.php @@ -9,20 +9,16 @@ * @package FormsCRM * @version 1.0.0 * @copyright 2021 Closemarketing - * - * phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound - * phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound */ defined( 'ABSPATH' ) || exit; -define( 'MAX_LIMIT_HOLDED_API', 500 ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Legacy constant, changing would break compatibility. +define( 'FORMSCRM_MAX_LIMIT_HOLDED_API', 500 ); /** * Class for Holded connection. */ class CRMLIB_HOLDED { - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy class name, changing would break compatibility. /** * Gets information from Holded CRM * @@ -133,7 +129,7 @@ public function search_by_email( $module, $email, $apikey ) { } } - if ( count( $contacts['data'] ) === MAX_LIMIT_HOLDED_API ) { + if ( count( $contacts['data'] ) === FORMSCRM_MAX_LIMIT_HOLDED_API ) { ++$page; } else { $next = false; @@ -394,7 +390,7 @@ public function create_entry( $settings, $merge_vars ) { foreach ( $merge_vars as $element ) { if ( false !== strpos( $element['name'], '|' ) ) { $data_field = explode( '|', $element['name'] ); - if ( is_array( $data_field ) && ! empty( $data_field ) ) { + if ( is_array( $data_field ) ) { $contact[ $data_field[0] ][ $data_field[1] ] = (string) $element['value']; } } elseif ( 'tags' === $element['name'] ) { diff --git a/includes/formscrm-library/class-contactform7.php b/includes/formscrm-library/class-contactform7.php index 0ade192..14e2468 100644 --- a/includes/formscrm-library/class-contactform7.php +++ b/includes/formscrm-library/class-contactform7.php @@ -6,8 +6,6 @@ * @author David Perez * @copyright 2021 Closemarketing * @version 3.3 - * - * phpcs:disable WordPress.Files.FileName.InvalidClassFileName */ defined( 'ABSPATH' ) || exit; @@ -21,8 +19,6 @@ * @version 1.0 */ class FORMSCRM_CF7_Settings { - // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- File name follows plugin convention. - /** * CRM LIB external * @@ -56,32 +52,6 @@ public function show_cm_metabox( $panels ) { return $panels; } - /** - * Include library connector - * - * @param string $crmtype Type of CRM. - * @return void - */ - private function include_library( $crmtype ) { - if ( isset( $crmtype ) ) { - $crmname = strtolower( $crmtype ); - $crmclassname = str_replace( ' ', '', $crmname ); - $crmclassname = 'CRMLIB_' . strtoupper( $crmclassname ); - $crmname = str_replace( ' ', '_', $crmname ); - - $array_path = formscrm_get_crmlib_path(); - if ( isset( $array_path[ $crmname ] ) ) { - include_once $array_path[ $crmname ]; - } - - formscrm_debug_message( $array_path[ $crmname ] ); - - if ( class_exists( $crmclassname ) ) { - $this->crmlib = new $crmclassname(); - } - } - } - /** * Adds CRM options in Contact Form 7 * @@ -150,9 +120,11 @@ public function settings_add_crm( $args ) {

- + + crmlib = formscrm_get_api_class( $cf7_crm['fc_crm_type'] ); + ?>

- include_library( $cf7_crm['fc_crm_type'] ); ?>