View source
<?php
namespace Drupal\Tests\uc_role\Functional;
use Drupal\uc_order\Entity\Order;
use Drupal\Tests\uc_store\Functional\UbercartBrowserTestBase;
use Drupal\user\Entity\User;
class RoleCheckoutTest extends UbercartBrowserTestBase {
protected static $modules = [
'uc_payment',
'uc_payment_pack',
'uc_role',
];
protected $customer;
protected function setUp() {
parent::setUp();
$this->customer = $this
->drupalCreateUser();
\Drupal::configFactory()
->getEditable('system.mail')
->set('interface.uc_order', 'test_mail_collector')
->save();
}
public function testCheckoutRoleAssignment() {
$this
->drupalLogin($this->adminUser);
$method = $this
->createPaymentMethod('other');
$rid = $this
->drupalCreateRole([
'access content',
]);
$this
->drupalGet('node/' . $this->product
->id() . '/edit/features');
$this
->submitForm([
'feature' => 'role',
], 'Add');
$this
->submitForm([
'role' => $rid,
], 'Save feature');
$order = $this
->createOrder([
'uid' => 0,
'payment_method' => $method['id'],
]);
$order->products[1]->data->shippable = 1;
$order
->save();
uc_payment_enter($order
->id(), 'other', $order
->getTotal());
$uid = \Drupal::database()
->query('SELECT uid FROM {uc_orders} ORDER BY order_id DESC')
->fetchField();
$account = User::load($uid);
$order = Order::load($order
->id());
$this
->assertEquals('payment_received', $order
->getStatusId(), 'Shippable order was set to payment received.');
$this
->assertMailString('subject', 'Account details', 4, 'New account email was sent');
$this
->assertMailString('subject', 'Your Order at Ubercart', 4, 'Customer invoice was sent');
$this
->assertMailString('subject', 'New Order at Ubercart', 4, 'Admin notification was sent');
\Drupal::state()
->set('system.test_mail_collector', []);
$order = $this
->createOrder([
'uid' => 0,
'primary_email' => $this->customer
->getEmail(),
'payment_method' => $method['id'],
]);
$order->products[2]->data->shippable = 0;
$order
->save();
uc_payment_enter($order
->id(), 'other', $order
->getTotal());
$account = User::load($this->customer
->id());
$order = Order::load($order
->id());
$this
->assertEquals('completed', $order
->getStatusId(), 'Non-shippable order was set to completed.');
$this
->assertNoMailString('subject', 'Account details', 4, 'New account email was sent');
$this
->assertMailString('subject', 'Your Order at Ubercart', 4, 'Customer invoice was sent');
$this
->assertMailString('subject', 'New Order at Ubercart', 4, 'Admin notification was sent');
}
}