public function ProductVariationFieldInjectionTest::testInjectedVariationDefault in Commerce Core 8.2
Tests the fields from the attribute render.
1 call to ProductVariationFieldInjectionTest::testInjectedVariationDefault()
- ProductVariationFieldInjectionTest::testInjectedFieldsWithLayoutBuilderInstalled in modules/
product/ tests/ src/ Functional/ ProductVariationFieldInjectionTest.php - Verifies installing Layout Builder does not break field injection.
File
- modules/
product/ tests/ src/ Functional/ ProductVariationFieldInjectionTest.php, line 72
Class
- ProductVariationFieldInjectionTest
- Tests the product variation field display injection.
Namespace
Drupal\Tests\commerce_product\FunctionalCode
public function testInjectedVariationDefault() {
// Hide the variations field, so it does not render the variant titles.
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $product_view_display */
$product_view_display = commerce_get_entity_display('commerce_product', $this->product
->bundle(), 'view');
$product_view_display
->removeComponent('variations');
$product_view_display
->save();
$this
->drupalGet($this->product
->toUrl());
$this
->assertSession()
->pageTextContains('Testing product variation field injection!');
$this
->assertSession()
->pageTextContains('Price');
$this
->assertSession()
->pageTextContains('$999.00');
$this
->assertSession()
->elementNotExists('css', 'div[data-quickedit-field-id="commerce_product_variation/*"]');
// We hide the SKU by default.
$this
->assertSession()
->pageTextNotContains('INJECTION-CYAN');
// Set a display for the color attribute.
/** @var \Drupal\Core\Entity\Entity\EntityViewDisplay $variation_view_display */
$variation_view_display = commerce_get_entity_display('commerce_product_variation', 'default', 'view');
$variation_view_display
->removeComponent('title');
$variation_view_display
->setComponent('attribute_color', [
'label' => 'above',
'type' => 'entity_reference_label',
]);
// Set the display for the SKU.
$variation_view_display
->setComponent('sku', [
'label' => 'hidden',
'type' => 'string',
]);
$variation_view_display
->save();
// Have to call this save to get the cache to clear, we set the tags
// correctly in a hook, but unless you trigger the submit it doesn't seem
// to clear. Something additional happens on save that we're missing.
$this
->drupalGet('admin/commerce/config/product-variation-types/default/edit/display');
$this
->submitForm([], 'Save');
$this
->drupalGet($this->product
->toUrl());
$this
->assertSession()
->pageTextNotContains($this->product
->label() . ' - Cyan');
$this
->assertSession()
->pageTextContains('INJECTION-CYAN');
$this
->assertSession()
->pageTextContains('$999.00');
}