only in patch2:
unchanged:
--- a/tests/src/Kernel/CommerceMigrateTestTrait.php
+++ b/tests/src/Kernel/CommerceMigrateTestTrait.php
@@ -9,7 +9,9 @@ use Drupal\commerce_order\Entity\OrderItem;
use Drupal\commerce_price\Entity\Currency;
use Drupal\commerce_price\Entity\CurrencyInterface;
use Drupal\commerce_product\Entity\Product;
+use Drupal\commerce_product\Entity\ProductType;
use Drupal\commerce_product\Entity\ProductVariation;
+use Drupal\commerce_product\Entity\ProductVariationType;
use Drupal\commerce_store\Entity\Store;
use Drupal\profile\Entity\Profile;
@@ -217,6 +219,23 @@ trait CommerceMigrateTestTrait {
}
/**
+ * Asserts a product type entity.
+ *
+ * @param string $id
+ * The product type id.
+ * @param string $expected_label
+ * The expected label.
+ * @param string $expected_description
+ * The expected description.
+ */
+ public function assertProductTypeEntity($id, $expected_label, $expected_description) {
+ $product_type = ProductType::load($id);
+ $this->assertInstanceOf(ProductType::class, $product_type);
+ $this->assertSame($expected_label, $product_type->label());
+ $this->assertSame($expected_description, $product_type->getDescription());
+ }
+
+ /**
* Asserts a product variation.
*
* @param int $id
@@ -249,6 +268,26 @@ trait CommerceMigrateTestTrait {
}
/**
+ * Asserts a product variation type.
+ *
+ * @param string $id
+ * The product variation type.
+ * @param string $expected_label
+ * The expected label.
+ * @param string $expected_order_item_type_id
+ * The expected order item type id.
+ * @param bool $expected_should_generate_title
+ * The expected indicator that a title is generated.
+ */
+ public function assertProductVariationTypeEntity($id, $expected_label, $expected_order_item_type_id, $expected_should_generate_title) {
+ $variation_type = ProductVariationType::load($id);
+ $this->assertInstanceOf(ProductVariationType::class, $variation_type);
+ $this->assertSame($expected_label, $variation_type->label());
+ $this->assertSame($expected_order_item_type_id, $variation_type->getOrderItemTypeId());
+ $this->assertSame($expected_should_generate_title, $variation_type->shouldGenerateTitle());
+ }
+
+ /**
* Asserts a store entity.
*
* @param int $id
only in patch2:
unchanged:
--- a/tests/src/Kernel/d7/Commerce/ProductTypeTest.php
+++ b/tests/src/Kernel/d7/Commerce/ProductTypeTest.php
@@ -2,7 +2,7 @@
namespace Drupal\Tests\commerce_migrate\Kernel\d7\Commerce;
-use Drupal\commerce_product\Entity\ProductType;
+use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
/**
* Tests line item migration.
@@ -11,6 +11,8 @@ use Drupal\commerce_product\Entity\ProductType;
*/
class ProductTypeTest extends Commerce1TestBase {
+ use CommerceMigrateTestTrait;
+
/**
* Modules to enable.
*
@@ -37,15 +39,11 @@ class ProductTypeTest extends Commerce1TestBase {
* Test product type migration from Drupal 7 to 8.
*/
public function testProductType() {
- $bags_cases = ProductType::load('bags_cases');
- $this->assertNotNull($bags_cases);
- $this->assertEquals('Bags & Cases', $bags_cases->label());
- $this->assertEquals('A Bags & Cases is a content type which contain product variations.', $bags_cases->getDescription());
-
- $tops = ProductType::load('tops');
- $this->assertNotNull($tops);
- $this->assertEquals('Tops', $tops->label());
- $this->assertEquals('A Tops is a content type which contain product variations.', $tops->getDescription());
+ $description = 'A Bags & Cases is a content type which contain product variations.';
+ $this->assertProductTypeEntity('bags_cases', 'Bags & Cases', $description);
+
+ $description = 'A Tops is a content type which contain product variations.';
+ $this->assertProductTypeEntity('tops', 'Tops', $description);
/** @var \Drupal\Core\Entity\EntityFieldManager $field_manager */
$field_manager = \Drupal::service('entity_field.manager');
only in patch2:
unchanged:
--- a/tests/src/Kernel/d7/Commerce/ProductVariationTypeTest.php
+++ b/tests/src/Kernel/d7/Commerce/ProductVariationTypeTest.php
@@ -2,7 +2,7 @@
namespace Drupal\Tests\commerce_migrate\Kernel\d7\Commerce;
-use Drupal\commerce_product\Entity\ProductVariationType;
+use Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait;
/**
* Tests product variation type migration.
@@ -11,6 +11,8 @@ use Drupal\commerce_product\Entity\ProductVariationType;
*/
class ProductVariationTypeTest extends Commerce1TestBase {
+ use CommerceMigrateTestTrait;
+
/**
* Modules to enable.
*
@@ -42,11 +44,7 @@ class ProductVariationTypeTest extends Commerce1TestBase {
* Product variation types in Drupal 8 are product types in Drupal 7.
*/
public function testProductVariationType() {
- $variation_type = ProductVariationType::load('bags_cases');
- $this->assertNotNull($variation_type);
- $this->assertEquals($variation_type->label(), 'Bags & Cases');
- $this->assertFalse($variation_type->shouldGenerateTitle());
- $this->assertEquals($variation_type->getOrderItemTypeId(), 'default');
+ $this->assertProductVariationTypeEntity('bags_cases', 'Bags & Cases', 'default', FALSE);
}
}