public function RoleTest::testRolePurchaseCheckout in Ubercart 8.4
Tests purchase of role.
File
- uc_role/
tests/ src/ Functional/ RoleTest.php, line 34
Class
- RoleTest
- Tests the role purchase functionality.
Namespace
Drupal\Tests\uc_role\FunctionalCode
public function testRolePurchaseCheckout() {
// Add role assignment to a free, non-shippable product.
$product = $this
->createProduct([
'price' => 0,
'shippable' => 0,
]);
$rid = $this
->drupalCreateRole([
'access content',
]);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node/' . $product
->id() . '/edit/features');
$this
->submitForm([
'feature' => 'role',
], 'Add');
$edit = [
'role' => $rid,
'end_override' => TRUE,
'expire_relative_duration' => 1,
'expire_relative_granularity' => 'day',
];
$this
->submitForm($edit, 'Save feature');
// Check out with the test product.
$this
->addToCart($product);
$order = $this
->checkout();
// Test that the role was granted.
// @todo Re-enable when Rules is available.
// $this->assertTrue($order->getOwner()->hasRole($rid), 'Existing user was granted role.');
// Test that the email is correct.
$role = Role::load($rid);
// @todo Re-enable when Rules is available.
// $this->assertMailString('subject', $role->label(), 4, 'Role assignment email mentions role in subject line.');
// Test that the role product / user relation is deleted with the user.
user_delete($order
->getOwnerId());
// Run cron to ensure deleted users are handled correctly.
$this
->cronRun();
}