2019-03-13 12:31:37 -04:00
|
|
|
<?php
|
|
|
|
|
namespace Helper;
|
|
|
|
|
|
|
|
|
|
// here you can define custom actions
|
|
|
|
|
// all public methods declared in helper class will be available in $I
|
2019-03-21 21:43:24 -04:00
|
|
|
class Wpunit extends \Codeception\Module {
|
2019-04-24 15:05:42 -04:00
|
|
|
/**
|
|
|
|
|
* HOOK:
|
|
|
|
|
* triggered after module is created and configuration is loaded
|
|
|
|
|
*/
|
2019-05-09 23:11:00 -04:00
|
|
|
public function _initialize() {
|
2019-07-09 00:49:11 -04:00
|
|
|
// Helper classes
|
2019-04-24 15:05:42 -04:00
|
|
|
require_once __DIR__ . '/crud-helpers/wcg-helper.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/customer.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/coupon.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/product.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/product-variation.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/shipping-method.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/tax-rate.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/order-item.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/order.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/refund.php';
|
|
|
|
|
require_once __DIR__ . '/crud-helpers/cart.php';
|
2023-04-18 23:48:08 -04:00
|
|
|
require_once __DIR__ . '/../Utils/class-wc-product-advanced.php';
|
2019-04-24 15:05:42 -04:00
|
|
|
}
|
2019-04-24 13:08:29 -04:00
|
|
|
|
2019-05-09 23:11:00 -04:00
|
|
|
/**
|
|
|
|
|
* HOOK:
|
|
|
|
|
* executed before suite.
|
|
|
|
|
*/
|
|
|
|
|
public function _beforeSuite( $settings = null ) {
|
|
|
|
|
$helper = $this->product();
|
2024-05-16 21:27:54 -04:00
|
|
|
$helper->create_attribute( 'size', [ 'small', 'medium', 'large' ], 'Product size' );
|
|
|
|
|
$helper->create_attribute( 'color', [ 'red', 'blue', 'green' ], 'Product color' );
|
2019-05-09 23:11:00 -04:00
|
|
|
codecept_debug( 'ATTRIBUTES_LOADED' );
|
2023-11-30 15:41:32 +02:00
|
|
|
add_action( 'init_graphql_request', [ self::class, 'shortcode_test_init' ] );
|
2019-09-03 15:36:48 -04:00
|
|
|
codecept_debug( 'SHORTCODE_INITIALIZED' );
|
2020-04-16 14:56:52 -04:00
|
|
|
\Stripe\Stripe::setApiKey(
|
|
|
|
|
defined( 'STRIPE_API_SECRET_KEY' ) ? STRIPE_API_SECRET_KEY : getenv( 'STRIPE_API_SECRET_KEY' )
|
|
|
|
|
);
|
2019-05-09 23:11:00 -04:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function cart() {
|
|
|
|
|
return \CartHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function coupon() {
|
|
|
|
|
return \CouponHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function customer() {
|
|
|
|
|
return \CustomerHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function order() {
|
|
|
|
|
return \OrderHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function item() {
|
|
|
|
|
return \OrderItemHelper::instance();
|
|
|
|
|
}
|
2019-04-16 17:48:39 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function product() {
|
|
|
|
|
return \ProductHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function product_variation() {
|
|
|
|
|
return \ProductVariationHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function refund() {
|
|
|
|
|
return \RefundHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function shipping_method() {
|
|
|
|
|
return \ShippingMethodHelper::instance();
|
|
|
|
|
}
|
2019-04-05 14:46:59 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function tax_rate() {
|
|
|
|
|
return \TaxRateHelper::instance();
|
|
|
|
|
}
|
2019-04-14 04:59:13 -04:00
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function get_nodes( $ids, $crud ) {
|
2022-08-26 14:53:36 -04:00
|
|
|
$nodes = [];
|
2022-02-04 15:00:44 -05:00
|
|
|
foreach ( $ids as $id ) {
|
2019-04-05 14:46:59 -04:00
|
|
|
$nodes[] = $crud->get_query_data( $id );
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
return [ 'nodes' => $nodes ];
|
2019-04-05 14:46:59 -04:00
|
|
|
}
|
|
|
|
|
|
2019-04-24 15:05:42 -04:00
|
|
|
public function clear_loader_cache( $loader_name ) {
|
2023-04-04 12:02:25 -04:00
|
|
|
$loader = \WPGraphQL::get_app_context()->get_loader( $loader_name );
|
2024-05-07 16:50:42 -04:00
|
|
|
$loader->clear_all();
|
2019-04-05 14:46:59 -04:00
|
|
|
}
|
2019-09-03 15:36:48 -04:00
|
|
|
|
|
|
|
|
public static function shortcode_test_init() {
|
2023-11-30 15:41:32 +02:00
|
|
|
add_shortcode( 'shortcode_test', [ self::class, 'shortcode_test_handler' ] );
|
2019-09-03 15:36:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function shortcode_test_handler( $atts ) {
|
|
|
|
|
return '<p>This is the product description.</p>';
|
|
|
|
|
}
|
2019-03-13 12:31:37 -04:00
|
|
|
}
|