Skip to content

Commit

Permalink
phpcs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
martynmjones committed Sep 20, 2024
1 parent c4b11d7 commit 55ba9bc
Showing 1 changed file with 67 additions and 59 deletions.
126 changes: 67 additions & 59 deletions tests/Unit/Product/Attributes/GtinMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,111 +12,119 @@
*
* Unit tests to confirm that the GTIN value is mapped correctly.
* The value should be prioritised in the following order:
*
*
* 1. WooCommerce Core: Global Unique ID
* 2. Google for WooCommerce: GTIN attribute
* 3. Google for WooCommerce: Attribute mapping rules
*/
class GtinMappingTest extends TestCase {

/** @var string $core_gtin Mock value to be used as the core gtin field. */
private $core_gtin = '219837492834';
/** @var string $core_gtin Mock value to be used as the core gtin field. */
private $core_gtin = '219837492834';

/** @var string $gla_gtin Mock value to be used as the Google for WooCommerce gtin field. */
private $gla_gtin = 'gla-gtin-field';
/** @var string $gla_gtin Mock value to be used as the Google for WooCommerce gtin field. */
private $gla_gtin = 'gla-gtin-field';

/** @var string $gla_attribute_mapping_gtin Mock value to be used as the Google for WooCommerce attribute mapping gtin value. */
private $gla_attribute_mapping_gtin = 'gla-attribute-mapping-gtin';
/** @var string $gla_attribute_mapping_gtin Mock value to be used as the Google for WooCommerce attribute mapping gtin value. */
private $gla_attribute_mapping_gtin = 'gla-attribute-mapping-gtin';

/**
* Test GTIN mapping from WooCommerce Core Global Unique ID.
*
* @return void
*
* @return void
*/
public function test_gtin_populated_from_wc_core_global_unique_id() {
$mock_product = WC_Helper_Product::create_simple_product( false );
$mock_product->set_global_unique_id( $this->core_gtin );
$mock_product = WC_Helper_Product::create_simple_product( false );
$mock_product->set_global_unique_id( $this->core_gtin );

$adapter = new WCProductAdapter();
$adapter->mapTypes( [
'wc_product' => $mock_product,
'targetCountry' => 'US',
'gla_attributes' => [
'gtin' => $this->gla_gtin
],
] );
$adapter->mapTypes(
[
'wc_product' => $mock_product,
'targetCountry' => 'US',
'gla_attributes' => [
'gtin' => $this->gla_gtin,
],
]
);

$this->assertEquals( $this->core_gtin, $adapter->getGtin() );
}

/**
* Test GTIN mapping from Google for WooCommerce GTIN attribute.
*
* @return void
*
* @return void
*/
public function test_gtin_populated_from_gla_gtin_attribute() {
$mock_product = WC_Helper_Product::create_simple_product( false );
$mock_product->set_sku( $this->gla_attribute_mapping_gtin );
$mock_product = WC_Helper_Product::create_simple_product( false );
$mock_product->set_sku( $this->gla_attribute_mapping_gtin );

$adapter = new WCProductAdapter();
$adapter->mapTypes( [
'wc_product' => $mock_product,
'targetCountry' => 'US',
'mapping_rules' => [
[
'attribute' => 'gtin',
'source' => 'product:sku',
'category_condition_type' => 'all',
'categories' => ''
]
],
'gla_attributes' => [
'gtin' => $this->gla_gtin
],
] );
$adapter->mapTypes(
[
'wc_product' => $mock_product,
'targetCountry' => 'US',
'mapping_rules' => [
[
'attribute' => 'gtin',
'source' => 'product:sku',
'category_condition_type' => 'all',
'categories' => '',
],
],
'gla_attributes' => [
'gtin' => $this->gla_gtin,
],
]
);

$this->assertEquals( $this->gla_gtin, $adapter->getGtin() );
}

/**
* Test GTIN mapping from Google for WooCommerce attribute mapping rules.
*
* @return void
*
* @return void
*/
public function test_gtin_populated_from_attribute_mapping_rules() {
$mock_product = WC_Helper_Product::create_simple_product( false );
$mock_product->set_sku( $this->gla_attribute_mapping_gtin );
$mock_product = WC_Helper_Product::create_simple_product( false );
$mock_product->set_sku( $this->gla_attribute_mapping_gtin );

$adapter = new WCProductAdapter();
$adapter->mapTypes( [
'wc_product' => $mock_product,
'targetCountry' => 'US',
'mapping_rules' => [
[
'attribute' => 'gtin',
'source' => 'product:sku',
'category_condition_type' => 'all',
'categories' => ''
]
],
] );
$adapter->mapTypes(
[
'wc_product' => $mock_product,
'targetCountry' => 'US',
'mapping_rules' => [
[
'attribute' => 'gtin',
'source' => 'product:sku',
'category_condition_type' => 'all',
'categories' => '',
],
],
]
);

$this->assertEquals( $this->gla_attribute_mapping_gtin, $adapter->getGtin() );
}

/**
* Test GTIN remains empty when no data is available.
*
* @return void
*
* @return void
*/
public function test_gtin_remains_empty_when_no_data_available() {
$mock_product = WC_Helper_Product::create_simple_product( false );

$adapter = new WCProductAdapter();
$adapter->mapTypes( [
'wc_product' => $mock_product,
'targetCountry' => 'US',
] );
$adapter->mapTypes(
[
'wc_product' => $mock_product,
'targetCountry' => 'US',
]
);

$this->assertEquals( '', $adapter->getGtin() );
}
Expand Down

0 comments on commit 55ba9bc

Please sign in to comment.