PaymentReferenceTest.php in Payment 8.2
File
modules/payment_reference/tests/src/Unit/Plugin/Field/FieldType/PaymentReferenceTest.php
View source
<?php
namespace Drupal\Tests\payment_reference\Unit\Plugin\Field\FieldType;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\payment\QueueInterface;
use Drupal\payment_reference\Plugin\Field\FieldType\PaymentReference;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class PaymentReferenceTest extends UnitTestCase {
protected $moduleHandler;
protected $queue;
protected $stringTranslation;
protected $sut;
protected $targetId;
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);
}
public function testDefaultStorageSettings() {
$settings = $this->sut
->defaultStorageSettings();
$this
->assertIsArray($settings);
}
public function testDefaultFieldSettings() {
$settings = $this->sut
->defaultFieldSettings();
$this
->assertIsArray($settings);
}
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']);
}
public function testStorageSettingsForm() {
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$has_data = TRUE;
$this
->assertSame([], $this->sut
->storageSettingsForm($form, $form_state, $has_data));
}
}