class PaymentMethodConfigurationBaseTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationBase
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationBaseTestBase
- class \Drupal\Tests\payment\Unit\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationBaseTest
- class \Drupal\Tests\payment\Unit\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationBaseTestBase
Expanded class hierarchy of PaymentMethodConfigurationBaseTest
File
- tests/
src/ Unit/ Plugin/ Payment/ MethodConfiguration/ PaymentMethodConfigurationBaseTest.php, line 15
Namespace
Drupal\Tests\payment\Unit\Plugin\Payment\MethodConfigurationView source
class PaymentMethodConfigurationBaseTest extends PaymentMethodConfigurationBaseTestBase {
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\Payment\MethodConfiguration\PaymentMethodConfigurationBase|\PHPUnit\Framework\MockObject\MockObject
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->pluginDefinition = array(
'description' => $this
->randomMachineName(),
'label' => $this
->randomMachineName(),
);
$this->sut = $this
->getMockBuilder(PaymentMethodConfigurationBase::class)
->setConstructorArgs(array(
[],
'',
$this->pluginDefinition,
$this->stringTranslation,
$this->moduleHandler,
))
->getMockForAbstractClass();
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'module_handler',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->moduleHandler,
),
array(
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
/** @var \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase $class_name */
$class_name = get_class($this->sut);
$sut = $class_name::create($container, [], '', []);
$this
->assertInstanceOf(PaymentMethodConfigurationBase::class, $sut);
}
/**
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$configuration = $this->sut
->defaultConfiguration();
$this
->assertIsArray($configuration);
foreach (array(
'message_text',
'message_text_format',
) as $key) {
$this
->assertArrayHasKey($key, $configuration);
$this
->assertIsString($configuration[$key]);
}
}
/**
* @covers ::calculateDependencies
*/
public function testCalculateDependencies() {
$this
->assertSame([], $this->sut
->calculateDependencies());
}
/**
* @covers ::getMessageText
* @covers ::setMessageText
*/
public function testGetMessageText() {
$message_text = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setMessageText($message_text));
$this
->assertSame($message_text, $this->sut
->getMessageText());
}
/**
* @covers ::getMessageTextFormat
* @covers ::setMessageTextFormat
*/
public function testGetMessageTextFormat() {
$message_text_format = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setMessageTextFormat($message_text_format));
$this
->assertSame($message_text_format, $this->sut
->getMessageTextFormat());
}
/**
* @covers ::buildConfigurationForm
*/
public function testBuildConfigurationFormWithoutFilter() {
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$this->moduleHandler
->expects($this
->once())
->method('moduleExists')
->with('filter')
->willReturn(FALSE);
$message_text = $this
->randomMachineName();
$this->sut
->setMessageText($message_text);
$build = $this->sut
->buildConfigurationForm($form, $form_state);
$expected_build = array(
'message' => array(
'#tree' => TRUE,
'#type' => 'textarea',
'#title' => 'Payment form message',
'#default_value' => $message_text,
),
);
$this
->assertEquals($expected_build, $build);
}
/**
* @covers ::buildConfigurationForm
*/
public function testBuildConfigurationFormWithFilter() {
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$this->moduleHandler
->expects($this
->once())
->method('moduleExists')
->with('filter')
->willReturn(TRUE);
$message_text = $this
->randomMachineName();
$message_format = $this
->randomMachineName();
$this->sut
->setMessageText($message_text);
$this->sut
->setMessageTextFormat($message_format);
$build = $this->sut
->buildConfigurationForm($form, $form_state);
$expected_build = array(
'message' => array(
'#tree' => TRUE,
'#type' => 'text_format',
'#title' => 'Payment form message',
'#default_value' => $message_text,
'#format' => $message_format,
),
);
$this
->assertEquals($expected_build, $build);
}
/**
* @covers ::setConfiguration
* @covers ::getConfiguration
*/
public function testGetConfiguration() {
$configuration = array(
$this
->randomMachineName() => $this
->randomMachineName(),
) + $this->sut
->defaultConfiguration();
$return = $this->sut
->setConfiguration($configuration);
$this
->assertSame(NULL, $return);
$this
->assertSame($configuration, $this->sut
->getConfiguration());
}
/**
* @covers ::submitConfigurationForm
*/
public function testSubmitConfigurationFormWithoutFilter() {
$message_text = $this
->randomMachineName();
$this->moduleHandler
->expects($this
->once())
->method('moduleExists')
->with('filter')
->willReturn(FALSE);
$form = array(
'message' => array(
'#parents' => array(
'foo',
'bar',
'message',
),
),
);
$form_state = $this
->createMock(FormStateInterface::class);
$form_state
->expects($this
->atLeastOnce())
->method('getValues')
->willReturn(array(
'foo' => array(
'bar' => array(
'message' => $message_text,
),
),
));
$this->sut
->submitConfigurationForm($form, $form_state);
$this
->assertSame($message_text, $this->sut
->getMessageText());
}
/**
* @covers ::submitConfigurationForm
*/
public function testSubmitConfigurationFormWithFilter() {
$message_text = $this
->randomMachineName();
$message_format = $this
->randomMachineName();
$this->moduleHandler
->expects($this
->once())
->method('moduleExists')
->with('filter')
->willReturn(TRUE);
$form = array(
'message' => array(
'#parents' => array(
'foo',
'bar',
'message',
),
),
);
$form_state = $this
->createMock(FormStateInterface::class);
$form_state
->expects($this
->atLeastOnce())
->method('getValues')
->willReturn(array(
'foo' => array(
'bar' => array(
'message' => array(
'value' => $message_text,
'format' => $message_format,
),
),
),
));
$this->sut
->submitConfigurationForm($form, $form_state);
$this
->assertSame($message_text, $this->sut
->getMessageText());
$this
->assertSame($message_format, $this->sut
->getMessageTextFormat());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentMethodConfigurationBaseTest:: |
protected | property | The class under test. | |
PaymentMethodConfigurationBaseTest:: |
public | function |
Overrides PaymentMethodConfigurationBaseTestBase:: |
|
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::buildConfigurationForm | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::buildConfigurationForm | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::calculateDependencies | |
PaymentMethodConfigurationBaseTest:: |
function | @covers ::create @covers ::__construct | ||
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::defaultConfiguration | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::setConfiguration @covers ::getConfiguration | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::getMessageText @covers ::setMessageText | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::getMessageTextFormat @covers ::setMessageTextFormat | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::submitConfigurationForm | |
PaymentMethodConfigurationBaseTest:: |
public | function | @covers ::submitConfigurationForm | |
PaymentMethodConfigurationBaseTestBase:: |
protected | property | The module handler. | |
PaymentMethodConfigurationBaseTestBase:: |
protected | property | The plugin's definition. | |
PaymentMethodConfigurationBaseTestBase:: |
protected | property | The string translator. | |
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. |