Make create_attribute function for PHPUNIT more versatile by removing hardcoding.

This commit is contained in:
Peter Fabian 2018-07-06 16:08:32 +02:00
parent 1091eb5feb
commit e769029af6
1 changed files with 5 additions and 5 deletions

View File

@ -224,16 +224,15 @@ class WC_Helper_Product {
*
* @since 2.3
*
* @param string $attribute_name Name of attribute to create.
* @param array(string) $terms Terms to create for the attribute.
* @return array
*/
public static function create_attribute() {
public static function create_attribute( $attribute_name = 'size', $terms = array( 'small', 'large' ) ) {
global $wpdb;
$return = array();
$attribute_name = 'size';
$terms = array( 'small', 'large' );
// Create attribute.
$attribute = array(
'attribute_label' => $attribute_name,
@ -245,7 +244,6 @@ class WC_Helper_Product {
$wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
$return['attribute_id'] = $wpdb->insert_id;
// Register the taxonomy.
$array_format = array(
'%s',
'%s',
@ -282,6 +280,8 @@ class WC_Helper_Product {
'name' => $attribute_name,
),
);
// Register the taxonomy.
register_taxonomy( 'pa_' . $attribute_name, array( 'product' ), $taxonomy_data );
// Set product attributes global.