You are here

class PaymentFormTest in Payment 8.2

Same name in this branch
  1. 8.2 modules/payment_form/tests/src/Unit/Entity/Payment/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Entity\Payment\PaymentFormTest
  2. 8.2 modules/payment_form/tests/src/Unit/Plugin/Payment/Type/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Payment\Type\PaymentFormTest
  3. 8.2 modules/payment_form/tests/src/Unit/Plugin/Field/FieldFormatter/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldFormatter\PaymentFormTest
  4. 8.2 modules/payment_form/tests/src/Unit/Plugin/Field/FieldWidget/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldWidget\PaymentFormTest
  5. 8.2 modules/payment_form/tests/src/Unit/Plugin/Field/FieldType/PaymentFormTest.php \Drupal\Tests\payment_form\Unit\Plugin\Field\FieldType\PaymentFormTest

@coversDefaultClass \Drupal\payment_form\Plugin\Field\FieldType\PaymentForm

@group Payment Form Field

Hierarchy

Expanded class hierarchy of PaymentFormTest

File

modules/payment_form/tests/src/Unit/Plugin/Field/FieldType/PaymentFormTest.php, line 17

Namespace

Drupal\Tests\payment_form\Unit\Plugin\Field\FieldType
View source
class PaymentFormTest extends UnitTestCase {

  /**
   * The Currency form helper.
   *
   * @var \Drupal\currency\FormHelperInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $currencyFormHelper;

  /**
   * The string translator.
   *
   * @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $stringTranslation;

  /**
   * The class under test.
   *
   * @var \Drupal\payment_form\Plugin\Field\FieldType\PaymentForm|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    $this->currencyFormHelper = $this
      ->createMock(FormHelperInterface::class);
    $this->stringTranslation = $this
      ->getStringTranslationStub();
    $container = new Container();
    $container
      ->set('currency.form_helper', $this->currencyFormHelper);
    $container
      ->set('string_translation', $this->stringTranslation);
    \Drupal::setContainer($container);
    $this->sut = $this
      ->getMockBuilder(PaymentForm::class)
      ->disableOriginalConstructor()
      ->setMethods([
      'getSetting',
    ])
      ->getMock();
  }

  /**
   * @covers ::fieldSettingsForm
   */
  public function testFieldSettingsForm() {
    $this->sut
      ->expects($this
      ->once())
      ->method('getSetting')
      ->with('currency_code');
    $form = [];

    /** @var \Drupal\Core\Form\FormStateInterface $form_state */
    $form_state = $this
      ->createMock(FormStateInterface::class);
    $this
      ->assertIsArray($this->sut
      ->fieldSettingsForm($form, $form_state));
  }

  /**
   * @covers ::schema
   */
  public function testSchema() {
    $field_storage_definition = $this
      ->createMock(FieldStorageDefinitionInterface::class);
    $schema = $this->sut
      ->schema($field_storage_definition);
    $this
      ->assertIsArray($schema);
    $this
      ->assertArrayHasKey('plugin_configuration', $schema['columns']);
    $this
      ->assertArrayHasKey('plugin_id', $schema['columns']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentFormTest::$currencyFormHelper protected property The Currency form helper.
PaymentFormTest::$stringTranslation protected property The string translator.
PaymentFormTest::$sut protected property The class under test.
PaymentFormTest::setUp protected function Overrides UnitTestCase::setUp
PaymentFormTest::testFieldSettingsForm public function @covers ::fieldSettingsForm
PaymentFormTest::testSchema public function @covers ::schema
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.
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.