public function ProductVariationAttributeMapperTest::testPrepareAttributes in Commerce Core 8.2
Tests preparing attributes.
@covers ::prepareAttributes
File
- modules/
product/ tests/ src/ Kernel/ ProductVariationAttributeMapperTest.php, line 222
Class
- ProductVariationAttributeMapperTest
- Tests the product variation attribute mapper.
Namespace
Drupal\Tests\commerce_product\KernelCode
public function testPrepareAttributes() {
$product = $this
->generateThreeByTwoScenario();
$variations = $product
->getVariations();
// Test from the initial variation.
$attributes = $this->mapper
->prepareAttributes(reset($variations), $variations);
$color_attribute = $attributes['attribute_color'];
$this
->assertEquals('color', $color_attribute
->getId());
$this
->assertEquals('Color', $color_attribute
->getLabel());
$this
->assertEquals('select', $color_attribute
->getElementType());
$this
->assertTrue($color_attribute
->isRequired());
$this
->assertEquals([
'2' => 'Blue',
'4' => 'Red',
], $color_attribute
->getValues());
$size_attribute = $attributes['attribute_size'];
$this
->assertEquals('size', $size_attribute
->getId());
$this
->assertEquals('Size', $size_attribute
->getLabel());
$this
->assertEquals('select', $size_attribute
->getElementType());
$this
->assertTrue($size_attribute
->isRequired());
$this
->assertEquals([
'7' => 'Small',
'8' => 'Medium',
'9' => 'Large',
], $size_attribute
->getValues());
// Test Blue Medium.
$attributes = $this->mapper
->prepareAttributes($variations[4], $variations);
$color_attribute = $attributes['attribute_color'];
$this
->assertEquals('color', $color_attribute
->getId());
$this
->assertEquals('Color', $color_attribute
->getLabel());
$this
->assertEquals('select', $color_attribute
->getElementType());
$this
->assertTrue($color_attribute
->isRequired());
$this
->assertEquals([
'2' => 'Blue',
'4' => 'Red',
], $color_attribute
->getValues());
$size_attribute = $attributes['attribute_size'];
$this
->assertEquals('size', $size_attribute
->getId());
$this
->assertEquals('Size', $size_attribute
->getLabel());
$this
->assertEquals('select', $size_attribute
->getElementType());
$this
->assertTrue($size_attribute
->isRequired());
$this
->assertEquals([
'7' => 'Small',
'8' => 'Medium',
], $size_attribute
->getValues());
}