set_virtual( true ); $product->set_regular_price( '10' ); $product->set_sale_price( '5' ); $product->set_category_ids( array( $category['term_id'] ) ); $product->save(); $product = wc_get_product( $product ); // Reload so status is current. $expected = array( 'foo', 'product', 'type-product', 'post-' . $product->get_id(), 'status-publish', 'first', 'instock', 'product_cat-some-category', 'sale', 'virtual', 'purchasable', 'product-type-simple', ); $actual = array_values( wc_get_product_class( 'foo', $product ) ); $this->assertEquals( $expected, $actual, print_r( $actual, true ) ); // All taxonomies. add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_true' ); $expected = array( 'foo', 'product', 'type-product', 'post-' . $product->get_id(), 'status-publish', 'instock', 'product_cat-some-category', 'sale', 'virtual', 'purchasable', 'product-type-simple', ); $actual = array_values( wc_get_product_class( 'foo', $product ) ); $this->assertEquals( $expected, $actual, print_r( $actual, true ) ); add_filter( 'woocommerce_get_product_class_include_taxonomies', '__return_false' ); $product->delete( true ); wp_delete_term( $category['term_id'], 'product_cat' ); } /** * Test: test_wc_dropdown_variation_attribute_options_no_attributes. */ public function test_wc_dropdown_variation_attribute_options_no_attributes() { $this->expectOutputString( '' ); wc_dropdown_variation_attribute_options(); } /** * Test: test_wc_dropdown_variation_attribute_options_should_return_attributes_list. */ public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list() { $product = WC_Helper_Product::create_variation_product(); $this->expectOutputString( '' ); wc_dropdown_variation_attribute_options( array( 'product' => $product, 'attribute' => 'pa_size', ) ); } /** * Test: test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element. */ public function test_wc_dropdown_variation_attribute_options_should_return_attributes_list_and_selected_element() { $product = WC_Helper_Product::create_variation_product(); $_REQUEST['attribute_pa_size'] = 'large'; $this->expectOutputString( '' ); wc_dropdown_variation_attribute_options( array( 'product' => $product, 'attribute' => 'pa_size', ) ); unset( $_REQUEST['attribute_pa_size'] ); } /** * Test wc_query_string_form_fields. * * @return void */ public function test_wc_query_string_form_fields() { $actual_html = wc_query_string_form_fields( '?test=1', array(), '', true ); $expected_html = ''; $this->assertEquals( $expected_html, $actual_html ); $actual_html = wc_query_string_form_fields( '?test=1&test2=something', array(), '', true ); $expected_html = ''; $this->assertEquals( $expected_html, $actual_html ); $actual_html = wc_query_string_form_fields( '?test.something=something.else', array(), '', true ); $expected_html = ''; $this->assertEquals( $expected_html, $actual_html ); $actual_html = wc_query_string_form_fields( '?test+something=something+else', array(), '', true ); $expected_html = ''; $this->assertEquals( $expected_html, $actual_html ); $actual_html = wc_query_string_form_fields( '?test%20something=something%20else', array(), '', true ); $expected_html = ''; $this->assertEquals( $expected_html, $actual_html ); } /** * Test test_wc_get_pay_buttons(). */ public function test_wc_get_pay_buttons() { // Test default. ob_start(); wc_get_pay_buttons(); $actual_html = ob_get_clean(); $this->assertEquals( '', $actual_html ); // Include a payment gateway that supports "pay button". add_filter( 'woocommerce_payment_gateways', function( $gateways ) { $gateways[] = 'WC_Mock_Payment_Gateway'; return $gateways; } ); WC()->payment_gateways()->init(); // Test pay buttons HTML. ob_start(); wc_get_pay_buttons(); $actual_html = ob_get_clean(); $gateway = new WC_Mock_Payment_Gateway(); $expected_html = sprintf( '
', $gateway->get_pay_button_id() ); $this->assertEquals( $expected_html, $actual_html ); } public function test_hidden_field() { $actual_html = woocommerce_form_field('test', array( 'type' => 'hidden', 'id' => 'test_field', 'input_class' => array( 'test-field' ), 'custom_attributes' => array( 'data-total' => '10' ), 'return' => true ), 'test value'); $expected_html = '

'; $this->assertEquals( $expected_html, $actual_html ); } }