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