public function ProductVariationAttributeMapperTest::testSelectWithOptionalAttributes in Commerce Core 8.2
Tests selecting a variation when there are optional attributes.
@covers ::selectVariation
File
- modules/
product/ tests/ src/ Kernel/ ProductVariationAttributeMapperTest.php, line 192
Class
- ProductVariationAttributeMapperTest
- Tests the product variation attribute mapper.
Namespace
Drupal\Tests\commerce_product\KernelCode
public function testSelectWithOptionalAttributes() {
$product = $this
->generateThreeByTwoOptionalScenario();
$variations = $product
->getVariations();
$selected_variation = $this->mapper
->selectVariation($variations, [
'attribute_ram' => $this->ramAttributes['16gb']
->id(),
]);
$this
->assertEquals($variations[1]
->id(), $selected_variation
->id());
$selected_variation = $this->mapper
->selectVariation($variations, [
'attribute_ram' => $this->ramAttributes['16gb']
->id(),
'attribute_disk1' => $this->disk1Attributes['1tb']
->id(),
'attribute_disk2' => $this->disk2Attributes['1tb']
->id(),
]);
$this
->assertEquals($variations[2]
->id(), $selected_variation
->id());
$selected_variation = $this->mapper
->selectVariation($variations, [
'attribute_ram' => $this->ramAttributes['16gb']
->id(),
'attribute_disk1' => $this->disk1Attributes['1tb']
->id(),
'attribute_disk2' => $this->disk2Attributes['2tb']
->id(),
]);
// Falls back to 16GBx1TB, 16GBx1TBx2TB is invalid.
$this
->assertEquals($variations[1]
->id(), $selected_variation
->id());
}