public function ProductAdminTest::testEditVariation in Commerce Core 8.2
Tests editing a product variation.
File
- modules/
product/ tests/ src/ Functional/ ProductAdminTest.php, line 345
Class
- ProductAdminTest
- Create, view, edit, delete, and change products.
Namespace
Drupal\Tests\commerce_product\FunctionalCode
public function testEditVariation() {
$product = $this
->createEntity('commerce_product', [
'type' => 'default',
]);
$variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'product_id' => $product
->id(),
'sku' => strtolower($this
->randomMachineName()),
]);
// Check the integrity of the variation form.
$this
->drupalGet($variation
->toUrl('edit-form'));
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->fieldExists('sku[0][value]');
$this
->assertSession()
->fieldExists('price[0][number]');
$this
->assertSession()
->buttonExists('Save');
$new_sku = strtolower($this
->randomMachineName());
$new_price_amount = '1.11';
$variations_edit = [
'sku[0][value]' => $new_sku,
'price[0][number]' => $new_price_amount,
'status[value]' => 1,
];
$this
->submitForm($variations_edit, 'Save');
$this
->assertSession()
->addressEquals($variation
->toUrl('collection'));
$this->container
->get('entity_type.manager')
->getStorage('commerce_product_variation')
->resetCache([
$variation
->id(),
]);
$variation = ProductVariation::load($variation
->id());
$this
->assertEquals($new_sku, $variation
->getSku());
$this
->assertEquals($new_price_amount, $variation
->getPrice()
->getNumber());
}