You are here

public function DisablePaymentMethodConfigurationTest::testExecute in Payment 8.2

@covers ::execute

File

tests/src/Unit/Controller/DisablePaymentMethodConfigurationTest.php, line 35

Class

DisablePaymentMethodConfigurationTest
@coversDefaultClass \Drupal\payment\Controller\DisablePaymentMethodConfiguration

Namespace

Drupal\Tests\payment\Unit\Controller

Code

public function testExecute() {
  $url = 'http://example.com/' . $this
    ->randomMachineName();
  $urlObject = $this
    ->getMockBuilder(Url::class)
    ->disableOriginalConstructor()
    ->getMock();
  $urlObject
    ->expects($this
    ->once())
    ->method('setAbsolute')
    ->with(TRUE)
    ->willReturn($urlObject);
  $urlObject
    ->expects($this
    ->once())
    ->method('toString')
    ->willReturn($url);
  $payment_method_configuration = $this
    ->createMock(PaymentMethodConfigurationInterface::class);
  $payment_method_configuration
    ->expects($this
    ->atLeastOnce())
    ->method('disable');
  $payment_method_configuration
    ->expects($this
    ->atLeastOnce())
    ->method('save');
  $payment_method_configuration
    ->expects($this
    ->atLeastOnce())
    ->method('toUrl')
    ->with('collection')
    ->willReturn($urlObject);
  $response = $this->sut
    ->execute($payment_method_configuration);
  $this
    ->assertInstanceOf(RedirectResponse::class, $response);
  $this
    ->assertSame($url, $response
    ->getTargetUrl());
}