PurchasedEntityFormSaveTest.php in Commerce Pricelist 8
File
tests/src/Functional/PurchasedEntityFormSaveTest.php
View source
<?php
namespace Drupal\Tests\commerce_pricelist\Functional;
use Drupal\commerce_pricelist\Entity\PriceListItem;
class PurchasedEntityFormSaveTest extends PriceListBrowserTestBase {
public function testProductFormSave() {
$variation_a = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
]);
$variation_b = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
]);
$this->product = $this
->createEntity('commerce_product', [
'type' => 'default',
'variations' => [
$variation_a,
$variation_b,
],
'stores' => $this->stores,
]);
$priceListItem = $this
->createEntity('price_list_item', [
'type' => 'default',
'purchased_entity' => $variation_b,
]);
$variation_b
->set('field_price_list_item', [
$priceListItem,
]);
$variation_b
->save();
$edit = [
'title[0][value]' => 'lll',
];
$this
->drupalPostForm('/product/' . $this->product
->id() . '/edit', $edit, t('Save'));
\Drupal::service('entity_type.manager')
->getStorage('price_list_item')
->resetCache([
$priceListItem
->id(),
]);
$priceListItem = PriceListItem::load($priceListItem
->id());
$this
->assertEquals($variation_b
->id(), $priceListItem
->getPurchasedEntity()
->id());
}
}