Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Leverage the WooCommerce test framework #26

Merged
merged 58 commits into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
086aa82
Install WooCommerce as a dev dependency via Composer, and ensure its …
stevegrunwell Jan 4, 2018
21ad543
Simplify the test bootstrapping tremendously by using WooCommerce's t…
stevegrunwell Jan 4, 2018
15d11c8
Merge branch 'feature/tests-for-data-store' into fix/woocommerce-test…
stevegrunwell Jan 5, 2018
0dd2906
Add a helper method to retrieve the unmodified contents of a woocomme…
stevegrunwell Jan 5, 2018
8a316a6
For consistency, use wc_custom_order_table()->get_table_name() to ret…
stevegrunwell Jan 5, 2018
f62ce24
When retrieving the date columns from a WC_Order object, explicitly c…
stevegrunwell Jan 5, 2018
8e2b43c
Instead of extending Abstract_WC_Order_Data_Store_CPT directly, exten…
stevegrunwell Jan 5, 2018
b44367a
Now that we're extending WC_Order_Data_Store_CPT, remove any code tha…
stevegrunwell Jan 5, 2018
86700f5
Update the class comment for WC_Order_Data_Store_Custom_Table
stevegrunwell Jan 5, 2018
fbf04b1
Simplify WC_Order_Data_Store_Custom_Table::create(), only setting the…
stevegrunwell Jan 5, 2018
f6089b4
Remove more methods (and related tests) that are directly copied from…
stevegrunwell Jan 5, 2018
58a7140
Update the test-coverage Composer script to only run the 'plugin' tes…
stevegrunwell Jan 5, 2018
22f2fa3
Remove a giant get_order() method which, based on the parent class, h…
stevegrunwell Jan 5, 2018
6af8a5e
Add a test for get_order_id_by_order_key()
stevegrunwell Jan 5, 2018
c918d3f
Add tests around delete() and clean up the method a bit
stevegrunwell Jan 5, 2018
2fde693
Merge branch 'develop' into feature/use-woocommerce-test-tools
stevegrunwell Jan 8, 2018
f7679e8
There's a lot going on here, but the general goal is to replace meta …
stevegrunwell Jan 9, 2018
ce90a8e
Rework some of the non-instance-dependent methods to be static.
stevegrunwell Jan 9, 2018
7b27060
Use a LEFT JOIN instead of a regular JOIN for the custom orders table
stevegrunwell Jan 9, 2018
eae6f27
While using a numeric database column is better for doing math, the c…
stevegrunwell Jan 9, 2018
5a172ba
Ensure the custom table is always installed when running the test suite
stevegrunwell Jan 9, 2018
89418f7
Use the same WHERE clause rewriting for customer queries
stevegrunwell Jan 9, 2018
ed8ca1a
Prevent the test environment from enqueueing email actions
stevegrunwell Jan 9, 2018
b66f767
Extend the data store used for Customers as well, as the stock versio…
stevegrunwell Jan 9, 2018
0511f79
Ensure the woocommerce_orders table is truncated after each test
stevegrunwell Jan 9, 2018
d3dbfc5
The cart_tax and total_tax properties are different within WooCommerc…
stevegrunwell Jan 9, 2018
6866839
WooCommerce saves date_completed and date_paid as Unix timestamps, no…
stevegrunwell Jan 10, 2018
dd1315f
Clean up the DataStoreTest class to remove some leakage on the 'wooco…
stevegrunwell Jan 10, 2018
a713df4
Add two new table columns: billing_index and shipping_index.
stevegrunwell Jan 10, 2018
2a96d54
Rewrite search_orders() to search all of the following:
stevegrunwell Jan 10, 2018
09bcff6
Use the liquidweb/woocommerce fork as the dev dependency.
stevegrunwell Jan 10, 2018
7e8eff7
Ensure get_order_data_from_table() uses the get_table_name() helper
stevegrunwell Jan 10, 2018
dcb685d
WooCommerce *stores* prices_include_tax as a 'yes' or 'no', but the h…
stevegrunwell Jan 11, 2018
e869bc0
Use the WooCommerce helpers for creating dummy products/orders instea…
stevegrunwell Jan 11, 2018
0f2462d
Update the inline comments for the WC_Custom_Order_Table class
stevegrunwell Jan 11, 2018
84bd22c
Clean up the customer data store so it passes coding standards checks.
stevegrunwell Jan 11, 2018
0a0840e
Minor PHP_CodeSniffer-whitespace adjustments
stevegrunwell Jan 11, 2018
0caaf35
Ensure the test suite can run on PHP 5.3.
stevegrunwell Jan 11, 2018
adb7c2e
With https://github.com/woocommerce/woocommerce/pull/18417 merged int…
stevegrunwell Jan 11, 2018
19a3e82
Set the minimum *development* version to PHP 7.0.
stevegrunwell Jan 11, 2018
3773011
Install the same tooling + leverage the WooCommerce PHP_CodeSniffer c…
stevegrunwell Jan 11, 2018
d6df611
Simplify the Travis file, removing older versions of PHP and includin…
stevegrunwell Jan 11, 2018
05269e0
Move the bin/ directory under tests/, since the only script in there …
stevegrunwell Jan 11, 2018
68e58ec
When referencing a file, it helps if you use the right filename
stevegrunwell Jan 11, 2018
9b76148
Remove the defaultTestSuite property from the PHPUnit configuration
stevegrunwell Jan 11, 2018
92b4571
Specify the exact path to PHP_CodeSniffer
stevegrunwell Jan 11, 2018
969d1e7
Permit multisite tests to fail (for now), as there's a bug within the…
stevegrunwell Jan 11, 2018
e2bdc79
Use the allow_failures node within the test matrix
stevegrunwell Jan 11, 2018
e87d78d
Coding standards cleanup:
stevegrunwell Jan 11, 2018
46666dd
Fix inline comments based on PHPCS report
stevegrunwell Jan 11, 2018
cb52023
Whitelist direct database queries in the order data store
stevegrunwell Jan 11, 2018
a4591e5
Restructure the filter_database_queries() function to avoid variable …
stevegrunwell Jan 11, 2018
b7804c8
Whitelist a more complicated SQL query for search_orders()
stevegrunwell Jan 11, 2018
809235a
Remove an empty() call that could cause trouble on PHP < 5.5
stevegrunwell Jan 11, 2018
09f6c17
Merge pull request #28 from liquidweb/fix/extend-order-data-store
bswatson Jan 11, 2018
0686ca8
Merge branch 'develop' into fix/woocommerce-test-suite-errors
stevegrunwell Jan 11, 2018
eba07de
Merge branch 'feature/use-woocommerce-test-tools' into fix/woocommerc…
stevegrunwell Jan 11, 2018
9ac856f
Merge pull request #31 from liquidweb/fix/woocommerce-test-suite-errors
bswatson Jan 12, 2018
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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/tests/coverage
/vendor
composer.lock
tests/coverage
vendor
19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
"composer/installers": "^1.4",
"xrstf/composer-php52": "^1.0"
},
"require-dev": {
"woocommerce/woocommerce": "dev-master"
},
"autoload": {
"classmap": ["includes"]
"classmap": [
"includes"
]
},
"autoload-dev": {
"classmap": [
"vendor/woocommerce/woocommerce/tests/framework"
]
},
"autoload-dev": {
"classmap": ["tests/test-tools"]
Expand All @@ -27,5 +37,12 @@
"test-coverage": [
"phpunit --coverage-html=tests/coverage"
]
},
"extra": {
"installer-paths": {
"vendor/{$vendor}/{$name}": [
"woocommerce/woocommerce"
]
}
}
}
214 changes: 214 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
defaultTestSuite="plugin"
>
<testsuites>
<testsuite>
<!-- Plugin-specific tests. -->
<testsuite name="plugin">
<directory prefix="test-" suffix=".php">./tests/</directory>
<exclude>tests/test-sample.php</exclude>
</testsuite>

<!-- WooCommerce core test suite. -->
<testsuite name="core">
<directory suffix=".php">./vendor/woocommerce/woocommerce/tests/unit-tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
Expand Down
90 changes: 17 additions & 73 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,91 +1,35 @@
<?php
/**
* PHPUnit bootstrap file
* Bootstrap the PHPUnit test suite(s).
*
* Since WooCommerce Custom Order Tables is meant to integrate seamlessly with WooCommerce itself,
* the bootstrap relies heavily on the WooCommerce core test suite.
*
* @package Woocommerce_Order_Tables
*/

$_tests_dir = getenv( 'WP_TESTS_DIR' );
$_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
$_bootstrap = dirname( __DIR__ ) . '/vendor/woocommerce/woocommerce/tests/bootstrap.php';

if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
// Verify that Composer dependencies have been installed.
if ( ! file_exists( $_bootstrap ) ) {
echo "\033[0;31mUnable to find the WooCommerce test bootstrap file. Have you run `composer install`?\033[0;m" . PHP_EOL;
exit( 1 );

if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL;
} elseif ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo "\033[0;31mCould not find $_tests_dir/includes/functions.php, have you run `bin/install-wp-tests.sh`?\033[0;m" . PHP_EOL;
exit( 1 );
}

// Give access to tests_add_filter() function.
// Gives access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';

/**
* Manually load the plugin being tested.
*/
// Manually load the plugin on muplugins_loaded.
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/wc-custom-order-table.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';
require __DIR__ . '/../vendor/autoload_52.php';
require __DIR__ . '/testcase.php';

/*
* Automatically activate WooCommerce in the test environment.
*
* If WooCommerce cannot be activated, an error message will be thrown and the test execution
* halted, with a non-zero exit code.
*/
$activated = activate_plugin( 'woocommerce/woocommerce.php' );

// If the issue is that the plugin isn't installed, attempt to install it.
if ( is_wp_error( $activated ) && 'plugin_not_found' === $activated->get_error_code() ) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

echo PHP_EOL . "WooCommerce is not currently installed in the test environment, attempting to install...";

// Retrieve information about WooCommerce.
$plugin_data = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/woocommerce.json' );

if ( ! is_wp_error( $plugin_data ) ) {
$plugin_data = json_decode( wp_remote_retrieve_body( $plugin_data ) );
$plugin_url = $plugin_data->download_link;
} else {
$plugin_url = false;
}

// Download the plugin from the WordPress.org repository.
$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
$installed = $upgrader->install( $plugin_url );

if ( true === $installed ) {
echo "\033[0;32mOK\033[0;m" . PHP_EOL . PHP_EOL;
} else {
echo "\033[0;31mFAIL\033[0;m" . PHP_EOL;

if ( is_wp_error( $installed ) ) {
printf( 'Unable to install WooCommerce: %s.', $installed->get_error_message() );
}

printf(
'Please download and install WooCommerce into %s' . PHP_EOL,
trailingslashit(dirname( dirname( $_tests_dir ) ) )
);

exit( 1 );
}

// Try once again to activate.
$activated = activate_plugin( 'woocommerce/woocommerce.php' );
}

// Nothing more we can do, unfortunately.
if ( is_wp_error( $activated ) ) {
echo PHP_EOL . 'WooCommerce could not automatically be activated in the test environment:';
echo PHP_EOL . $activated->get_error_message();
echo PHP_EOL . PHP_EOL . "\033[0;31mUnable to proceed with tests, aborting.\033[0m";
echo PHP_EOL;
exit( 1 );
}
// Finally, Start up the WP testing environment.
require_once $_bootstrap;
require_once __DIR__ . '/testcase.php';
Loading