public function ProductKitTest::testProductKitNodeForm in Ubercart 8.4
Tests creating product kits through the node form.
File
- uc_product_kit/
tests/ src/ Functional/ ProductKitTest.php, line 45
Class
- ProductKitTest
- Tests product kit functionality.
Namespace
Drupal\Tests\uc_product_kit\FunctionalCode
public function testProductKitNodeForm() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$this
->drupalLogin($this->adminUser);
// Allow the default quantity to be set.
$edit = [
'uc_product_add_to_cart_qty' => TRUE,
];
$this
->drupalGet('admin/store/config/products');
$this
->submitForm($edit, 'Save configuration');
// Create some test products.
$products = [];
for ($i = 0; $i < 3; $i++) {
$products[$i] = $this
->createProduct();
}
// Test the product kit fields.
$this
->drupalGet('node/add/product_kit');
foreach ([
'mutable',
'products[]',
] as $field) {
$assert
->fieldExists($field);
}
// Test creation of a basic kit.
$title_key = 'title[0][value]';
$body_key = 'body[0][value]';
$edit = [
$title_key => $this
->randomMachineName(32),
$body_key => $this
->randomMachineName(64),
'products[]' => [
$products[0]
->id(),
$products[1]
->id(),
$products[2]
->id(),
],
];
$this
->drupalGet('node/add/product_kit');
$this
->submitForm($edit, 'Save');
$assert
->pageTextContains(format_string('Product kit @title has been created.', [
'@title' => $edit[$title_key],
]));
$assert
->pageTextContains($edit[$body_key], 'Product kit body found.');
$assert
->pageTextContains('1 × ' . $products[0]
->label(), 'Product 1 title found.');
$assert
->pageTextContains('1 × ' . $products[1]
->label(), 'Product 2 title found.');
$assert
->pageTextContains('1 × ' . $products[2]
->label(), 'Product 3 title found.');
$total = $products[0]->price->value + $products[1]->price->value + $products[2]->price->value;
$assert
->pageTextContains(uc_currency_format($total), 'Product kit total found.');
}