/**
  * Test the title generation.
  */
 public function testTitleGeneration()
 {
     /** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation */
     $variation = $this->createEntity('commerce_product_variation', ['type' => 'test_default', 'sku' => strtolower($this->randomMachineName())]);
     /** @var \Drupal\commerce_product\Entity\ProductInterface $product */
     $product = $this->createEntity('commerce_product', ['type' => 'default', 'title' => 'My product', 'variations' => [$variation]]);
     $this->assertFalse($variation->getTitle());
     $this->variationType->setGenerateTitle(TRUE);
     $this->variationType->save();
     /** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation */
     $variation = $this->createEntity('commerce_product_variation', ['type' => 'test_default', 'sku' => strtolower($this->randomMachineName())]);
     /** @var \Drupal\commerce_product\Entity\ProductInterface $product */
     $product = $this->createEntity('commerce_product', ['type' => 'default', 'title' => 'My second product', 'variations' => [$variation]]);
     $this->assertEqual($variation->getTitle(), $product->getTitle());
     // @todo Create attributes, then retest title generation.
 }
 /**
  * Helper method to create an attribute field on a variation type.
  *
  * @param \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type
  *   The variation type.
  * @param string $field_name
  *   The field name.
  */
 protected function createAttributeField(ProductVariationTypeInterface $variation_type, $field_name)
 {
     $attribute_vocabulary = Vocabulary::create(['name' => $field_name, 'vid' => $field_name]);
     $attribute_vocabulary->save();
     $field_storage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'commerce_product_variation', 'type' => 'entity_reference', 'cardinality' => 1, 'settings' => ['target_type' => 'taxonomy_term']]);
     $field_storage->save();
     $field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $variation_type->id(), 'label' => $field_name, 'settings' => ['handler' => 'default:taxonomy_term', 'handler_settings' => ['target_bundles' => [$attribute_vocabulary->id() => $attribute_vocabulary->id()], 'auto_create' => TRUE]], 'required' => TRUE, 'translatable' => FALSE]);
     $field->setThirdPartySetting('commerce_product', 'attribute_widget_title', '');
     $field->setThirdPartySetting('commerce_product', 'attribute_widget', 'select');
     $field->setThirdPartySetting('commerce_product', 'attribute_field', TRUE);
     $field->save();
 }