You are here

class UnavailableTest in Payment 8.2

Same name in this branch
  1. 8.2 tests/src/Unit/Plugin/Payment/Method/UnavailableTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\Method\UnavailableTest
  2. 8.2 tests/src/Unit/Plugin/Payment/Type/UnavailableTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\Type\UnavailableTest

@coversDefaultClass \Drupal\payment\Plugin\Payment\Method\Unavailable

@group Payment

Hierarchy

Expanded class hierarchy of UnavailableTest

File

tests/src/Unit/Plugin/Payment/Method/UnavailableTest.php, line 18

Namespace

Drupal\Tests\payment\Unit\Plugin\Payment\Method
View source
class UnavailableTest extends UnitTestCase {

  /**
   * The plugin definition.
   *
   * @var array
   */
  protected $pluginDefinition;

  /**
   * The payment status manager.
   *
   * @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $paymentStatusManager;

  /**
   * The class under test.
   *
   * @var \Drupal\payment\Plugin\Payment\Method\Unavailable
   */
  protected $sut;

  /**
   * The token utility.
   *
   * @var \Drupal\Core\Utility\Token
   */
  protected $token;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    parent::setUp();
    $this->token = $this
      ->getMockBuilder(Token::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->paymentStatusManager = $this
      ->createMock(PaymentStatusManagerInterface::class);
    $this->pluginDefinition = array(
      'label' => $this
        ->randomMachineName(),
    );
    $this->sut = new Unavailable([], '', $this->pluginDefinition, $this->token, $this->paymentStatusManager);
  }

  /**
   * @covers ::defaultConfiguration
   */
  public function testDefaultConfiguration() {
    $this
      ->assertSame([], $this->sut
      ->defaultConfiguration());
  }

  /**
   * @covers ::getPluginLabel
   */
  public function testGetPluginLabel() {
    $this
      ->assertSame($this->pluginDefinition['label'], $this->sut
      ->getPluginLabel());
  }

  /**
   * @covers ::calculateDependencies
   */
  public function testCalculateDependencies() {
    $this
      ->assertSame([], $this->sut
      ->calculateDependencies());
  }

  /**
   * @covers ::getConfiguration
   */
  public function testGetConfiguration() {
    $this
      ->assertSame([], $this->sut
      ->getConfiguration());
  }

  /**
   * @covers ::setConfiguration
   */
  public function testSetConfiguration() {
    $this
      ->assertSame($this->sut, $this->sut
      ->setConfiguration([]));
  }

  /**
   * @covers ::getSupportedCurrencies
   */
  public function testGetSupportedCurrencies() {
    $method = new \ReflectionMethod($this->sut, 'getSupportedCurrencies');
    $method
      ->setAccessible(TRUE);
    $this
      ->assertSame([], $method
      ->invoke($this->sut));
  }

  /**
   * @covers ::setPayment
   * @covers ::getPayment
   */
  public function testGetPayment() {
    $payment = $this
      ->createMock(PaymentInterface::class);
    $this
      ->assertSame($this->sut, $this->sut
      ->setPayment($payment));
    $this
      ->assertSame($payment, $this->sut
      ->getPayment());
  }

  /**
   * @covers ::buildConfigurationForm
   */
  public function testBuildConfigurationForm() {
    $form = [];
    $form_state = $this
      ->createMock(FormStateInterface::class);
    $payment = $this
      ->createMock(PaymentInterface::class);
    $elements = $this->sut
      ->buildConfigurationForm($form, $form_state, $payment);
    $this
      ->assertIsArray($elements);
    $this
      ->assertEmpty($elements);
  }

  /**
   * @covers ::executePaymentAccess
   */
  public function testExecutePaymentAccess() {
    $account = $this
      ->createMock(AccountInterface::class);
    $this
      ->assertFalse($this->sut
      ->executePaymentAccess($account)
      ->isAllowed());
  }

  /**
   * @covers ::executePayment
   */
  public function testExecutePayment() {
    $this
      ->expectException(\RuntimeException::class);
    $this->sut
      ->executePayment();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnavailableTest::$paymentStatusManager protected property The payment status manager.
UnavailableTest::$pluginDefinition protected property The plugin definition.
UnavailableTest::$sut protected property The class under test.
UnavailableTest::$token protected property The token utility.
UnavailableTest::setUp public function Overrides UnitTestCase::setUp
UnavailableTest::testBuildConfigurationForm public function @covers ::buildConfigurationForm
UnavailableTest::testCalculateDependencies public function @covers ::calculateDependencies
UnavailableTest::testDefaultConfiguration public function @covers ::defaultConfiguration
UnavailableTest::testExecutePayment public function @covers ::executePayment
UnavailableTest::testExecutePaymentAccess public function @covers ::executePaymentAccess
UnavailableTest::testGetConfiguration public function @covers ::getConfiguration
UnavailableTest::testGetPayment public function @covers ::setPayment @covers ::getPayment
UnavailableTest::testGetPluginLabel public function @covers ::getPluginLabel
UnavailableTest::testGetSupportedCurrencies public function @covers ::getSupportedCurrencies
UnavailableTest::testSetConfiguration public function @covers ::setConfiguration
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.