Skip to content

Commit

Permalink
devops: tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed May 15, 2024
1 parent 045062e commit e184488
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 189 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ENV PATH "$PATH:~/.composer/vendor/bin"
# Install wp-browser globally
RUN composer global require --optimize-autoloader \
wp-cli/wp-cli-bundle:* \
lucatume/wp-browser:3.2.3 \
lucatume/wp-browser:^4 \
phpunit/phpunit:^9.6 \
codeception/module-asserts:* \
codeception/module-cli:* \
Expand All @@ -48,6 +48,7 @@ RUN composer global require --optimize-autoloader \
codeception/module-rest:* \
codeception/module-webdriver:* \
codeception/util-universalframework:* \
guzzlehttp/guzzle \
league/factory-muffin \
league/factory-muffin-faker \
stripe/stripe-php \
Expand All @@ -74,8 +75,8 @@ ENV PROJECT_DIR="${PLUGINS_DIR}/wp-graphql-woocommerce"
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
RUN a2enmod rewrite


WORKDIR /var/www/html

# Set codecept wrapper
COPY bin/codecept /usr/local/bin/codecept
RUN chmod 755 /usr/local/bin/codecept
Expand Down
6 changes: 4 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Security Policy

## Supported Versions

Current only the most stable release has security update support.
Meaning security patches are always patched the latest stable release.
Meaning security patches are always patched the latest stable release.

## Reporting a Vulnerability
Do not report potential security vulnerabilities here. Email them privately to our security team at support@axistaylor.com

Do not report potential security vulnerabilities here. Report your finding using the contact form found [here](https://woographql.com/support#contact) or email them privately to our security team at <support@axistaylor.com>
2 changes: 1 addition & 1 deletion bin/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ install_local_test_library() {
# Install testing library dependencies.
composer install
composer require --dev -W \
lucatume/wp-browser:3.2.3 \
lucatume/wp-browser:^4 \
phpunit/phpunit:^9.6 \
codeception/lib-asserts:* \
codeception/module-asserts:* \
Expand Down
26 changes: 12 additions & 14 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@ if [ "$USING_XDEBUG" == "1" ]; then
fi

# Run WordPress docker entrypoint.
# shellcheck disable=SC1091
. docker-entrypoint.sh 'apache2'

set +u

# Ensure mysql is loaded
wait-for-it -s -t 300 ${DB_HOST}:${DB_PORT} -- echo "Application database is operationally..."
wait-for-it -s -t 300 "${DB_HOST}:${DB_PORT}" -- echo "Application database is operationally..."

# Setup tester scripts.
if [ ! -f $WP_ROOT_FOLDER/setup-database.sh ]; then
ln -s $PROJECT_DIR/bin/setup-database.sh $WP_ROOT_FOLDER/setup-database.sh
chmod +x $WP_ROOT_FOLDER/setup-database.sh
if [ ! -f "$WP_ROOT_FOLDER/setup-database.sh" ]; then
ln -s "$PROJECT_DIR/bin/setup-database.sh" "$WP_ROOT_FOLDER/setup-database.sh"
chmod +x "$WP_ROOT_FOLDER/setup-database.sh"
fi

# Update our domain to just be the docker container's IP address
export WORDPRESS_DOMAIN=${WORDPRESS_DOMAIN-$( hostname -i )}
export WORDPRESS_URL="http://$WORDPRESS_DOMAIN"
if [ -f $PROJECT_DIR/.env.docker ]; then
rm $PROJECT_DIR/.env.docker
fi
echo "WORDPRESS_DOMAIN=$WORDPRESS_DOMAIN" >> $PROJECT_DIR/.env.docker
echo "WORDPRESS_URL=$WORDPRESS_URL" >> $PROJECT_DIR/.env.docker
echo "WORDPRESS_DOMAIN=$WORDPRESS_DOMAIN" > "$PROJECT_DIR/.env.docker"
echo "WORDPRESS_URL=$WORDPRESS_URL" >> "$PROJECT_DIR/.env.docker"

# Config WordPress
if [ -f "${WP_ROOT_FOLDER}/wp-config.php" ]; then
echo "Deleting old wp-config.php"
rm ${WP_ROOT_FOLDER}/wp-config.php
rm -f "${WP_ROOT_FOLDER}/wp-config.php"
fi

echo "Creating wp-config.php..."
Expand Down Expand Up @@ -83,15 +81,15 @@ if wp config has GRAPHQL_DEBUG --allow-root; then
wp config delete GRAPHQL_DEBUG --allow-root
fi
if [[ -n "$GRAPHQL_DEBUG" ]]; then
wp config set GRAPHQL_DEBUG $GRAPHQL_DEBUG --allow-root
wp config set GRAPHQL_DEBUG "$GRAPHQL_DEBUG" --allow-root
fi

if [[ -n "$IMPORT_WC_PRODUCTS" ]]; then
echo "Installing & Activating WordPress Importer..."
wp plugin install wordpress-importer --activate --allow-root
echo "Importing store products..."
wp import \
${PLUGINS_DIR}/woocommerce/sample-data/sample_products.xml \
"${PLUGINS_DIR}/woocommerce/sample-data/sample_products.xml" \
--authors=skip --allow-root
fi

Expand All @@ -100,10 +98,10 @@ wp rewrite structure '/%year%/%monthnum%/%postname%/' --allow-root

echo "Prepare for app database dump..."
if [ ! -d "${PROJECT_DIR}/local/db" ]; then
mkdir ${PROJECT_DIR}/local/db
mkdir "${PROJECT_DIR}/local/db"
fi
if [ -f "${PROJECT_DIR}/local/db/app_db.sql" ]; then
rm ${PROJECT_DIR}/local/db/app_db.sql
rm -f "${PROJECT_DIR}/local/db/app_db.sql"
fi

echo "Dumping app database..."
Expand Down
36 changes: 21 additions & 15 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ paths:
envs: tests/_envs
params:
- env
- .env
- .env.docker
actor_suffix: Tester
settings:
Expand All @@ -26,43 +25,50 @@ 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"
modules:
config:
WPDb:
\Tests\WPGraphQL\Codeception\Module\WPGraphQL:
endpoint: '%WORDPRESS_URL%/graphql'
auth_header: 'Basic %TEST_SITE_ADMIN_APP_PASSWORD%'
\lucatume\WPBrowser\Module\WPCLI:
path: '%WP_ROOT_FOLDER%'
throw: true
\lucatume\WPBrowser\Module\WPDb:
dsn: 'mysql:host=%DB_HOST%;dbname=%DB_NAME%'
user: '%DB_USER%'
password: '%DB_PASSWORD%'
dump: 'local/db/app_db.sql'
populate: false
cleanup: false
populate: true
cleanup: true
waitlock: 10
url: '%WORDPRESS_URL%'
urlReplacement: true
tablePrefix: '%WP_TABLE_PREFIX%'
WPBrowser:
\lucatume\WPBrowser\Module\WPBrowser:
url: '%WORDPRESS_URL%'
wpRootFolder: '%WP_CORE_DIR%'
adminUsername: '%ADMIN_USERNAME%'
adminPassword: '%ADMIN_PASSWORD%'
adminPath: '/wp-admin'
REST:
\lucatume\WPBrowser\Module\REST:
depends: WPBrowser
url: '%WORDPRESS_URL%'
cookies: false
WPFilesystem:
\lucatume\WPBrowser\Module\WPFilesystem:
wpRootFolder: '%WP_CORE_DIR%'
plugins: '/wp-content/plugins'
mu-plugins: '/wp-content/mu-plugins'
themes: '/wp-content/themes'
uploads: '/wp-content/uploads'
WPLoader:
\lucatume\WPBrowser\Module\WPLoader:
skipInstall: true
wpRootFolder: '%WP_CORE_DIR%'
dbName: '%DB_NAME%'
dbHost: '%DB_HOST%'
Expand Down
6 changes: 6 additions & 0 deletions docs/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@
- [Using Product Bundle Data + Mutations](using-product-bundle-data-and-mutations.md)
- [Using Product Add-ons Data + Mutations](using-product-addons-data-and-mutations.md)

## Extending WooGraphQL

- [Registering New Product Types](registering-new-product-types.md)
- [Extending Mutations](extending-mutations.md)

## Contributing

- [Testing Quick-Start Guide](testing-quick-start.md)
- [Local CLI Testing](local-testing.md)
- [Development with Docker](development-w-docker.md)
- [CLI Testing with Docker](testing-w-docker.md)

## Glossary

- [Schema Docs](https://woographql.com/schema)
2 changes: 1 addition & 1 deletion includes/class-wp-graphql-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private function includes() {
require $include_directory_path . 'functions.php';

/**
* WPGRAPHQL_AUTOLOAD can be set to "false" to prevent the autoloader from running.
* WPGRAPHQL_WOOCOMMERCE_AUTOLOAD can be set to "false" to prevent the autoloader from running.
* In most cases, this is not something that should be disabled, but some environments
* may bootstrap their dependencies in a global autoloader that will autoload files
* before we get to this point, and requiring the autoloader again can trigger fatal errors.
Expand Down
2 changes: 1 addition & 1 deletion includes/utils/class-session-transaction-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function pop_transaction_id( $payload, $input, $unfiltered_input, $contex
}

// Bail if not the expected mutation.
if ( ! str_starts_with( $this->transaction_id, "wooSession_{$mutation}_" ) ) {
if ( str_starts_with( $this->transaction_id, "wooSession_{$mutation}_" ) ) {
return;
}

Expand Down
85 changes: 42 additions & 43 deletions tests/_support/Helper/GraphQLE2E.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public function getCatalog() {
}

// Create cart page.
$wpdb = $this->getModule( 'WPDb' );
$wpdb = $this->getModule( '\lucatume\WPBrowser\Module\WPDb' );
$cart_page_id = $wpdb->havePostInDatabase(
[
'post_type' => 'page',
Expand All @@ -697,12 +697,6 @@ public function getCatalog() {
);
$wpdb->haveOptionInDatabase( 'woocommerce_checkout_page_id', $checkout_page_id );

global $wp_rewrite;
// Set the permalink structure
$wp_rewrite->set_permalink_structure( '/%postname%/' );
// Flush the rules and tell it to write htaccess
$wp_rewrite->flush_rules( true );

return $product_catalog;
}

Expand All @@ -713,7 +707,8 @@ public function getCatalog() {
* @return void
*/
public function _setupStore() {
$wpdb = $this->getModule( 'WPDb' );
$wpdb = $this->getModule( '\lucatume\WPBrowser\Module\WPDb' );

$wpdb->useTheme( 'twentytwentyone' );
// Turn on tax calculations and store shipping countries. Important!
$wpdb->haveOptionInDatabase( 'woocommerce_ship_to_countries', 'all' );
Expand Down Expand Up @@ -743,39 +738,43 @@ public function _setupStore() {
// }
// );

// Create Shipping Zones.
$zone = new \WC_Shipping_Zone();
$zone->set_zone_name( 'Local' );
$zone->set_zone_order( 1 );
$zone->add_location( 'GB', 'country' );
$zone->add_location( 'CB*', 'postcode' );
$zone->save();
$zone->add_shipping_method( 'flat_rate' );
$zone->add_shipping_method( 'free_shipping' );

$zone = new \WC_Shipping_Zone();
$zone->set_zone_name( 'Europe' );
$zone->set_zone_order( 2 );
$zone->add_location( 'EU', 'continent' );
$zone->save();
$zone->add_shipping_method( 'flat_rate' );
$zone->add_shipping_method( 'free_shipping' );

$zone = new \WC_Shipping_Zone();
$zone->set_zone_name( 'California' );
$zone->set_zone_order( 3 );
$zone->add_location( 'US:CA', 'state' );
$zone->save();
$zone->add_shipping_method( 'flat_rate' );
$zone->add_shipping_method( 'free_shipping' );

$zone = new \WC_Shipping_Zone();
$zone->set_zone_name( 'US' );
$zone->set_zone_order( 4 );
$zone->add_location( 'US', 'country' );
$zone->save();
$zone->add_shipping_method( 'flat_rate' );
$zone->add_shipping_method( 'free_shipping' );
// // Create Shipping Zones.
// $cli = $this->getModule( '\lucatume\WPBrowser\Module\WPCLI' );
// $zone_id = $cli->cliToString( [ 'wc', 'shipping_zone', 'create', '--name', 'Local', '--order', '1', '--porcelain' ] );
// $zone_id = absint( $zone_id );

// $zone = new \WC_Shipping_Zone();
// $zone->set_zone_name( 'Local' );
// $zone->set_zone_order( 1 );
// $zone->add_location( 'GB', 'country' );
// $zone->add_location( 'CB*', 'postcode' );
// $zone->save();
// $zone->add_shipping_method( 'flat_rate' );
// $zone->add_shipping_method( 'free_shipping' );

// $zone = new \WC_Shipping_Zone();
// $zone->set_zone_name( 'Europe' );
// $zone->set_zone_order( 2 );
// $zone->add_location( 'EU', 'continent' );
// $zone->save();
// $zone->add_shipping_method( 'flat_rate' );
// $zone->add_shipping_method( 'free_shipping' );

// $zone = new \WC_Shipping_Zone();
// $zone->set_zone_name( 'California' );
// $zone->set_zone_order( 3 );
// $zone->add_location( 'US:CA', 'state' );
// $zone->save();
// $zone->add_shipping_method( 'flat_rate' );
// $zone->add_shipping_method( 'free_shipping' );

// $zone = new \WC_Shipping_Zone();
// $zone->set_zone_name( 'US' );
// $zone->set_zone_order( 4 );
// $zone->add_location( 'US', 'country' );
// $zone->save();
// $zone->add_shipping_method( 'flat_rate' );
// $zone->add_shipping_method( 'free_shipping' );
}

/**
Expand All @@ -789,7 +788,7 @@ public function _setupStore() {
* @return void
*/
public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple', &$term_id = 0 ) {
$wpdb = $this->getModule( 'WPDb' );
$wpdb = $this->getModule( '\lucatume\WPBrowser\Module\WPDb' );

// Create Product
$product_id = $wpdb->havePostInDatabase(
Expand Down Expand Up @@ -857,7 +856,7 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple'
public function setupStoreAndUsers() {
$this->_setupStore();

$wpdb = $this->getModule( 'WPDb' );
$wpdb = $this->getModule( '\lucatume\WPBrowser\Module\WPDb' );
$userId = $wpdb->haveUserInDatabase(
'jimbo1234',
'customer',
Expand Down
34 changes: 31 additions & 3 deletions tests/functional.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,35 @@ modules:
enabled:
- Asserts
- REST
- WPBrowser
- WPDb
- WPLoader
- \lucatume\WPBrowser\Module\WPCLI
- \lucatume\WPBrowser\Module\WPBrowser
- \lucatume\WPBrowser\Module\WPDb
- \lucatume\WPBrowser\Module\WPLoader
- \Tests\WPGraphQL\Codeception\Module\QueryAsserts
- \Tests\WPGraphQL\Codeception\Module\WPGraphQL
- \Helper\GraphQLE2E
config:
\lucatume\WPBrowser\Module\WPLoader:
loadOnly: true
wpRootFolder: '%WP_ROOT_FOLDER%'
dbName: '%DB_NAME%'
dbHost: '%DB_HOST%'
dbUser: '%DB_USER%'
dbPassword: '%DB_PASSWORD%'
tablePrefix: '%WP_TABLE_PREFIX%'
domain: '%WORDPRESS_DOMAIN%'
adminEmail: '%ADMIN_EMAIL%'
title: 'WooGraphQL Tests'
plugins:
- woocommerce/woocommerce.php
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
- wp-graphql/wp-graphql.php
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
activatePlugins:
- woocommerce/woocommerce.php
- woocommerce-gateway-stripe/woocommerce-gateway-stripe.php
- wp-graphql/wp-graphql.php
- wp-graphql-jwt-authentication/wp-graphql-jwt-authentication.php
- wp-graphql-woocommerce/wp-graphql-woocommerce.php
bootstrap: _bootstrap.php
Loading

0 comments on commit e184488

Please sign in to comment.