public function ProductAdminTest::testDeleteVariation in Commerce Core 8.2
Tests deleting a product variation.
File
- modules/
product/ tests/ src/ Functional/ ProductAdminTest.php, line 426
Class
- ProductAdminTest
- Create, view, edit, delete, and change products.
Namespace
Drupal\Tests\commerce_product\FunctionalCode
public function testDeleteVariation() {
$product = $this
->createEntity('commerce_product', [
'title' => $this
->randomMachineName(),
'type' => 'default',
]);
$variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'product_id' => $product
->id(),
'sku' => strtolower($this
->randomMachineName()),
]);
$this
->drupalGet($variation
->toUrl('delete-form'));
$this
->assertSession()
->pageTextContains(t("Are you sure you want to delete the @variation variation?", [
'@variation' => $variation
->label(),
]));
$this
->assertSession()
->pageTextContains(t('This action cannot be undone.'));
$this
->submitForm([], 'Delete');
$this
->assertSession()
->addressEquals($variation
->toUrl('collection'));
$this->container
->get('entity_type.manager')
->getStorage('commerce_product_variation')
->resetCache();
$variation_exists = (bool) ProductVariation::load($variation
->id());
$this
->assertEmpty($variation_exists, 'The new variation has been deleted from the database.');
}