-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWooCommerceDB.php
More file actions
54 lines (39 loc) · 1.02 KB
/
WooCommerceDB.php
File metadata and controls
54 lines (39 loc) · 1.02 KB
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
<?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();
}
/**
* 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;
}
}