You are here

public function ProductAdminTest::testEditProduct in Commerce Core 8.2

Tests editing a product.

File

modules/product/tests/src/Functional/ProductAdminTest.php, line 111

Class

ProductAdminTest
Create, view, edit, delete, and change products.

Namespace

Drupal\Tests\commerce_product\Functional

Code

public function testEditProduct() {
  $product = $this
    ->createEntity('commerce_product', [
    'type' => 'default',
  ]);

  // Check the integrity of the edit form.
  $this
    ->drupalGet($product
    ->toUrl('edit-form'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldExists('title[0][value]');
  $title = $this
    ->randomMachineName();
  $store_ids = EntityHelper::extractIds($this->stores);
  $edit = [
    'title[0][value]' => $title,
  ];
  foreach ($store_ids as $store_id) {
    $edit['stores[target_id][value][' . $store_id . ']'] = $store_id;
  }
  $this
    ->submitForm($edit, 'Save');
  $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_product')
    ->resetCache([
    $product
      ->id(),
  ]);
  $product = Product::load($product
    ->id());
  $this
    ->assertEquals($product
    ->getTitle(), $title, 'The product title successfully updated.');
  $this
    ->assertFieldValues($product
    ->getStores(), $this->stores, 'Updated product has the correct associated stores.');
  $this
    ->assertFieldValues($product
    ->getStoreIds(), $store_ids, 'Updated product has the correct associated store ids.');
}