class BasicTest in Payment 8.2
Same name in this branch
- 8.2 tests/src/Unit/Plugin/Payment/MethodConfiguration/BasicTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\MethodConfiguration\BasicTest
- 8.2 tests/src/Unit/Plugin/Payment/Method/BasicTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\Method\BasicTest
- 8.2 tests/src/Unit/Plugin/Payment/LineItem/BasicTest.php \Drupal\Tests\payment\Unit\Plugin\Payment\LineItem\BasicTest
@coversDefaultClass \Drupal\payment\Plugin\Payment\LineItem\Basic
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\Payment\LineItem\BasicTest
Expanded class hierarchy of BasicTest
File
- tests/
src/ Unit/ Plugin/ Payment/ LineItem/ BasicTest.php, line 16
Namespace
Drupal\Tests\payment\Unit\Plugin\Payment\LineItemView source
class BasicTest extends UnitTestCase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection|\PHPUnit\Framework\MockObject\MockObject
*/
protected $database;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\Payment\LineItem\Basic
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->database = $this
->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
$this->stringTranslation = $this
->getStringTranslationStub();
$configuration = [];
$plugin_id = $this
->randomMachineName();
$plugin_definition = [];
$this->sut = new Basic($configuration, $plugin_id, $plugin_definition, $this->stringTranslation, $this->database);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'database',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->database,
),
array(
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$configuration = [];
$plugin_definition = [];
$plugin_id = $this
->randomMachineName();
$sut = Basic::create($container, $configuration, $plugin_id, $plugin_definition);
$this
->assertInstanceOf(Basic::class, $sut);
}
/**
* @covers ::defaultConfiguration
*/
public function testDefaultConfiguration() {
$configuration = array(
'currency_code' => NULL,
'name' => NULL,
'quantity' => 1,
'amount' => 0,
'description' => NULL,
);
$this
->assertEquals($configuration, $this->sut
->defaultConfiguration());
}
/**
* @covers ::setAmount
* @covers ::getAmount
*/
public function testGetAmount() {
$amount = mt_rand();
$this
->assertSame($this->sut, $this->sut
->setAmount($amount));
$this
->assertSame($amount, $this->sut
->getAmount());
}
/**
* @covers ::setCurrencyCode
* @covers ::getCurrencyCode
*/
public function testGetCurrencyCode() {
$currency_code = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setCurrencyCode($currency_code));
$this
->assertSame($currency_code, $this->sut
->getCurrencyCode());
}
/**
* @covers ::setDescription
* @covers ::getDescription
*/
public function testGetDescription() {
$description = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setDescription($description));
$this
->assertSame($description, $this->sut
->getDescription());
}
/**
* @covers ::buildConfigurationForm
*/
public function testBuildConfigurationForm() {
$form = [];
$form_state = $this
->createMock(FormStateInterface::class);
$form_elements = $this->sut
->buildConfigurationForm($form, $form_state);
$this
->assertIsArray($form_elements);
}
/**
* @covers ::submitConfigurationForm
*/
public function testSubmitConfigurationForm() {
$amount = mt_rand();
$currency_code = $this
->randomMachineName(3);
$description = $this
->randomMachineName();
$name = $this
->randomMachineName();
$payment_id = mt_rand();
$quantity = mt_rand();
$form = array(
'#parents' => array(
'foo',
'bar',
),
);
$form_state = $this
->createMock(FormStateInterface::class);
$form_state
->expects($this
->atLeastOnce())
->method('getValues')
->willReturn(array(
'foo' => array(
'bar' => array(
'amount' => array(
'amount' => $amount,
'currency_code' => $currency_code,
),
'description' => $description,
'name' => $name,
'payment_id' => $payment_id,
'quantity' => $quantity,
),
),
));
$this->sut
->submitConfigurationForm($form, $form_state);
$this
->assertSame($amount, $this->sut
->getAmount());
$this
->assertSame($currency_code, $this->sut
->getCurrencyCode());
$this
->assertSame($description, $this->sut
->getDescription());
$this
->assertSame($name, $this->sut
->getName());
$this
->assertSame($quantity, $this->sut
->getQuantity());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BasicTest:: |
protected | property | The database connection. | |
BasicTest:: |
protected | property | The string translator. | |
BasicTest:: |
protected | property | The class under test. | |
BasicTest:: |
public | function |
Overrides UnitTestCase:: |
|
BasicTest:: |
public | function | @covers ::buildConfigurationForm | |
BasicTest:: |
function | @covers ::create @covers ::__construct | ||
BasicTest:: |
public | function | @covers ::defaultConfiguration | |
BasicTest:: |
public | function | @covers ::setAmount @covers ::getAmount | |
BasicTest:: |
public | function | @covers ::setCurrencyCode @covers ::getCurrencyCode | |
BasicTest:: |
public | function | @covers ::setDescription @covers ::getDescription | |
BasicTest:: |
public | function | @covers ::submitConfigurationForm | |
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. |