Skip to content

Commit

Permalink
chore: update deps, backfill tests, cleanup readme links (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine authored Jun 12, 2024
1 parent d5b1ea8 commit 8043eb5
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 187 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- chore: Declare `strict_types` in all PHP files.
- chore: Update Composer dev-dependencies and fix test compatibility with `wp-graphql-test-case` v3.0.x.
- docs: Add docs on using Multi-page forms.
- tests: Add test for `GFUtils::get_last_form_page()`.

## v0.12.6.1

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

A WordPress plugin that adds <a href="https://wpgraphql.com" target="_blank">WPGraphQL</a> support for <a href="https://gravityforms.com" target="_blank">Gravity Forms</a>.

* [Join the WPGraphQL community on Slack.](https://join.slack.com/t/wp-graphql/shared_invite/zt-3vloo60z-PpJV2PFIwEathWDOxCTTLA)
* [Join the WPGraphQL community on Discord.](https://discord.gg/Hp6fQbqvwe)
* [Documentation](#documentation)

-----
Expand Down Expand Up @@ -58,7 +58,7 @@ v0.x.y.z: "Patch" releases. These releases are reserved for addressing issue wit

Development of WPGraphQL for Gravity Forms is provided by [AxePress Development](https://axepress.dev). Community contributions are _welcome_ and **encouraged**.

Basic support is provided for free, both in [this repo](https://github.com/axewp/wp-graphql-gravity-forms/issues) and in [WPGraphQL Slack](https://join.slack.com/t/wp-graphql/shared_invite/zt-3vloo60z-PpJV2PFIwEathWDOxCTTLA).
Basic support is provided for free, both in [this repo](https://github.com/axewp/wp-graphql-gravity-forms/issues) and in [WPGraphQL's official Discord](https://discord.gg/Hp6fQbqvwe).

Priority support and custom development are available to [our Sponsors](https://github.com/sponsors/AxeWP).

Expand Down
273 changes: 138 additions & 135 deletions composer.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions tests/wpunit/FormFieldConnectionPageFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function tearDown(): void {
}

private function generate_form_pages( int $count = 1 ): array {
$fields = [];
$fields = [];
$field_id = 1;

for ( $i = 0; $i < $count; $i++ ) {
Expand Down Expand Up @@ -137,12 +137,12 @@ public function testFilterByPageNumber(): void {
* Test with empty offset.
*/
$variables = [
'formId' => $this->form_id,
'formId' => $this->form_id,
'pageNumber' => 0,
];

$expected = $wp_query;
$actual = $this->graphql( compact( 'query', 'variables' ) );
$actual = $this->graphql( compact( 'query', 'variables' ) );

$this->assertResponseIsValid( $actual );
$this->assertArrayNotHasKey( 'errors', $actual );
Expand Down Expand Up @@ -170,7 +170,6 @@ public function testFilterByPageNumber(): void {

$this->assertValidPageFields( $expected, $actual );


/**
* Test the last two results.
*/
Expand Down Expand Up @@ -198,14 +197,15 @@ private function assertValidPageFields( array $expected, array $actual ): void {
$this->assertArrayHasKey( 'data', $actual );
$this->assertCount( 2, $actual['data']['gfForm']['formFields']['nodes'] );


$this->assertEquals( $expected[0]['id'], $actual['data']['gfForm']['formFields']['nodes'][0]['databaseId'] );
$this->assertEquals( $expected[0]['pageNumber'], $actual['data']['gfForm']['formFields']['nodes'][0]['pageNumber'] );
$this->assertEquals( $expected[1]['id'], $actual['data']['gfForm']['formFields']['nodes'][1]['databaseId'] );
$this->assertEquals( $expected[1]['pageNumber'], $actual['data']['gfForm']['formFields']['nodes'][1]['pageNumber'] );
$this->assertEquals( GFHelpers::get_enum_for_value( FormFieldTypeEnum::$type, $expected[1]['type'] ), $actual['data']['gfForm']['formFields']['nodes'][1]['type'] );
$this->assertEquals( $expected[1]['nextButton']['text'], $actual['data']['gfForm']['formFields']['nodes'][1]['nextButton']['text'] );
$this->assertEquals(
$expected[1]['previousButton']['text'], $actual['data']['gfForm']['formFields']['nodes'][1]['previousButton']['text'] );
$this->assertEquals(
$expected[1]['previousButton']['text'],
$actual['data']['gfForm']['formFields']['nodes'][1]['previousButton']['text']
);
}
}
75 changes: 73 additions & 2 deletions tests/wpunit/GFUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,80 @@ public function testGetForms(): void {
* Tests GFUtils::get_last_form_page().
*/
public function testGetLastFormPage(): void {
$this->markTestIncomplete(
'This test has not been implemented yet. Requires PageField arguments.'
// These will increment.
$id = 1;
$page_number = 1;

$form_id = $this->factory->form->create(
array_merge(
[
'fields' => [
$this->factory->field->create(
array_merge(
$this->tester->getPropertyHelper( 'NumberField' )->values,
[
'id' => $id++,
'pageNumber' => $page_number,
'isRequired' => true,
]
)
),
$this->factory->field->create(
array_merge(
$this->tester->getPropertyHelper( 'PageField' )->values,
[
'id' => $id++,
'pageNumber' => ++$page_number,
'isRequired' => false,
'conditionalLogic' => [
'actionType' => 'show',
'logicType' => 'all',
'rules' => [
[
'fieldId' => 1,
'operator' => 'is',
'value' => 2,
],
],
],
]
)
),
$this->factory->field->create(
array_merge(
$this->tester->getPropertyHelper( 'NumberField' )->values,
[
'id' => $id++,
'pageNumber' => $page_number,
'isRequired' => true,
]
)
),
$this->factory->field->create(
array_merge(
$this->tester->getPropertyHelper( 'PageField' )->values,
[
'id' => $id++,
'pageNumber' => ++$page_number,
]
)
),
],
],
$this->tester->getFormDefaultArgs()
)
);

$expected = 3;

$form = $this->factory->form->get_object_by_id( $form_id );

$actual = GFUtils::get_last_form_page( $form );

$this->assertEquals( $expected, $actual );

// Cleanup.
$this->factory->form->delete( $form_id );
}

/**
Expand Down
18 changes: 10 additions & 8 deletions tests/wpunit/RadioFieldOtherChoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ public function field_helper() {
* Generates the form fields from factory. Must be wrappend in an array.
*/
public function generate_fields(): array {
return [ $this->factory->field->create(
array_merge(
$this->property_helper->values,
[
'enableOtherChoice' => true,
]
)
) ];
return [
$this->factory->field->create(
array_merge(
$this->property_helper->values,
[
'enableOtherChoice' => true,
]
)
),
];
}

/**
Expand Down
60 changes: 29 additions & 31 deletions tests/wpunit/SubmitFormMultipageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setUp(): void {

wp_set_current_user( $this->admin->ID );

$this->fields = $this->generate_form_fields();
$this->fields = $this->generate_form_fields();
$this->form_id = $this->factory->form->create(
array_merge(
[ 'fields' => $this->fields ],
Expand All @@ -33,7 +33,6 @@ public function setUp(): void {
$this->clearSchema();
}


/**
* {@inheritDoc}
*/
Expand All @@ -47,15 +46,15 @@ public function tearDown(): void {

private function generate_form_fields(): array {
// This will increment as we use them.
$id = 1;
$id = 1;
$page_number = 1;

return [
$this->factory->field->create(
array_merge(
$this->tester->getPropertyHelper( 'NumberField' )->values,
[
'id' => $id++,
'id' => $id++,
'pageNumber' => $page_number,
'isRequired' => true,
]
Expand All @@ -65,28 +64,28 @@ private function generate_form_fields(): array {
array_merge(
$this->tester->getPropertyHelper( 'PageField' )->values,
[
'id' => $id++,
'pageNumber' => ++$page_number,
'isRequired' => false,
'id' => $id++,
'pageNumber' => ++$page_number,
'isRequired' => false,
'conditionalLogic' => [
'actionType' => 'show',
'logicType' => 'all',
'rules' => [
'logicType' => 'all',
'rules' => [
[
'fieldId' => 1,
'fieldId' => 1,
'operator' => 'is',
'value' => 2
]
]
]
'value' => 2,
],
],
],
]
)
),
$this->factory->field->create(
array_merge(
$this->tester->getPropertyHelper( 'NumberField' )->values,
[
'id' => $id++,
'id' => $id++,
'pageNumber' => $page_number,
'isRequired' => true,
]
Expand All @@ -105,13 +104,13 @@ private function generate_form_fields(): array {
array_merge(
$this->tester->getPropertyHelper( 'NumberField' )->values,
[
'id' => $id++,
'pageNumber' => $page_number,
'isRequired' => true,
'id' => $id++,
'pageNumber' => $page_number,
'isRequired' => true,
'defaultValue' => 'default value',
]
)
)
),
];
}

Expand Down Expand Up @@ -158,12 +157,12 @@ public function testSubmit(): void {
'input' => [
'id' => $this->form_id,
'saveAsDraft' => false,
]
],
];

// Submit the first page with invalid value.
$variables['input']['sourcePage'] = 1;
$variables['input']['targetPage'] = 2;
$variables['input']['sourcePage'] = 1;
$variables['input']['targetPage'] = 2;
$variables['input']['fieldValues'] = [];

$actual = $this->graphql( compact( 'query', 'variables' ) );
Expand All @@ -173,12 +172,12 @@ public function testSubmit(): void {
$this->assertNotEmpty( $actual['data']['submitGfForm']['errors'] );
$this->assertEquals( 1, $actual['data']['submitGfForm']['targetPageNumber'], 'The target page number should be the invalid page' );

$this->clear_form_field_state();
$this->clear_form_field_state();

// On a value that isnt 2, the 3rd page should be the target page.
$variables['input']['fieldValues'] = [
[
'id' => 1,
'id' => 1,
'value' => '0',
],
];
Expand All @@ -200,7 +199,7 @@ public function testSubmit(): void {

$variables['input']['fieldValues'] = [
[
'id' => 1,
'id' => 1,
'value' => '2',
],
];
Expand Down Expand Up @@ -244,7 +243,7 @@ public function testSubmit(): void {
$variables['input']['fieldValues'],
[
[
'id' => 3,
'id' => 3,
'value' => '2',
],
]
Expand Down Expand Up @@ -284,7 +283,7 @@ public function testSubmit(): void {
$variables['input']['fieldValues'],
[
[
'id' => 5,
'id' => 5,
'value' => '1',
],
]
Expand All @@ -298,14 +297,13 @@ public function testSubmit(): void {
$this->assertNull( $actual['data']['submitGfForm']['targetPageNumber'] );
$this->assertEmpty( $actual['data']['submitGfForm']['targetPageFormFields'] );


// Test as Draft.
$this->clear_form_field_state();

$variables['input']['saveAsDraft'] = true;
$variables['input']['fieldValues'] = [];
$variables['input']['sourcePage'] = 1;
$variables['input']['targetPage'] = 3;
$variables['input']['sourcePage'] = 1;
$variables['input']['targetPage'] = 3;

$actual = $this->graphql( compact( 'query', 'variables' ) );

Expand All @@ -324,7 +322,7 @@ public function testSubmit(): void {
private function clear_form_field_state(): void {
$form = GFAPI::get_form( $this->form_id );

foreach( $form['fields'] as $field ) {
foreach ( $form['fields'] as $field ) {
unset( $field->failed_validation );
unset( $field->validation_message );
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'harness-software/wp-graphql-gravity-forms',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => 'e68b7c0b1d9aaf702384eae00af7d3c94e6c0f29',
'reference' => 'd5b1ea8aba7e845b05970af4f6bbbf9c0c4683b3',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'harness-software/wp-graphql-gravity-forms' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => 'e68b7c0b1d9aaf702384eae00af7d3c94e6c0f29',
'reference' => 'd5b1ea8aba7e845b05970af4f6bbbf9c0c4683b3',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit 8043eb5

Please sign in to comment.