You are here

public function SelectPaymentMethodConfigurationTest::testAccess in Payment 8.2

@covers ::access

File

tests/src/Unit/Controller/SelectPaymentMethodConfigurationTest.php, line 116

Class

SelectPaymentMethodConfigurationTest
@coversDefaultClass \Drupal\payment\Controller\SelectPaymentMethodConfiguration

Namespace

Drupal\Tests\payment\Unit\Controller

Code

public function testAccess() {
  $definitions = [
    'payment_unavailable' => [],
    'foo' => [
      'description' => $this
        ->randomMachineName(),
      'label' => $this
        ->randomMachineName(),
    ],
    'bar' => [
      'description' => $this
        ->randomMachineName(),
      'label' => $this
        ->randomMachineName(),
    ],
  ];
  $this->paymentMethodConfigurationManager
    ->expects($this
    ->exactly(2))
    ->method('getDefinitions')
    ->willReturn($definitions);
  $this->paymentMethodConfigurationAccessControlHandler
    ->expects($this
    ->at(0))
    ->method('createAccess')
    ->with('foo', $this->currentUser, [], TRUE)
    ->willReturn(AccessResult::allowed());
  $this->paymentMethodConfigurationAccessControlHandler
    ->expects($this
    ->at(1))
    ->method('createAccess')
    ->with('foo', $this->currentUser, [], TRUE)
    ->willReturn(AccessResult::forbidden());
  $this->paymentMethodConfigurationAccessControlHandler
    ->expects($this
    ->at(2))
    ->method('createAccess')
    ->with('bar', $this->currentUser, [], TRUE)
    ->willReturn(AccessResult::forbidden());
  $this
    ->assertTrue($this->sut
    ->access()
    ->isAllowed());
  $this
    ->assertFalse($this->sut
    ->access()
    ->isAllowed());
}