public function FulfillmentRulesEventsTest::testRulesEvents in Ubercart 8.4
Tests the one event provided by uc_fulfillment.
File
- shipping/
uc_fulfillment/ tests/ src/ Functional/ FulfillmentRulesEventsTest.php, line 50
Class
- FulfillmentRulesEventsTest
- Tests the one event that uc_fulfillment provides for use in Rules module.
Namespace
Drupal\Tests\uc_fulfillment\FunctionalCode
public function testRulesEvents() {
// Create one reaction rule for each event that uc_fulfillment triggers.
$rule_data = [
1 => [
'uc_fulfillment_shipment_save',
'A shipment is saved',
],
];
foreach ($rule_data as $i => list($event_name, $description)) {
$rule[$i] = $this->expressionManager
->createRule();
$message[$i] = 'RULES message ' . $i . ': ' . $description;
$rule[$i]
->addAction('rules_system_message', ContextConfig::create()
->setValue('message', $message[$i])
->setValue('type', 'status'));
$config_entity = $this->rulesStorage
->create([
'id' => 'rule' . $i,
'events' => [
[
'event_name' => $event_name,
],
],
'expression' => $rule[$i]
->getConfiguration(),
]);
$config_entity
->save();
}
// A payment method for the order.
$method = $this
->createPaymentMethod('other');
// Create an anonymous, shippable order.
$order = $this
->createOrder([
'uid' => 0,
'payment_method' => $method['id'],
'primary_email' => $this
->randomMachineName() . '@example.org',
]);
$order->products[1]->data->shippable = 1;
$order
->save();
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
// Select product and create one package.
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$this
->submitForm([
'shipping_types[small_package][table][' . $order
->id() . '][checked]' => 1,
], 'Create one package');
// Select all packages and make shipment using the default "Manual" method.
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments/new');
$this
->submitForm([
'shipping_types[small_package][table][' . $order
->id() . '][checked]' => 1,
], 'Ship packages');
// Make the shipment.
// This should trigger the uc_fulfillment_shipment_save event.
$edit = $this
->populateShipmentForm();
$this
->submitForm($edit, 'Save shipment');
// Check for message triggered by the event.
$assert
->pageTextContains($message[1], '"' . $message[1] . '" IS shown');
}