*CODING STANDARDS ONLY* Add method visibility, clean up inline documentation.

This commit is contained in:
Steve Grunwell 2020-03-12 15:57:32 +00:00
parent 2383670020
commit 0a5161ea3d
2 changed files with 65 additions and 45 deletions

View File

@ -1,13 +1,17 @@
<?php <?php
/**
* Tests for the WC_Data class.
*
* @package WooCommerce\Tests\CRUD
*/
/** /**
* Meta * Class WC_Tests_CRUD_Data
* @package WooCommerce\Tests\CRUD
*/ */
class WC_Tests_CRUD_Data extends WC_Unit_Test_Case { class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Restore UTC on failire. * Restore UTC on failure.
*/ */
public function tearDown() { public function tearDown() {
parent::tearDown(); parent::tearDown();
@ -52,17 +56,17 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
} }
/** /**
* Test: get_data * Test: get_data.
*/ */
function test_get_data() { public function test_get_data() {
$object = new WC_Mock_WC_Data(); $object = new WC_Mock_WC_Data();
$this->assertInternalType( 'array', $object->get_data() ); $this->assertInternalType( 'array', $object->get_data() );
} }
/** /**
* Test: delete_meta_data_by_mid * Test: delete_meta_data_by_mid.
*/ */
function test_delete_meta_data_by_mid() { public function test_delete_meta_data_by_mid() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
$meta_id = add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true ); $meta_id = add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
@ -71,9 +75,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
} }
/** /**
* Test: set_props * Test: set_props.
*/ */
function test_set_props() { public function test_set_props() {
$object = new WC_Mock_WC_Data(); $object = new WC_Mock_WC_Data();
$data_to_set = array( $data_to_set = array(
'content' => 'I am a fish', 'content' => 'I am a fish',
@ -97,7 +101,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Tests reading and getting set metadata. * Tests reading and getting set metadata.
*/ */
function test_get_meta_data() { public function test_get_meta_data() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
$object->add_meta_data( 'test_meta_key', 'val1', true ); $object->add_meta_data( 'test_meta_key', 'val1', true );
@ -118,7 +122,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Tests that the meta data cache is not shared among instances. * Tests that the meta data cache is not shared among instances.
*/ */
function test_get_meta_data_shared_bug() { public function test_get_meta_data_shared_bug() {
$object = new WC_Order(); $object = new WC_Order();
$object->add_meta_data( 'test_meta_key', 'val1', true ); $object->add_meta_data( 'test_meta_key', 'val1', true );
$object->add_meta_data( 'test_multi_meta_key', 'val2' ); $object->add_meta_data( 'test_multi_meta_key', 'val2' );
@ -135,9 +139,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
} }
/** /**
* Tests the cache invalidation after an order is saved * Tests the cache invalidation after an order is saved.
*/ */
function test_get_meta_data_cache_invalidation() { public function test_get_meta_data_cache_invalidation() {
$object = new WC_Order(); $object = new WC_Order();
$object->add_meta_data( 'test_meta_key', 'val1', true ); $object->add_meta_data( 'test_meta_key', 'val1', true );
$object->add_meta_data( 'test_multi_meta_key', 'val2' ); $object->add_meta_data( 'test_multi_meta_key', 'val2' );
@ -154,7 +158,10 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
$this->assertEquals( 'updated value', $metas[0]->value ); $this->assertEquals( 'updated value', $metas[0]->value );
} }
function test_get_meta_data_cache_invalidation_array_to_scalar() { /**
* Ensure get_meta_data() can overwrite array meta values with scalar values.
*/
public function test_get_meta_data_cache_invalidation_array_to_scalar() {
$object = new WC_Order(); $object = new WC_Order();
$object->add_meta_data( 'test_meta_key', array( 'val1' ), true ); $object->add_meta_data( 'test_meta_key', array( 'val1' ), true );
$object->add_meta_data( 'test_multi_meta_key', 'val2' ); $object->add_meta_data( 'test_multi_meta_key', 'val2' );
@ -174,7 +181,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test getting meta by ID. * Test getting meta by ID.
*/ */
function test_get_meta() { public function test_get_meta() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
$object->add_meta_data( 'test_meta_key', 'val1', true ); $object->add_meta_data( 'test_meta_key', 'val1', true );
@ -183,11 +190,11 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
$object->save_meta_data(); $object->save_meta_data();
$object = new WC_Mock_WC_Data( $object_id ); $object = new WC_Mock_WC_Data( $object_id );
// test single meta key // test single meta key.
$single_meta = $object->get_meta( 'test_meta_key' ); $single_meta = $object->get_meta( 'test_meta_key' );
$this->assertEquals( 'val1', $single_meta ); $this->assertEquals( 'val1', $single_meta );
// test getting multiple // test getting multiple.
$meta = $object->get_meta( 'test_multi_meta_key', false ); $meta = $object->get_meta( 'test_multi_meta_key', false );
$i = 2; $i = 2;
foreach ( $meta as $data ) { foreach ( $meta as $data ) {
@ -200,7 +207,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test seeing if meta exists. * Test seeing if meta exists.
*/ */
function test_has_meta() { public function test_has_meta() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
$object->add_meta_data( 'test_meta_key', 'val1', true ); $object->add_meta_data( 'test_meta_key', 'val1', true );
@ -215,9 +222,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
} }
/** /**
* Test getting meta that hasn't been set * Test getting meta that hasn't been set.
*/ */
function test_get_meta_no_meta() { public function test_get_meta_no_meta() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
$object = new WC_Mock_WC_Data( $object_id ); $object = new WC_Mock_WC_Data( $object_id );
@ -232,7 +239,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test setting meta. * Test setting meta.
*/ */
function test_set_meta_data() { public function test_set_meta_data() {
global $wpdb; global $wpdb;
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
@ -274,7 +281,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test adding meta data. * Test adding meta data.
*/ */
function test_add_meta_data() { public function test_add_meta_data() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
$data = 'add_meta_data_' . time(); $data = 'add_meta_data_' . time();
@ -286,7 +293,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test updating meta data. * Test updating meta data.
*/ */
function test_update_meta_data() { public function test_update_meta_data() {
global $wpdb; global $wpdb;
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
@ -314,7 +321,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test deleting meta. * Test deleting meta.
*/ */
function test_delete_meta_data() { public function test_delete_meta_data() {
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true ); add_metadata( 'post', $object_id, 'test_meta_key', 'val1', true );
@ -329,9 +336,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test saving metadata.. (Actually making sure changes are written to DB) * Test saving metadata (Actually making sure changes are written to DB).
*/ */
function test_save_meta_data() { public function test_save_meta_data() {
global $wpdb; global $wpdb;
$object = $this->create_test_post(); $object = $this->create_test_post();
$object_id = $object->get_id(); $object_id = $object->get_id();
@ -355,7 +362,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
$object->update_meta_data( 'test_meta_key_2', 'updated_value', $raw_metadata[1]->meta_id ); $object->update_meta_data( 'test_meta_key_2', 'updated_value', $raw_metadata[1]->meta_id );
$object->save(); $object->save();
$object = new WC_Mock_WC_Data( $object_id ); // rereads from the DB $object = new WC_Mock_WC_Data( $object_id ); // rereads from the DB.
$this->assertEmpty( $object->get_meta( 'test_meta_key' ) ); $this->assertEmpty( $object->get_meta( 'test_meta_key' ) );
$this->assertEquals( 'updated_value', $object->get_meta( 'test_meta_key_2' ) ); $this->assertEquals( 'updated_value', $object->get_meta( 'test_meta_key_2' ) );
@ -364,7 +371,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test reading/getting user meta data too. * Test reading/getting user meta data too.
*/ */
function test_usermeta() { public function test_usermeta() {
$object = $this->create_test_user(); $object = $this->create_test_user();
$object_id = $object->get_id(); $object_id = $object->get_id();
$object->add_meta_data( 'test_meta_key', 'val1', true ); $object->add_meta_data( 'test_meta_key', 'val1', true );
@ -379,7 +386,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
* Test adding meta data/updating meta data just added without keys colliding when changing * Test adding meta data/updating meta data just added without keys colliding when changing
* data before a save. * data before a save.
*/ */
function test_add_meta_data_overwrite_before_save() { public function test_add_meta_data_overwrite_before_save() {
$object = new WC_Mock_WC_Data(); $object = new WC_Mock_WC_Data();
$object->add_meta_data( 'test_field_0', 'another field', true ); $object->add_meta_data( 'test_field_0', 'another field', true );
$object->add_meta_data( 'test_field_1', 'another field', true ); $object->add_meta_data( 'test_field_1', 'another field', true );
@ -390,8 +397,10 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test protected method set_date_prop by testing a order date setter. * Test protected method set_date_prop by testing a order date setter.
*
* @param string $timezone The default timezone to operate under.
*/ */
function set_date_prop_gmt_offset( $timezone = 'UTC' ) { public function set_date_prop_gmt_offset( $timezone = 'UTC' ) {
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
date_default_timezone_set( $timezone ); date_default_timezone_set( $timezone );
@ -441,8 +450,10 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test protected method set_date_prop by testing a order date setter. * Test protected method set_date_prop by testing a order date setter.
*
* @param string $timezone The default timezone to operate under.
*/ */
function set_date_prop_timezone_string( $timezone = 'UTC' ) { public function set_date_prop_timezone_string( $timezone = 'UTC' ) {
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
date_default_timezone_set( $timezone ); date_default_timezone_set( $timezone );
@ -492,7 +503,7 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
/** /**
* Test protected method set_date_prop by testing a order date setter. * Test protected method set_date_prop by testing a order date setter.
*/ */
function test_set_date_prop_server_timezone() { public function test_set_date_prop_server_timezone() {
$this->set_date_prop_gmt_offset(); $this->set_date_prop_gmt_offset();
$this->set_date_prop_timezone_string(); $this->set_date_prop_timezone_string();
@ -506,9 +517,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
} }
/** /**
* Test applying changes * Test applying changes.
*/ */
function test_apply_changes() { public function test_apply_changes() {
$data = array( $data = array(
'prop1' => 'value1', 'prop1' => 'value1',
'prop2' => 'value2', 'prop2' => 'value2',
@ -534,9 +545,9 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
} }
/** /**
* Test applying changes with a nested array * Test applying changes with a nested array.
*/ */
function test_apply_changes_nested() { public function test_apply_changes_nested() {
$data = array( $data = array(
'prop1' => 'value1', 'prop1' => 'value1',
'prop2' => array( 'prop2' => array(

View File

@ -1,8 +1,14 @@
<?php <?php
/**
* Tests for the WC_Install class.
*
* @package WooCommerce\Tests\Util
*/
/** /**
* Class WC_Tests_Install. * Class WC_Tests_Install.
* @package WooCommerce\Tests\Util *
* @covers WC_Install
*/ */
class WC_Tests_Install extends WC_Unit_Test_Case { class WC_Tests_Install extends WC_Unit_Test_Case {
@ -51,7 +57,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
* Test - create pages. * Test - create pages.
*/ */
public function test_create_pages() { public function test_create_pages() {
// Clear options // Clear options.
delete_option( 'woocommerce_shop_page_id' ); delete_option( 'woocommerce_shop_page_id' );
delete_option( 'woocommerce_cart_page_id' ); delete_option( 'woocommerce_cart_page_id' );
delete_option( 'woocommerce_checkout_page_id' ); delete_option( 'woocommerce_checkout_page_id' );
@ -64,13 +70,13 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
$this->assertGreaterThan( 0, get_option( 'woocommerce_checkout_page_id' ) ); $this->assertGreaterThan( 0, get_option( 'woocommerce_checkout_page_id' ) );
$this->assertGreaterThan( 0, get_option( 'woocommerce_myaccount_page_id' ) ); $this->assertGreaterThan( 0, get_option( 'woocommerce_myaccount_page_id' ) );
// Delete pages // Delete pages.
wp_delete_post( get_option( 'woocommerce_shop_page_id' ), true ); wp_delete_post( get_option( 'woocommerce_shop_page_id' ), true );
wp_delete_post( get_option( 'woocommerce_cart_page_id' ), true ); wp_delete_post( get_option( 'woocommerce_cart_page_id' ), true );
wp_delete_post( get_option( 'woocommerce_checkout_page_id' ), true ); wp_delete_post( get_option( 'woocommerce_checkout_page_id' ), true );
wp_delete_post( get_option( 'woocommerce_myaccount_page_id' ), true ); wp_delete_post( get_option( 'woocommerce_myaccount_page_id' ), true );
// Clear options // Clear options.
delete_option( 'woocommerce_shop_page_id' ); delete_option( 'woocommerce_shop_page_id' );
delete_option( 'woocommerce_cart_page_id' ); delete_option( 'woocommerce_cart_page_id' );
delete_option( 'woocommerce_checkout_page_id' ); delete_option( 'woocommerce_checkout_page_id' );
@ -88,7 +94,7 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
* Test - create roles. * Test - create roles.
*/ */
public function test_create_roles() { public function test_create_roles() {
// Clean existing install first // Clean existing install first.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
define( 'WP_UNINSTALL_PLUGIN', true ); define( 'WP_UNINSTALL_PLUGIN', true );
define( 'WC_REMOVE_ALL_DATA', true ); define( 'WC_REMOVE_ALL_DATA', true );
@ -143,11 +149,14 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
public function test_get_tables_enables_filter() { public function test_get_tables_enables_filter() {
$this->assertNotContains( 'some_table_name', WC_Install::get_tables() ); $this->assertNotContains( 'some_table_name', WC_Install::get_tables() );
add_filter( 'woocommerce_install_get_tables', function ( $tables ) { add_filter(
$tables[] = 'some_table_name'; 'woocommerce_install_get_tables',
function ( $tables ) {
$tables[] = 'some_table_name';
return $tables; return $tables;
} ); }
);
$this->assertContains( 'some_table_name', WC_Install::get_tables() ); $this->assertContains( 'some_table_name', WC_Install::get_tables() );
} }