class PaymentReferenceTest in Payment 8.2
Same name in this branch
- 8.2 modules/payment_reference/tests/src/Unit/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\PaymentReferenceTest
- 8.2 modules/payment_reference/tests/src/Unit/Element/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Element\PaymentReferenceTest
- 8.2 modules/payment_reference/tests/src/Unit/Plugin/Payment/Type/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Plugin\Payment\Type\PaymentReferenceTest
- 8.2 modules/payment_reference/tests/src/Unit/Plugin/Field/FieldWidget/PaymentReferenceTest.php \Drupal\Tests\payment_reference\Unit\Plugin\Field\FieldWidget\PaymentReferenceTest
- 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\Payment\Type\PaymentReference
@group Payment Reference Field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment_reference\Unit\Plugin\Payment\Type\PaymentReferenceTest
Expanded class hierarchy of PaymentReferenceTest
File
- modules/
payment_reference/ tests/ src/ Unit/ Plugin/ Payment/ Type/ PaymentReferenceTest.php, line 23
Namespace
Drupal\Tests\payment_reference\Unit\Plugin\Payment\TypeView source
class PaymentReferenceTest extends UnitTestCase {
/**
* The event dispatcher.
*
* @var \Drupal\payment\EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $eventDispatcher;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityFieldManager;
/**
* The payment.
*
* @var \Drupal\payment\Entity\PaymentInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $payment;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference
*/
protected $sut;
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $urlGenerator;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->eventDispatcher = $this
->createMock(EventDispatcherInterface::class);
$this->entityFieldManager = $this
->createMock(EntityFieldManagerInterface::class);
$this->urlGenerator = $this
->createMock(UrlGeneratorInterface::class);
$this->urlGenerator
->expects($this
->any())
->method('generateFromRoute')
->willReturn('http://example.com');
$this->stringTranslation = $this
->getStringTranslationStub();
$this->payment = $this
->createMock(PaymentInterface::class);
$this->sut = new PaymentReference([], 'payment_reference', [], $this->eventDispatcher, $this->urlGenerator, $this->entityFieldManager, $this->stringTranslation);
$this->sut
->setPayment($this->payment);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'entity_field.manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->entityFieldManager,
),
array(
'payment.event_dispatcher',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->eventDispatcher,
),
array(
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
),
array(
'url_generator',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->urlGenerator,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$configuration = [];
$plugin_definition = [];
$plugin_id = $this
->randomMachineName();
$sut = PaymentReference::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(PaymentReference::class, $sut);
}
/**
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$this
->assertIsArray($this->sut
->defaultConfiguration());
}
/**
* @covers ::setEntityTypeId
* @covers ::getEntityTypeId
*/
public function testGetEntityTypeId() {
$id = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setEntityTypeId($id));
$this
->assertSame($id, $this->sut
->getEntityTypeId());
}
/**
* @covers ::setBundle
* @covers ::getBundle
*/
public function testGetBundle() {
$bundle = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setBundle($bundle));
$this
->assertSame($bundle, $this->sut
->getBundle());
}
/**
* @covers ::setFieldName
* @covers ::getFieldName
*/
public function testGetFieldName() {
$name = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setFieldName($name));
$this
->assertSame($name, $this->sut
->getFieldName());
}
/**
* @covers ::getPaymentDescription
*
* @depends testGetEntityTypeId
* @depends testGetBundle
* @depends testGetFieldName
*/
public function testGetPaymentDescription() {
$entity_type_id = $this
->randomMachineName();
$bundle = $this
->randomMachineName();
$field_name = $this
->randomMachineName();
$label = $this
->randomMachineName();
$field_definition = $this
->createMock(FieldDefinitionInterface::class);
$field_definition
->expects($this
->atLeastOnce())
->method('getLabel')
->willReturn($label);
$definitions = array(
$field_name => $field_definition,
);
$this->entityFieldManager
->expects($this
->atLeastOnce())
->method('getFieldDefinitions')
->with($entity_type_id, $bundle)
->willReturn($definitions);
$this->sut
->setEntityTypeId($entity_type_id);
$this->sut
->setBundle($bundle);
$this->sut
->setFieldName($field_name);
$this
->assertSame($label, $this->sut
->getPaymentDescription());
}
/**
* @covers ::getPaymentDescription
*/
public function testGetPaymentDescriptionWithNonExistingField() {
$entity_type_id = $this
->randomMachineName();
$bundle = $this
->randomMachineName();
$this->entityFieldManager
->expects($this
->atLeastOnce())
->method('getFieldDefinitions')
->with($entity_type_id, $bundle)
->willReturn([]);
$this->sut
->setEntityTypeId($entity_type_id);
$this->sut
->setBundle($bundle);
$this
->assertInstanceOf(TranslatableMarkup::class, $this->sut
->getPaymentDescription());
}
/**
* @covers ::resumeContextAccess
*
* @dataProvider providerTestResumeContextAccess
*/
public function testResumeContextAccess($expected, $payment_owner_id, $account_id) {
$account = $this
->createMock(AccountInterface::class);
$account
->expects($this
->atLeastOnce())
->method('id')
->willReturn($account_id);
$this->payment
->expects($this
->atLeastOnce())
->method('getOwnerId')
->willReturn($payment_owner_id);
$access = $this->sut
->resumeContextAccess($account);
$this
->assertInstanceOf(AccessResultInterface::class, $access);
$this
->assertSame($expected, $access
->isAllowed());
}
/**
* Provides data to self::testResumeContextAccess().
*/
public function providerTestResumeContextAccess() {
$id_a = mt_rand();
$id_b = mt_rand();
return array(
array(
TRUE,
$id_a,
$id_a,
),
array(
TRUE,
$id_b,
$id_b,
),
array(
FALSE,
$id_a,
$id_b,
),
);
}
/**
* @covers ::doGetResumeContextResponse
*/
public function testDoGetResumeContextResponse() {
$response = $this->sut
->getResumeContextResponse();
$this
->assertInstanceOf(ResponseInterface::class, $response);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentReferenceTest:: |
protected | property | The entity field manager. | |
PaymentReferenceTest:: |
protected | property | The event dispatcher. | |
PaymentReferenceTest:: |
protected | property | The payment. | |
PaymentReferenceTest:: |
protected | property | The string translator. | |
PaymentReferenceTest:: |
protected | property | The class under test. | |
PaymentReferenceTest:: |
protected | property | The URL generator. | |
PaymentReferenceTest:: |
public | function | Provides data to self::testResumeContextAccess(). | |
PaymentReferenceTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PaymentReferenceTest:: |
function | @covers ::create @covers ::__construct | ||
PaymentReferenceTest:: |
public | function | @covers ::defaultConfiguration | |
PaymentReferenceTest:: |
public | function | @covers ::doGetResumeContextResponse | |
PaymentReferenceTest:: |
public | function | @covers ::setBundle @covers ::getBundle | |
PaymentReferenceTest:: |
public | function | @covers ::setEntityTypeId @covers ::getEntityTypeId | |
PaymentReferenceTest:: |
public | function | @covers ::setFieldName @covers ::getFieldName | |
PaymentReferenceTest:: |
public | function | @covers ::getPaymentDescription | |
PaymentReferenceTest:: |
public | function | @covers ::getPaymentDescription | |
PaymentReferenceTest:: |
public | function | @covers ::resumeContextAccess | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |