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\Element\PaymentReference

@group Payment Reference Field

Hierarchy

Expanded class hierarchy of PaymentReferenceTest

File

modules/payment_reference/tests/src/Unit/Element/PaymentReferenceTest.php, line 28

Namespace

Drupal\Tests\payment_reference\Unit\Element
View source
class PaymentReferenceTest extends UnitTestCase {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $currentUser;

  /**
   * The date formatter.
   *
   * @var \Drupal\Core\Datetime\DateFormatter|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $dateFormatter;

  /**
   * The link generator.
   *
   * @var \Drupal\Core\Utility\LinkGeneratorInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $linkGenerator;

  /**
   * The payment method manager.
   *
   * @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodManagerInterface
   */
  protected $paymentMethodManager;

  /**
   * The payment method type.
   *
   * @var \Drupal\plugin\PluginType\PluginTypeInterface|\Prophecy\Prophecy\ObjectProphecy
   */
  protected $paymentMethodType;

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

  /**
   * The payment storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $paymentStorage;

  /**
   * The plugin selector manager.
   *
   * @var \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorManagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $pluginSelectorManager;

  /**
   * The renderer.
   *
   * @var \Drupal\Core\Render\RendererInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $renderer;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $requestStack;

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

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

  /**
   * The url generator.
   *
   * @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $urlGenerator;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $this->currentUser = $this
      ->createMock(AccountInterface::class);
    $this->dateFormatter = $this
      ->getMockBuilder(DateFormatter::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->linkGenerator = $this
      ->createMock(LinkGeneratorInterface::class);
    $this->paymentMethodManager = $this
      ->createMock(PaymentMethodManagerInterface::class);
    $this->stringTranslation = $this
      ->getStringTranslationStub();
    $this->paymentMethodType = $this
      ->prophesize(PluginTypeInterface::class);
    $this->paymentQueue = $this
      ->createMock(QueueInterface::class);
    $this->paymentStorage = $this
      ->createMock(EntityStorageInterface::class);
    $this->pluginSelectorManager = $this
      ->createMock(PluginSelectorManagerInterface::class);
    $this->renderer = $this
      ->createMock(RendererInterface::class);
    $this->requestStack = $this
      ->getMockBuilder(RequestStack::class)
      ->disableOriginalConstructor()
      ->getMock();
    $this->urlGenerator = $this
      ->createMock(UrlGeneratorInterface::class);
    $configuration = [];
    $plugin_id = $this
      ->randomMachineName();
    $plugin_definition = [];
    $this->sut = new PaymentReference($configuration, $plugin_id, $plugin_definition, $this->requestStack, $this->paymentStorage, $this->stringTranslation, $this->dateFormatter, $this->linkGenerator, $this->renderer, $this->currentUser, $this->pluginSelectorManager, $this->paymentMethodType
      ->reveal(), new Random(), $this->paymentQueue);
  }

  /**
   * @covers ::create
   * @covers ::__construct
   */
  function testCreate() {
    $entity_type_manager = $this
      ->createMock(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->expects($this
      ->once())
      ->method('getStorage')
      ->with('payment')
      ->willReturn($this->paymentStorage);
    $plugin_type_manager = $this
      ->prophesize(PluginTypeManagerInterface::class);
    $plugin_type_manager
      ->getPluginType('payment_method')
      ->willReturn($this->paymentMethodType
      ->reveal());
    $container = $this
      ->createMock(ContainerInterface::class);
    $map = array(
      array(
        'current_user',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->currentUser,
      ),
      array(
        'date.formatter',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->dateFormatter,
      ),
      array(
        'entity_type.manager',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $entity_type_manager,
      ),
      array(
        'link_generator',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->linkGenerator,
      ),
      array(
        'payment_reference.queue',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->paymentQueue,
      ),
      array(
        'plugin.manager.plugin.plugin_selector',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->pluginSelectorManager,
      ),
      array(
        'plugin.plugin_type_manager',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $plugin_type_manager
          ->reveal(),
      ),
      array(
        'renderer',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->renderer,
      ),
      array(
        'request_stack',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->requestStack,
      ),
      array(
        'string_translation',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->stringTranslation,
      ),
    );
    $container
      ->expects($this
      ->any())
      ->method('get')
      ->willReturnMap($map);
    $configuration = [];
    $plugin_id = $this
      ->randomMachineName();
    $plugin_definition = [];
    $sut = PaymentReference::create($container, $configuration, $plugin_id, $plugin_definition);
    $this
      ->assertInstanceOf(PaymentReference::class, $sut);
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
PaymentReferenceTest::$currentUser protected property The current user.
PaymentReferenceTest::$dateFormatter protected property The date formatter.
PaymentReferenceTest::$linkGenerator protected property The link generator.
PaymentReferenceTest::$paymentMethodManager protected property The payment method manager.
PaymentReferenceTest::$paymentMethodType protected property The payment method type.
PaymentReferenceTest::$paymentQueue protected property The payment queue.
PaymentReferenceTest::$paymentStorage protected property The payment storage.
PaymentReferenceTest::$pluginSelectorManager protected property The plugin selector manager.
PaymentReferenceTest::$renderer protected property The renderer.
PaymentReferenceTest::$requestStack protected property The request stack.
PaymentReferenceTest::$stringTranslation protected property The string translator.
PaymentReferenceTest::$sut protected property The class under test.
PaymentReferenceTest::$urlGenerator protected property The url generator.
PaymentReferenceTest::setUp public function Overrides UnitTestCase::setUp
PaymentReferenceTest::testCreate function @covers ::create @covers ::__construct
PaymentReferenceTest::testGetPaymentQueue public function @covers ::getPaymentQueue
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.