class PaymentStatusesDisplayTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Element\PaymentStatusesDisplay
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Element\PaymentStatusesDisplayTest
Expanded class hierarchy of PaymentStatusesDisplayTest
File
- tests/
src/ Unit/ Element/ PaymentStatusesDisplayTest.php, line 16
Namespace
Drupal\Tests\payment\Unit\ElementView source
class PaymentStatusesDisplayTest extends UnitTestCase {
/**
* The fate formatter.
*
* @var \Drupal\Core\Datetime\DateFormatter|\PHPUnit\Framework\MockObject\MockObject
*/
protected $dateFormatter;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\payment\Element\PaymentStatusesDisplay
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->dateFormatter = $this
->getMockBuilder(DateFormatter::class)
->disableOriginalConstructor()
->getMock();
$this->stringTranslation = $this
->getStringTranslationStub();
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$this->sut = new PaymentStatusesDisplay($configuration, $plugin_id, $plugin_definition, $this->stringTranslation, $this->dateFormatter);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'date.formatter',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->dateFormatter,
),
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 = PaymentStatusesDisplay::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(PaymentStatusesDisplay::class, $sut);
}
/**
* @covers ::getInfo
*/
public function testGetInfo() {
$info = $this->sut
->getInfo();
$this
->assertIsArray($info);
foreach ($info['#pre_render'] as $callback) {
$this
->assertTrue(is_callable($callback));
}
}
/**
* @covers ::preRender
*/
public function testPreRender() {
$payment_status_created = mt_rand();
$payment_status = $this
->createMock(PaymentStatusInterface::class);
$payment_status
->expects($this
->atLeastOnce())
->method('getCreated')
->willReturn($payment_status_created);
$payment_status
->expects($this
->atLeastOnce())
->method('getPluginDefinition')
->willReturn([
'label' => 'Example',
]);
$this->dateFormatter
->expects($this
->once())
->method('format')
->with($payment_status_created);
$element = array(
'#payment_statuses' => [
$payment_status,
],
);
$build = $this->sut
->preRender($element);
$this
->assertSame('table', $build['table']['#type']);
}
/**
* @covers ::preRender
*/
public function testPreRenderWithoutPayment() {
$this
->expectException(\InvalidArgumentException::class);
$element = [];
$this->sut
->preRender($element);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentStatusesDisplayTest:: |
protected | property | The fate formatter. | |
PaymentStatusesDisplayTest:: |
protected | property | The string translator. | |
PaymentStatusesDisplayTest:: |
protected | property | The class under test. | |
PaymentStatusesDisplayTest:: |
public | function |
Overrides UnitTestCase:: |
|
PaymentStatusesDisplayTest:: |
function | @covers ::create @covers ::__construct | ||
PaymentStatusesDisplayTest:: |
public | function | @covers ::getInfo | |
PaymentStatusesDisplayTest:: |
public | function | @covers ::preRender | |
PaymentStatusesDisplayTest:: |
public | function | @covers ::preRender | |
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. |