FulfillmentRulesEventsTest.php in Ubercart 8.4
File
shipping/uc_fulfillment/tests/src/Functional/FulfillmentRulesEventsTest.php
View source
<?php
namespace Drupal\Tests\uc_fulfillment\Functional;
use Drupal\rules\Context\ContextConfig;
class FulfillmentRulesEventsTest extends FulfillmentTestBase {
protected static $modules = [
'rules',
];
protected $rulesStorage;
protected $expressionManager;
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this->rulesStorage = $this->container
->get('entity_type.manager')
->getStorage('rules_reaction_rule');
$this->expressionManager = $this->container
->get('plugin.manager.rules_expression');
}
public function testRulesEvents() {
$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();
}
$method = $this
->createPaymentMethod('other');
$order = $this
->createOrder([
'uid' => 0,
'payment_method' => $method['id'],
'primary_email' => $this
->randomMachineName() . '@example.org',
]);
$order->products[1]->data->shippable = 1;
$order
->save();
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/packages');
$this
->submitForm([
'shipping_types[small_package][table][' . $order
->id() . '][checked]' => 1,
], 'Create one package');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/shipments/new');
$this
->submitForm([
'shipping_types[small_package][table][' . $order
->id() . '][checked]' => 1,
], 'Ship packages');
$edit = $this
->populateShipmentForm();
$this
->submitForm($edit, 'Save shipment');
$assert
->pageTextContains($message[1], '"' . $message[1] . '" IS shown');
}
}