Download the PHP package level-level/wp-browser-woocommerce without Composer
On this page you can find all versions of the php package level-level/wp-browser-woocommerce. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download level-level/wp-browser-woocommerce
More information about level-level/wp-browser-woocommerce
Files in level-level/wp-browser-woocommerce
Package wp-browser-woocommerce
Short Description WooCommerce object factories for WP Browser integration tests.
License MIT
Informations about the package wp-browser-woocommerce
wp-browser-woocommerce
This library simplifies testing of WooCommerce themes and plugins with wp-browser. Several Unit Test Factories are added that allow you to quickly create WooCommerce products and orders within an integration test.
Getting started
Before getting started with wp-browser-woocommerce
, make sure you read the excellent documentation for wp-browser first.
Installation
To install wp-browser-woocommerce
you use composer. The library is published on packagist.
Your first WooCommerce test
Tests written with wp-browser-woocommerce
are a lot like regular wp-browser
integration tests. By extending from \LevelLevel\WPBrowserWooCommerce\WCTestCase
instead of the regular \WPTestCase
, you will get access to WooCommerce unit test factories.
Factories
The factories provide methods to allow for quick object creation. The factories are access with the $this->factory()
method on a testcase.
In the background, the factories use the WooCommerce REST API methods to create and retrieve objects. These are not actual GET
/POST
requests, but rather internal calls to the methods that would process the regular requests to the API.
All factories extend from the WordPress default WP_UnitTest_Factory_For_Thing. All methods that are specified on this base class are available on the factories you will use in WooCommerce tests.
In this documentation you will only find the most used ones, refer to the base class or WordPress documentation for others.
Orders
You can access the order factory by using $this->factory()->order
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to an order are the same as you can give to the order creation API endpoint.
create_and_get($args)
returns the result of wc_get_order()
for the created object.
See https://woocommerce.github.io/woocommerce-rest-api-docs/#create-an-order
Example:
Products
You can access the order factory by using $this->factory()->product
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to an order are the same as you can give to the product creation API endpoint.
create_and_get($args)
returns the result of wc_get_product()
for the created object.
See https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-product
Example:
Tax rates
You can access the order factory by using $this->factory()->tax_rate
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to an order are the same as you can give to the product creation API endpoint.
create_and_get($args)
returns an array, as tax rates have no data class/model within WooCommerce.
See https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-tax-rate
Example:
Coupons
You can access the coupon factory by using $this->factory()->coupon
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to a coupon are the same as you can give to the coupon creation API endpoint.
create_and_get($args)
returns the result of new WC_Coupon( $coupon_id )
for the created object.
See https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-coupon
Example:
Shipping zones
You can access the shipping zone factory by using $this->factory()->shipping_zone
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to a shipping zone are the same as you can give to the shipping zone creation API endpoint.
create_and_get($args)
returns the result of new WC_Shipping_Zone( $shipping_zone_id )
for the created object.
See https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#create-a-shipping-zone
Example:
Adding locations
It's possible to add location rules to shipping zones. See the code below for an example:
Shipping zone methods
You can access the shipping zone method factory by using $this->factory()->shipping_zone_method
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to a shipping zone method are the same as you can give to the shipping zone method creation API endpoint.
create_and_get($args)
returns an WC_Shipping_Method
object.
Not that you have to set a zone_id, as created with the shipping_zone
factory.
Example:
Subscriptions
The subscription factory can only be used when the WooCommerce Subscriptions plugin is installed and activated.
You can access the subscription factory by using $this->factory()->subscription
within a WooCommerce integration test.
The main method you'll use is create_and_get( $args )
. The input you can give to a subscription are the same as you can give to the subscription creation API endpoint.
create_and_get($args)
returns the result of wcs_get_subscription( $subscription_id )
for the created object.
See https://woocommerce.github.io/subscriptions-rest-api-docs/v1.html#create-a-subscription
Example:
Testcases
For most testcases you will want to use \LevelLevel\WPBrowserWooCommerce\WCTestCase
Ajax calls
For ajax calls, the regular \WPAjaxTestCase would be replaced with \LevelLevel\WPBrowserWooCommerce\WCAjaxTestCase
Example:
Development
wp-browser-woocommerce
is actively being used at Level Level. The library will get new features as we need them for client projects.
Roadmap
The main focus is on implementing more factories for other WooCommerce objects such as customers, and refunds.
After this, focus might shift to popular extensions for WooCommerce, such as Subscriptions or Bookings.
Contributing
Feel free to open issues or create pull requests if you feel something is missing or working incorrectly.