class ListPaymentStatusesTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Controller\ListPaymentStatuses
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Controller\ListPaymentStatusesTest
Expanded class hierarchy of ListPaymentStatusesTest
File
- tests/
src/ Unit/ Controller/ ListPaymentStatusesTest.php, line 17
Namespace
Drupal\Tests\payment\Unit\ControllerView source
class ListPaymentStatusesTest extends UnitTestCase {
/**
* The payment method plugin manager.
*
* @var \Drupal\payment\Plugin\Payment\Status\PaymentStatusManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentStatusManager;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $renderer;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\payment\Controller\ListPaymentStatuses
*/
protected $sut;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->paymentStatusManager = $this
->createMock(PaymentStatusManagerInterface::class);
$this->renderer = $this
->createMock(RendererInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->sut = new ListPaymentStatuses($this->stringTranslation, $this->renderer, $this->paymentStatusManager);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = [
[
'plugin.manager.payment.status',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentStatusManager,
],
[
'renderer',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->renderer,
],
[
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
],
];
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = ListPaymentStatuses::create($container);
$this
->assertInstanceOf(ListPaymentStatuses::class, $sut);
}
/**
* @covers ::execute
* @covers ::buildListingLevel
* @covers ::buildHierarchy
* @covers ::buildHierarchyLevel
* @covers ::sort
*/
function testListing() {
$plugin_id_a = $this
->randomMachineName();
$plugin_id_b = $this
->randomMachineName();
$definitions = [
$plugin_id_a => [
'label' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
],
$plugin_id_b => [
'label' => $this
->randomMachineName(),
'description' => $this
->randomMachineName(),
'parent_id' => $plugin_id_a,
],
];
$operations_a = [
'title' => $this
->randomMachineName(),
];
$operations_provider_a = $this
->createMock(PluginOperationsProviderInterface::class);
$operations_provider_a
->expects($this
->once())
->method('getOperations')
->with($plugin_id_a)
->willReturn($operations_a);
$map = [
[
$plugin_id_a,
TRUE,
$definitions[$plugin_id_a],
],
[
$plugin_id_b,
TRUE,
$definitions[$plugin_id_b],
],
];
$this->paymentStatusManager
->expects($this
->exactly(count($map)))
->method('getDefinition')
->willReturnMap($map);
$this->paymentStatusManager
->expects($this
->atLeastOnce())
->method('getDefinitions')
->willReturn($definitions);
$map = [
[
$plugin_id_a,
$operations_provider_a,
],
[
$plugin_id_b,
NULL,
],
];
$this->paymentStatusManager
->expects($this
->exactly(2))
->method('getOperationsProvider')
->willReturnMap($map);
$this->stringTranslation
->expects($this
->any())
->method('translate')
->will($this
->returnArgument(0));
$build = $this->sut
->execute();
foreach ($build['#header'] as $key => $label) {
$build['#header'][$key] = (string) $label;
}
$expected = [
'#header' => [
'Title',
'Description',
'Operations',
],
'#type' => 'table',
$plugin_id_a => [
'label' => [
'#markup' => $definitions[$plugin_id_a]['label'],
],
'description' => [
'#markup' => $definitions[$plugin_id_a]['description'],
],
'operations' => [
'#type' => 'operations',
'#links' => $operations_a,
],
],
$plugin_id_b => [
'label' => [
'#markup' => $definitions[$plugin_id_b]['label'],
],
'description' => [
'#markup' => $definitions[$plugin_id_b]['description'],
],
'operations' => [
'#type' => 'operations',
'#links' => [],
],
],
];
$this
->assertSame($expected, $build);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ListPaymentStatusesTest:: |
protected | property | The payment method plugin manager. | |
ListPaymentStatusesTest:: |
protected | property | The renderer. | |
ListPaymentStatusesTest:: |
protected | property | The string translator. | |
ListPaymentStatusesTest:: |
protected | property | The class under test. | |
ListPaymentStatusesTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ListPaymentStatusesTest:: |
function | @covers ::create @covers ::__construct | ||
ListPaymentStatusesTest:: |
function | @covers ::execute @covers ::buildListingLevel @covers ::buildHierarchy @covers ::buildHierarchyLevel @covers ::sort | ||
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. |