From a68585e9297b140383e8c7974fd8b62496bbcf1c Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 7 Apr 2024 07:04:13 +0000 Subject: [PATCH] tests: lint tests --- CHANGELOG.md | 1 + tests/_support/AcceptanceTester.php | 16 +- tests/_support/Factory/DraftEntry.php | 7 +- tests/_support/Factory/Entry.php | 4 +- tests/_support/Factory/Field.php | 9 +- tests/_support/Factory/Form.php | 1 + tests/_support/Helper/Acceptance.php | 2 - tests/_support/Helper/Functional.php | 2 - .../Helper/GFHelpers/ExpectedFormFields.php | 333 +++++++++--------- tests/_support/Helper/GFHelpers/GFHelpers.php | 9 +- .../Helper/GFHelpers/PropertyHelper.php | 73 ++-- tests/_support/Helper/GFHelpers/inc/Dummy.php | 1 - tests/_support/Helper/Unit.php | 2 - tests/_support/Helper/Wpunit.php | 88 +++-- tests/_support/TestCase/FormFieldTestCase.php | 42 +-- .../TestCase/FormFieldTestCaseInterface.php | 25 +- tests/_support/TestCase/GFGraphQLTestCase.php | 16 +- tests/_support/UnitTester.php | 16 +- tests/_support/WpunitTester.php | 16 +- tests/acceptance/ActivationCest.php | 1 - tests/unit/UtilsUtilsTest.php | 2 +- tests/wpunit/AddressFieldTest.php | 38 +- tests/wpunit/CaptchaFieldTest.php | 30 +- tests/wpunit/ChainedSelectFieldTest.php | 22 +- tests/wpunit/CheckboxFieldTest.php | 21 +- tests/wpunit/ConsentFieldTest.php | 19 +- tests/wpunit/DateFieldTest.php | 31 +- tests/wpunit/DeleteDraftEntryMutationTest.php | 10 +- tests/wpunit/DeleteEntryMutationTest.php | 6 +- tests/wpunit/EmailFieldTest.php | 32 +- tests/wpunit/EntryConnectionQueriesTest.php | 9 +- tests/wpunit/EntryQueriesTest.php | 49 ++- tests/wpunit/FileUploadFieldTest.php | 31 +- tests/wpunit/FileUploadMultipleFieldTest.php | 43 +-- tests/wpunit/FormConnectionQueriesTest.php | 1 - tests/wpunit/FormQueriesTest.php | 27 +- tests/wpunit/GFTest.php | 1 + tests/wpunit/GFUtilsTest.php | 34 +- tests/wpunit/HiddenFieldTest.php | 29 +- tests/wpunit/HtmlFieldTest.php | 24 +- tests/wpunit/ListFieldColumnsTest.php | 34 +- tests/wpunit/ListFieldTest.php | 32 +- tests/wpunit/MultiSelectFieldTest.php | 21 +- tests/wpunit/NameFieldTest.php | 31 +- tests/wpunit/NumberFieldTest.php | 30 +- tests/wpunit/OptionCheckboxFieldTest.php | 33 +- tests/wpunit/OptionRadioFieldTest.php | 31 +- tests/wpunit/OptionSelectFieldTest.php | 32 +- tests/wpunit/PageFieldTest.php | 24 +- tests/wpunit/PhoneFieldTest.php | 30 +- .../wpunit/PostCategoryCheckboxFieldTest.php | 27 +- .../PostCategoryMultiSelectFieldTest.php | 26 +- tests/wpunit/PostCategoryRadioFieldTest.php | 26 +- tests/wpunit/PostCategorySelectFieldTest.php | 26 +- tests/wpunit/PostContentFieldTest.php | 33 +- tests/wpunit/PostExcerptFieldTest.php | 33 +- tests/wpunit/PostImageFieldTest.php | 36 +- tests/wpunit/PostTagsCheckboxFieldTest.php | 27 +- tests/wpunit/PostTagsMultiSelectFieldTest.php | 26 +- tests/wpunit/PostTagsRadioFieldTest.php | 26 +- tests/wpunit/PostTagsTextFieldTest.php | 24 +- tests/wpunit/PostTitleFieldTest.php | 33 +- tests/wpunit/ProductCalculationFieldTest.php | 21 +- tests/wpunit/ProductHiddenFieldTest.php | 21 +- tests/wpunit/ProductPriceFieldTest.php | 21 +- tests/wpunit/ProductRadioFieldTest.php | 21 +- tests/wpunit/ProductSelectFieldTest.php | 21 +- tests/wpunit/ProductSingleFieldTest.php | 21 +- tests/wpunit/QuantityHiddenFieldTest.php | 33 +- tests/wpunit/QuantityNumberFieldTest.php | 33 +- tests/wpunit/QuantitySelectFieldTest.php | 32 +- tests/wpunit/QuizCheckboxFieldTest.php | 23 +- tests/wpunit/QuizRadioFieldTest.php | 24 +- tests/wpunit/QuizSelectFieldTest.php | 21 +- tests/wpunit/RadioFieldTest.php | 33 +- tests/wpunit/SectionFieldTest.php | 24 +- tests/wpunit/SelectFieldTest.php | 33 +- tests/wpunit/SettingsTest.php | 6 +- tests/wpunit/ShippingRadioFieldTest.php | 30 +- tests/wpunit/ShippingSelectFieldTest.php | 30 +- tests/wpunit/ShippingSingleFieldTest.php | 30 +- tests/wpunit/SignatureFieldTest.php | 34 +- tests/wpunit/SubmitDraftEntryMutationTest.php | 9 +- tests/wpunit/SubmitFormMutationTest.php | 28 +- tests/wpunit/TextAreaFieldTest.php | 33 +- tests/wpunit/TextFieldTest.php | 30 +- tests/wpunit/TimeFieldTest.php | 33 +- tests/wpunit/TotalFieldTest.php | 33 +- tests/wpunit/UpdateDraftEntryMutationTest.php | 5 +- tests/wpunit/UpdateEntryMutationTest.php | 6 +- tests/wpunit/WebsiteFieldTest.php | 30 +- 91 files changed, 1146 insertions(+), 1337 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86825fdb..79634d59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - chore: Lock WPBrowser to <3.5.0 to prevent conflicts with Codeception. - chore: Implement strict PHPStan rules and fix resulting issues. - chore: Add traversable type hints throughout the codebase. +- tests: Lint tests. - ci: Update GitHub Actions to latest versions. - ci: Test plugin compatibility with WordPress 6.5.0. - ci: Test plugin compatibility with PHP 8.2. diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 7359a122..36b925f4 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -3,6 +3,7 @@ /** * Inherited Methods + * * @method void wantToTest($text) * @method void wantTo($text) * @method void execute($callable) @@ -14,13 +15,12 @@ * @method void comment($description) * @method void pause() * - * @SuppressWarnings(PHPMD) -*/ -class AcceptanceTester extends \Codeception\Actor -{ - use _generated\AcceptanceTesterActions; + * @SuppressWarnings(\PHPMD) + */ +class AcceptanceTester extends \Codeception\Actor { + use _generated\AcceptanceTesterActions; - /** - * Define custom actions here - */ + /** + * Define custom actions here + */ } diff --git a/tests/_support/Factory/DraftEntry.php b/tests/_support/Factory/DraftEntry.php index 92b51608..0d21017f 100644 --- a/tests/_support/Factory/DraftEntry.php +++ b/tests/_support/Factory/DraftEntry.php @@ -14,7 +14,6 @@ * Class - Entry */ class DraftEntry extends \WP_UnitTest_Factory_For_Thing { - /** * Constructor * @@ -22,6 +21,7 @@ class DraftEntry extends \WP_UnitTest_Factory_For_Thing { */ public function __construct( $factory = null ) { parent::__construct( $factory ); + $this->default_generation_definitions = [ 'source_url' => '', 'page_number' => 1, @@ -34,7 +34,7 @@ public function __construct( $factory = null ) { * * @param array $args entry arguments. */ - public function create_object( $args ) : string { + public function create_object( $args ): string { $form = GFAPI::get_form( $args['form_id'] ); $entry = array_replace( @@ -101,9 +101,8 @@ public function update_object( $resume_token, $properties ) { * Gets the draft entry from an object id. * * @param string $resume_token . - * @return array */ - public function get_object_by_id( $resume_token ) : array { + public function get_object_by_id( $resume_token ): array { return GFFormsModel::get_draft_submission_values( $resume_token ); } diff --git a/tests/_support/Factory/Entry.php b/tests/_support/Factory/Entry.php index 364fe14c..448aa9f1 100644 --- a/tests/_support/Factory/Entry.php +++ b/tests/_support/Factory/Entry.php @@ -15,7 +15,6 @@ * Class - Entry */ class Entry extends \WP_UnitTest_Factory_For_Thing { - /** * Constructor * @@ -23,6 +22,7 @@ class Entry extends \WP_UnitTest_Factory_For_Thing { */ public function __construct( $factory = null ) { parent::__construct( $factory ); + $this->default_generation_definitions = [ 'id' => new WP_UnitTest_Generator_Sequence( '%s' ), 'currency' => 'USD', @@ -34,7 +34,7 @@ public function __construct( $factory = null ) { * * @param array $args entry arguments. */ - public function create_object( $args ) : int { + public function create_object( $args ): int { return GFAPI::add_entry( $args ); } diff --git a/tests/_support/Factory/Field.php b/tests/_support/Factory/Field.php index 985da6e5..886d8cfa 100644 --- a/tests/_support/Factory/Field.php +++ b/tests/_support/Factory/Field.php @@ -7,7 +7,6 @@ namespace Tests\WPGraphQL\GF\Factory; -use GF_Field; use GF_Fields; use WP_UnitTest_Generator_Sequence; @@ -15,7 +14,6 @@ * Class - Field */ class Field extends \WP_UnitTest_Factory_For_Thing { - /** * Constructor * @@ -23,6 +21,7 @@ class Field extends \WP_UnitTest_Factory_For_Thing { */ public function __construct( $factory = null ) { parent::__construct( $factory ); + $this->default_generation_definitions = [ 'id' => new WP_UnitTest_Generator_Sequence( '%s' ), 'label' => new WP_UnitTest_Generator_Sequence( 'Field label %s' ), @@ -58,8 +57,8 @@ public function create_many( $count, $args = [], $generation_definitions = null /** * Updates a field object. * - * @param GF_Field $field . - * @param array $args properties to update. + * @param \GF_Field $field . + * @param array $args properties to update. */ public function update_object( $field, $args ) { foreach ( $args as $key => $value ) { @@ -71,7 +70,7 @@ public function update_object( $field, $args ) { /** * Get the field object. Returns itself. * - * @param GF_Field $field . + * @param \GF_Field $field . */ public function get_object_by_id( $field ) { return $field; diff --git a/tests/_support/Factory/Form.php b/tests/_support/Factory/Form.php index 3255a18d..4cc9d39b 100644 --- a/tests/_support/Factory/Form.php +++ b/tests/_support/Factory/Form.php @@ -22,6 +22,7 @@ class Form extends \WP_UnitTest_Factory_For_Thing { */ public function __construct( $factory = null ) { parent::__construct( $factory ); + $this->default_generation_definitions = [ 'title' => new WP_UnitTest_Generator_Sequence( 'Form title %s' ), 'description' => new WP_UnitTest_Generator_Sequence( 'Form description %s' ), diff --git a/tests/_support/Helper/Acceptance.php b/tests/_support/Helper/Acceptance.php index 0594cb0b..90f4bfb3 100644 --- a/tests/_support/Helper/Acceptance.php +++ b/tests/_support/Helper/Acceptance.php @@ -5,6 +5,4 @@ // all public methods declared in helper class will be available in $I class Acceptance extends \Codeception\Module { - - } diff --git a/tests/_support/Helper/Functional.php b/tests/_support/Helper/Functional.php index 99d7125c..64c4a362 100644 --- a/tests/_support/Helper/Functional.php +++ b/tests/_support/Helper/Functional.php @@ -5,6 +5,4 @@ // all public methods declared in helper class will be available in $I class Functional extends \Codeception\Module { - - } diff --git a/tests/_support/Helper/GFHelpers/ExpectedFormFields.php b/tests/_support/Helper/GFHelpers/ExpectedFormFields.php index 091dfeca..9dc684f4 100644 --- a/tests/_support/Helper/GFHelpers/ExpectedFormFields.php +++ b/tests/_support/Helper/GFHelpers/ExpectedFormFields.php @@ -7,25 +7,24 @@ namespace Helper\GFHelpers; -use WPGraphQL\GF\Type\Enum; use GF_Field; use WPGraphQL\GF\Extensions\GFChainedSelects\Type\Enum\ChainedSelectFieldAlignmentEnum; use WPGraphQL\GF\Extensions\GFSignature\Type\Enum\SignatureFieldBorderStyleEnum; use WPGraphQL\GF\Extensions\GFSignature\Type\Enum\SignatureFieldBorderWidthEnum; +use WPGraphQL\GF\Type\Enum; use WPGraphQL\GF\Type\Enum\AmPmEnum; trait ExpectedFormFields { - - public function add_icon_url_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'addIconUrl', ! empty( $field->addIconUrl ) ? $field->addIconUrl : static::IS_NULL ); + public function add_icon_url_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'addIconUrl', ! empty( $field->addIconUrl ) ? $field->addIconUrl : self::IS_NULL ); } - public function address_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'addressType', ! empty( $field->addressType ) ? GFHelpers::get_enum_for_value( Enum\AddressFieldTypeEnum::$type, $field->addressType ) : static::IS_NULL ); + public function address_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'addressType', ! empty( $field->addressType ) ? GFHelpers::get_enum_for_value( Enum\AddressFieldTypeEnum::$type, $field->addressType ) : self::IS_NULL ); - $properties[] = $this->expectedField( 'defaultCountry', ! empty( $field->defaultCountry ) ? GFHelpers::get_enum_for_value( Enum\AddressFieldCountryEnum::$type, $field->defaultCountry ) : static::IS_NULL ); - $properties[] = $this->expectedField( 'defaultProvince', ! empty( $field->defaultProvince ) ? GFHelpers::get_enum_for_value( Enum\AddressFieldProvinceEnum::$type, $field->defaultProvince ) : static::IS_NULL ); - $properties[] = $this->expectedField( 'defaultState', ! empty( $field->defaultState ) ? GFHelpers::get_enum_for_value( Enum\AddressFielStateeEnum::$type, $field->defaultState ) : static::IS_NULL ); + $properties[] = $this->expectedField( 'defaultCountry', ! empty( $field->defaultCountry ) ? GFHelpers::get_enum_for_value( Enum\AddressFieldCountryEnum::$type, $field->defaultCountry ) : self::IS_NULL ); + $properties[] = $this->expectedField( 'defaultProvince', ! empty( $field->defaultProvince ) ? GFHelpers::get_enum_for_value( Enum\AddressFieldProvinceEnum::$type, $field->defaultProvince ) : self::IS_NULL ); + $properties[] = $this->expectedField( 'defaultState', ! empty( $field->defaultState ) ? GFHelpers::get_enum_for_value( Enum\AddressFielStateeEnum::$type, $field->defaultState ) : self::IS_NULL ); $input_keys = [ 'autocompleteAttribute' => 'autocompleteAttribute', @@ -42,86 +41,86 @@ public function address_setting( GF_Field $field, array &$properties ) : void { $properties[] = $this->expected_inputs( $input_keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function admin_label_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'adminLabel', ! empty( $field->adminLabel ) ? $field->adminLabel : static::IS_NULL ); + public function admin_label_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'adminLabel', ! empty( $field->adminLabel ) ? $field->adminLabel : self::IS_NULL ); } - public function autocomplete_setting( GF_Field $field, array &$properties ) : void { + public function autocomplete_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasAutocomplete', ! empty( $field->enableAutocomplete ) ); if ( ! in_array( $field->type, [ 'address', 'email', 'name' ], true ) ) { - $properties[] = $this->expectedField( 'autocompleteAttribute', ! empty( $field->autocompleteAttribute ) ? $field->autocompleteAttribute : static::IS_NULL ); + $properties[] = $this->expectedField( 'autocompleteAttribute', ! empty( $field->autocompleteAttribute ) ? $field->autocompleteAttribute : self::IS_NULL ); } } - public function background_color_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'backgroundColor', ! empty( $field->backgroundColor ) ? $field->backgroundColor : static::IS_NULL ); + public function background_color_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'backgroundColor', ! empty( $field->backgroundColor ) ? $field->backgroundColor : self::IS_NULL ); } - public function base_price_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'price', ! empty( $field->basePrice ) ? floatval( preg_replace( '/[^\d\.]/', '', $field->basePrice ) ) : static::IS_NULL ); - $properties[] = $this->expectedField( 'formattedPrice', ! empty( $field->basePrice ) ? $field->basePrice : static::IS_NULL ); + public function base_price_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'price', ! empty( $field->basePrice ) ? floatval( preg_replace( '/[^\d\.]/', '', $field->basePrice ) ) : self::IS_NULL ); + $properties[] = $this->expectedField( 'formattedPrice', ! empty( $field->basePrice ) ? $field->basePrice : self::IS_NULL ); } - public function border_color_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'borderColor', ! empty( $field->borderColor ) ? $field->borderColor : static::IS_NULL ); + public function border_color_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'borderColor', ! empty( $field->borderColor ) ? $field->borderColor : self::IS_NULL ); } - public function border_style_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'borderStyle', ! empty( $field->borderStyle ) ? GFHelpers::get_enum_for_value( SignatureFieldBorderStyleEnum::$type, $field->borderStyle ) : static::IS_NULL ); + public function border_style_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'borderStyle', ! empty( $field->borderStyle ) ? GFHelpers::get_enum_for_value( SignatureFieldBorderStyleEnum::$type, $field->borderStyle ) : self::IS_NULL ); } - public function border_width_setting( GF_Field $field, array &$properties ) : void { + public function border_width_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'borderWidth', GFHelpers::get_enum_for_value( SignatureFieldBorderWidthEnum::$type, $field->borderWidth ?? 0 ) ); } - public function box_width_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'boxWidth', isset( $field->boxWidth ) ? (int) $field->boxWidth : static::IS_NULL ); + public function box_width_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'boxWidth', isset( $field->boxWidth ) ? (int) $field->boxWidth : self::IS_NULL ); } - public function calculation_setting( GF_Field $field, array &$properties ) : void { + public function calculation_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'isCalculation', ! empty( $field->enableCalculation ) ); - $properties[] = $this->expectedField( 'calculationFormula', ! empty( $field->calculationFormula ) ? $field->calculationFormula : static::IS_NULL ); - $properties[] = $this->expectedField( 'calculationRounding', isset( $field->calculationRounding ) ? (int) $field->calculationRounding : static::IS_NULL ); + $properties[] = $this->expectedField( 'calculationFormula', ! empty( $field->calculationFormula ) ? $field->calculationFormula : self::IS_NULL ); + $properties[] = $this->expectedField( 'calculationRounding', isset( $field->calculationRounding ) ? (int) $field->calculationRounding : self::IS_NULL ); } - public function captcha_badge_setting( GF_Field $field, array &$properties ) : void { + public function captcha_badge_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'captchaBadgePosition', GFHelpers::get_enum_for_value( Enum\CaptchaFieldBadgePositionEnum::$type, $field->captchaBadge ?? 'bottomright' ) ); } - public function captcha_bg_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'simpleCaptchaBackgroundColor', ! empty( $field->simpleCaptchaBackgroundColor ) ? $field->simpleCaptchaBackgroundColor : static::IS_NULL ); + public function captcha_bg_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'simpleCaptchaBackgroundColor', ! empty( $field->simpleCaptchaBackgroundColor ) ? $field->simpleCaptchaBackgroundColor : self::IS_NULL ); } - public function captcha_fg_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'simpleCaptchaFontColor', ! empty( $field->simpleCaptchaFontColor ) ? $field->simpleCaptchaFontColor : static::IS_NULL ); + public function captcha_fg_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'simpleCaptchaFontColor', ! empty( $field->simpleCaptchaFontColor ) ? $field->simpleCaptchaFontColor : self::IS_NULL ); } - public function captcha_language_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'captchaLanguage', ! empty( $field->captchaLanguage ) ? $field->captchaLanguage : static::IS_NULL ); + public function captcha_language_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'captchaLanguage', ! empty( $field->captchaLanguage ) ? $field->captchaLanguage : self::IS_NULL ); } - public function captcha_size_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'simpleCaptchaSize', ! empty( $field->simpleCaptchaSize ) ? GFHelpers::get_enum_for_value( Enum\FormFieldSizeEnum::$type, $field->simpleCaptchaSize ) : static::IS_NULL ); + public function captcha_size_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'simpleCaptchaSize', ! empty( $field->simpleCaptchaSize ) ? GFHelpers::get_enum_for_value( Enum\FormFieldSizeEnum::$type, $field->simpleCaptchaSize ) : self::IS_NULL ); } - public function captcha_theme_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'captchaTheme', ! empty( $field->captchaTheme ) ? GFHelpers::get_enum_for_value( Enum\CaptchaFieldThemeEnum::$type, $field->captchaTheme ) : static::IS_NULL ); + public function captcha_theme_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'captchaTheme', ! empty( $field->captchaTheme ) ? GFHelpers::get_enum_for_value( Enum\CaptchaFieldThemeEnum::$type, $field->captchaTheme ) : self::IS_NULL ); } - public function captcha_type_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'captchaType', ! empty( $field->captchaType ) ? GFHelpers::get_enum_for_value( Enum\CaptchaFieldTypeEnum::$type, $field->captchaType ) : static::IS_NULL ); + public function captcha_type_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'captchaType', ! empty( $field->captchaType ) ? GFHelpers::get_enum_for_value( Enum\CaptchaFieldTypeEnum::$type, $field->captchaType ) : self::IS_NULL ); } - public function chained_selects_alignment_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'chainedSelectsAlignment', ! empty( $field->chainedSelectsAlignment ) ? GFHelpers::get_enum_for_value( ChainedSelectFieldAlignmentEnum::$type, $field->chainedSelectsAlignment ) : static::IS_NULL ); + public function chained_selects_alignment_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'chainedSelectsAlignment', ! empty( $field->chainedSelectsAlignment ) ? GFHelpers::get_enum_for_value( ChainedSelectFieldAlignmentEnum::$type, $field->chainedSelectsAlignment ) : self::IS_NULL ); } - public function chained_selects_hide_inactive_setting( GF_Field $field, array &$properties ) : void { + public function chained_selects_hide_inactive_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'shouldHideInactiveChoices', ! empty( $field->chainedSelectsHideInactive ) ); } - public function choices_setting( GF_Field $field, array &$properties ) : void { + public function choices_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasChoiceValue', ! empty( $field->enableChoiceValue ) ); $keys = [ @@ -138,7 +137,7 @@ public function choices_setting( GF_Field $field, array &$properties ) : void { $properties[] = $this->expected_choices( $keys, ! empty( $field->choices ) ? $field->choices : [] ); } - public function chained_choices_setting( GF_Field $field, array &$properties ) : void { + public function chained_choices_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasChoiceValue', ! empty( $field->enableChoiceValue ) ); $choice_keys = [ @@ -157,7 +156,7 @@ public function chained_choices_setting( GF_Field $field, array &$properties ) : $properties[] = $this->expected_inputs( $input_keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function columns_setting( GF_Field $field, array &$properties ) : void { + public function columns_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasColumns', ! empty( $field->enableColumns ) ); $choice_keys = [ @@ -167,26 +166,26 @@ public function columns_setting( GF_Field $field, array &$properties ) : void { $properties[] = $this->expected_choices( $choice_keys, ! empty( $field->choices ) ? $field->choices : [] ); } - public function conditional_logic_field_setting( GF_Field $field, array &$properties ) : void { + public function conditional_logic_field_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->get_expected_conditional_logic_fields( $field->conditionalLogic ); } - public function conditional_logic_page_setting( GF_Field $field, array &$properties ) : void { + public function conditional_logic_page_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->get_expected_conditional_logic_fields( $field->conditionalLogic ); } - public function content_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'content', ! empty( $field->content ) ? $field->content : static::IS_NULL ); + public function content_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'content', ! empty( $field->content ) ? $field->content : self::IS_NULL ); } - public function copy_values_option( GF_Field $field, array &$properties ) : void { + public function copy_values_option( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'shouldCopyValuesOption', ! empty( $field->enableCopyValuesOption ) ); - $properties[] = $this->expectedField( 'copyValuesOptionFieldId', isset( $field->copyValuesOptionField ) ? (int) $field->copyValuesOptionField : static::IS_NULL ); - $properties[] = $this->expectedField( 'copyValuesOptionLabel', ! empty( $field->copyValuesOptionLabel ) ? $field->copyValuesOptionLabel : static::IS_NULL ); + $properties[] = $this->expectedField( 'copyValuesOptionFieldId', isset( $field->copyValuesOptionField ) ? (int) $field->copyValuesOptionField : self::IS_NULL ); + $properties[] = $this->expectedField( 'copyValuesOptionLabel', ! empty( $field->copyValuesOptionLabel ) ? $field->copyValuesOptionLabel : self::IS_NULL ); } - public function credit_card_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'supportedCreditCards', ! empty( $field->creditCards ) ? $field->creditCards : static::IS_NULL ); + public function credit_card_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'supportedCreditCards', ! empty( $field->creditCards ) ? $field->creditCards : self::IS_NULL ); $keys = [ 'customLabel' => 'customLabel', @@ -198,12 +197,12 @@ public function credit_card_setting( GF_Field $field, array &$properties ) : voi $properties[] = $this->expected_inputs( $keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function css_class_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'cssClass', ! empty( $field->cssClass ) ? $field->cssClass : static::IS_NULL ); + public function css_class_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'cssClass', ! empty( $field->cssClass ) ? $field->cssClass : self::IS_NULL ); } - public function date_format_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'dateFormat', ! empty( $field->dateFormat ) ? GFHelpers::get_enum_for_value( Enum\DateFieldFormatEnum::$type, $field->dateFormat ) : static::IS_NULL ); + public function date_format_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'dateFormat', ! empty( $field->dateFormat ) ? GFHelpers::get_enum_for_value( Enum\DateFieldFormatEnum::$type, $field->dateFormat ) : self::IS_NULL ); $keys = [ 'autocompleteAttribute' => 'autocompleteAttribute', @@ -217,40 +216,40 @@ public function date_format_setting( GF_Field $field, array &$properties ) : voi $properties[] = $this->expected_inputs( $keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function date_input_type_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'dateType', ! empty( $field->dateType ) ? GFHelpers::get_enum_for_value( Enum\DateFieldTypeEnum::$type, $field->dateType ) : static::IS_NULL ); - $properties[] = $this->expectedField( 'calendarIconType', ! empty( $field->calendarIconType ) ? GFHelpers::get_enum_for_value( Enum\FormFieldCalendarIconTypeEnum::$type, $field->calendarIconType ) : static::IS_NULL ); - $properties[] = $this->expectedField( 'calendarIconUrl', ! empty( $field->calendarIconUrl ) ? $field->calendarIconUrl : static::IS_NULL ); + public function date_input_type_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'dateType', ! empty( $field->dateType ) ? GFHelpers::get_enum_for_value( Enum\DateFieldTypeEnum::$type, $field->dateType ) : self::IS_NULL ); + $properties[] = $this->expectedField( 'calendarIconType', ! empty( $field->calendarIconType ) ? GFHelpers::get_enum_for_value( Enum\FormFieldCalendarIconTypeEnum::$type, $field->calendarIconType ) : self::IS_NULL ); + $properties[] = $this->expectedField( 'calendarIconUrl', ! empty( $field->calendarIconUrl ) ? $field->calendarIconUrl : self::IS_NULL ); } - public function default_value_setting( GF_Field $field, array &$properties ) : void { + public function default_value_setting( GF_Field $field, array &$properties ): void { if ( 'email' !== $field->type ) { - $properties[] = $this->expectedField( 'defaultValue', ! empty( $field->defaultValue ) ? $field->defaultValue : static::IS_NULL ); + $properties[] = $this->expectedField( 'defaultValue', ! empty( $field->defaultValue ) ? $field->defaultValue : self::IS_NULL ); } } - public function default_value_textarea_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'defaultValue', ! empty( $field->defaultValue ) ? $field->defaultValue : static::IS_NULL ); + public function default_value_textarea_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'defaultValue', ! empty( $field->defaultValue ) ? $field->defaultValue : self::IS_NULL ); } - public function delete_icon_url_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'deleteIconUrl', ! empty( $field->deleteIconUrl ) ? $field->deleteIconUrl : static::IS_NULL ); + public function delete_icon_url_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'deleteIconUrl', ! empty( $field->deleteIconUrl ) ? $field->deleteIconUrl : self::IS_NULL ); } - public function description_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'description', ! empty( $field->description ) ? $field->description : static::IS_NULL ); - $properties[] = $this->expectedField( 'descriptionPlacement', ! empty( $field->descriptionPlacement ) ? GFHelpers::get_enum_for_value( Enum\FormFieldDescriptionPlacementEnum::$type, $field->descriptionPlacement ) : static::IS_NULL ); + public function description_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'description', ! empty( $field->description ) ? $field->description : self::IS_NULL ); + $properties[] = $this->expectedField( 'descriptionPlacement', ! empty( $field->descriptionPlacement ) ? GFHelpers::get_enum_for_value( Enum\FormFieldDescriptionPlacementEnum::$type, $field->descriptionPlacement ) : self::IS_NULL ); } - public function disable_margins_setting( GF_Field $field, array &$properties ) : void { + public function disable_margins_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasMargins', empty( $field->disableMargins ) ); } - public function duplicate_setting( GF_Field $field, array &$properties ) : void { + public function duplicate_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'shouldAllowDuplicates', empty( $field->noDuplicates ) ); } - public function email_confirm_setting( GF_Field $field, array &$properties ) : void { + public function email_confirm_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasEmailConfirmation', ! empty( $field->emailConfirmEnabled ) ); $keys = [ @@ -266,28 +265,27 @@ public function email_confirm_setting( GF_Field $field, array &$properties ) : v $properties[] = $this->expected_inputs( $keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - - public function enable_enhanced_ui_setting( GF_Field $field, array &$properties ) : void { + public function enable_enhanced_ui_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasEnhancedUI', ! empty( $field->enableEnhancedUI ) ); } - public function error_message_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'errorMessage', ! empty( $field->errorMessage ) ? $field->errorMessage : static::IS_NULL ); + public function error_message_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'errorMessage', ! empty( $field->errorMessage ) ? $field->errorMessage : self::IS_NULL ); } - public function file_extensions_setting( GF_Field $field, array &$properties ) : void { + public function file_extensions_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'allowedExtensions', explode( ',', $field->allowedExtensions ) ); } - public function file_size_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'maxFileSize', ! empty( $field->maxFileSize ) ? $field->maxFileSize : static::IS_NULL ); + public function file_size_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'maxFileSize', ! empty( $field->maxFileSize ) ? $field->maxFileSize : self::IS_NULL ); } - public function force_ssl_field_setting( GF_Field $field, array &$properties ) : void { + public function force_ssl_field_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'isSSLForced', ! empty( $field->forceSSL ) ); } - public function gquiz_setting_choices( GF_Field $field, array &$properties ) : void { + public function gquiz_setting_choices( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasWeightedScore', ! empty( $field->gquizWeightedScoreEnabled ) ); $keys = [ @@ -299,46 +297,46 @@ public function gquiz_setting_choices( GF_Field $field, array &$properties ) : v $properties[] = $this->expected_choices( $keys, ! empty( $field->choices ) ? $field->choices : [] ); } - public function gquiz_setting_show_answer_explanation( GF_Field $field, array &$properties ) : void { + public function gquiz_setting_show_answer_explanation( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'shouldShowAnswerExplanation', ! empty( $field->gquizShowAnswerExplanation ) ); - $properties[] = $this->expectedField( 'answerExplanation', ! empty( $field->gquizAnswerExplanation ) ? $field->gquizAnswerExplanation : static::IS_NULL ); + $properties[] = $this->expectedField( 'answerExplanation', ! empty( $field->gquizAnswerExplanation ) ? $field->gquizAnswerExplanation : self::IS_NULL ); } - public function gquiz_setting_randomize_quiz_choices( GF_Field $field, array &$properties ) : void { + public function gquiz_setting_randomize_quiz_choices( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'shouldRandomizeQuizChoices', ! empty( $field->gquizEnableRandomizeQuizChoices ) ); } - public function gquiz_setting_question( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'label', ! empty( $field->label ) ? $field->label : static::IS_NULL ); + public function gquiz_setting_question( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'label', ! empty( $field->label ) ? $field->label : self::IS_NULL ); } - public function input_mask_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'inputMaskValue', ! empty( $field->inputMaskValue ) ? $field->inputMaskValue : static::IS_NULL ); + public function input_mask_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'inputMaskValue', ! empty( $field->inputMaskValue ) ? $field->inputMaskValue : self::IS_NULL ); $properties[] = $this->expectedField( 'hasInputMask', ! empty( $field->inputMask ) ); } - public function label_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'label', ! empty( $field->label ) ? $field->label : static::IS_NULL ); + public function label_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'label', ! empty( $field->label ) ? $field->label : self::IS_NULL ); } - public function label_placement_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'labelPlacement', ! empty( $field->labelPlacement ) ? GFHelpers::get_enum_for_value( Enum\FormFieldLabelPlacementEnum::$type, $field->labelPlacement ) : static::IS_NULL ); + public function label_placement_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'labelPlacement', ! empty( $field->labelPlacement ) ? GFHelpers::get_enum_for_value( Enum\FormFieldLabelPlacementEnum::$type, $field->labelPlacement ) : self::IS_NULL ); } - public function maxlen_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'maxLength', isset( $field->maxLength ) ? (int) $field->maxLength : static::IS_NULL ); + public function maxlen_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'maxLength', isset( $field->maxLength ) ? (int) $field->maxLength : self::IS_NULL ); } - public function maxrows_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'maxRows', isset( $field->maxRows ) ? (int) $field->maxRows : static::IS_NULL ); + public function maxrows_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'maxRows', isset( $field->maxRows ) ? (int) $field->maxRows : self::IS_NULL ); } - public function multiple_files_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'maxFiles', isset( $field->maxFiles ) ? (int) $field->maxFiles : static::IS_NULL ); + public function multiple_files_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'maxFiles', isset( $field->maxFiles ) ? (int) $field->maxFiles : self::IS_NULL ); $properties[] = $this->expectedField( 'canAcceptMultipleFiles', ! empty( $field->multipleFiles ) ); } - public function name_setting( GF_Field $field, array &$properties ) : void { + public function name_setting( GF_Field $field, array &$properties ): void { $input_keys = [ 'autocompleteAttribute' => 'autocompleteAttribute', 'defaultValue' => 'defaultValue', @@ -362,23 +360,23 @@ public function name_setting( GF_Field $field, array &$properties ) : void { $properties[] = $this->expected_choices( $choice_keys, ! empty( $field->choices ) ? $field->choices : [] ); } - public function next_button_setting( GF_Field $field, array &$properties ) : void { + public function next_button_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedObject( 'nextButton', [ - $this->expectedField( 'type', ! empty( $field->nextButton['type'] ) ? GFHelpers::get_enum_for_value( Enum\FormButtonTypeEnum::$type, $field->nextButton['type'] ) : static::IS_NULL ), - $this->expectedField( 'text', ! empty( $field->nextButton['text'] ) ? $field->nextButton['text'] : static::IS_NULL ), - $this->expectedField( 'imageUrl', ! empty( $field->nextButton['imageUrl'] ) ? $field->nextButton['imageUrl'] : static::IS_NULL ), + $this->expectedField( 'type', ! empty( $field->nextButton['type'] ) ? GFHelpers::get_enum_for_value( Enum\FormButtonTypeEnum::$type, $field->nextButton['type'] ) : self::IS_NULL ), + $this->expectedField( 'text', ! empty( $field->nextButton['text'] ) ? $field->nextButton['text'] : self::IS_NULL ), + $this->expectedField( 'imageUrl', ! empty( $field->nextButton['imageUrl'] ) ? $field->nextButton['imageUrl'] : self::IS_NULL ), $this->get_expected_conditional_logic_fields( ! empty( $field->nextButton['conditionalLogic'] ) ? $field->nextButton['conditionalLogic'] : [] ), ] ); } - public function number_format_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'numberFormat', ! empty( $field->numberFormat ) ? GFHelpers::get_enum_for_value( Enum\NumberFieldFormatEnum::$type, $field->numberFormat ) : static::IS_NULL ); + public function number_format_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'numberFormat', ! empty( $field->numberFormat ) ? GFHelpers::get_enum_for_value( Enum\NumberFieldFormatEnum::$type, $field->numberFormat ) : self::IS_NULL ); } - public function other_choice_setting( GF_Field $field, array &$properties ) : void { + public function other_choice_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasOtherChoice', ! empty( $field->enableOtherChoice ) ); if ( 'quiz' === $field->type ) { @@ -386,11 +384,11 @@ public function other_choice_setting( GF_Field $field, array &$properties ) : vo } } - public function password_field_setting( GF_Field $field, array &$properties ) : void { + public function password_field_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'isPasswordInput', ! empty( $field->enablePasswordInput ) ); } - public function password_setting( GF_Field $field, array &$properties ) : void { + public function password_setting( GF_Field $field, array &$properties ): void { $keys = [ 'customLabel' => 'customLabel', 'id' => 'id', @@ -402,52 +400,52 @@ public function password_setting( GF_Field $field, array &$properties ) : void { $properties[] = $this->expected_inputs( $keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function password_strength_setting( GF_Field $field, array &$properties ) : void { + public function password_strength_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasPasswordStrengthIndicator', ! empty( $field->passwordStrengthEnabled ) ); - $properties[] = $this->expectedField( 'minPasswordStrength', ! empty( $field->minPasswordStrength ) ? GFHelpers::get_enum_for_value( Enum\PasswordFieldMinStrengthEnum::$type, $field->minPasswordStrength ) : static::IS_NULL ); + $properties[] = $this->expectedField( 'minPasswordStrength', ! empty( $field->minPasswordStrength ) ? GFHelpers::get_enum_for_value( Enum\PasswordFieldMinStrengthEnum::$type, $field->minPasswordStrength ) : self::IS_NULL ); } - public function password_visibility_setting( GF_Field $field, array &$properties ) : void { + public function password_visibility_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasPasswordVisibilityToggle', ! empty( $field->passwordVisibilityEnabled ) ); } - public function pen_color_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'penColor', ! empty( $field->penColor ) ? $field->penColor : static::IS_NULL ); + public function pen_color_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'penColor', ! empty( $field->penColor ) ? $field->penColor : self::IS_NULL ); } - public function pen_size_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'penSize', ! empty( $field->penSize ) ? $field->penSize : static::IS_NULL ); + public function pen_size_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'penSize', ! empty( $field->penSize ) ? $field->penSize : self::IS_NULL ); } - public function phone_format_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'phoneFormat', ! empty( $field->phoneFormat ) ? GFHelpers::get_enum_for_value( Enum\PhoneFieldFormatEnum::$type, $field->phoneFormat ) : static::IS_NULL ); + public function phone_format_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'phoneFormat', ! empty( $field->phoneFormat ) ? GFHelpers::get_enum_for_value( Enum\PhoneFieldFormatEnum::$type, $field->phoneFormat ) : self::IS_NULL ); } - public function placeholder_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'placeholder', ! empty( $field->placeholder ) ? $field->placeholder : static::IS_NULL ); + public function placeholder_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'placeholder', ! empty( $field->placeholder ) ? $field->placeholder : self::IS_NULL ); } - public function placeholder_textarea_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'placeholder', ! empty( $field->placeholder ) ? $field->placeholder : static::IS_NULL ); + public function placeholder_textarea_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'placeholder', ! empty( $field->placeholder ) ? $field->placeholder : self::IS_NULL ); } - public function post_category_checkbox_setting( GF_Field $field, array &$properties ) : void { + public function post_category_checkbox_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasAllCategories', ! empty( $field->displayAllCategories ) ); } - public function post_category_initial_item_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'dropdownPlaceholder', ! empty( $field->categoryInitialItem ) ? $field->categoryInitialItem : static::IS_NULL ); + public function post_category_initial_item_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'dropdownPlaceholder', ! empty( $field->categoryInitialItem ) ? $field->categoryInitialItem : self::IS_NULL ); } - public function post_custom_field_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'postCustomFieldName', ! empty( $field->postCustomFieldName ) ? $field->postCustomFieldName : static::IS_NULL ); + public function post_custom_field_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'postCustomFieldName', ! empty( $field->postCustomFieldName ) ? $field->postCustomFieldName : self::IS_NULL ); } - public function post_image_featured_image( GF_Field $field, array &$properties ) : void { + public function post_image_featured_image( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'isFeaturedImage', ! empty( $field->postFeaturedImage ) ); } - public function post_image_setting( GF_Field $field, array &$properties ) : void { + public function post_image_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'allowedExtensions', explode( ',', $field->allowedExtensions ) ); $properties[] = $this->expectedField( 'hasAlt', ! empty( $field->displayAlt ) ); $properties[] = $this->expectedField( 'hasCaption', ! empty( $field->displayCaption ) ); @@ -455,49 +453,48 @@ public function post_image_setting( GF_Field $field, array &$properties ) : void $properties[] = $this->expectedField( 'hasTitle', ! empty( $field->displayTitle ) ); } - public function prepopulate_field_setting( GF_Field $field, array &$properties ) : void { + public function prepopulate_field_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'canPrepopulate', ! empty( $field->allowsPrepopulate ) ); if ( ( empty( $field->inputs ) && ! in_array( $field->type, [ 'date', 'email', 'time', 'password' ], true ) ) || 'checkbox' === $field->type ) { - $properties[] = $this->expectedField( 'inputName', ! empty( $field->inputName ) ? $field->inputName : static::IS_NULL ); + $properties[] = $this->expectedField( 'inputName', ! empty( $field->inputName ) ? $field->inputName : self::IS_NULL ); } } - - public function previous_button_setting( GF_Field $field, array &$properties ) : void { + public function previous_button_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedObject( 'previousButton', [ - $this->expectedField( 'type', ! empty( $field->previousButton['type'] ) ? GFHelpers::get_enum_for_value( Enum\FormButtonTypeEnum::$type, $field->previousButton['type'] ) : static::IS_NULL ), - $this->expectedField( 'text', ! empty( $field->previousButton['text'] ) ? $field->previousButton['text'] : static::IS_NULL ), - $this->expectedField( 'imageUrl', ! empty( $field->previousButton['imageUrl'] ) ? $field->previousButton['imageUrl'] : static::IS_NULL ), + $this->expectedField( 'type', ! empty( $field->previousButton['type'] ) ? GFHelpers::get_enum_for_value( Enum\FormButtonTypeEnum::$type, $field->previousButton['type'] ) : self::IS_NULL ), + $this->expectedField( 'text', ! empty( $field->previousButton['text'] ) ? $field->previousButton['text'] : self::IS_NULL ), + $this->expectedField( 'imageUrl', ! empty( $field->previousButton['imageUrl'] ) ? $field->previousButton['imageUrl'] : self::IS_NULL ), $this->get_expected_conditional_logic_fields( ! empty( $field->previousButton['conditionalLogic'] ) ? $field->previousButton['conditionalLogic'] : [] ), ] ); } - public function product_field_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'productField', isset( $field->productField ) ? (int) $field->productField : static::IS_NULL ); + public function product_field_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'productField', isset( $field->productField ) ? (int) $field->productField : self::IS_NULL ); } - public function range_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'rangeMax', isset( $field->rangeMax ) ? (float) $field->rangeMax : static::IS_NULL ); - $properties[] = $this->expectedField( 'rangeMin', isset( $field->rangeMin ) ? (float) $field->rangeMin : static::IS_NULL ); + public function range_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'rangeMax', isset( $field->rangeMax ) ? (float) $field->rangeMax : self::IS_NULL ); + $properties[] = $this->expectedField( 'rangeMin', isset( $field->rangeMin ) ? (float) $field->rangeMin : self::IS_NULL ); } - public function rich_text_editor_setting( GF_Field $field, array &$properties ) : void { + public function rich_text_editor_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasRichTextEditor', ! empty( $field->useRichTextEditor ) ); } - public function rules_setting( GF_Field $field, array &$properties ) : void { + public function rules_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'isRequired', ! empty( $field->isRequired ) ); } - public function size_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'size', ! empty( $field->size ) ? GFHelpers::get_enum_for_value( Enum\FormFieldSizeEnum::$type, $field->size ) : static::IS_NULL ); + public function size_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'size', ! empty( $field->size ) ? GFHelpers::get_enum_for_value( Enum\FormFieldSizeEnum::$type, $field->size ) : self::IS_NULL ); } - public function select_all_choices_setting( GF_Field $field, array &$properties ) : void { + public function select_all_choices_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'hasSelectAll', ! empty( $field->enableSelectAll ) ); $keys = [ @@ -509,12 +506,12 @@ public function select_all_choices_setting( GF_Field $field, array &$properties $properties[] = $this->expected_inputs( $keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function sub_label_placement_setting( GF_Field $field, array &$properties ) : void { + public function sub_label_placement_setting( GF_Field $field, array &$properties ): void { $properties[] = $this->expectedField( 'subLabelPlacement', GFHelpers::get_enum_for_value( Enum\FormFieldSubLabelPlacementEnum::$type, ! empty( $field->subLabelPlacement ) ? $field->subLabelPlacement : 'inherit' ) ); } - public function time_format_setting( GF_Field $field, array &$properties ) : void { - $properties[] = $this->expectedField( 'timeFormat', ! empty( $field->timeFormat ) ? GFHelpers::get_enum_for_value( Enum\TimeFieldFormatEnum::$type, $field->timeFormat ) : static::IS_NULL ); + public function time_format_setting( GF_Field $field, array &$properties ): void { + $properties[] = $this->expectedField( 'timeFormat', ! empty( $field->timeFormat ) ? GFHelpers::get_enum_for_value( Enum\TimeFieldFormatEnum::$type, $field->timeFormat ) : self::IS_NULL ); $keys = [ 'autocompleteAtribute' => 'autocompleteAtribute', @@ -528,10 +525,10 @@ public function time_format_setting( GF_Field $field, array &$properties ) : voi $properties[] = $this->expected_inputs( $keys, ! empty( $field->inputs ) ? $field->inputs : [] ); } - public function expected_choices( array $keys, array $choices ) : ?array { + public function expected_choices( array $keys, array $choices ): ?array { $expected_nodes = []; if ( empty( $choices ) ) { - return $this->expectedField( 'choices', static::IS_NULL ); + return $this->expectedField( 'choices', self::IS_NULL ); } foreach ( $choices as $index => $choice ) { @@ -540,7 +537,7 @@ public function expected_choices( array $keys, array $choices ) : ?array { foreach ( $keys as $name => $key ) { switch ( $name ) { case 'price': - $expected_fields[] = $this->expectedField( $name, ! empty( $choice['price'] ) ? floatval( preg_replace( '/[^\d\.]/', '', $choice['price'] ) ) : static::IS_NULL ); + $expected_fields[] = $this->expectedField( $name, ! empty( $choice['price'] ) ? floatval( preg_replace( '/[^\d\.]/', '', $choice['price'] ) ) : self::IS_NULL ); break; case 'choices': $expected_fields[] = $this->expected_choices( $keys, $choice['choices'] ?? [] ); @@ -549,7 +546,7 @@ public function expected_choices( array $keys, array $choices ) : ?array { $expected_fields[] = $this->expectedField( $name, (string) $choice[ $key ] ); break; default: - $expected_fields[] = $this->expectedField( $name, $choice[ $key ] ?? static::IS_NULL ); + $expected_fields[] = $this->expectedField( $name, $choice[ $key ] ?? self::IS_NULL ); break; } } @@ -566,24 +563,24 @@ public function expected_choices( array $keys, array $choices ) : ?array { ); } - public function expected_inputs( array $keys, array $inputs ) : array { + public function expected_inputs( array $keys, array $inputs ): array { $expected_nodes = []; foreach ( $inputs as $index => $input ) { $expected_fields = []; foreach ( $keys as $name => $key ) { switch ( $name ) { case 'id': - $expected_fields[] = $this->expectedField( $name, isset( $input[ $key ] ) ? (float) $input[ $key ] : static::IS_NULL ); + $expected_fields[] = $this->expectedField( $name, isset( $input[ $key ] ) ? (float) $input[ $key ] : self::IS_NULL ); break; case 'defaultValue': - $expected_fields[] = $this->expectedField( $name, isset( $input[ $key ] ) ? (string) $input[ $key ] : static::IS_NULL ); + $expected_fields[] = $this->expectedField( $name, isset( $input[ $key ] ) ? (string) $input[ $key ] : self::IS_NULL ); break; case 'hasChoiceValue': case 'isHidden': $expected_fields[] = $this->expectedField( $name, ! empty( $input[ $key ] ) ); break; default: - $expected_fields[] = $this->expectedField( $name, isset( $input[ $key ] ) ? $input[ $key ] : static::IS_NULL ); + $expected_fields[] = $this->expectedField( $name, isset( $input[ $key ] ) ? $input[ $key ] : self::IS_NULL ); } } @@ -601,7 +598,7 @@ public function expected_inputs( array $keys, array $inputs ) : array { public function expected_field_value( string $key, $values ) { if ( null === $values ) { - return $this->expectedField( $key, static::IS_NULL ); + return $this->expectedField( $key, self::IS_NULL ); } if ( is_array( $values ) ) { @@ -609,27 +606,27 @@ public function expected_field_value( string $key, $values ) { foreach ( $values as $name => $value ) { switch ( $value ) { case 'codecept_field_value_is_null': - $value = static::IS_NULL; + $value = self::IS_NULL; break; case 'codecept_field_value_not_null': - $value = static::NOT_NULL; + $value = self::NOT_NULL; break; case 'codecept_field_value_not_falsy': - $value = static::NOT_FALSY; + $value = self::NOT_FALSY; break; case 'codecept_field_value_is_falsy': - $value = static::IS_FALSY; + $value = self::IS_FALSY; break; } switch ( (string) $name ) { case 'amPm': - $expected[] = $this->expectedField( $name, isset( $value ) ? GFHelpers::get_enum_for_value( AmPmEnum::$type, $value ) : static::IS_NULL ); + $expected[] = $this->expectedField( $name, isset( $value ) ? GFHelpers::get_enum_for_value( AmPmEnum::$type, $value ) : self::IS_NULL ); break; case 'url': - $expected[] = $this->expectedField( $name, ! empty( $value ) ? static::NOT_FALSY : static::IS_NULL ); + $expected[] = $this->expectedField( $name, ! empty( $value ) ? self::NOT_FALSY : self::IS_NULL ); break; case 'basePath': - $expected[] = $this->expectedField( $name, $this->is_draft ? static::IS_NULL : static::NOT_FALSY ); + $expected[] = $this->expectedField( $name, $this->is_draft ? self::IS_NULL : self::NOT_FALSY ); break; default: $expected[] = $this->expectedField( $name, $value ); diff --git a/tests/_support/Helper/GFHelpers/GFHelpers.php b/tests/_support/Helper/GFHelpers/GFHelpers.php index 3e0bc827..a4ce1a14 100644 --- a/tests/_support/Helper/GFHelpers/GFHelpers.php +++ b/tests/_support/Helper/GFHelpers/GFHelpers.php @@ -16,7 +16,7 @@ abstract class GFHelpers { /** * Provides access to dummy functions. * - * @var Dummy + * @var \Dummy */ public $dummy; @@ -26,6 +26,7 @@ abstract class GFHelpers { * @var array */ public $keys; + /** * The generated list of values. * @@ -33,7 +34,6 @@ abstract class GFHelpers { */ public $values; - /** * Constructor * @@ -49,8 +49,6 @@ public function __construct( array $keys ) { /** * Flattens key => value pairs to grab all the keys. - * - * @param array $keys */ public function get_keys( array $keys ) { $return_values = []; @@ -68,7 +66,6 @@ public function get_keys( array $keys ) { /** * Gets the key => value pair for the given key name. * - * @param string $key * @param [type] $value */ public function get( string $key, $value = null ) { @@ -77,8 +74,6 @@ public function get( string $key, $value = null ) { /** * Gets all key => value pairs for the defined keys. - * - * @param array $keys */ public function getAll( array $keys ) { $return_values = []; diff --git a/tests/_support/Helper/GFHelpers/PropertyHelper.php b/tests/_support/Helper/GFHelpers/PropertyHelper.php index bf06939f..c899c07e 100644 --- a/tests/_support/Helper/GFHelpers/PropertyHelper.php +++ b/tests/_support/Helper/GFHelpers/PropertyHelper.php @@ -3,7 +3,6 @@ namespace Helper\GFHelpers; class PropertyHelper extends GFHelpers { - public function addIconUrl( $value = null ) { return ! empty( $value ) ? $value : 'someurl.test'; } @@ -92,7 +91,7 @@ public function chainedSelectsAlignment( $value = null ) { return ! empty( $value ) ? $value : null; } - public function chainedSelectsHideInactive( $value = null ) : bool { + public function chainedSelectsHideInactive( $value = null ): bool { return ! empty( $value ); } @@ -100,7 +99,7 @@ public function choices( $value = null ) { return ! empty( $value ) ? $value : null; } - public function copyValuesOptionDefault( $value = null ) : bool { + public function copyValuesOptionDefault( $value = null ): bool { return ! empty( $value ); } @@ -144,91 +143,91 @@ public function description( $value = null ) { return ! empty( $value ) ? $value : $this->dummy->text(); } - public function descriptionPlacement( $value = null ) : string { + public function descriptionPlacement( $value = null ): string { return null !== $value ? $value : 'above'; } - public function disableQuantity( $value = null ) : bool { + public function disableQuantity( $value = null ): bool { return null !== $value ? $value : false; } - public function disableMargins( $value = null ) : bool { + public function disableMargins( $value = null ): bool { return null !== $value ? $value : $this->dummy->yesno(); } - public function displayAlt( $value = null ) : bool { + public function displayAlt( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - - public function displayAllCategories( $value = null ) : bool { + public function displayAllCategories( $value = null ): bool { return ! empty( $value ); } - public function displayCaption( $value = null ) : bool { + public function displayCaption( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function displayDescription( $value = null ) : bool { + public function displayDescription( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function displayOnly( $value = null ) : bool { + public function displayOnly( $value = null ): bool { return ! empty( $value ); } - public function displayTitle( $value = null ) : bool { + public function displayTitle( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function emailConfirmEnabled( $value = null ) : bool { + public function emailConfirmEnabled( $value = null ): bool { return ! empty( $value ); } - public function enableAutocomplete( $value = null ) : bool { + public function enableAutocomplete( $value = null ): bool { return null !== $value ? ! empty( $value ) : (bool) $this->dummy->yesno(); } - public function enableCalculation( $value = null ) : bool { + public function enableCalculation( $value = null ): bool { return ! empty( $value ); } - public function enableChoiceValue( $value = null ) : bool { + public function enableChoiceValue( $value = null ): bool { return null !== $value ? ! empty( $value ) : (bool) $this->dummy->yesno(); } - public function enableCopyValuesOption( $value = null ) : bool { + public function enableCopyValuesOption( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function enableEnhancedUI( $value = null ) : bool { + public function enableEnhancedUI( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function enableOtherChoice( $value = null ) : bool { + public function enableOtherChoice( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function enablePasswordInput( $value = null ) : bool { + public function enablePasswordInput( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function enablePrice( $value = null ) : bool { + public function enablePrice( $value = null ): bool { return null !== $value ? ! empty( $value ) : true; } - public function gquizEnableRandomizeQuizChoices( bool $value = null ) : bool { + public function gquizEnableRandomizeQuizChoices( ?bool $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function enableSelectAll( $value = null ) : bool { + public function enableSelectAll( $value = null ): bool { return null !== $value ? ! empty( $value ) : $this->dummy->yesno(); } - public function enableColumns( $value = null ) : bool { + + public function enableColumns( $value = null ): bool { return null !== $value ? ! empty( $value ) : false; } - public function gquizWeightedScoreEnabled( bool $value = null ) : ?bool { + public function gquizWeightedScoreEnabled( ?bool $value = null ): ?bool { return null !== $value ? $value : $this->dummy->yesno(); } @@ -256,14 +255,14 @@ public function inputType( $value = null ) { return ! empty( $value ) ? $value : null; } - public function gquizAnswerExplanation( string $value = null ) : ?string { + public function gquizAnswerExplanation( ?string $value = null ): ?string { return ! empty( $value ) ? $value : $this->dummy->sentence( 1, 3 ); } - public function gquizIsCorrect( bool $value = null ) : ?bool { + public function gquizIsCorrect( ?bool $value = null ): ?bool { return null !== $value ? ! empty( $value ) : (bool) $this->dummy->yesno(); } - public function hasInputMask( bool $value = null ) : ?bool { + public function hasInputMask( ?bool $value = null ): ?bool { return null !== $value ? $value : $this->dummy->yesno(); } @@ -305,11 +304,12 @@ public function maxFileSize( $value = null ) { public function maxLength( $value = null ) { return ! empty( $value ) ? $value : ( rand( 100, 550 ) ?: null ); } + public function maxRows( $value = null ) { return ! empty( $value ) ? $value : ( rand( 3, 10 ) ?: null ); } - public function multipleFiles( $value = null ) : bool { + public function multipleFiles( $value = null ): bool { return ! empty( $value ); } @@ -325,7 +325,7 @@ public function nameFormat( $value = null ) { return ! empty( $value ) ? $value : 'advanced'; } - public function noDuplicates( bool $value = null ) : bool { + public function noDuplicates( ?bool $value = null ): bool { return null !== $value ? $value : false; } @@ -345,10 +345,10 @@ public function penSize( $value = null ) { return ! empty( $value ) ? $value : $this->dummy->number( 1, 3 ); } - public function personalDataErase( $value = null ) : bool { + public function personalDataErase( $value = null ): bool { return null !== $value ? ! empty( $value ) : (bool) $this->dummy->yesno(); } - public function personalDataExport( $value = null ) : bool { + public function personalDataExport( $value = null ): bool { return null !== $value ? ! empty( $value ) : (bool) $this->dummy->yesno(); } @@ -376,7 +376,7 @@ public function productField( $value = null ) { return ! empty( $value ) ? $value : ''; } - public function gquizFieldType( string $value = null ) : string { + public function gquizFieldType( ?string $value = null ): string { return ! empty( $value ) ? $value : 'CHECKBOX'; } @@ -388,7 +388,7 @@ public function rangeMax( $value = null ) { return ! empty( $value ) ? $value : null; } - public function gquizShowAnswerExplanation( bool $value = null ): ?bool { + public function gquizShowAnswerExplanation( ?bool $value = null ): ?bool { return null !== $value ? ! empty( $value ) : (bool) $this->dummy->yesno(); } @@ -404,7 +404,7 @@ public function simpleCaptchaSize( $value = null ) { return $this->size( $value ); } - public function size( $value = null ) : string { + public function size( $value = null ): string { return $value ?: 'medium'; } @@ -461,5 +461,4 @@ public function name( $value = null ) { public function gquizWeight( $value = null ) { return ! empty( $value ) ? $value : $this->dummy->number( 0, 5 ); } - } diff --git a/tests/_support/Helper/GFHelpers/inc/Dummy.php b/tests/_support/Helper/GFHelpers/inc/Dummy.php index 5f2b6ae4..d528a069 100644 --- a/tests/_support/Helper/GFHelpers/inc/Dummy.php +++ b/tests/_support/Helper/GFHelpers/inc/Dummy.php @@ -75,7 +75,6 @@ public function ymd() { return( rand( 1943, 2025 ) . '-0' . rand( 1, 9 ) . '-' . rand( 11, 30 ) ); } - public function hm( $s = false ) { $t = rand( 1, 12 ) . ':' . rand( 10, 59 ); diff --git a/tests/_support/Helper/Unit.php b/tests/_support/Helper/Unit.php index 1303b789..808ce73b 100644 --- a/tests/_support/Helper/Unit.php +++ b/tests/_support/Helper/Unit.php @@ -5,6 +5,4 @@ // all public methods declared in helper class will be available in $I class Unit extends \Codeception\Module { - - } diff --git a/tests/_support/Helper/Wpunit.php b/tests/_support/Helper/Wpunit.php index f730f0c6..24a2c224 100644 --- a/tests/_support/Helper/Wpunit.php +++ b/tests/_support/Helper/Wpunit.php @@ -14,15 +14,13 @@ * All public methods declared in helper class will be available in $I */ class Wpunit extends \Codeception\Module { - /** * Generates the property helper for the field. * * @param string $type . * @param array $args . - * @return PropertyHelper */ - public function getPropertyHelper( string $type, array $args = [] ) : PropertyHelper { + public function getPropertyHelper( string $type, array $args = [] ): PropertyHelper { $interface_defaults = $this->getDefaultArgs(); $field_defaults = call_user_func( [ $this, "get{$type}Args" ] ); @@ -34,7 +32,7 @@ public function getPropertyHelper( string $type, array $args = [] ) : PropertyHe /** * Gets the default args used by all fields. */ - public function getDefaultArgs() : array { + public function getDefaultArgs(): array { return [ 'displayOnly', [ 'conditionalLogic' => null ], @@ -53,7 +51,7 @@ public function getDefaultArgs() : array { /** * Get the default args for an address field. */ - public function getAddressFieldArgs() : array { + public function getAddressFieldArgs(): array { return [ 'addressType', 'adminLabel', @@ -87,7 +85,7 @@ public function getAddressFieldArgs() : array { /** * Get the default args for a Captcha field. */ - public function getCaptchaFieldArgs() : array { + public function getCaptchaFieldArgs(): array { return [ 'captchaBadgePosition', 'captchaLanguage', @@ -108,7 +106,7 @@ public function getCaptchaFieldArgs() : array { /** * Get the default args for a ChainedSelect field. */ - public function getChainedSelectFieldArgs() : array { + public function getChainedSelectFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -222,7 +220,7 @@ public function getChainedSelectFieldArgs() : array { /** * Get the default args for a Checkbox field. */ - public function getCheckboxFieldArgs() : array { + public function getCheckboxFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -268,7 +266,7 @@ public function getCheckboxFieldArgs() : array { /** * Get the default args for a consent field. */ - public function getConsentFieldArgs() : array { + public function getConsentFieldArgs(): array { return [ 'adminLabel', 'checkboxLabel', @@ -313,7 +311,7 @@ public function getConsentFieldArgs() : array { /** * Get the default args for a consent field. */ - public function getDateFieldArgs() : array { + public function getDateFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -346,7 +344,7 @@ public function getDateFieldArgs() : array { /** * Get the default args for an email field. */ - public function getEmailFieldArgs() : array { + public function getEmailFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -393,7 +391,7 @@ public function getEmailFieldArgs() : array { /** * Get the default args for an email field. */ - public function getFileUploadFieldArgs() : array { + public function getFileUploadFieldArgs(): array { return [ 'adminLabel', 'allowedExtensions', @@ -414,7 +412,7 @@ public function getFileUploadFieldArgs() : array { /** * Get the default args for a hidden field. */ - public function getHiddenFieldArgs() : array { + public function getHiddenFieldArgs(): array { return [ [ 'cssClass' => null ], [ 'adminLabel' => null ], @@ -431,7 +429,7 @@ public function getHiddenFieldArgs() : array { /** * Get args for HTML field. */ - public function getHtmlFieldArgs() : array { + public function getHtmlFieldArgs(): array { return [ 'adminLabel', 'content', @@ -442,10 +440,11 @@ public function getHtmlFieldArgs() : array { [ 'type' => 'html' ], ]; } + /** * Get the default args for a list field. */ - public function getListFieldArgs() : array { + public function getListFieldArgs(): array { return [ 'addIconUrl', 'adminLabel', @@ -484,7 +483,7 @@ public function getListFieldArgs() : array { /** * Get the default args for a MultiSelect field. */ - public function getMultiSelectFieldArgs() : array { + public function getMultiSelectFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -525,7 +524,7 @@ public function getMultiSelectFieldArgs() : array { /** * Get the default args for a name field. */ - public function getNameFieldArgs() : array { + public function getNameFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -615,7 +614,7 @@ public function getNameFieldArgs() : array { /** * Get the default args for a number field. */ - public function getNumberFieldArgs() : array { + public function getNumberFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -645,7 +644,7 @@ public function getNumberFieldArgs() : array { /** * Get the default args for an Option field. */ - public function getOptionFieldArgs() : array { + public function getOptionFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -694,7 +693,7 @@ public function getOptionFieldArgs() : array { /** * Get args for page field. */ - public function getPageFieldArgs() : array { + public function getPageFieldArgs(): array { return [ 'adminLabel', [ @@ -722,7 +721,7 @@ public function getPageFieldArgs() : array { /** * Get the default args for a Phone field. */ - public function getPhoneFieldArgs() : array { + public function getPhoneFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -748,7 +747,7 @@ public function getPhoneFieldArgs() : array { /** * Get the default args for a PostContent field. */ - public function getPostContentFieldArgs() : array { + public function getPostContentFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -770,7 +769,7 @@ public function getPostContentFieldArgs() : array { /** * Get the default args for a PostContent field. */ - public function getPostCategoryFieldArgs() : array { + public function getPostCategoryFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -793,7 +792,7 @@ public function getPostCategoryFieldArgs() : array { /** * Get the default args for a PostExcerpt field. */ - public function getPostExcerptFieldArgs() : array { + public function getPostExcerptFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -812,11 +811,10 @@ public function getPostExcerptFieldArgs() : array { ]; } - /** * Get the default args for an email field. */ - public function getPostImageFieldArgs() : array { + public function getPostImageFieldArgs(): array { return [ 'adminLabel', 'allowedExtensions', @@ -839,7 +837,7 @@ public function getPostImageFieldArgs() : array { /** * Get the default args for a PostContent field. */ - public function getPostTagsFieldArgs() : array { + public function getPostTagsFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -860,7 +858,7 @@ public function getPostTagsFieldArgs() : array { /** * Get the default args for a PostTitle field. */ - public function getPostTitleFieldArgs() : array { + public function getPostTitleFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -882,7 +880,7 @@ public function getPostTitleFieldArgs() : array { /** * Get the default args for a Product field */ - public function getProductFieldArgs() : array { + public function getProductFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -906,11 +904,10 @@ public function getProductFieldArgs() : array { ]; } - /** * Get the default args for a quantity field. */ - public function getQuantityFieldArgs() : array { + public function getQuantityFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -933,7 +930,7 @@ public function getQuantityFieldArgs() : array { /** * Get the default args for a Quiz field */ - public function getQuizFieldArgs() : array { + public function getQuizFieldArgs(): array { return [ 'autocompleteAttribute', 'adminLabel', @@ -994,7 +991,7 @@ public function getQuizFieldArgs() : array { /** * Get the default args for a radio field. */ - public function getRadioFieldArgs() : array { + public function getRadioFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -1034,7 +1031,7 @@ public function getRadioFieldArgs() : array { /** * Get args for section field. */ - public function getSectionFieldArgs() : array { + public function getSectionFieldArgs(): array { return [ 'adminLabel', [ 'displayOnly' => true ], @@ -1047,7 +1044,7 @@ public function getSectionFieldArgs() : array { /** * Get the default args for a select field. */ - public function getSelectFieldArgs() : array { + public function getSelectFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -1091,7 +1088,7 @@ public function getSelectFieldArgs() : array { /** * Get the default args for a shipping field. */ - public function getShippingFieldArgs() : array { + public function getShippingFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -1108,11 +1105,10 @@ public function getShippingFieldArgs() : array { ]; } - /** * Get the default args for a signature field. */ - public function getSignatureFieldArgs() : array { + public function getSignatureFieldArgs(): array { return [ 'adminLabel', 'backgroundColor', @@ -1138,7 +1134,7 @@ public function getSignatureFieldArgs() : array { /** * Get the default args for a text field. */ - public function getTextFieldArgs() : array { + public function getTextFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -1165,7 +1161,7 @@ public function getTextFieldArgs() : array { /** * Get the default args for a textarea field. */ - public function getTextAreaFieldArgs() : array { + public function getTextAreaFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -1189,7 +1185,7 @@ public function getTextAreaFieldArgs() : array { /** * Get the default args for a time field. */ - public function getTimeFieldArgs() : array { + public function getTimeFieldArgs(): array { return [ 'adminLabel', 'allowsPrepopulate', @@ -1232,7 +1228,7 @@ public function getTimeFieldArgs() : array { /** * Get the default args for a total field. */ - public function getTotalFieldArgs() : array { + public function getTotalFieldArgs(): array { return [ 'adminLabel', 'description', @@ -1243,11 +1239,10 @@ public function getTotalFieldArgs() : array { ]; } - /** * Get default args for website field. */ - public function getWebsiteFieldArgs() : array { + public function getWebsiteFieldArgs(): array { return [ 'adminLabel', 'defaultValue', @@ -1270,7 +1265,7 @@ public function getWebsiteFieldArgs() : array { * * @param array $args . */ - public function getFormDefaultArgs( $args = [] ) : array { + public function getFormDefaultArgs( $args = [] ): array { return array_merge( [ 'button' => [ @@ -1479,7 +1474,6 @@ public function getFormDefaultArgs( $args = [] ) : array { ); } - /** * Converts a string value to its Enum equivalent * @@ -1502,7 +1496,7 @@ public function get_enum_for_value( string $enumName, $value ) { * @param array $default . * @param array $custom . */ - public function merge_default_args( array $default, array $custom = [] ) : array { + public function merge_default_args( array $default, array $custom = [] ): array { array_walk( $default, static function ( &$value ) use ( $custom ) { diff --git a/tests/_support/TestCase/FormFieldTestCase.php b/tests/_support/TestCase/FormFieldTestCase.php index 3f75f092..8c7ee005 100644 --- a/tests/_support/TestCase/FormFieldTestCase.php +++ b/tests/_support/TestCase/FormFieldTestCase.php @@ -10,8 +10,8 @@ namespace Tests\WPGraphQL\GF\TestCase; -use GFFormsModel; use GFAPI; +use GFFormsModel; use GF_Field; use Helper\GFHelpers\ExpectedFormFields; use WPGraphQL\GF\Registry\FieldChoiceRegistry; @@ -59,6 +59,7 @@ class FormFieldTestCase extends GFGraphQLTestCase { public function setUp(): void { // Before... $this->is_draft = false; + parent::setUp(); wp_set_current_user( $this->admin->ID ); @@ -124,15 +125,13 @@ public function tearDown(): void { * @uses $this->fields * @uses $this->form_args */ - public function createTestForm() : int { - $form_id = $this->factory->form->create( + public function createTestForm(): int { + return $this->factory->form->create( array_merge( [ 'fields' => $this->fields ], $this->form_args, ) ); - - return $form_id; } /** @@ -140,15 +139,11 @@ public function createTestForm() : int { * * @uses $this->form * @uses $this->value - * - * @return integer */ - public function createTestEntry() : int { - $entry_id = $this->factory->entry->create( + public function createTestEntry(): int { + return $this->factory->entry->create( [ 'form_id' => $this->form_id ] + $this->value ); - - return $entry_id; } /** @@ -157,13 +152,11 @@ public function createTestEntry() : int { * @uses $this->get_draft_field_values() * @uses $this->form_id * @uses $this->value - * - * @return string */ - public function createDraftEntry() : string { + public function createDraftEntry(): string { $draft_entry_field_values = $this->get_draft_field_values(); - $draft_token = $this->factory->draft_entry->create( + return $this->factory->draft_entry->create( [ 'form_id' => $this->form_id, 'entry' => $this->value + [ @@ -173,8 +166,6 @@ public function createDraftEntry() : string { 'fieldValues' => $draft_entry_field_values, ] ); - - return $draft_token; } /** @@ -190,7 +181,7 @@ public function generate_form_args() { ); } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[0]->id; } @@ -246,6 +237,7 @@ public function draft_field_value_input() { public function updated_field_value_input() { return $this->updated_field_value; } + /** * The graphql field value input. */ @@ -256,7 +248,7 @@ public function updated_draft_field_value_input() { /** * The entire GraphQL query with the form field values added. */ - protected function entry_query() : string { + protected function entry_query(): string { return " query getFieldValue(\$id: ID!, \$idType: EntryIdTypeEnum) { gfEntry(id: \$id, idType: \$idType ) { @@ -295,7 +287,7 @@ protected function runTestField(): void { $this->assertArrayNotHasKey( 'errors', $response, 'field has errors' ); // Assert that their are no debug messages. - $this->assertEmpty( $response['extensions']['debug'], print_r($response['extensions']['debug'], true ) ); + $this->assertEmpty( $response['extensions']['debug'], print_r( $response['extensions']['debug'], true ) ); $expected = $this->expected_field_response( $form ); @@ -320,7 +312,7 @@ protected function runTestField(): void { /** * Tests submitting the field values as a draft entry with submitGfForm. */ - protected function runTestSubmitDraft() : void { + protected function runTestSubmitDraft(): void { $this->is_draft = true; wp_set_current_user( $this->admin->ID ); @@ -347,7 +339,7 @@ protected function runTestSubmitDraft() : void { /** * Tests submitting the field values as an entry with submitGfForm. */ - protected function runtestSubmitForm() : void { + protected function runtestSubmitForm(): void { $this->is_draft = false; $form = $this->factory->form->get_object_by_id( $this->form_id ); wp_set_current_user( $this->admin->ID ); @@ -364,7 +356,7 @@ protected function runtestSubmitForm() : void { $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = $this->expected_mutation_response( 'submitGfForm', $this->field_value ); - + $this->assertQuerySuccessful( $response, $expected ); $this->assertEquals( $response['data']['submitGfForm']['errors'], null ); @@ -382,7 +374,7 @@ protected function runtestSubmitForm() : void { /** * Tests updating the field value with updateGfEntry. */ - protected function runtestUpdateEntry() : void { + protected function runtestUpdateEntry(): void { $this->is_draft = false; wp_set_current_user( $this->admin->ID ); @@ -409,7 +401,7 @@ protected function runtestUpdateEntry() : void { /** * Tests updating the draft field value with updateGfEntry. */ - protected function runTestUpdateDraft() : void { + protected function runTestUpdateDraft(): void { $this->is_draft = true; wp_set_current_user( $this->admin->ID ); diff --git a/tests/_support/TestCase/FormFieldTestCaseInterface.php b/tests/_support/TestCase/FormFieldTestCaseInterface.php index 3e41f338..81e3cd41 100644 --- a/tests/_support/TestCase/FormFieldTestCaseInterface.php +++ b/tests/_support/TestCase/FormFieldTestCaseInterface.php @@ -16,7 +16,7 @@ public function field_helper(); /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array; + public function generate_fields(): array; /** * The value as expected in GraphQL. @@ -45,47 +45,44 @@ public function value(); /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string; + public function field_query(): string; /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string; + public function submit_form_mutation(): string; /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string; + public function update_entry_mutation(): string; /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string; + public function update_draft_entry_mutation(): string; /** * The expected WPGraphQL field response. * - * @param array $form the current form instance. + * @param array $form The current form array. */ - public function expected_field_response( array $form ) : array; + public function expected_field_response( array $form ): array; /** * The expected WPGraphQL mutation response. * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value) : array; + public function expected_mutation_response( string $mutationName, $value ): array; /** * Checks if values submitted by GraphQL are the same as whats stored on the server. * - * @param array $actual_entry . - * @param array $form . + * @param array $actual_entry . + * @param array $form The form array. */ - public function check_saved_values( $actual_entry, $form ) : void; + public function check_saved_values( $actual_entry, $form ): void; } diff --git a/tests/_support/TestCase/GFGraphQLTestCase.php b/tests/_support/TestCase/GFGraphQLTestCase.php index 9ead8def..32c1ab59 100644 --- a/tests/_support/TestCase/GFGraphQLTestCase.php +++ b/tests/_support/TestCase/GFGraphQLTestCase.php @@ -11,7 +11,6 @@ namespace Tests\WPGraphQL\GF\TestCase; use Helper\GFHelpers\GFHelpers; -use RuntimeException; use WPGraphQL\GF\Type\Enum; /** @@ -40,7 +39,7 @@ class GFGraphQLTestCase extends \Tests\WPGraphQL\TestCase\WPGraphQLTestCase { /** * Creates users and loads factories. */ - public function setUp() : void { + public function setUp(): void { parent::setUp(); // Load factories. @@ -84,7 +83,6 @@ public function tearDown(): void { * Programmatically generate an expectedField array for assertions. * * @param array $value_array . - * @return array */ protected function get_expected_fields( $value_array ): array { $expected = []; @@ -96,23 +94,23 @@ protected function get_expected_fields( $value_array ): array { public function get_expected_conditional_logic_fields( $conditional_logic ) { if ( empty( $conditional_logic ) ) { - return $this->expectedField( 'conditionalLogic', static::IS_NULL ); + return $this->expectedField( 'conditionalLogic', self::IS_NULL ); } return $this->expectedObject( 'conditionalLogic', [ - $this->expectedField( 'actionType', ! empty( $conditional_logic['actionType'] ) ? GFHelpers::get_enum_for_value( Enum\ConditionalLogicActionTypeEnum::$type, $conditional_logic['actionType'] ) : static::IS_NULL ), + $this->expectedField( 'actionType', ! empty( $conditional_logic['actionType'] ) ? GFHelpers::get_enum_for_value( Enum\ConditionalLogicActionTypeEnum::$type, $conditional_logic['actionType'] ) : self::IS_NULL ), $this->expectedField( 'logicType', - ! empty( $conditional_logic['actionType'] ) ? GFHelpers::get_enum_for_value( Enum\ConditionalLogicLogicTypeEnum::$type, $conditional_logic['logicType'] ) : static::IS_NULL + ! empty( $conditional_logic['actionType'] ) ? GFHelpers::get_enum_for_value( Enum\ConditionalLogicLogicTypeEnum::$type, $conditional_logic['logicType'] ) : self::IS_NULL ), $this->expectedNode( 'rules', [ - $this->expectedField( 'fieldId', ! empty( $conditional_logic['rules'][0]['fieldId'] ) ? (float) $conditional_logic['rules'][0]['fieldId'] : static::IS_NULL ), - $this->expectedField( 'operator', ! empty( $conditional_logic['rules'][0]['operator'] ) ? GFHelpers::get_enum_for_value( Enum\FormRuleOperatorEnum::$type, $conditional_logic['rules'][0]['operator'] ) : static::IS_NULL ), - $this->expectedField( 'value', ! empty( $conditional_logic['rules'][0]['value'] ) ? $conditional_logic['rules'][0]['value'] : static::IS_NULL ), + $this->expectedField( 'fieldId', ! empty( $conditional_logic['rules'][0]['fieldId'] ) ? (float) $conditional_logic['rules'][0]['fieldId'] : self::IS_NULL ), + $this->expectedField( 'operator', ! empty( $conditional_logic['rules'][0]['operator'] ) ? GFHelpers::get_enum_for_value( Enum\FormRuleOperatorEnum::$type, $conditional_logic['rules'][0]['operator'] ) : self::IS_NULL ), + $this->expectedField( 'value', ! empty( $conditional_logic['rules'][0]['value'] ) ? $conditional_logic['rules'][0]['value'] : self::IS_NULL ), ], 0 ), diff --git a/tests/_support/UnitTester.php b/tests/_support/UnitTester.php index 3a743e27..ea5312bf 100644 --- a/tests/_support/UnitTester.php +++ b/tests/_support/UnitTester.php @@ -3,6 +3,7 @@ /** * Inherited Methods + * * @method void wantToTest($text) * @method void wantTo($text) * @method void execute($callable) @@ -14,13 +15,12 @@ * @method void comment($description) * @method void pause() * - * @SuppressWarnings(PHPMD) -*/ -class UnitTester extends \Codeception\Actor -{ - use _generated\UnitTesterActions; + * @SuppressWarnings(\PHPMD) + */ +class UnitTester extends \Codeception\Actor { + use _generated\UnitTesterActions; - /** - * Define custom actions here - */ + /** + * Define custom actions here + */ } diff --git a/tests/_support/WpunitTester.php b/tests/_support/WpunitTester.php index 21e52c50..b5dd1857 100644 --- a/tests/_support/WpunitTester.php +++ b/tests/_support/WpunitTester.php @@ -3,6 +3,7 @@ /** * Inherited Methods + * * @method void wantToTest($text) * @method void wantTo($text) * @method void execute($callable) @@ -14,13 +15,12 @@ * @method void comment($description) * @method void pause() * - * @SuppressWarnings(PHPMD) -*/ -class WpunitTester extends \Codeception\Actor -{ - use _generated\WpunitTesterActions; + * @SuppressWarnings(\PHPMD) + */ +class WpunitTester extends \Codeception\Actor { + use _generated\WpunitTesterActions; - /** - * Define custom actions here - */ + /** + * Define custom actions here + */ } diff --git a/tests/acceptance/ActivationCest.php b/tests/acceptance/ActivationCest.php index 0c29d562..fec4c18d 100644 --- a/tests/acceptance/ActivationCest.php +++ b/tests/acceptance/ActivationCest.php @@ -1,7 +1,6 @@ [ 'type' => 'String', diff --git a/tests/wpunit/AddressFieldTest.php b/tests/wpunit/AddressFieldTest.php index 923c02e4..5a80aaef 100644 --- a/tests/wpunit/AddressFieldTest.php +++ b/tests/wpunit/AddressFieldTest.php @@ -20,28 +20,32 @@ class AddressFieldTest extends FormFieldTestCase implements FormFieldTestCaseInt public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -55,7 +59,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -73,7 +77,6 @@ public function field_value() { ]; } - /** * Sets the value as expected by Gravity Forms. */ @@ -102,14 +105,10 @@ public function updated_field_value() { ]; } - - /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on AddressField { addressType @@ -172,10 +171,8 @@ public function field_query() : string { /** * SubmitForm mutation string. - * - * @return string */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: AddressFieldInput!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, addressValues: $value}}) { @@ -212,8 +209,6 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. - * - * @return string */ public function update_entry_mutation(): string { return ' @@ -246,8 +241,6 @@ public function update_entry_mutation(): string { /** * Returns the UpdateDraftEntry mutation string. - * - * @return string */ public function update_draft_entry_mutation(): string { return ' @@ -277,13 +270,11 @@ public function update_draft_entry_mutation(): string { } '; } + /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'addressValues', $this->field_value ); @@ -311,9 +302,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -343,8 +333,8 @@ public function expected_mutation_response( string $mutationName, $value ) : arr /** * Checks if values submitted by GraphQL are the same as whats stored on the server. * - * @param array $actual_entry . - * @param array $form . + * @param array $actual_entry . + * @param array $form The form array. */ public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value['street'], $actual_entry[ $form['fields'][0]['inputs'][0]['id'] ], 'Submit mutation entry value 1 not equal' ); diff --git a/tests/wpunit/CaptchaFieldTest.php b/tests/wpunit/CaptchaFieldTest.php index 797cc580..b619d23c 100644 --- a/tests/wpunit/CaptchaFieldTest.php +++ b/tests/wpunit/CaptchaFieldTest.php @@ -29,28 +29,32 @@ public function setUp(): void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -74,7 +78,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ), $this->factory->field->create( $this->captcha_field_helper->values ), @@ -112,7 +116,7 @@ public function updated_value() { /** * The entire GraphQL query with the form field values added. */ - protected function entry_query() : string { + protected function entry_query(): string { return " query getFieldValue(\$id: ID!, \$idType: EntryIdTypeEnum) { gfEntry(id: \$id, idType: \$idType ) { @@ -128,10 +132,8 @@ protected function entry_query() : string { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on CaptchaField { displayOnly @@ -172,10 +174,8 @@ public function field_query() : string { * Returns the SubmitForm graphQL query. * * The $value can be anything since we're using google's test keys. - * - * @return string */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: [{id: $fieldId, value: $value}, {id:' . $this->fields[1]->id . ' value:"123456"}]}) { @@ -252,13 +252,11 @@ public function update_draft_entry_mutation(): string { } '; } + /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); return [ @@ -279,14 +277,14 @@ public function expected_field_response( array $form ) : array { ), ]; } + /** * The expected WPGraphQL mutation response. * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ChainedSelectFieldTest.php b/tests/wpunit/ChainedSelectFieldTest.php index 52d12a13..ba1b1a57 100644 --- a/tests/wpunit/ChainedSelectFieldTest.php +++ b/tests/wpunit/ChainedSelectFieldTest.php @@ -18,28 +18,32 @@ class ChainedSelectFieldTest extends FormFieldTestCase implements FormFieldTestC public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -63,6 +67,7 @@ public function generate_fields() : array { public function field_value() { return [ '2015', 'Acura', 'MDX' ]; } + /** * The graphql field value input. */ @@ -83,7 +88,6 @@ public function field_value_input() { ]; } - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -124,13 +128,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return ' ... on ChainedSelectField { adminLabel @@ -277,9 +278,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -309,9 +308,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/CheckboxFieldTest.php b/tests/wpunit/CheckboxFieldTest.php index f27171c0..90cb82c6 100644 --- a/tests/wpunit/CheckboxFieldTest.php +++ b/tests/wpunit/CheckboxFieldTest.php @@ -17,28 +17,32 @@ class CheckboxFieldTest extends FormFieldTestCase implements FormFieldTestCaseIn public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -168,7 +172,6 @@ public function updated_field_value_input() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -179,13 +182,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return ' ... on CheckboxField { adminLabel @@ -360,9 +360,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -392,9 +390,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ConsentFieldTest.php b/tests/wpunit/ConsentFieldTest.php index 64de8ab0..b47be0aa 100644 --- a/tests/wpunit/ConsentFieldTest.php +++ b/tests/wpunit/ConsentFieldTest.php @@ -18,28 +18,32 @@ class ConsentFieldTest extends FormFieldTestCase implements FormFieldTestCaseInt public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -106,10 +110,8 @@ public function updated_value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return ' ... on ConsentField { adminLabel @@ -222,9 +224,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -254,9 +254,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/DateFieldTest.php b/tests/wpunit/DateFieldTest.php index 2ff3fdaf..64853d87 100644 --- a/tests/wpunit/DateFieldTest.php +++ b/tests/wpunit/DateFieldTest.php @@ -17,30 +17,35 @@ class DateFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterf public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -51,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -69,7 +74,6 @@ public function updated_field_value() { return $this->property_helper->dummy->ymd(); } - /** * The value as expected by Gravity Forms. */ @@ -79,10 +83,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on DateField { adminLabel @@ -135,7 +137,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ( $formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -166,7 +168,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -191,7 +193,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -214,11 +216,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -246,9 +246,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -280,7 +279,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/DeleteDraftEntryMutationTest.php b/tests/wpunit/DeleteDraftEntryMutationTest.php index a1d958e4..518c042e 100644 --- a/tests/wpunit/DeleteDraftEntryMutationTest.php +++ b/tests/wpunit/DeleteDraftEntryMutationTest.php @@ -17,7 +17,6 @@ class DeleteDraftEntryMutationTest extends GFGraphQLTestCase { private $draft_token; private $text_field_helper; - /** * Run before each test. */ @@ -55,7 +54,7 @@ public function tearDown(): void { /** * Tests `deleteGfDraftEntry`. */ - public function testDeleteGfDraftEntry() : void { + public function testDeleteGfDraftEntry(): void { $query = $this->delete_mutation(); $variables = [ @@ -85,7 +84,7 @@ public function testDeleteGfDraftEntry() : void { /** * Tests `deleteGfDraftEntry`. */ - public function testDeleteGfDraftEntry_globalId() : void { + public function testDeleteGfDraftEntry_globalId(): void { $query = $this->delete_mutation(); // Test Global Id @@ -108,7 +107,7 @@ public function testDeleteGfDraftEntry_globalId() : void { /** * Tests `deleteGfDraftEntry` when a bad resumeToken is supplied. */ - public function testDeleteGfDraftEntry_badToken() : void { + public function testDeleteGfDraftEntry_badToken(): void { wp_set_current_user( $this->admin->ID ); $query = $this->delete_mutation(); @@ -124,12 +123,13 @@ public function testDeleteGfDraftEntry_badToken() : void { $this->factory->draft_entry->delete( $this->draft_token ); } + /** * Creates the mutation. * * @param array $args . */ - public function delete_mutation() : string { + public function delete_mutation(): string { return ' mutation deleteGfDraftEntry( $id: ID!, diff --git a/tests/wpunit/DeleteEntryMutationTest.php b/tests/wpunit/DeleteEntryMutationTest.php index 9cb2b89e..a29f80bb 100644 --- a/tests/wpunit/DeleteEntryMutationTest.php +++ b/tests/wpunit/DeleteEntryMutationTest.php @@ -57,7 +57,7 @@ public function tearDown(): void { /** * Tests `deleteGfEntry`. */ - public function testDeleteGfEntry() : void { + public function testDeleteGfEntry(): void { $query = $this->delete_mutation(); $variables = [ @@ -101,7 +101,7 @@ public function testDeleteGfEntry() : void { /** * Tests `deleteGfEntry` when a bad entryId is supplied. */ - public function testDeleteGfEntry_badToken() : void { + public function testDeleteGfEntry_badToken(): void { $query = $this->delete_mutation(); // Test Global Id @@ -127,7 +127,7 @@ public function testDeleteGfEntry_badToken() : void { * * @param array $args . */ - public function delete_mutation( array $args = [] ) : string { + public function delete_mutation( array $args = [] ): string { return ' mutation deleteGfEntry( $id: ID!, diff --git a/tests/wpunit/EmailFieldTest.php b/tests/wpunit/EmailFieldTest.php index b8f3128c..831ab7d4 100644 --- a/tests/wpunit/EmailFieldTest.php +++ b/tests/wpunit/EmailFieldTest.php @@ -12,37 +12,41 @@ * Class -EmailFieldTest. */ class EmailFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { - /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -93,7 +97,6 @@ public function updated_field_value_input() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -103,10 +106,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on EmailField { adminLabel @@ -157,7 +158,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ( $formId: ID!, $fieldId: Int!, $value: EmailFieldInput!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, emailValues: $value}}) { @@ -188,7 +189,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: EmailFieldInput! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, emailValues: $value} }) { @@ -213,7 +214,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: EmailFieldInput! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, emailValues: $value} }) { @@ -236,11 +237,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -268,9 +267,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -302,7 +300,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/EntryConnectionQueriesTest.php b/tests/wpunit/EntryConnectionQueriesTest.php index bbda1a89..8409efc3 100644 --- a/tests/wpunit/EntryConnectionQueriesTest.php +++ b/tests/wpunit/EntryConnectionQueriesTest.php @@ -5,12 +5,7 @@ * @package . */ -use GraphQLRelay\Relay; use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; -use WPGraphQL\GF\Type\Enum; -use Helper\GFHelpers\GFHelpers; -use WPGraphQL\GF\Data\Loader\DraftEntriesLoader; -use WPGraphQL\GF\Data\Loader\EntriesLoader; /** * Class - EntryConnectionQueriesTest @@ -67,7 +62,7 @@ public function tearDown(): void { /** * Tests `gfEntries`. */ - public function testEntriesQuery() : void { + public function testEntriesQuery(): void { wp_set_current_user( $this->admin->ID ); $query = ' @@ -132,7 +127,7 @@ public function testEntriesCount() { /** * Tests the form->entries connection only contains entries on the form. */ - public function testFormOnlyContainsRelatedEntries() : void { + public function testFormOnlyContainsRelatedEntries(): void { $form_id = $this->factory->form->create( array_merge( [ 'fields' => $this->fields ], diff --git a/tests/wpunit/EntryQueriesTest.php b/tests/wpunit/EntryQueriesTest.php index 1f37d3ce..d636b264 100644 --- a/tests/wpunit/EntryQueriesTest.php +++ b/tests/wpunit/EntryQueriesTest.php @@ -6,11 +6,11 @@ */ use GraphQLRelay\Relay; -use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; -use WPGraphQL\GF\Type\Enum; use Helper\GFHelpers\GFHelpers; +use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; use WPGraphQL\GF\Data\Loader\DraftEntriesLoader; use WPGraphQL\GF\Data\Loader\EntriesLoader; +use WPGraphQL\GF\Type\Enum; /** * Class - EntryQueriesTest @@ -65,10 +65,8 @@ public function tearDown(): void { /** * Returns the full entry query for reuse. - * - * @return string */ - private function get_entry_query() : string { + private function get_entry_query(): string { return ' query getEntry($id: ID!, $idType: EntryIdTypeEnum) { gfEntry(id: $id, idType: $idType) { @@ -115,7 +113,7 @@ private function get_entry_query() : string { /** * Tests `gfEntry`. */ - public function testEntryQuery() : void { + public function testEntryQuery(): void { wp_set_current_user( $this->admin->ID ); $global_id = Relay::toGlobalId( EntriesLoader::$name, $this->entry_id ); @@ -192,7 +190,7 @@ public function testEmptyEntryQuery() { /** * Tests `gfEntry` with draft entry. */ - public function testDraftEntryQuery() : void { + public function testDraftEntryQuery(): void { wp_set_current_user( $this->admin->ID ); $draft_token = $this->factory->draft_entry->create( @@ -249,34 +247,31 @@ public function testDraftEntryQuery() : void { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $entry, array $form ) : array { + public function expected_field_response( array $entry, array $form ): array { return [ $this->expectedObject( 'gfEntry', [ - $this->expectedField( 'createdByDatabaseId', ! empty( $entry['created_by'] ) ? (int) $entry['created_by'] : static::IS_NULL ), - $this->expectedField( 'createdById', ! empty( $entry['created_by'] ) ? $this->toRelayId( 'user', $entry['created_by'] ) : static::IS_NULL ), + $this->expectedField( 'createdByDatabaseId', ! empty( $entry['created_by'] ) ? (int) $entry['created_by'] : self::IS_NULL ), + $this->expectedField( 'createdById', ! empty( $entry['created_by'] ) ? $this->toRelayId( 'user', $entry['created_by'] ) : self::IS_NULL ), $this->expectedObject( 'createdBy', [ - $this->expectedField( 'databaseId', ! empty( $entry['created_by'] ) ? (int) $entry['created_by'] : static::IS_NULL ), + $this->expectedField( 'databaseId', ! empty( $entry['created_by'] ) ? (int) $entry['created_by'] : self::IS_NULL ), ] ), - $this->expectedField( 'databaseId', ! empty( $entry['id'] ) ? (int) $entry['id'] : static::IS_NULL ), - $this->expectedField( 'dateCreated', ! empty( $entry['date_created'] ) ? get_date_from_gmt( $entry['date_created'] ) : static::IS_NULL ), - $this->expectedField( 'dateCreatedGmt', ! empty( $entry['date_created'] ) ? $entry['date_created'] : static::IS_NULL ), - $this->expectedField( 'dateUpdated', ! empty( $entry['date_updated'] ) ? get_date_from_gmt( $entry['date_updated'] ) : static::IS_NULL ), - $this->expectedField( 'dateUpdatedGmt', ! empty( $entry['date_updated'] ) ? $entry['date_updated'] : static::IS_NULL ), - $this->expectedField( 'formDatabaseId', ! empty( $form['id'] ) ? (int) $form['id'] : static::IS_NULL ), + $this->expectedField( 'databaseId', ! empty( $entry['id'] ) ? (int) $entry['id'] : self::IS_NULL ), + $this->expectedField( 'dateCreated', ! empty( $entry['date_created'] ) ? get_date_from_gmt( $entry['date_created'] ) : self::IS_NULL ), + $this->expectedField( 'dateCreatedGmt', ! empty( $entry['date_created'] ) ? $entry['date_created'] : self::IS_NULL ), + $this->expectedField( 'dateUpdated', ! empty( $entry['date_updated'] ) ? get_date_from_gmt( $entry['date_updated'] ) : self::IS_NULL ), + $this->expectedField( 'dateUpdatedGmt', ! empty( $entry['date_updated'] ) ? $entry['date_updated'] : self::IS_NULL ), + $this->expectedField( 'formDatabaseId', ! empty( $form['id'] ) ? (int) $form['id'] : self::IS_NULL ), $this->expectedObject( 'form', [ - $this->expectedField( 'databaseId', isset( $form['id'] ) ? (int) $form['id'] : static::IS_NULL ), + $this->expectedField( 'databaseId', isset( $form['id'] ) ? (int) $form['id'] : self::IS_NULL ), ] ), $this->expectedObject( @@ -292,15 +287,15 @@ public function expected_field_response( array $entry, array $form ) : array { ] ), $this->expectedField( 'id', $this->toRelayId( EntriesLoader::$name, $entry['id'] ) ), - $this->expectedField( 'ip', ! empty( $entry['ip'] ) ? $entry['ip'] : static::IS_NULL ), + $this->expectedField( 'ip', ! empty( $entry['ip'] ) ? $entry['ip'] : self::IS_NULL ), $this->expectedField( 'isDraft', ! empty( $entry['resume_token'] ) ), $this->expectedField( 'isSubmitted', ! empty( $entry['id'] ) ), $this->expectedField( 'isRead', ! empty( $entry['is_read'] ) ), $this->expectedField( 'isStarred', ! empty( $entry['isStarred'] ) ), - $this->expectedField( 'resumeToken', ! empty( $entry['resumeToken'] ) ? $entry['resumeToken'] : static::IS_NULL ), - $this->expectedField( 'sourceUrl', ! empty( $entry['source_url'] ) ? $entry['source_url'] : static::IS_NULL ), - $this->expectedField( 'status', ! empty( $entry['status'] ) ? GFHelpers::get_enum_for_value( Enum\EntryStatusEnum::$type, $entry['status'] ) : static::IS_NULL ), - $this->expectedField( 'userAgent', ! empty( $entry['user_agent'] ) ? $entry['user_agent'] : static::IS_NULL ), + $this->expectedField( 'resumeToken', ! empty( $entry['resumeToken'] ) ? $entry['resumeToken'] : self::IS_NULL ), + $this->expectedField( 'sourceUrl', ! empty( $entry['source_url'] ) ? $entry['source_url'] : self::IS_NULL ), + $this->expectedField( 'status', ! empty( $entry['status'] ) ? GFHelpers::get_enum_for_value( Enum\EntryStatusEnum::$type, $entry['status'] ) : self::IS_NULL ), + $this->expectedField( 'userAgent', ! empty( $entry['user_agent'] ) ? $entry['user_agent'] : self::IS_NULL ), ] ), ]; diff --git a/tests/wpunit/FileUploadFieldTest.php b/tests/wpunit/FileUploadFieldTest.php index 97aa40e4..06fe9dde 100644 --- a/tests/wpunit/FileUploadFieldTest.php +++ b/tests/wpunit/FileUploadFieldTest.php @@ -74,28 +74,32 @@ public function tearDown(): void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -109,7 +113,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -182,10 +186,8 @@ public function updated_field_value_input() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on FileUploadField { adminLabel @@ -225,10 +227,8 @@ public function field_query() : string { /** * SubmitForm mutation string. - * - * @return string */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: [Upload!], $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, fileUploadValues: $value}}) { @@ -262,8 +262,6 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. - * - * @return string */ public function update_entry_mutation(): string { return ' @@ -293,8 +291,6 @@ public function update_entry_mutation(): string { /** * Returns the UpdateDraftEntry mutation string. - * - * @return string */ public function update_draft_entry_mutation(): string { return ' @@ -321,13 +317,11 @@ public function update_draft_entry_mutation(): string { } '; } + /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected_field_value = $this->field_value; @@ -364,9 +358,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { $form = $this->factory->form->get_object_by_id( $this->form_id ); $url = ! $this->is_draft ? $this->factory->entry->get_object_by_id( $this->entry_id )[ $form['fields'][0]->id ] : null; diff --git a/tests/wpunit/FileUploadMultipleFieldTest.php b/tests/wpunit/FileUploadMultipleFieldTest.php index ae62c711..4d619a23 100644 --- a/tests/wpunit/FileUploadMultipleFieldTest.php +++ b/tests/wpunit/FileUploadMultipleFieldTest.php @@ -15,29 +15,29 @@ * Class -FileUploadMultipleFieldTest */ class FileUploadMultipleFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { - /** * Set up. */ public function setUp(): void { // Before... - copy( dirname( __FILE__ ) . '/../_support/files/img1.png', '/tmp/img1.png' ); + copy( __DIR__ . '/../_support/files/img1.png', '/tmp/img1.png' ); $stat = stat( dirname( '/tmp/img1.png' ) ); $perms = $stat['mode'] & 0000666; chmod( '/tmp/img1.png', $perms ); - copy( dirname( __FILE__ ) . '/../_support/files/img2.png', '/tmp/img2.png' ); + copy( __DIR__ . '/../_support/files/img2.png', '/tmp/img2.png' ); $stat = stat( dirname( '/tmp/img2.png' ) ); $perms = $stat['mode'] & 0000666; chmod( '/tmp/img2.png', $perms ); - copy( dirname( __FILE__ ) . '/../_support/files/img2.png', '/tmp/img3.png' ); + copy( __DIR__ . '/../_support/files/img2.png', '/tmp/img3.png' ); $stat = stat( dirname( '/tmp/img3.png' ) ); $perms = $stat['mode'] & 0000666; chmod( '/tmp/img3.png', $perms ); - copy( dirname( __FILE__ ) . '/../_support/files/img2.png', '/tmp/img4.png' ); + copy( __DIR__ . '/../_support/files/img2.png', '/tmp/img4.png' ); $stat = stat( dirname( '/tmp/img4.png' ) ); $perms = $stat['mode'] & 0000666; chmod( '/tmp/img4.png', $perms ); + parent::setUp(); global $_gf_uploaded_files; @@ -46,36 +46,42 @@ public function setUp(): void { public function tearDown(): void { GFFormsModel::delete_files( $this->entry_id, $this->factory->form->get_object_by_id( $this->form_id ) ); + parent::tearDown(); } + /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -89,7 +95,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -191,10 +197,8 @@ public function updated_field_value_input() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on FileUploadField { adminLabel @@ -234,10 +238,8 @@ public function field_query() : string { /** * SubmitForm mutation string. - * - * @return string */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: [Upload!], $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, fileUploadValues: $value}}) { @@ -271,8 +273,6 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. - * - * @return string */ public function update_entry_mutation(): string { return ' @@ -302,8 +302,6 @@ public function update_entry_mutation(): string { /** * Returns the UpdateDraftEntry mutation string. - * - * @return string */ public function update_draft_entry_mutation(): string { return ' @@ -330,13 +328,11 @@ public function update_draft_entry_mutation(): string { } '; } + /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $urls = json_decode( $this->factory->entry->get_object_by_id( $this->entry_id )[ $form['fields'][0]->id ] ); @@ -377,9 +373,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { $form = $this->factory->form->get_object_by_id( $this->form_id ); $urls = ! $this->is_draft ? json_decode( $this->factory->entry->get_object_by_id( $this->entry_id )[ $form['fields'][0]->id ] ) : []; diff --git a/tests/wpunit/FormConnectionQueriesTest.php b/tests/wpunit/FormConnectionQueriesTest.php index 495fdb0c..93c1a896 100644 --- a/tests/wpunit/FormConnectionQueriesTest.php +++ b/tests/wpunit/FormConnectionQueriesTest.php @@ -233,7 +233,6 @@ public function testBackwardPagination() { $this->assertEqualSets( $expected['data']['gfForms']['nodes'], $actual['data']['gfForms']['nodes'] ); } - public function testFormIdsWhereArgs() { $form_id_two = $this->form_ids[2]; $form_id_one = $this->form_ids[1]; diff --git a/tests/wpunit/FormQueriesTest.php b/tests/wpunit/FormQueriesTest.php index a7c88fe9..e94524c2 100644 --- a/tests/wpunit/FormQueriesTest.php +++ b/tests/wpunit/FormQueriesTest.php @@ -6,11 +6,11 @@ */ use GraphQLRelay\Relay; -use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; -use WPGraphQL\GF\Type\Enum; -use WPGraphQL\GF\Extensions\GFQuiz\Type\Enum as QuizEnum; use Helper\GFHelpers\GFHelpers; +use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; use WPGraphQL\GF\Data\Loader\FormsLoader; +use WPGraphQL\GF\Extensions\GFQuiz\Type\Enum as QuizEnum; +use WPGraphQL\GF\Type\Enum; /** * Class - FormQueriesTest @@ -59,7 +59,7 @@ public function tearDown(): void { /** * Tests `gfForm`. */ - public function testFormQuery() : void { + public function testFormQuery(): void { $global_id = Relay::toGlobalId( FormsLoader::$name, $this->form_id ); $form = GFAPI::get_form( $this->form_id ); $confirmation_key = key( $form['confirmations'] ); @@ -105,7 +105,7 @@ public function testFormQuery() : void { /** * Returns the full form query for reuse. */ - private function get_form_query() : string { + private function get_form_query(): string { return ' query getForm( $id: ID!, $idType: FormIdTypeEnum ) { gfForm( id: $id, idType: $idType ) { @@ -308,12 +308,9 @@ private function get_form_query() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form, string $confirmation_key ) : array { + public function expected_field_response( array $form, string $confirmation_key ): array { return [ $this->expectedObject( 'gfForm', @@ -338,7 +335,7 @@ public function expected_field_response( array $form, string $confirmation_key ) $this->expectedField( 'isDefault', $form['confirmations'][ $confirmation_key ]['isDefault'] ), $this->expectedField( 'message', $form['confirmations'][ $confirmation_key ]['message'] ), $this->expectedField( 'name', $form['confirmations'][ $confirmation_key ]['name'] ), - $this->expectedField( 'pageId', $form['confirmations'][ $confirmation_key ]['pageId'] ?? static::IS_NULL ), + $this->expectedField( 'pageId', $form['confirmations'][ $confirmation_key ]['pageId'] ?? self::IS_NULL ), $this->expectedField( 'queryString', $form['confirmations'][ $confirmation_key ]['queryString'] ), $this->expectedField( 'type', GFHelpers::get_enum_for_value( Enum\FormConfirmationTypeEnum::$type, $form['confirmations'][ $confirmation_key ]['type'] ) ), $this->expectedField( 'url', $form['confirmations'][ $confirmation_key ]['url'] ), @@ -519,7 +516,7 @@ public function expected_field_response( array $form, string $confirmation_key ) ] ), // This is null, since grading type is PASSFAIL. - $this->expectedField( 'grades', static::IS_NULL ), + $this->expectedField( 'grades', self::IS_NULL ), // $this->expectedNode( // 'grades', // [ @@ -531,11 +528,11 @@ public function expected_field_response( array $form, string $confirmation_key ) $this->expectedField( 'gradingType', GFHelpers::get_enum_for_value( QuizEnum\QuizFieldGradingTypeEnum::$type, $form['gravityformsquiz']['grading'] ) ), $this->expectedField( 'hasInstantFeedback', ! empty( $form['gravityformsquiz']['instantFeedback'] ) ), // This is null because grading type is PASSFAIL. - $this->expectedField( 'hasLetterConfirmationMessage', static::IS_NULL ), + $this->expectedField( 'hasLetterConfirmationMessage', self::IS_NULL ), $this->expectedField( 'hasPassFailConfirmationMessage', ! empty( $form['gravityformsquiz']['passfailDisplayConfirmation'] ) ), $this->expectedField( 'isShuffleFieldsEnabled', ! empty( $form['gravityformsquiz']['shuffleFields'] ) ), - $this->expectedField( 'letterConfirmation', static::IS_NULL ), - $this->expectedField( 'maxScore', static::IS_NULL ), + $this->expectedField( 'letterConfirmation', self::IS_NULL ), + $this->expectedField( 'maxScore', self::IS_NULL ), $this->expectedObject( 'passConfirmation', [ diff --git a/tests/wpunit/GFTest.php b/tests/wpunit/GFTest.php index 9520cb4e..3971927c 100644 --- a/tests/wpunit/GFTest.php +++ b/tests/wpunit/GFTest.php @@ -12,6 +12,7 @@ class GFTest extends \Codeception\TestCase\WPTestCase { public function setUp(): void { // Before... parent::setUp(); + \WPGraphQL::clear_schema(); } diff --git a/tests/wpunit/GFUtilsTest.php b/tests/wpunit/GFUtilsTest.php index dc5862eb..9e115746 100644 --- a/tests/wpunit/GFUtilsTest.php +++ b/tests/wpunit/GFUtilsTest.php @@ -6,8 +6,8 @@ */ use GraphQL\Error\UserError; -use WPGraphQL\GF\Utils\GFUtils; use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; +use WPGraphQL\GF\Utils\GFUtils; /** * Class - GFUtilsTest @@ -60,7 +60,7 @@ public function tearDown(): void { /** * Tests GFUtils::get_ip(). */ - public function testGetIp() : void { + public function testGetIp(): void { $ip = '192.168.0.1'; $actual = GFUtils::get_ip( $ip ); @@ -75,7 +75,7 @@ public function testGetIp() : void { /** * Tests GFUtils::get_form(). */ - public function testGetForm() : void { + public function testGetForm(): void { $expected = $this->factory->form->get_object_by_id( $this->form_id ); // No second parameter. @@ -88,12 +88,10 @@ public function testGetForm() : void { $actual = GFUtils::get_form( $this->form_id + 1 ); } - - /** * Tests GFUtils::get_form() for trashed forms. */ - public function testGetForm_trash() : void { + public function testGetForm_trash(): void { // Create Trash Entry. $form_id = $this->factory->form->create( array_merge( [ 'fields' => $this->fields ], $this->tester->getFormDefaultArgs() ) ); $is_updated = \GFFormsModel::trash_form( $form_id ); @@ -113,7 +111,7 @@ public function testGetForm_trash() : void { /** * Tests GFUtils::get_forms(). */ - public function testGetForms() : void { + public function testGetForms(): void { $expected = $this->factory->form->get_object_by_id( $this->form_id ); $actual = GFUtils::get_forms( [ $this->form_id ] ); @@ -123,7 +121,7 @@ public function testGetForms() : void { /** * Tests GFUtils::get_last_form_page(). */ - public function testGetLastFormPage() : void { + public function testGetLastFormPage(): void { $this->markTestIncomplete( 'This test has not been implemented yet. Requires PageField arguments.' ); @@ -132,7 +130,7 @@ public function testGetLastFormPage() : void { /** * Tests GFUtils::get_form_unique_id(). */ - public function testGetFormUniqueId() : void { + public function testGetFormUniqueId(): void { $expected = GFUtils::get_form_unique_id( $this->form_id ); $actual = GFUtils::get_form_unique_id( $this->form_id ); $this->assertEquals( $expected, $actual ); @@ -141,7 +139,7 @@ public function testGetFormUniqueId() : void { /** * Tests GFUtils::get_field_by_id(). */ - public function testGetFieldById() : void { + public function testGetFieldById(): void { $form = $this->factory->form->get_object_by_id( $this->form_id ); $expected = $this->fields[0]; $actual = GFUtils::get_field_by_id( $form, $this->fields[0]->id ); @@ -158,7 +156,7 @@ public function testGetFieldById() : void { /** * Tests GFUtils::get_entry(). */ - public function testGetEntry() : void { + public function testGetEntry(): void { $expected = $this->factory->entry->get_object_by_id( $this->entry_id ); $actual = GFUtils::get_entry( $this->entry_id ); $this->assertEquals( $expected, $actual ); @@ -172,7 +170,7 @@ public function testGetEntry() : void { /** * Tests GFUtils::update_entry(). */ - public function testUpdateEntry() : void { + public function testUpdateEntry(): void { $entry_data = $this->factory->entry->get_object_by_id( $this->entry_id ); $entry_data['is_starred'] = true; @@ -192,7 +190,7 @@ public function testUpdateEntry() : void { /** * Tests GFUtils::get_draft_entry(). */ - public function testGetDraftEntry() : void { + public function testGetDraftEntry(): void { $expected = $this->factory->draft_entry->get_object_by_id( $this->draft_token ); $actual = GFUtils::get_draft_entry( $this->draft_token ); $this->assertEquals( $expected, $actual ); @@ -206,7 +204,7 @@ public function testGetDraftEntry() : void { /** * Tests GFUtils::get_draft_submission(). */ - public function testGetDraftSubmission() : void { + public function testGetDraftSubmission(): void { $expected_entry = $this->factory->draft_entry->get_object_by_id( $this->draft_token ); $expected = json_decode( $expected_entry['submission'], true ); @@ -219,7 +217,7 @@ public function testGetDraftSubmission() : void { /** * Tests GFUtils::get_resume_url(). */ - public function testGetResumeUrl() : void { + public function testGetResumeUrl(): void { $url = site_url(); $expected = $url . '?gf_token=' . $this->draft_token; $actual = GFUtils::get_resume_url( $this->draft_token, $url ); @@ -232,7 +230,7 @@ public function testGetResumeUrl() : void { /** * Tests GFUtils::save_draft_submission(); */ - public function testSaveDraftSubmission() : void { + public function testSaveDraftSubmission(): void { $form = $this->factory->form->get_object_by_id( $this->form_id ); $entry_data = $this->factory->draft_entry->get_object_by_id( $this->draft_token ); $submission = json_decode( $entry_data['submission'], true ); @@ -266,7 +264,7 @@ public function testSaveDraftSubmission() : void { /** * Tests GFUtils::submit_form() when invalid. */ - public function testSubmitForm_invalid() : void { + public function testSubmitForm_invalid(): void { $form = $this->factory->form->get_object_by_id( $this->form_id ); $input_values = [ 'input_' . $form['fields'][0]->id => 'value2', @@ -280,7 +278,7 @@ public function testSubmitForm_invalid() : void { /** * Tests GFUtils::submit_form(). */ - public function testSubmitForm() : void { + public function testSubmitForm(): void { $form = $this->factory->form->get_object_by_id( $this->form_id ); $input_values = [ 'input_' . $form['fields'][0]->id => 'value1', diff --git a/tests/wpunit/HiddenFieldTest.php b/tests/wpunit/HiddenFieldTest.php index 8cadc5e4..ac10c2e0 100644 --- a/tests/wpunit/HiddenFieldTest.php +++ b/tests/wpunit/HiddenFieldTest.php @@ -11,35 +11,39 @@ /** * Class -HiddenFieldTest. */ -class HiddenFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class HiddenFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -81,7 +85,7 @@ public function value() { /** * The GraphQL query string. */ - public function field_query() : string { + public function field_query(): string { return ' ... on HiddenField { canPrepopulate @@ -101,7 +105,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -132,7 +136,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -158,7 +162,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -181,11 +185,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -213,9 +215,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -247,7 +248,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/HtmlFieldTest.php b/tests/wpunit/HtmlFieldTest.php index 2ddeb9c4..7075fc5c 100644 --- a/tests/wpunit/HtmlFieldTest.php +++ b/tests/wpunit/HtmlFieldTest.php @@ -28,7 +28,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -44,7 +44,6 @@ public function field_value() { public function updated_field_value() { return ''; } - /** * The value as expected by Gravity Forms. */ @@ -53,10 +52,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on HtmlField { conditionalLogic { @@ -79,29 +76,27 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ''; } /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ''; } /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ''; } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); return [ @@ -128,9 +123,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return []; } @@ -140,5 +134,5 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void {} + public function check_saved_values( $actual_entry, $form ): void {} } diff --git a/tests/wpunit/ListFieldColumnsTest.php b/tests/wpunit/ListFieldColumnsTest.php index 7407bd07..144a80d1 100644 --- a/tests/wpunit/ListFieldColumnsTest.php +++ b/tests/wpunit/ListFieldColumnsTest.php @@ -12,37 +12,42 @@ /** * Class -ListFieldTest. */ -class ListFieldColumnsTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class ListFieldColumnsTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -79,7 +84,7 @@ public function generate_form_args() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -151,10 +156,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on ListField { addIconUrl @@ -199,7 +202,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: [ListFieldInput]!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, listValues: $value}}) { @@ -232,7 +235,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: [ListFieldInput] ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, listValues: $value} }) { @@ -259,7 +262,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: [ListFieldInput]! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, listValues: $value} }) { @@ -284,11 +287,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'listValues', $this->field_value ); @@ -316,9 +317,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -350,11 +350,11 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $actual_value = maybe_unserialize( $actual_entry[ $form['fields'][0]->id ], true ); // Convert to GraphQL ListFieldInput - $converted_value = array_map( fn( $value) => [ 'values' => array_values( $value ) ], $actual_value ); + $converted_value = array_map( static fn ( $value ) => [ 'values' => array_values( $value ) ], $actual_value ); $this->assertEquals( $this->field_value, $converted_value, 'Submit mutation entry value not equal' ); } diff --git a/tests/wpunit/ListFieldTest.php b/tests/wpunit/ListFieldTest.php index 1dfdfd76..cdc83ca6 100644 --- a/tests/wpunit/ListFieldTest.php +++ b/tests/wpunit/ListFieldTest.php @@ -19,30 +19,35 @@ class ListFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterf public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -111,10 +116,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on ListField { addIconUrl @@ -159,7 +162,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: [ListFieldInput]!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, listValues: $value}}) { @@ -192,7 +195,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: [ListFieldInput] ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, listValues: $value} }) { @@ -219,7 +222,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: [ListFieldInput]! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, listValues: $value} }) { @@ -244,11 +247,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'listValues', $this->field_value ); @@ -276,9 +277,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -310,11 +310,11 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $actual_value = maybe_unserialize( $actual_entry[ $form['fields'][0]->id ], true ); // Convert to GraphQL ListFieldInput - $converted_value = array_map( fn( $value) => [ 'values' => [ $value ] ], $actual_value ); + $converted_value = array_map( static fn ( $value ) => [ 'values' => [ $value ] ], $actual_value ); $this->assertEquals( $this->field_value, $converted_value, 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/MultiSelectFieldTest.php b/tests/wpunit/MultiSelectFieldTest.php index 06cde6e8..cc4f77ec 100644 --- a/tests/wpunit/MultiSelectFieldTest.php +++ b/tests/wpunit/MultiSelectFieldTest.php @@ -18,28 +18,32 @@ class MultiSelectFieldTest extends FormFieldTestCase implements FormFieldTestCas public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -67,7 +71,6 @@ public function field_value() { ]; } - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -84,13 +87,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return ' ... on MultiSelectField { adminLabel @@ -214,9 +214,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -246,9 +244,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/NameFieldTest.php b/tests/wpunit/NameFieldTest.php index bba60872..4e06d72a 100644 --- a/tests/wpunit/NameFieldTest.php +++ b/tests/wpunit/NameFieldTest.php @@ -17,28 +17,32 @@ class NameFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterf public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -104,10 +108,8 @@ public function updated_field_value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on NameField { adminLabel @@ -168,10 +170,8 @@ public function field_query() : string { /** * SubmitForm mutation string. - * - * @return string */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: NameFieldInput!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, nameValues: $value}}) { @@ -207,8 +207,6 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. - * - * @return string */ public function update_entry_mutation(): string { return ' @@ -240,8 +238,6 @@ public function update_entry_mutation(): string { /** * Returns the UpdateDraftEntry mutation string. - * - * @return string */ public function update_draft_entry_mutation(): string { return ' @@ -270,13 +266,11 @@ public function update_draft_entry_mutation(): string { } '; } + /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'nameValues', $this->field_value ); @@ -304,9 +298,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/NumberFieldTest.php b/tests/wpunit/NumberFieldTest.php index 53c42212..e0f8f5f3 100644 --- a/tests/wpunit/NumberFieldTest.php +++ b/tests/wpunit/NumberFieldTest.php @@ -18,28 +18,32 @@ class NumberFieldTest extends FormFieldTestCase implements FormFieldTestCaseInte public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +75,6 @@ public function updated_field_value() { return (string) $this->property_helper->dummy->number(); } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +84,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on NumberField { adminLabel @@ -131,7 +132,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -162,7 +163,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -187,7 +188,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -210,11 +211,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -242,9 +241,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -276,7 +274,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/OptionCheckboxFieldTest.php b/tests/wpunit/OptionCheckboxFieldTest.php index 7c5f0c44..37e54e8a 100644 --- a/tests/wpunit/OptionCheckboxFieldTest.php +++ b/tests/wpunit/OptionCheckboxFieldTest.php @@ -20,28 +20,32 @@ class OptionCheckboxFieldTest extends FormFieldTestCase implements FormFieldTest public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -71,7 +75,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -124,11 +128,10 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } - /** * The value as expected in GraphQL. */ @@ -247,7 +250,6 @@ public function updated_field_value_input() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -262,10 +264,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on OptionField { adminLabel @@ -336,7 +336,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: [CheckboxFieldInput]!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, checkboxValues: $value}}) { @@ -387,7 +387,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: [CheckboxFieldInput]! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, checkboxValues: $value} }) { @@ -417,7 +417,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: [CheckboxFieldInput]! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, checkboxValues: $value} }) { @@ -444,11 +444,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'checkboxValues', $this->field_value ); @@ -476,9 +474,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -505,7 +502,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value[0]['value'], $actual_entry[ $form['fields'][1]['inputs'][0]['id'] ] ); $this->assertEquals( $this->field_value[1]['value'], $actual_entry[ $form['fields'][1]['inputs'][1]['id'] ] ); $this->assertEquals( $this->field_value[2]['value'], $actual_entry[ $form['fields'][1]['inputs'][2]['id'] ] ); diff --git a/tests/wpunit/OptionRadioFieldTest.php b/tests/wpunit/OptionRadioFieldTest.php index fbb95677..b3ac8d39 100644 --- a/tests/wpunit/OptionRadioFieldTest.php +++ b/tests/wpunit/OptionRadioFieldTest.php @@ -20,28 +20,32 @@ class OptionRadioFieldTest extends FormFieldTestCase implements FormFieldTestCas public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -71,7 +75,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -103,7 +107,7 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } @@ -143,10 +147,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on OptionField { adminLabel @@ -191,7 +193,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -222,7 +224,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -248,7 +250,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -271,11 +273,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -303,9 +303,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -332,7 +331,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertStringStartsWith( $this->field_value_input(), $actual_entry[ $form['fields'][1]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/OptionSelectFieldTest.php b/tests/wpunit/OptionSelectFieldTest.php index b70cbf65..defe5cc6 100644 --- a/tests/wpunit/OptionSelectFieldTest.php +++ b/tests/wpunit/OptionSelectFieldTest.php @@ -20,28 +20,32 @@ class OptionSelectFieldTest extends FormFieldTestCase implements FormFieldTestCa public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -75,7 +79,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -110,11 +114,10 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } - /** * The value as expected in GraphQL. */ @@ -151,10 +154,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on OptionField { adminLabel @@ -202,7 +203,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -233,7 +234,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -259,7 +260,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -282,11 +283,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -314,9 +313,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -343,7 +341,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertStringStartsWith( $this->field_value_input, $actual_entry[ $form['fields'][1]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/PageFieldTest.php b/tests/wpunit/PageFieldTest.php index a227b256..c53c2fd9 100644 --- a/tests/wpunit/PageFieldTest.php +++ b/tests/wpunit/PageFieldTest.php @@ -29,7 +29,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -45,7 +45,6 @@ public function field_value() { public function updated_field_value() { return ''; } - /** * The value as expected by Gravity Forms. */ @@ -54,10 +53,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on PageField { conditionalLogic { @@ -105,29 +102,27 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ''; } /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ''; } /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ''; } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); return [ @@ -154,9 +149,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return []; } @@ -166,5 +160,5 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void {} + public function check_saved_values( $actual_entry, $form ): void {} } diff --git a/tests/wpunit/PhoneFieldTest.php b/tests/wpunit/PhoneFieldTest.php index f3a287cd..187b6d46 100644 --- a/tests/wpunit/PhoneFieldTest.php +++ b/tests/wpunit/PhoneFieldTest.php @@ -18,28 +18,32 @@ class PhoneFieldTest extends FormFieldTestCase implements FormFieldTestCaseInter public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -53,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +75,6 @@ public function updated_field_value() { return (string) $this->property_helper->dummy->telephone(); } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +84,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on PhoneField { adminLabel @@ -126,7 +127,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -157,7 +158,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -182,7 +183,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -205,11 +206,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -237,9 +236,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -271,7 +269,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/PostCategoryCheckboxFieldTest.php b/tests/wpunit/PostCategoryCheckboxFieldTest.php index 76dc1e23..0082cff4 100644 --- a/tests/wpunit/PostCategoryCheckboxFieldTest.php +++ b/tests/wpunit/PostCategoryCheckboxFieldTest.php @@ -18,14 +18,16 @@ public function setUp(): void { // Before... $this->cat_id_1 = self::factory()->category->create(); $this->cat_id_2 = self::factory()->category->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_category( $this->cat_id_1 ); wp_delete_category( $this->cat_id_2 ); + parent::tearDown(); } @@ -35,28 +37,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -70,7 +76,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -198,6 +204,7 @@ public function field_value_input() { ], ]; } + /** * The graphql field value input. */ @@ -239,8 +246,6 @@ public function updated_draft_field_value() { ]; } - - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -280,13 +285,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on PostCategoryField { adminLabel canPrepopulate @@ -466,9 +468,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -498,9 +498,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostCategoryMultiSelectFieldTest.php b/tests/wpunit/PostCategoryMultiSelectFieldTest.php index 61272a42..ce6f5808 100644 --- a/tests/wpunit/PostCategoryMultiSelectFieldTest.php +++ b/tests/wpunit/PostCategoryMultiSelectFieldTest.php @@ -19,14 +19,16 @@ public function setUp(): void { // Before... $this->cat_id_1 = self::factory()->category->create(); $this->cat_id_2 = self::factory()->category->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_category( $this->cat_id_1 ); wp_delete_category( $this->cat_id_2 ); + parent::tearDown(); } @@ -36,28 +38,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -71,7 +77,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -120,6 +126,7 @@ public function field_value_input() { $this->fields[0]['choices'][1]['value'], ]; } + /** * The graphql field value input. */ @@ -127,7 +134,6 @@ public function updated_field_value_input() { return [ $this->fields[0]['choices'][2]['value'] ]; } - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -146,13 +152,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return ' ... on PostCategoryField { adminLabel @@ -281,9 +284,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -313,9 +314,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostCategoryRadioFieldTest.php b/tests/wpunit/PostCategoryRadioFieldTest.php index 523717e6..62d1356b 100644 --- a/tests/wpunit/PostCategoryRadioFieldTest.php +++ b/tests/wpunit/PostCategoryRadioFieldTest.php @@ -18,14 +18,16 @@ public function setUp(): void { // Before... $this->cat_id_1 = self::factory()->category->create(); $this->cat_id_2 = self::factory()->category->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_category( $this->cat_id_1 ); wp_delete_category( $this->cat_id_2 ); + parent::tearDown(); } @@ -35,28 +37,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -70,7 +76,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -113,6 +119,7 @@ public function field_value() { public function field_value_input() { return $this->fields[0]['choices'][0]['value']; } + /** * The graphql field value input. */ @@ -127,7 +134,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['text'] . ':' . $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -135,13 +141,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->field_value_input ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on PostCategoryField { adminLabel canPrepopulate @@ -271,9 +274,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -303,9 +304,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostCategorySelectFieldTest.php b/tests/wpunit/PostCategorySelectFieldTest.php index 1531cbad..3489c605 100644 --- a/tests/wpunit/PostCategorySelectFieldTest.php +++ b/tests/wpunit/PostCategorySelectFieldTest.php @@ -18,14 +18,16 @@ public function setUp(): void { // Before... $this->cat_id_1 = self::factory()->category->create(); $this->cat_id_2 = self::factory()->category->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_category( $this->cat_id_1 ); wp_delete_category( $this->cat_id_2 ); + parent::tearDown(); } @@ -35,28 +37,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -70,7 +76,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -113,6 +119,7 @@ public function field_value() { public function field_value_input() { return $this->fields[0]['choices'][0]['value']; } + /** * The graphql field value input. */ @@ -127,7 +134,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['text'] . ':' . $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -135,13 +141,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->field_value_input ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on PostCategoryField { adminLabel canPrepopulate @@ -274,9 +277,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -306,9 +307,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostContentFieldTest.php b/tests/wpunit/PostContentFieldTest.php index d9a1b607..0c2b90bd 100644 --- a/tests/wpunit/PostContentFieldTest.php +++ b/tests/wpunit/PostContentFieldTest.php @@ -12,37 +12,42 @@ /** * Class -PostContentFieldTest. */ -class PostContentFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class PostContentFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +76,6 @@ public function updated_field_value() { return $this->property_helper->dummy->words( 1, 5 ); } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +85,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on PostContentField { adminLabel @@ -124,7 +126,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -155,7 +157,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -180,7 +182,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -203,11 +205,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -235,9 +235,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -269,7 +268,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/PostExcerptFieldTest.php b/tests/wpunit/PostExcerptFieldTest.php index 261a103f..f817016f 100644 --- a/tests/wpunit/PostExcerptFieldTest.php +++ b/tests/wpunit/PostExcerptFieldTest.php @@ -12,37 +12,42 @@ /** * Class -PostExcerptFieldTest. */ -class PostExcerptFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class PostExcerptFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +76,6 @@ public function updated_field_value() { return $this->property_helper->dummy->words( 1, 5 ); } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +85,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return '... on PostExcerptField { adminLabel canPrepopulate @@ -122,7 +124,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -153,7 +155,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -178,7 +180,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -201,11 +203,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -233,9 +233,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -267,7 +266,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/PostImageFieldTest.php b/tests/wpunit/PostImageFieldTest.php index 1f64ffef..b5d687c1 100644 --- a/tests/wpunit/PostImageFieldTest.php +++ b/tests/wpunit/PostImageFieldTest.php @@ -46,11 +46,11 @@ class PostImageFieldTest extends FormFieldTestCase implements FormFieldTestCaseI public function setUp(): void { // Before... - copy( dirname( __FILE__ ) . '/../_support/files/img1.png', '/tmp/img1.png' ); + copy( __DIR__ . '/../_support/files/img1.png', '/tmp/img1.png' ); $stat = stat( dirname( '/tmp/img1.png' ) ); $perms = $stat['mode'] & 0000666; chmod( '/tmp/img1.png', $perms ); - copy( dirname( __FILE__ ) . '/../_support/files/img2.png', '/tmp/img2.png' ); + copy( __DIR__ . '/../_support/files/img2.png', '/tmp/img2.png' ); $stat = stat( dirname( '/tmp/img2.png' ) ); $perms = $stat['mode'] & 0000666; chmod( '/tmp/img2.png', $perms ); @@ -73,34 +73,39 @@ public function tearDown(): void { parent::tearDown(); } + /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -114,7 +119,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -210,10 +215,8 @@ public function updated_field_value_input() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on PostImageField { adminLabel @@ -260,10 +263,8 @@ public function field_query() : string { /** * SubmitForm mutation string. - * - * @return string */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: ImageInput!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, imageValues: $value}}) { @@ -300,8 +301,6 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. - * - * @return string */ public function update_entry_mutation(): string { return ' @@ -334,8 +333,6 @@ public function update_entry_mutation(): string { /** * Returns the UpdateDraftEntry mutation string. - * - * @return string */ public function update_draft_entry_mutation(): string { return ' @@ -365,13 +362,11 @@ public function update_draft_entry_mutation(): string { } '; } + /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. - * @return array + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $value = $this->is_draft ? $this->draft_field_value : $this->field_value; @@ -405,9 +400,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { if ( empty( $value['url'] ) || $this->is_draft ) { unset( $value['url'] ); } diff --git a/tests/wpunit/PostTagsCheckboxFieldTest.php b/tests/wpunit/PostTagsCheckboxFieldTest.php index fb749c56..4229a3a7 100644 --- a/tests/wpunit/PostTagsCheckboxFieldTest.php +++ b/tests/wpunit/PostTagsCheckboxFieldTest.php @@ -20,15 +20,17 @@ public function setUp(): void { $this->tag_id_1 = self::factory()->tag->create(); $this->tag_id_2 = self::factory()->tag->create(); $this->tag_id_3 = self::factory()->tag->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_term( $this->tag_id_1, 'post_tag' ); wp_delete_term( $this->tag_id_2, 'post_tag' ); wp_delete_term( $this->tag_id_3, 'post_tag' ); + parent::tearDown(); } @@ -38,28 +40,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -73,7 +79,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -165,6 +171,7 @@ public function field_value_input() { ], ]; } + /** * The graphql field value input. */ @@ -186,8 +193,6 @@ public function updated_field_value_input() { ]; } - - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -221,13 +226,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on PostTagsField { adminLabel canPrepopulate @@ -378,9 +380,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -410,9 +410,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostTagsMultiSelectFieldTest.php b/tests/wpunit/PostTagsMultiSelectFieldTest.php index 77fbb306..3be819b3 100644 --- a/tests/wpunit/PostTagsMultiSelectFieldTest.php +++ b/tests/wpunit/PostTagsMultiSelectFieldTest.php @@ -21,15 +21,17 @@ public function setUp(): void { $this->tag_id_1 = self::factory()->tag->create(); $this->tag_id_2 = self::factory()->tag->create(); $this->tag_id_3 = self::factory()->tag->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_term( $this->tag_id_1, 'post_tag' ); wp_delete_term( $this->tag_id_2, 'post_tag' ); wp_delete_term( $this->tag_id_3, 'post_tag' ); + parent::tearDown(); } @@ -39,28 +41,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -74,7 +80,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -123,6 +129,7 @@ public function field_value_input() { $this->fields[0]['choices'][1]['value'], ]; } + /** * The graphql field value input. */ @@ -130,7 +137,6 @@ public function updated_field_value_input() { return [ $this->fields[0]['choices'][2]['value'] ]; } - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -149,13 +155,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return ' ... on PostTagsField { adminLabel @@ -283,9 +286,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -315,9 +316,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostTagsRadioFieldTest.php b/tests/wpunit/PostTagsRadioFieldTest.php index f39fe3a6..3a6d7e63 100644 --- a/tests/wpunit/PostTagsRadioFieldTest.php +++ b/tests/wpunit/PostTagsRadioFieldTest.php @@ -20,15 +20,17 @@ public function setUp(): void { $this->tag_id_1 = self::factory()->tag->create(); $this->tag_id_2 = self::factory()->tag->create(); $this->tag_id_3 = self::factory()->tag->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_term( $this->tag_id_1, 'post_tag' ); wp_delete_term( $this->tag_id_2, 'post_tag' ); wp_delete_term( $this->tag_id_3, 'post_tag' ); + parent::tearDown(); } @@ -38,28 +40,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -73,7 +79,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -116,6 +122,7 @@ public function field_value() { public function field_value_input() { return $this->fields[0]['choices'][0]['value']; } + /** * The graphql field value input. */ @@ -130,7 +137,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -138,13 +144,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->field_value_input ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on PostTagsField { adminLabel canPrepopulate @@ -273,9 +276,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -305,9 +306,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostTagsTextFieldTest.php b/tests/wpunit/PostTagsTextFieldTest.php index ae37a079..19ba17fd 100644 --- a/tests/wpunit/PostTagsTextFieldTest.php +++ b/tests/wpunit/PostTagsTextFieldTest.php @@ -20,15 +20,17 @@ public function setUp(): void { $this->tag_id_1 = self::factory()->tag->create(); $this->tag_id_2 = self::factory()->tag->create(); $this->tag_id_3 = self::factory()->tag->create(); + parent::setUp(); $this->clearSchema(); } - public function tearDown() : void { + public function tearDown(): void { wp_delete_term( $this->tag_id_1, 'post_tag' ); wp_delete_term( $this->tag_id_2, 'post_tag' ); wp_delete_term( $this->tag_id_3, 'post_tag' ); + parent::tearDown(); } @@ -38,28 +40,32 @@ public function tearDown() : void { public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -73,7 +79,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -105,13 +111,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->field_value_input ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on PostTagsField { adminLabel canPrepopulate @@ -237,9 +240,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -269,9 +270,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/PostTitleFieldTest.php b/tests/wpunit/PostTitleFieldTest.php index 56369565..49b082db 100644 --- a/tests/wpunit/PostTitleFieldTest.php +++ b/tests/wpunit/PostTitleFieldTest.php @@ -12,37 +12,42 @@ /** * Class -PostTitleFieldTest. */ -class PostTitleFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class PostTitleFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +76,6 @@ public function updated_field_value() { return $this->property_helper->dummy->words( 1, 5 ); } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +85,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on PostTitleField { adminLabel @@ -122,7 +124,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -153,7 +155,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -178,7 +180,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -201,11 +203,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -233,9 +233,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -267,7 +266,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/ProductCalculationFieldTest.php b/tests/wpunit/ProductCalculationFieldTest.php index 3ec4bf9a..39a5e9ce 100644 --- a/tests/wpunit/ProductCalculationFieldTest.php +++ b/tests/wpunit/ProductCalculationFieldTest.php @@ -17,28 +17,32 @@ class ProductCalculationFieldTest extends FormFieldTestCase implements FormField public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { $label = $this->property_helper->dummy->words( 2 ); return [ $this->factory->field->create( @@ -131,7 +135,6 @@ public function updated_field_value() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -143,13 +146,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on ProductField { adminLabel canPrepopulate @@ -278,9 +278,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -310,9 +308,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ProductHiddenFieldTest.php b/tests/wpunit/ProductHiddenFieldTest.php index 5c717f39..08d1b522 100644 --- a/tests/wpunit/ProductHiddenFieldTest.php +++ b/tests/wpunit/ProductHiddenFieldTest.php @@ -17,28 +17,32 @@ class ProductHiddenFieldTest extends FormFieldTestCase implements FormFieldTestC public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -118,7 +122,6 @@ public function updated_field_value() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -130,13 +133,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on ProductField { adminLabel canPrepopulate @@ -261,9 +261,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -293,9 +291,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ProductPriceFieldTest.php b/tests/wpunit/ProductPriceFieldTest.php index 658c58dd..1fe65da8 100644 --- a/tests/wpunit/ProductPriceFieldTest.php +++ b/tests/wpunit/ProductPriceFieldTest.php @@ -17,28 +17,32 @@ class ProductPriceFieldTest extends FormFieldTestCase implements FormFieldTestCa public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -100,7 +104,6 @@ public function updated_field_value() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -108,13 +111,10 @@ public function value() { return [ $this->fields[0]['id'] => $this->field_value_input ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on ProductField { adminLabel canPrepopulate @@ -242,9 +242,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -274,9 +272,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ProductRadioFieldTest.php b/tests/wpunit/ProductRadioFieldTest.php index 2b82c3ea..f474c940 100644 --- a/tests/wpunit/ProductRadioFieldTest.php +++ b/tests/wpunit/ProductRadioFieldTest.php @@ -17,28 +17,32 @@ class ProductRadioFieldTest extends FormFieldTestCase implements FormFieldTestCa public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -124,7 +128,6 @@ public function updated_field_value() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -132,13 +135,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->fields[0]->choices[0]['value'] . '|5' ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on ProductField { adminLabel canPrepopulate @@ -276,9 +276,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -308,9 +306,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ProductSelectFieldTest.php b/tests/wpunit/ProductSelectFieldTest.php index a86feadc..26e5c886 100644 --- a/tests/wpunit/ProductSelectFieldTest.php +++ b/tests/wpunit/ProductSelectFieldTest.php @@ -17,28 +17,32 @@ class ProductSelectFieldTest extends FormFieldTestCase implements FormFieldTestC public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -126,7 +130,6 @@ public function updated_field_value() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -134,13 +137,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->fields[0]->choices[0]['value'] . '|5' ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on ProductField { adminLabel canPrepopulate @@ -281,9 +281,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -313,9 +311,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/ProductSingleFieldTest.php b/tests/wpunit/ProductSingleFieldTest.php index 043a3641..2ccc2c38 100644 --- a/tests/wpunit/ProductSingleFieldTest.php +++ b/tests/wpunit/ProductSingleFieldTest.php @@ -17,28 +17,32 @@ class ProductSingleFieldTest extends FormFieldTestCase implements FormFieldTestC public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -119,7 +123,6 @@ public function updated_field_value() { ]; } - /** * The value as expected by Gravity Forms. */ @@ -131,13 +134,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on ProductField { adminLabel canPrepopulate @@ -273,9 +273,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -305,9 +303,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/QuantityHiddenFieldTest.php b/tests/wpunit/QuantityHiddenFieldTest.php index 8f2e1db4..d735badb 100644 --- a/tests/wpunit/QuantityHiddenFieldTest.php +++ b/tests/wpunit/QuantityHiddenFieldTest.php @@ -20,28 +20,32 @@ class QuantityHiddenFieldTest extends FormFieldTestCase implements FormFieldTest public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -71,7 +75,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -101,11 +105,10 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } - /** * The value as expected in GraphQL. */ @@ -128,7 +131,6 @@ public function updated_field_value_input() { return $this->updated_field_value; } - /** * The value as expected by Gravity Forms. */ @@ -142,10 +144,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on QuantityField { adminLabel @@ -176,7 +176,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -207,7 +207,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -233,7 +233,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -256,11 +256,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -288,9 +286,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -317,7 +314,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][1]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/QuantityNumberFieldTest.php b/tests/wpunit/QuantityNumberFieldTest.php index 6a067453..2df17d7a 100644 --- a/tests/wpunit/QuantityNumberFieldTest.php +++ b/tests/wpunit/QuantityNumberFieldTest.php @@ -20,28 +20,32 @@ class QuantityNumberFieldTest extends FormFieldTestCase implements FormFieldTest public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -78,7 +82,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -108,11 +112,10 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } - /** * The value as expected in GraphQL. */ @@ -135,7 +138,6 @@ public function updated_field_value_input() { return $this->updated_field_value; } - /** * The value as expected by Gravity Forms. */ @@ -149,10 +151,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on QuantityField { adminLabel @@ -195,7 +195,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -226,7 +226,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -252,7 +252,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -275,11 +275,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -307,9 +305,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -336,7 +333,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][1]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/QuantitySelectFieldTest.php b/tests/wpunit/QuantitySelectFieldTest.php index a4c26840..96a3569d 100644 --- a/tests/wpunit/QuantitySelectFieldTest.php +++ b/tests/wpunit/QuantitySelectFieldTest.php @@ -20,28 +20,32 @@ class QuantitySelectFieldTest extends FormFieldTestCase implements FormFieldTest public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -80,7 +84,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -136,7 +140,7 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } @@ -162,7 +166,6 @@ public function updated_field_value_input() { return $this->updated_field_value; } - /** * The value as expected by Gravity Forms. */ @@ -176,10 +179,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on QuantityField { adminLabel @@ -227,7 +228,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -258,7 +259,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -284,7 +285,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -307,11 +308,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -339,9 +338,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -368,7 +366,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][1]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/QuizCheckboxFieldTest.php b/tests/wpunit/QuizCheckboxFieldTest.php index 80b24426..ea8b6ab4 100644 --- a/tests/wpunit/QuizCheckboxFieldTest.php +++ b/tests/wpunit/QuizCheckboxFieldTest.php @@ -17,28 +17,32 @@ class QuizCheckboxFieldTest extends FormFieldTestCase implements FormFieldTestCa public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -159,6 +163,7 @@ public function field_value_input() { ], ]; } + /** * The graphql field value input. */ @@ -180,8 +185,6 @@ public function updated_field_value_input() { ]; } - - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -215,13 +218,10 @@ public function value() { ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on QuizField { adminLabel answerExplanation @@ -375,9 +375,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -407,9 +405,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/QuizRadioFieldTest.php b/tests/wpunit/QuizRadioFieldTest.php index e1a1512a..288e02b1 100644 --- a/tests/wpunit/QuizRadioFieldTest.php +++ b/tests/wpunit/QuizRadioFieldTest.php @@ -17,28 +17,32 @@ class QuizRadioFieldTest extends FormFieldTestCase implements FormFieldTestCaseI public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -110,6 +114,7 @@ public function field_value() { public function field_value_input() { return $this->fields[0]['choices'][0]['text']; } + /** * The graphql field value input. */ @@ -117,8 +122,6 @@ public function updated_field_value_input() { return $this->fields[0]['choices'][2]['text']; } - - /** * The value as expected in GraphQL when updating from field_value(). */ @@ -126,7 +129,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['text']; } - /** * The value as expected by Gravity Forms. */ @@ -134,13 +136,10 @@ public function value() { return [ (string) $this->fields[0]['id'] => $this->field_value_input ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on QuizField { adminLabel answerExplanation @@ -272,9 +271,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -304,9 +301,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/QuizSelectFieldTest.php b/tests/wpunit/QuizSelectFieldTest.php index 49e84720..47360d91 100644 --- a/tests/wpunit/QuizSelectFieldTest.php +++ b/tests/wpunit/QuizSelectFieldTest.php @@ -17,28 +17,32 @@ class QuizSelectFieldTest extends FormFieldTestCase implements FormFieldTestCase public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrapped in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -111,7 +115,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -119,13 +122,10 @@ public function value() { return [ $this->fields[0]['id'] => $this->field_value ]; } - /** * The GraphQL query string. - * - * @return string */ - public function field_query():string { + public function field_query(): string { return '... on QuizField { adminLabel answerExplanation @@ -262,9 +262,7 @@ public function update_draft_entry_mutation(): string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); @@ -294,9 +292,8 @@ public function expected_field_response( array $form ): array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ):array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, diff --git a/tests/wpunit/RadioFieldTest.php b/tests/wpunit/RadioFieldTest.php index 1852b581..bc1c4dde 100644 --- a/tests/wpunit/RadioFieldTest.php +++ b/tests/wpunit/RadioFieldTest.php @@ -12,37 +12,42 @@ /** * Class -RadioFieldTest. */ -class RadioFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class RadioFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +76,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +85,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return '... on RadioField { adminLabel canPrepopulate @@ -129,7 +131,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -160,7 +162,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -185,7 +187,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -208,11 +210,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -240,9 +240,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -274,7 +273,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/SectionFieldTest.php b/tests/wpunit/SectionFieldTest.php index ef8c0e79..5dfa7e3a 100644 --- a/tests/wpunit/SectionFieldTest.php +++ b/tests/wpunit/SectionFieldTest.php @@ -28,7 +28,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -44,7 +44,6 @@ public function field_value() { public function updated_field_value() { return ''; } - /** * The value as expected by Gravity Forms. */ @@ -54,10 +53,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on SectionField { conditionalLogic { @@ -78,29 +75,27 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ''; } /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ''; } /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ''; } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); return [ @@ -127,9 +122,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return []; } @@ -139,5 +133,5 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void {} + public function check_saved_values( $actual_entry, $form ): void {} } diff --git a/tests/wpunit/SelectFieldTest.php b/tests/wpunit/SelectFieldTest.php index d3e2d592..6fa7abc4 100644 --- a/tests/wpunit/SelectFieldTest.php +++ b/tests/wpunit/SelectFieldTest.php @@ -12,37 +12,42 @@ /** * Class -SelectFieldTest. */ -class SelectFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class SelectFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -71,7 +76,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -81,10 +85,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on SelectField { adminLabel @@ -134,7 +136,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -165,7 +167,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -190,7 +192,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -213,11 +215,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -245,9 +245,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -279,7 +278,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/SettingsTest.php b/tests/wpunit/SettingsTest.php index ab40d944..6a997e3c 100644 --- a/tests/wpunit/SettingsTest.php +++ b/tests/wpunit/SettingsTest.php @@ -1,7 +1,6 @@ assertQuerySuccessful( $response, $expected ); } - public function expected_field_response() : array { + public function expected_field_response(): array { return [ $this->expectedObject( 'gfSettings', diff --git a/tests/wpunit/ShippingRadioFieldTest.php b/tests/wpunit/ShippingRadioFieldTest.php index 7b1da760..a694b79d 100644 --- a/tests/wpunit/ShippingRadioFieldTest.php +++ b/tests/wpunit/ShippingRadioFieldTest.php @@ -17,28 +17,32 @@ class ShippingRadioFieldTest extends FormFieldTestCase implements FormFieldTestC public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -63,7 +67,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -110,7 +114,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -120,10 +123,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on ShippingField { adminLabel @@ -165,7 +166,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -196,7 +197,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -221,7 +222,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -244,11 +245,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -276,9 +275,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -310,7 +308,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/ShippingSelectFieldTest.php b/tests/wpunit/ShippingSelectFieldTest.php index b6010c83..99f16044 100644 --- a/tests/wpunit/ShippingSelectFieldTest.php +++ b/tests/wpunit/ShippingSelectFieldTest.php @@ -17,28 +17,32 @@ class ShippingSelectFieldTest extends FormFieldTestCase implements FormFieldTest public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -65,7 +69,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -112,7 +116,6 @@ public function updated_field_value() { return $this->fields[0]['choices'][2]['value']; } - /** * The value as expected by Gravity Forms. */ @@ -122,10 +125,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on ShippingField { adminLabel @@ -171,7 +172,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -202,7 +203,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -227,7 +228,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -250,11 +251,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -282,9 +281,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -316,7 +314,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/ShippingSingleFieldTest.php b/tests/wpunit/ShippingSingleFieldTest.php index 61457e2e..12d2d12c 100644 --- a/tests/wpunit/ShippingSingleFieldTest.php +++ b/tests/wpunit/ShippingSingleFieldTest.php @@ -17,28 +17,32 @@ class ShippingSingleFieldTest extends FormFieldTestCase implements FormFieldTest public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -77,7 +81,6 @@ public function updated_field_value() { return $this->property_helper->basePrice(); } - /** * The value as expected by Gravity Forms. */ @@ -87,10 +90,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on ShippingField { adminLabel @@ -119,7 +120,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -150,7 +151,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -175,7 +176,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -198,11 +199,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -230,9 +229,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -264,7 +262,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/SignatureFieldTest.php b/tests/wpunit/SignatureFieldTest.php index 5fb919a4..e99cb404 100644 --- a/tests/wpunit/SignatureFieldTest.php +++ b/tests/wpunit/SignatureFieldTest.php @@ -11,37 +11,42 @@ /** * Class -SignatureFieldTest. */ -class SignatureFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class SignatureFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -52,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -87,10 +92,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on SignatureField { adminLabel @@ -130,7 +133,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -161,7 +164,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -186,7 +189,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -209,11 +212,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); // $expected[] = $this->expected_field_value( 'value', $this->factory->entry->get_object_by_id( $this->entry_id )[ $form['fields'][0]->id ] ); @@ -241,9 +242,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -257,7 +257,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr $this->expectedNode( 'nodes', [ - $this->expected_field_value( 'value', static::NOT_FALSY ), + $this->expected_field_value( 'value', self::NOT_FALSY ), ] ), ] @@ -275,7 +275,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertStringEndsWith( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/SubmitDraftEntryMutationTest.php b/tests/wpunit/SubmitDraftEntryMutationTest.php index 57f80c9a..1f137dc6 100644 --- a/tests/wpunit/SubmitDraftEntryMutationTest.php +++ b/tests/wpunit/SubmitDraftEntryMutationTest.php @@ -16,7 +16,6 @@ class SubmitDraftEntryMutationTest extends GFGraphQLTestCase { private $draft_token; private $text_field_helper; - /** * Run before each test. */ @@ -57,7 +56,7 @@ public function tearDown(): void { /** * Tests `submitGfDraft */ - public function testSubmitGravityFormsDraftEntry() : void { + public function testSubmitGravityFormsDraftEntry(): void { $query = $this->submit_mutation(); $variables = [ @@ -80,7 +79,7 @@ public function testSubmitGravityFormsDraftEntry() : void { $this->factory->entry->delete( $expected['id'] ); } - public function testSubmitWithUrlConfirmation() : void { + public function testSubmitWithUrlConfirmation(): void { $form = GFAPI::get_form( $this->form_id ); $confirmation_id = array_keys( $form['confirmations'] )[0]; @@ -116,7 +115,7 @@ public function testSubmitWithUrlConfirmation() : void { $this->factory->entry->delete( $expected['id'] ); } - public function testSubmitWithPageConfirmation() : void { + public function testSubmitWithPageConfirmation(): void { $form = GFAPI::get_form( $this->form_id ); $page_id = $this->factory()->post->create( [ @@ -163,7 +162,7 @@ public function testSubmitWithPageConfirmation() : void { /** * Creates the mutation. */ - public function submit_mutation() : string { + public function submit_mutation(): string { return ' mutation submitGfDraftEntry ( $id: ID! diff --git a/tests/wpunit/SubmitFormMutationTest.php b/tests/wpunit/SubmitFormMutationTest.php index 8facc122..73261b6e 100644 --- a/tests/wpunit/SubmitFormMutationTest.php +++ b/tests/wpunit/SubmitFormMutationTest.php @@ -24,12 +24,12 @@ public function setUp(): void { /** * Tests `submitGfDraft */ - public function testSubmitFormWithEmptyFieldValues() : void { + public function testSubmitFormWithEmptyFieldValues(): void { // Create Form. $helper = $this->tester->getPropertyHelper( 'TextField' ); $fields = [ $this->factory->field->create( $helper->values ) ]; $form_id = $this->factory->form->create( array_merge( [ 'fields' => $fields ], $this->tester->getFormDefaultArgs() ) ); - + $query = $this->submit_mutation(); // Test with errors. @@ -57,7 +57,7 @@ public function testSubmitFormWithEmptyFieldValues() : void { $this->assertNotEmpty( $actual['data']['submitGfForm']['errors'][0]['message'] ); } - public function testSubmitForm() : void { + public function testSubmitForm(): void { // Create Form. $helper = $this->tester->getPropertyHelper( 'TextField' ); $fields = [ $this->factory->field->create( $helper->values ) ]; @@ -103,13 +103,12 @@ public function testSubmitForm() : void { $this->assertNotEmpty( $actual['data']['submitGfForm']['entry']['sourceUrl'] ); $this->assertEmpty( $actual['data']['submitGfForm']['entry']['userAgent'] ); - // Cleanup $this->factory->entry->delete( $actual['data']['submitGfForm']['entry']['databaseId'] ); $this->factory->form->delete( $form_id ); } - public function testSubmitWithUrlConfirmation() : void { + public function testSubmitWithUrlConfirmation(): void { // Create Form. $helper = $this->tester->getPropertyHelper( 'TextField' ); $fields = [ $this->factory->field->create( $helper->values ) ]; @@ -167,7 +166,7 @@ public function testSubmitWithUrlConfirmation() : void { $this->factory->form->delete( $form_id ); } - public function testSubmitWithPageConfirmation() : void { + public function testSubmitWithPageConfirmation(): void { // Create page. $page_id = $this->factory()->post->create( [ @@ -200,7 +199,7 @@ public function testSubmitWithPageConfirmation() : void { ], ], ] - ) + ) ); $query = $this->submit_mutation(); @@ -234,7 +233,7 @@ public function testSubmitWithPageConfirmation() : void { $this->factory->form->delete( $form_id ); } - public function testSubmitWithLoggedInUser() : void { + public function testSubmitWithLoggedInUser(): void { // Create Form. $helper = $this->tester->getPropertyHelper( 'TextField' ); $fields = [ $this->factory->field->create( $helper->values ) ]; @@ -256,7 +255,6 @@ public function testSubmitWithLoggedInUser() : void { ], ]; - wp_set_current_user( $this->admin->ID ); $actual = $this->graphql( compact( 'query', 'variables' ) ); @@ -274,7 +272,7 @@ public function testSubmitWithLoggedInUser() : void { $this->factory->form->delete( $form_id ); } - public function testSubmitWithEntryMeta() : void { + public function testSubmitWithEntryMeta(): void { // Create Form. $helper = $this->tester->getPropertyHelper( 'TextField' ); $fields = [ $this->factory->field->create( $helper->values ) ]; @@ -321,7 +319,7 @@ public function testSubmitWithEntryMeta() : void { $this->factory->form->delete( $form_id ); } - public function testSubmitWithPostCreation() : void { + public function testSubmitWithPostCreation(): void { $category = $this->factory->category->create_and_get(); $tag = $this->factory->tag->create_and_get(); @@ -489,7 +487,7 @@ public function testSubmitWithPostCreation() : void { wp_delete_post( $actual['data']['submitGfForm']['entry']['post']['databaseId'], true ); } - public function testSubmitWithOrderItems() : void { + public function testSubmitWithOrderItems(): void { // Create Form. $fields = [ @@ -538,7 +536,7 @@ public function testSubmitWithOrderItems() : void { ] )->values, [ - + 'inputs' => [ [ 'id' => 2.1, @@ -617,7 +615,7 @@ public function testSubmitWithOrderItems() : void { $this->tester->getFormDefaultArgs(), [ 'fields' => $fields, - + ], ) ); @@ -719,7 +717,7 @@ public function testSubmitWithOrderItems() : void { /** * Creates the mutation. */ - public function submit_mutation() : string { + public function submit_mutation(): string { return 'mutation SubmitForm( $input:SubmitGfFormInput! ) { submitGfForm(input:$input) { confirmation{ diff --git a/tests/wpunit/TextAreaFieldTest.php b/tests/wpunit/TextAreaFieldTest.php index beb19c29..436692e9 100644 --- a/tests/wpunit/TextAreaFieldTest.php +++ b/tests/wpunit/TextAreaFieldTest.php @@ -11,37 +11,42 @@ /** * Class -TextAreaFieldTest. */ -class TextAreaFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class TextAreaFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -52,7 +57,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -70,7 +75,6 @@ public function updated_field_value() { return $this->property_helper->dummy->words( 1, 5 ); } - /** * The value as expected by Gravity Forms. */ @@ -80,10 +84,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on TextAreaField { adminLabel @@ -124,7 +126,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -155,7 +157,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -180,7 +182,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -203,11 +205,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -235,9 +235,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -269,7 +268,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/TextFieldTest.php b/tests/wpunit/TextFieldTest.php index e5bba989..13af5514 100644 --- a/tests/wpunit/TextFieldTest.php +++ b/tests/wpunit/TextFieldTest.php @@ -17,28 +17,32 @@ class TextFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterf public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -70,7 +74,6 @@ public function updated_field_value() { return $this->property_helper->dummy->words( 1, 5 ); } - /** * The value as expected by Gravity Forms. */ @@ -80,10 +83,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on TextField { adminLabel @@ -128,7 +129,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -159,7 +160,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -184,7 +185,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -207,11 +208,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -239,9 +238,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -273,7 +271,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/TimeFieldTest.php b/tests/wpunit/TimeFieldTest.php index a59f6b1f..03e0cb6a 100644 --- a/tests/wpunit/TimeFieldTest.php +++ b/tests/wpunit/TimeFieldTest.php @@ -12,37 +12,42 @@ /** * Class -TimeFieldTest. */ -class TimeFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { +class TimeFieldTest extends FormFieldTestCase implements FormFieldTestCaseInterface { /** * Tests the field properties and values. */ public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } + /** * Sets the correct Field Helper. */ @@ -53,7 +58,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -89,7 +94,6 @@ public function updated_field_value_input() { return $this->updated_field_value['displayValue']; } - /** * The value as expected by Gravity Forms. */ @@ -99,10 +103,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on TimeField { adminLabel @@ -154,7 +156,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -190,7 +192,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -220,7 +222,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -248,11 +250,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'timeValues', $this->field_value ); @@ -280,9 +280,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -314,7 +313,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value['displayValue'], $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/TotalFieldTest.php b/tests/wpunit/TotalFieldTest.php index 1b1bbd26..1f648401 100644 --- a/tests/wpunit/TotalFieldTest.php +++ b/tests/wpunit/TotalFieldTest.php @@ -20,28 +20,32 @@ class TotalFieldTest extends FormFieldTestCase implements FormFieldTestCaseInter public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -68,7 +72,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( array_merge( @@ -98,11 +102,10 @@ public function generate_fields() : array { ]; } - public function mutation_value_field_id() : int { + public function mutation_value_field_id(): int { return $this->fields[1]->id; } - /** * The value as expected in GraphQL. */ @@ -125,7 +128,6 @@ public function updated_field_value_input() { return '$' . (string) $this->updated_field_value; } - /** * The value as expected by Gravity Forms. */ @@ -140,10 +142,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on TotalField { adminLabel @@ -166,7 +166,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: [ @@ -200,7 +200,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: [ @@ -229,7 +229,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: {id: $resumeToken, idType: RESUME_TOKEN, shouldValidate: true, fieldValues: [ @@ -255,11 +255,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][1] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -287,9 +285,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -316,7 +313,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][1]->id ], 'Submit mutation entry value not equal' ); } } diff --git a/tests/wpunit/UpdateDraftEntryMutationTest.php b/tests/wpunit/UpdateDraftEntryMutationTest.php index 3a64bf9b..201cdcb7 100644 --- a/tests/wpunit/UpdateDraftEntryMutationTest.php +++ b/tests/wpunit/UpdateDraftEntryMutationTest.php @@ -18,7 +18,6 @@ class UpdateDraftEntryMutationTest extends GFGraphQLTestCase { private $draft_token; private $text_field_helper; - /** * Run before each test. */ @@ -60,7 +59,7 @@ public function tearDown(): void { /** * Tests `updateGfDraft */ - public function testUpdateGfDraftEntry() : void { + public function testUpdateGfDraftEntry(): void { $query = $this->update_mutation(); $variables = [ @@ -95,7 +94,7 @@ public function testUpdateGfDraftEntry() : void { $this->assertEquals( $variables['fieldValues'][0]['value'], $response['data']['updateGfDraftEntry']['draftEntry']['formFields']['nodes'][0]['value'], 'Field values dont match' ); } - public function update_mutation() : string { + public function update_mutation(): string { return ' mutation updateGfDraftEntry ( $id: ID!, diff --git a/tests/wpunit/UpdateEntryMutationTest.php b/tests/wpunit/UpdateEntryMutationTest.php index 4bbfc599..57a4141b 100644 --- a/tests/wpunit/UpdateEntryMutationTest.php +++ b/tests/wpunit/UpdateEntryMutationTest.php @@ -9,7 +9,6 @@ use Tests\WPGraphQL\GF\TestCase\GFGraphQLTestCase; use WPGraphQL\GF\Data\Loader\EntriesLoader; use WPGraphQL\GF\Type\Enum\EntryStatusEnum; -use WPGraphQL\GF\Utils\GFUtils; /** * Class - UpdateEntryMutationTest @@ -20,7 +19,6 @@ class UpdateEntryMutationTest extends GFGraphQLTestCase { private $entry_id; private $text_field_helper; - /** * Run before each test. */ @@ -60,7 +58,7 @@ public function tearDown(): void { /** * Tests `updateGfDraft */ - public function testUpdateGfEntry() : void { + public function testUpdateGfEntry(): void { $query = $this->update_mutation(); $variables = [ @@ -110,7 +108,7 @@ public function testUpdateGfEntry() : void { $this->assertEquals( $variables['fieldValues'][0]['value'], $response['data']['updateGfEntry']['entry']['formFields']['nodes'][0]['value'], 'Field values dont match' ); } - public function update_mutation() : string { + public function update_mutation(): string { return ' mutation updateGfEntry ( $id: ID!, diff --git a/tests/wpunit/WebsiteFieldTest.php b/tests/wpunit/WebsiteFieldTest.php index 958a9055..ab0dd272 100644 --- a/tests/wpunit/WebsiteFieldTest.php +++ b/tests/wpunit/WebsiteFieldTest.php @@ -17,28 +17,32 @@ class WebsiteFieldTest extends FormFieldTestCase implements FormFieldTestCaseInt public function testField(): void { $this->runTestField(); } + /** * Tests submitting the field values as a draft entry with submitGfForm. */ public function testSubmitDraft(): void { $this->runTestSubmitDraft(); } + /** * Tests submitting the field values as an entry with submitGfForm. */ public function testSubmitForm(): void { $this->runtestSubmitForm(); } + /** * Tests updating the field value with updateGfEntry. */ public function testUpdateEntry(): void { $this->runtestUpdateEntry(); } + /** * Tests updating the draft field value with updateGfEntry. */ - public function testUpdateDraft():void { + public function testUpdateDraft(): void { $this->runTestUpdateDraft(); } @@ -52,7 +56,7 @@ public function field_helper() { /** * Generates the form fields from factory. Must be wrappend in an array. */ - public function generate_fields() : array { + public function generate_fields(): array { return [ $this->factory->field->create( $this->property_helper->values ) ]; } @@ -70,7 +74,6 @@ public function updated_field_value() { return 'https://www.' . $this->property_helper->dummy->words( 1 ) . '.co.uk'; } - /** * The value as expected by Gravity Forms. */ @@ -80,10 +83,8 @@ public function value() { /** * The GraphQL query string. - * - * @return string */ - public function field_query() : string { + public function field_query(): string { return ' ... on WebsiteField { adminLabel @@ -122,7 +123,7 @@ public function field_query() : string { /** * SubmitForm mutation string. */ - public function submit_form_mutation() : string { + public function submit_form_mutation(): string { return ' mutation ($formId: ID!, $fieldId: Int!, $value: String!, $draft: Boolean) { submitGfForm( input: { id: $formId, saveAsDraft: $draft, fieldValues: {id: $fieldId, value: $value}}) { @@ -153,7 +154,7 @@ public function submit_form_mutation() : string { /** * Returns the UpdateEntry mutation string. */ - public function update_entry_mutation() : string { + public function update_entry_mutation(): string { return ' mutation updateGfEntry( $entryId: ID!, $fieldId: Int!, $value: String! ){ updateGfEntry( input: { id: $entryId, shouldValidate: true, fieldValues: {id: $fieldId, value: $value} }) { @@ -178,7 +179,7 @@ public function update_entry_mutation() : string { /** * Returns the UpdateDraftEntry mutation string. */ - public function update_draft_entry_mutation() : string { + public function update_draft_entry_mutation(): string { return ' mutation updateGfDraftEntry( $resumeToken: ID!, $fieldId: Int!, $value: String! ){ updateGfDraftEntry( input: { id: $resumeToken, idType: RESUME_TOKEN, fieldValues: {id: $fieldId, value: $value} } ) { @@ -201,11 +202,9 @@ public function update_draft_entry_mutation() : string { } /** - * The expected WPGraphQL field response. - * - * @param array $form the current form instance. + * {@inheritDoc} */ - public function expected_field_response( array $form ) : array { + public function expected_field_response( array $form ): array { $expected = $this->getExpectedFormFieldValues( $form['fields'][0] ); $expected[] = $this->expected_field_value( 'value', $this->field_value ); @@ -233,9 +232,8 @@ public function expected_field_response( array $form ) : array { * * @param string $mutationName . * @param mixed $value . - * @return array */ - public function expected_mutation_response( string $mutationName, $value ) : array { + public function expected_mutation_response( string $mutationName, $value ): array { return [ $this->expectedObject( $mutationName, @@ -267,7 +265,7 @@ public function expected_mutation_response( string $mutationName, $value ) : arr * @param array $actual_entry . * @param array $form . */ - public function check_saved_values( $actual_entry, $form ) : void { + public function check_saved_values( $actual_entry, $form ): void { $this->assertEquals( $this->field_value, $actual_entry[ $form['fields'][0]->id ], 'Submit mutation entry value not equal' ); } }