public function AttributeTest::testAttributeUiSettings in Ubercart 8.4
Tests the attribute settings page.
File
- uc_attribute/
tests/ src/ Functional/ AttributeTest.php, line 386
Class
- AttributeTest
- Tests the product attribute API.
Namespace
Drupal\Tests\uc_attribute\FunctionalCode
public function testAttributeUiSettings() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
$product = $this
->createProduct();
$attribute = $this
->createAttribute([
'display' => 1,
]);
$option = $this
->createAttributeOption([
'aid' => $attribute->aid,
'price' => 30,
]);
$attribute->options[$option->oid] = $option;
uc_attribute_subject_save($attribute, 'product', $product
->id(), TRUE);
$qty = $product->default_qty->value;
if (!$qty) {
$qty = 1;
}
$adjust_price = uc_currency_format($option->price * $qty);
$total_price = uc_currency_format(($product->price->value + $option->price) * $qty);
$raw = [
'none' => $option->name . '</option>',
'adjustment' => $option->name . ', +' . $adjust_price . '</option>',
'total' => $total_price . '</option>',
];
foreach ([
'none',
'adjustment',
'total',
] as $type) {
$edit['uc_attribute_option_price_format'] = $type;
$this
->drupalGet('admin/store/config/products');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('node/' . $product
->id());
// Verify attribute option pricing is correct.
$assert
->responseContains($raw[$type]);
}
}