You are here

public function OrderRefreshTest::testShouldRefresh in Commerce Core 8.2

Tests the shouldRefresh() logic.

File

modules/order/tests/src/Kernel/OrderRefreshTest.php, line 137

Class

OrderRefreshTest
Tests the order refresh process.

Namespace

Drupal\Tests\commerce_order\Kernel

Code

public function testShouldRefresh() {
  $order_refresh = $this
    ->createOrderRefresh(time() + 3600);
  $order_type = OrderType::load($this->order
    ->bundle());
  $order_type
    ->setRefreshMode(OrderType::REFRESH_CUSTOMER)
    ->save();

  // Order does not belong to the current user.
  $this->container
    ->get('current_user')
    ->setAccount(new AnonymousUserSession());
  $this
    ->assertEmpty($order_refresh
    ->shouldRefresh($this->order));

  // Order belongs to the current user.
  $this->container
    ->get('current_user')
    ->setAccount($this->user);
  $this
    ->assertNotEmpty($order_refresh
    ->shouldRefresh($this->order));

  // Order should be refreshed for any user.
  $this->container
    ->get('current_user')
    ->setAccount(new AnonymousUserSession());
  $order_type = OrderType::load($this->order
    ->bundle());
  $order_type
    ->setRefreshMode(OrderType::REFRESH_ALWAYS)
    ->save();
  $this
    ->assertNotEmpty($order_refresh
    ->shouldRefresh($this->order));
}