You are here

class PaymentReferenceTest in Payment 8.2

Same name in this branch
  1. 8.2 modules/payment_reference/tests/src/Unit/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\PaymentReferenceTest
  2. 8.2 modules/payment_reference/tests/src/Unit/Element/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Element\PaymentReferenceTest
  3. 8.2 modules/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Plugin\Payment\Type\PaymentReferenceTest
  4. 8.2 modules/payment_reference/tests/src/Unit/Plugin/Field/FieldWidget/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Plugin\Field\FieldWidget\PaymentReferenceTest
  5. 8.2 modules/payment_reference/tests/src/Unit/Plugin/Field/FieldType/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Plugin\Field\FieldType\PaymentReferenceTest

@coversDefaultClass \Drupal\payment_reference\Plugin\Field\FieldType\PaymentReference

@group Payment Reference Field

Hierarchy

Expanded class hierarchy of PaymentReferenceTest

File

modules/payment_reference/tests/src/Unit/Plugin/Field/FieldType/PaymentReferenceTest.php, line 19

Namespace

Drupal\Tests\payment_reference\Unit\Plugin\Field\FieldType
View source
class PaymentReferenceTest extends UnitTestCase {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The payment queue.
   *
   * @var \Drupal\payment\QueueInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $queue;

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

  /**
   * The class under test.
   *
   * @var \Drupal\payment_reference\Plugin\Field\FieldType\PaymentReference
   */
  protected $sut;

  /**
   * The field's target_id typed data property.
   *
   * @var \Drupal\Core\TypedData\TypedDataInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $targetId;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    $this->moduleHandler = $this
      ->createMock(ModuleHandlerInterface::class);
    $this->queue = $this
      ->createMock(QueueInterface::class);
    $this->stringTranslation = $this
      ->getStringTranslationStub();
    $this->targetId = $this
      ->createMock(TypedDataInterface::class);
    $container = new ContainerBuilder();
    $container
      ->set('module_handler', $this->moduleHandler);
    $container
      ->set('payment_reference.queue', $this->queue);
    $container
      ->set('string_translation', $this->stringTranslation);
    \Drupal::setContainer($container);
    $this->sut = $this
      ->getMockBuilder(PaymentReference::class)
      ->disableOriginalConstructor()
      ->setMethods([
      'get',
    ])
      ->getMock();
    $this->sut
      ->expects($this
      ->any())
      ->method('get')
      ->with('target_id')
      ->willReturn($this->targetId);
  }

  /**
   * @covers ::defaultStorageSettings
   */
  public function testDefaultStorageSettings() {
    $settings = $this->sut
      ->defaultStorageSettings();
    $this
      ->assertIsArray($settings);
  }

  /**
   * @covers ::defaultFieldSettings
   */
  public function testDefaultFieldSettings() {
    $settings = $this->sut
      ->defaultFieldSettings();
    $this
      ->assertIsArray($settings);
  }

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

  /**
   * @covers ::storageSettingsForm
   */
  public function testStorageSettingsForm() {
    $form = [];
    $form_state = $this
      ->createMock(FormStateInterface::class);
    $has_data = TRUE;
    $this
      ->assertSame([], $this->sut
      ->storageSettingsForm($form, $form_state, $has_data));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentReferenceTest::$moduleHandler protected property The module handler.
PaymentReferenceTest::$queue protected property The payment queue.
PaymentReferenceTest::$stringTranslation protected property The string translator.
PaymentReferenceTest::$sut protected property The class under test.
PaymentReferenceTest::$targetId protected property The field's target_id typed data property.
PaymentReferenceTest::setUp protected function Overrides UnitTestCase::setUp
PaymentReferenceTest::testDefaultFieldSettings public function @covers ::defaultFieldSettings
PaymentReferenceTest::testDefaultStorageSettings public function @covers ::defaultStorageSettings
PaymentReferenceTest::testSchema public function @covers ::schema
PaymentReferenceTest::testStorageSettingsForm public function @covers ::storageSettingsForm
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.