View source
<?php
namespace Drupal\Tests\commerce_recurring\Kernel;
use Drupal\commerce_recurring\Entity\Subscription;
class BillingScheduleAccessTest extends RecurringKernelTestBase {
public static $modules = [
'commerce_recurring',
];
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->createUser();
}
public function testAccess() {
$account = $this
->createUser([], [
'access administration pages',
]);
$this
->assertFalse($this->billingSchedule
->access('view label', $account));
$this
->assertFalse($this->billingSchedule
->access('view', $account));
$this
->assertFalse($this->billingSchedule
->access('update', $account));
$this
->assertFalse($this->billingSchedule
->access('delete', $account));
$account = $this
->createUser([], [
'administer commerce_billing_schedule',
]);
$this
->assertTrue($this->billingSchedule
->access('view label', $account));
$this
->assertTrue($this->billingSchedule
->access('view', $account));
$this
->assertTrue($this->billingSchedule
->access('update', $account));
$this
->assertTrue($this->billingSchedule
->access('delete', $account));
$account = $this
->createUser([], [
'view own commerce_subscription',
]);
$this
->assertTrue($this->billingSchedule
->access('view label', $account));
$this
->assertFalse($this->billingSchedule
->access('view', $account));
$this
->assertFalse($this->billingSchedule
->access('update', $account));
$this
->assertFalse($this->billingSchedule
->access('delete', $account));
$account = $this
->createUser([], [
'view any commerce_subscription',
]);
$this
->assertTrue($this->billingSchedule
->access('view label', $account));
$this
->assertFalse($this->billingSchedule
->access('view', $account));
$this
->assertFalse($this->billingSchedule
->access('update', $account));
$this
->assertFalse($this->billingSchedule
->access('delete', $account));
$account = $this
->createUser([], [
'update any commerce_subscription',
]);
$this
->assertTrue($this->billingSchedule
->access('view label', $account));
$this
->assertFalse($this->billingSchedule
->access('view', $account));
$this
->assertFalse($this->billingSchedule
->access('update', $account));
$this
->assertFalse($this->billingSchedule
->access('delete', $account));
$account = $this
->createUser([], [
'administer commerce_subscription',
]);
$this
->assertTrue($this->billingSchedule
->access('view label', $account));
$this
->assertFalse($this->billingSchedule
->access('view', $account));
$this
->assertFalse($this->billingSchedule
->access('update', $account));
$this
->assertFalse($this->billingSchedule
->access('delete', $account));
$subscription = Subscription::create([
'type' => 'product_variation',
'title' => $this
->randomString(),
'uid' => $this->user
->id(),
'billing_schedule' => $this->billingSchedule,
'purchased_entity' => $this->variation,
'store_id' => $this->store
->id(),
'unit_price' => $this->variation
->getPrice(),
'starts' => time(),
'state' => 'active',
]);
$subscription
->save();
$account = $this
->createUser([], [
'administer commerce_billing_schedule',
]);
$this
->assertFalse($this->billingSchedule
->access('delete', $account));
}
}