-
Notifications
You must be signed in to change notification settings - Fork 2
/
WooCommerceDB.php
90 lines (66 loc) · 2.12 KB
/
WooCommerceDB.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Codeception\Module;
use Codeception\TestInterface;
/**
* The WooCommerce DB module.
*
* Extends WPDb to add WooCommerce-specific methods for easier shop data creation.
*/
class WooCommerceDB extends WPDb {
/**
* Runs before each test.
*
* Performs any base WooCommerce configuration to avoid the need to maintain them in a SQL dump.
*
* @param TestInterface $test
*/
public function _before( TestInterface $test ) {
parent::_before( $test );
// ensure the base pages are set
\WC_Install::create_pages();
}
/**
* Updates the settings for the specified payment gateway.
*
* TODO: move to a trait with PaymentGateway or PaymentGateway\Settings related methods.
*
* @param string $gateway_id the ID of the payment gateway
* @param array $settings the new settings
*/
public function havePaymentGatewaySettingsInDatabase( string $gateway_id, array $settings ) {
$setting_name = sprintf( 'woocommerce_%s_settings', $gateway_id );
$current_settings = get_option( $setting_name, [] );
update_option( $setting_name, array_merge( $current_settings, $settings ) );
}
/**
* Creates a simple product in the database.
*
* @param array $props product properties
* @return \WC_Product_Simple
*/
public function haveSimpleProductInDatabase( array $props = [] ) : \WC_Product_Simple {
$props = wp_parse_args( $props, [
'name' => 'Simple Product',
'regular_price' => 1.00,
'virtual' => false,
] );
$product = new \WC_Product_Simple();
$product->set_props( $props );
$product->save();
return $product;
}
/**
* Gets the ID of the first payment token in the database that matches the given criteria.
*
* @param array $args search criteria
* @return null|\WC_Payment_Token
*/
public function grabPaymentTokenFromDatabase( $args ) {
$entries = $this->grabAllFromDatabase( $this->grabPrefixedTableNameFor( 'woocommerce_payment_tokens' ), 'token_id', $args );
$token = null;
if ( is_array( $entries ) && isset( $entries[0]['token_id'] ) ) {
$token = \WC_Payment_Tokens::get( (int) $entries['0']['token_id'] );
}
return $token;
}
}