Skip to content

Commit 796f2fa

Browse files
authored
Merge pull request #35 from wp-graphql/feat/slight-wpgraphql-module-refactor
feat: "$request_headers" replaced with "$selected_options"
2 parents ef78ac4 + 15c7e58 commit 796f2fa

9 files changed

+179
-109
lines changed

.github/workflows/continous-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
codeception/module-phpbrowser:* \
5757
codeception/module-webdriver:* \
5858
wp-cli/wp-cli-bundle \
59-
lucatume/wp-browser:^3.1
59+
lucatume/wp-browser:^4
6060
6161
- name: Run Codeception Tests w/ Docker.
6262
env:

codeception.dist.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ extensions:
1818
enabled:
1919
- Codeception\Extension\RunFailed
2020
commands:
21-
- Codeception\Command\GenerateWPUnit
22-
- Codeception\Command\GenerateWPRestApi
23-
- Codeception\Command\GenerateWPRestController
24-
- Codeception\Command\GenerateWPRestPostTypeController
25-
- Codeception\Command\GenerateWPAjax
26-
- Codeception\Command\GenerateWPCanonical
27-
- Codeception\Command\GenerateWPXMLRPC
21+
- "lucatume\\WPBrowser\\Command\\GenerateWPUnit"
22+
- "lucatume\\WPBrowser\\Command\\GenerateWPRestApi"
23+
- "lucatume\\WPBrowser\\Command\\GenerateWPRestController"
24+
- "lucatume\\WPBrowser\\Command\\GenerateWPRestPostTypeController"
25+
- "lucatume\\WPBrowser\\Command\\GenerateWPAjax"
26+
- "lucatume\\WPBrowser\\Command\\GenerateWPCanonical"
27+
- "lucatume\\WPBrowser\\Command\\GenerateWPXMLRPC"
2828
params:
2929
- .env.testing
3030
- .env.docker

src/Codeception/Module/QueryAsserts.php

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Tests\WPGraphQL\Constraint\QueryErrorConstraint;
1111
use Tests\WPGraphQL\Constraint\QuerySuccessfulConstraint;
1212
use Tests\WPGraphQL\Logger\CodeceptLogger as Signal;
13+
use Tests\WPGraphQL\Utils\Utils;
1314

1415
/**
1516
* GraphQL Query Asserts Module for Codeception
@@ -120,6 +121,21 @@ private function get_not() {
120121
return $prefix;
121122
}
122123

124+
/**
125+
* The value returned for undefined resolved values.
126+
*
127+
* Clone of the "get" function from the Lodash JS libra
128+
*
129+
* @param array $object The object to query.
130+
* @param string $path The path of the property to get.
131+
* @param mixed $default The value returned for undefined resolved values.
132+
*
133+
* @return mixed
134+
*/
135+
public function lodashGet( array $data, string $string, $default = null ) {
136+
return Utils::lodashGet( $data, $string, $default );
137+
}
138+
123139
/**
124140
* Returns an expected "location" error data object.
125141
*

src/Codeception/Module/WPGraphQL.php

+94-73
Large diffs are not rendered by default.

tests/codeception/acceptance.suite.dist.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
actor: AcceptanceTester
99
modules:
1010
enabled:
11-
- WPDb
12-
- WPBrowser
11+
- \lucatume\WPBrowser\Module\WPDb
12+
- \lucatume\WPBrowser\Module\WPBrowser
1313
- \Helper\Acceptance
1414
config:
15-
WPDb:
15+
\lucatume\WPBrowser\Module\WPDb:
1616
dsn: '%TEST_SITE_DB_DSN%'
1717
user: '%TEST_DB_USER%'
1818
password: '%TEST_DB_PASSWORD%'
@@ -24,7 +24,7 @@ modules:
2424
urlReplacement: true
2525
tablePrefix: '%TEST_TABLE_PREFIX%'
2626

27-
WPBrowser:
27+
\lucatume\WPBrowser\Module\WPBrowser:
2828
url: '%TEST_SITE_WP_URL%'
2929
wpRootFolder: '%WP_ROOT_FOLDER%'
3030
adminUsername: '%TEST_SITE_ADMIN_USERNAME%'

tests/codeception/functional.suite.dist.yml

+6-20
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
actor: FunctionalTester
77
modules:
88
enabled:
9-
- WPDb
10-
- WPBrowser
11-
- WPFilesystem
129
- Asserts
10+
- \lucatume\WPBrowser\Module\WPDb
11+
- \lucatume\WPBrowser\Module\WPBrowser
12+
- \lucatume\WPBrowser\Module\WPFilesystem
1313
- \Tests\WPGraphQL\Codeception\Module\QueryAsserts
1414
- \Tests\WPGraphQL\Codeception\Module\WPGraphQL
1515
- \Helper\Functional
1616
config:
1717
\Tests\WPGraphQL\Codeception\Module\WPGraphQL:
1818
endpoint: '%TEST_SITE_WP_URL%/graphql'
1919
auth_header: 'Basic %TEST_SITE_ADMIN_APP_PASSWORD%'
20-
WPDb:
20+
\lucatume\WPBrowser\Module\WPDb:
2121
dsn: '%TEST_SITE_DB_DSN%'
2222
user: '%TEST_DB_USER%'
2323
password: '%TEST_DB_PASSWORD%'
@@ -29,30 +29,16 @@ modules:
2929
urlReplacement: true
3030
tablePrefix: '%TEST_TABLE_PREFIX%'
3131

32-
WPBrowser:
32+
\lucatume\WPBrowser\Module\WPBrowser:
3333
url: '%TEST_SITE_WP_URL%'
3434
wpRootFolder: '%WP_ROOT_FOLDER%'
3535
adminUsername: '%TEST_SITE_ADMIN_USERNAME%'
3636
adminPassword: '%TEST_SITE_ADMIN_PASSWORD%'
3737
adminPath: '/wp-admin'
3838

39-
WPFilesystem:
39+
\lucatume\WPBrowser\Module\WPFilesystem:
4040
wpRootFolder: '%WP_ROOT_FOLDER%'
4141
plugins: '/wp-content/plugins'
4242
mu-plugins: '/wp-content/mu-plugins'
4343
themes: '/wp-content/themes'
4444
uploads: '/wp-content/uploads'
45-
46-
WPLoader:
47-
loadOnly: true
48-
wpRootFolder: "%WP_ROOT_FOLDER%"
49-
dbName: "%TEST_DB_NAME%"
50-
dbHost: "%TEST_DB_HOST%"
51-
dbUser: "%TEST_DB_USER%"
52-
dbPassword: "%TEST_DB_PASSWORD%"
53-
tablePrefix: "%TEST_TABLE_PREFIX%"
54-
domain: "%TEST_SITE_WP_DOMAIN%"
55-
adminEmail: "%TEST_SITE_ADMIN_EMAIL%"
56-
title: "WPGraphQLTestcase"
57-
plugins: ['wp-graphql/wp-graphql.php']
58-
activatePlugins: ['wp-graphql/wp-graphql.php']

tests/codeception/functional/QueryAssertsModuleTestCest.php renamed to tests/codeception/functional/QueryAssertsModuleCest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use \FunctionalTester;
77
use Tests\WPGraphQL\Logger\CodeceptLogger as Signal;
88

9-
class QueryAssertsModuleTestCest {
9+
class QueryAssertsModuleCest {
1010
public function testAssertResponseIdValid( FunctionalTester $I ) {
1111
$data = [
1212
'data' => [

tests/codeception/functional/WPGraphQLModuleTestCest.php renamed to tests/codeception/functional/WPGraphQLModuleCest.php

+48-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use \FunctionalTester;
77
use Tests\WPGraphQL\Logger\CodeceptLogger as Signal;
88

9-
class WPGraphQLModuleTestCest {
9+
class WPGraphQLModuleCest {
1010
public function testGetRequest( FunctionalTester $I, $scenario ) {
1111
$I->wantTo( 'send a GET request to the GraphQL endpoint and return a response' );
1212

@@ -290,4 +290,51 @@ public function testConcurrentRequests( FunctionalTester $I, $scenario ) {
290290
]
291291
);
292292
}
293+
294+
public function testRequestOptions( FunctionalTester $I ) {
295+
$I->wantTo( 'send a request to the GraphQL endpoint with custom options' );
296+
297+
$query = 'mutation ( $input: CreatePostInput! ) {
298+
createPost( input: $input ) {
299+
post {
300+
id
301+
title
302+
slug
303+
status
304+
}
305+
}
306+
}';
307+
308+
$variables = [
309+
'input' => [
310+
'title' => 'Test Post',
311+
'content' => 'Test Post content',
312+
'slug' => 'test-post',
313+
'status' => 'DRAFT'
314+
]
315+
];
316+
317+
318+
$response = $I->postRequest( $query, $variables, [ 'suppress_mod_token' => true ] );
319+
320+
$I->assertQueryError( $response );
321+
322+
$response = $I->postRequest( $query, $variables );
323+
324+
$I->assertQuerySuccessful( $response, [ $I->expectField( 'createPost.post.id', Signal::NOT_NULL ) ] );
325+
326+
$id = $I->lodashGet( $response, 'data.createPost.post.id' );
327+
328+
$query = '
329+
query ( $id: ID! ) {
330+
post( id: $id ) {
331+
id
332+
}
333+
}
334+
';
335+
336+
$response = $I->postRequest( $query, [ 'id' => $id ], [ 'suppress_mod_token' => true ] );
337+
338+
$I->assertQuerySuccessful( $response, [ $I->expectField( 'post', Signal::IS_NULL ) ] );
339+
}
293340
}

tests/codeception/wpunit.suite.dist.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
actor: WpunitTester
66
modules:
77
enabled:
8-
- WPLoader
8+
- \lucatume\WPBrowser\Module\WPLoader
99
- \Helper\Wpunit
1010
config:
11-
WPLoader:
11+
\lucatume\WPBrowser\Module\WPLoader:
1212
wpRootFolder: "%WP_ROOT_FOLDER%"
1313
dbName: "%TEST_DB_NAME%"
1414
dbHost: "%TEST_DB_HOST%"

0 commit comments

Comments
 (0)