Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: "$request_headers" replaced with "$selected_options" #35

Merged
merged 4 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
codeception/module-phpbrowser:* \
codeception/module-webdriver:* \
wp-cli/wp-cli-bundle \
lucatume/wp-browser:^3.1
lucatume/wp-browser:^4

- name: Run Codeception Tests w/ Docker.
env:
Expand Down
14 changes: 7 additions & 7 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ extensions:
enabled:
- Codeception\Extension\RunFailed
commands:
- Codeception\Command\GenerateWPUnit
- Codeception\Command\GenerateWPRestApi
- Codeception\Command\GenerateWPRestController
- Codeception\Command\GenerateWPRestPostTypeController
- Codeception\Command\GenerateWPAjax
- Codeception\Command\GenerateWPCanonical
- Codeception\Command\GenerateWPXMLRPC
- "lucatume\\WPBrowser\\Command\\GenerateWPUnit"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestApi"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestController"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestPostTypeController"
- "lucatume\\WPBrowser\\Command\\GenerateWPAjax"
- "lucatume\\WPBrowser\\Command\\GenerateWPCanonical"
- "lucatume\\WPBrowser\\Command\\GenerateWPXMLRPC"
params:
- .env.testing
- .env.docker
16 changes: 16 additions & 0 deletions src/Codeception/Module/QueryAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Tests\WPGraphQL\Constraint\QueryErrorConstraint;
use Tests\WPGraphQL\Constraint\QuerySuccessfulConstraint;
use Tests\WPGraphQL\Logger\CodeceptLogger as Signal;
use Tests\WPGraphQL\Utils\Utils;

/**
* GraphQL Query Asserts Module for Codeception
Expand Down Expand Up @@ -120,6 +121,21 @@ private function get_not() {
return $prefix;
}

/**
* The value returned for undefined resolved values.
*
* Clone of the "get" function from the Lodash JS libra
*
* @param array $object The object to query.
* @param string $path The path of the property to get.
* @param mixed $default The value returned for undefined resolved values.
*
* @return mixed
*/
public function lodashGet( array $data, string $string, $default = null ) {
return Utils::lodashGet( $data, $string, $default );
}

/**
* Returns an expected "location" error data object.
*
Expand Down
167 changes: 94 additions & 73 deletions src/Codeception/Module/WPGraphQL.php

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/codeception/acceptance.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
actor: AcceptanceTester
modules:
enabled:
- WPDb
- WPBrowser
- \lucatume\WPBrowser\Module\WPDb
- \lucatume\WPBrowser\Module\WPBrowser
- \Helper\Acceptance
config:
WPDb:
\lucatume\WPBrowser\Module\WPDb:
dsn: '%TEST_SITE_DB_DSN%'
user: '%TEST_DB_USER%'
password: '%TEST_DB_PASSWORD%'
Expand All @@ -24,7 +24,7 @@ modules:
urlReplacement: true
tablePrefix: '%TEST_TABLE_PREFIX%'

WPBrowser:
\lucatume\WPBrowser\Module\WPBrowser:
url: '%TEST_SITE_WP_URL%'
wpRootFolder: '%WP_ROOT_FOLDER%'
adminUsername: '%TEST_SITE_ADMIN_USERNAME%'
Expand Down
26 changes: 6 additions & 20 deletions tests/codeception/functional.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
actor: FunctionalTester
modules:
enabled:
- WPDb
- WPBrowser
- WPFilesystem
- Asserts
- \lucatume\WPBrowser\Module\WPDb
- \lucatume\WPBrowser\Module\WPBrowser
- \lucatume\WPBrowser\Module\WPFilesystem
- \Tests\WPGraphQL\Codeception\Module\QueryAsserts
- \Tests\WPGraphQL\Codeception\Module\WPGraphQL
- \Helper\Functional
config:
\Tests\WPGraphQL\Codeception\Module\WPGraphQL:
endpoint: '%TEST_SITE_WP_URL%/graphql'
auth_header: 'Basic %TEST_SITE_ADMIN_APP_PASSWORD%'
WPDb:
\lucatume\WPBrowser\Module\WPDb:
dsn: '%TEST_SITE_DB_DSN%'
user: '%TEST_DB_USER%'
password: '%TEST_DB_PASSWORD%'
Expand All @@ -29,30 +29,16 @@ modules:
urlReplacement: true
tablePrefix: '%TEST_TABLE_PREFIX%'

WPBrowser:
\lucatume\WPBrowser\Module\WPBrowser:
url: '%TEST_SITE_WP_URL%'
wpRootFolder: '%WP_ROOT_FOLDER%'
adminUsername: '%TEST_SITE_ADMIN_USERNAME%'
adminPassword: '%TEST_SITE_ADMIN_PASSWORD%'
adminPath: '/wp-admin'

WPFilesystem:
\lucatume\WPBrowser\Module\WPFilesystem:
wpRootFolder: '%WP_ROOT_FOLDER%'
plugins: '/wp-content/plugins'
mu-plugins: '/wp-content/mu-plugins'
themes: '/wp-content/themes'
uploads: '/wp-content/uploads'

WPLoader:
loadOnly: true
wpRootFolder: "%WP_ROOT_FOLDER%"
dbName: "%TEST_DB_NAME%"
dbHost: "%TEST_DB_HOST%"
dbUser: "%TEST_DB_USER%"
dbPassword: "%TEST_DB_PASSWORD%"
tablePrefix: "%TEST_TABLE_PREFIX%"
domain: "%TEST_SITE_WP_DOMAIN%"
adminEmail: "%TEST_SITE_ADMIN_EMAIL%"
title: "WPGraphQLTestcase"
plugins: ['wp-graphql/wp-graphql.php']
activatePlugins: ['wp-graphql/wp-graphql.php']
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use \FunctionalTester;
use Tests\WPGraphQL\Logger\CodeceptLogger as Signal;

class QueryAssertsModuleTestCest {
class QueryAssertsModuleCest {
public function testAssertResponseIdValid( FunctionalTester $I ) {
$data = [
'data' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use \FunctionalTester;
use Tests\WPGraphQL\Logger\CodeceptLogger as Signal;

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

Expand Down Expand Up @@ -290,4 +290,51 @@ public function testConcurrentRequests( FunctionalTester $I, $scenario ) {
]
);
}

public function testRequestOptions( FunctionalTester $I ) {
$I->wantTo( 'send a request to the GraphQL endpoint with custom options' );

$query = 'mutation ( $input: CreatePostInput! ) {
createPost( input: $input ) {
post {
id
title
slug
status
}
}
}';

$variables = [
'input' => [
'title' => 'Test Post',
'content' => 'Test Post content',
'slug' => 'test-post',
'status' => 'DRAFT'
]
];


$response = $I->postRequest( $query, $variables, [ 'suppress_mod_token' => true ] );

$I->assertQueryError( $response );

$response = $I->postRequest( $query, $variables );

$I->assertQuerySuccessful( $response, [ $I->expectField( 'createPost.post.id', Signal::NOT_NULL ) ] );

$id = $I->lodashGet( $response, 'data.createPost.post.id' );

$query = '
query ( $id: ID! ) {
post( id: $id ) {
id
}
}
';

$response = $I->postRequest( $query, [ 'id' => $id ], [ 'suppress_mod_token' => true ] );

$I->assertQuerySuccessful( $response, [ $I->expectField( 'post', Signal::IS_NULL ) ] );
}
}
4 changes: 2 additions & 2 deletions tests/codeception/wpunit.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
actor: WpunitTester
modules:
enabled:
- WPLoader
- \lucatume\WPBrowser\Module\WPLoader
- \Helper\Wpunit
config:
WPLoader:
\lucatume\WPBrowser\Module\WPLoader:
wpRootFolder: "%WP_ROOT_FOLDER%"
dbName: "%TEST_DB_NAME%"
dbHost: "%TEST_DB_HOST%"
Expand Down
Loading