class PaymentLineItemLabelTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Plugin\views\field\PaymentLineItemLabel
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\views\field\PaymentLineItemLabelTest
Expanded class hierarchy of PaymentLineItemLabelTest
File
- tests/
src/ Unit/ Plugin/ views/ field/ PaymentLineItemLabelTest.php, line 18
Namespace
Drupal\Tests\payment\Unit\Plugin\views\fieldView source
class PaymentLineItemLabelTest extends UnitTestCase {
/**
* The line item manager.
*
* @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $paymentLineItemManager;
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\views\field\PaymentLineItemLabel
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->paymentLineItemManager = $this
->createMock(PaymentLineItemManagerInterface::class);
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$this->sut = new PaymentLineItemLabel($configuration, $plugin_id, $plugin_definition, $this->paymentLineItemManager);
$options = [
'relationship' => 'none',
];
$view_executable = $this
->getMockBuilder(ViewExecutable::class)
->disableOriginalConstructor()
->getMock();
$display = $this
->getMockBuilder(DisplayPluginBase::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->sut
->init($view_executable, $display, $options);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'plugin.manager.payment.line_item',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->paymentLineItemManager,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$sut = PaymentLineItemLabel::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(PaymentLineItemLabel::class, $sut);
}
/**
* @covers ::render
*/
public function testRender() {
$plugin_id = $this
->randomMachineName();
$plugin_label = $this
->randomMachineName();
$plugin_definition = [
'label' => $plugin_label,
];
$this->paymentLineItemManager
->expects($this
->atLeastOnce())
->method('getDefinition')
->with($plugin_id)
->willReturn($plugin_definition);
$result_row = new ResultRow();
$result_row->{$this->sut->field_alias} = $plugin_id;
$this
->assertSame($plugin_label, $this->sut
->render($result_row));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PaymentLineItemLabelTest:: |
protected | property | The line item manager. | |
PaymentLineItemLabelTest:: |
protected | property | The class under test. | |
PaymentLineItemLabelTest:: |
public | function |
Overrides UnitTestCase:: |
|
PaymentLineItemLabelTest:: |
function | @covers ::create @covers ::__construct | ||
PaymentLineItemLabelTest:: |
public | function | @covers ::render | |
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. |