public function ManualPaymentAdminTest::testPaymentCreation in Commerce Core 8.2
Tests creating a payment for an order.
File
- modules/
payment/ tests/ src/ Functional/ ManualPaymentAdminTest.php, line 106
Class
- ManualPaymentAdminTest
- Tests the admin UI for payments of type 'payment_manual'.
Namespace
Drupal\Tests\commerce_payment\FunctionalCode
public function testPaymentCreation() {
$this
->drupalGet($this->paymentUri . '/add');
$this
->assertSession()
->pageTextContains('Cash on delivery');
$this
->getSession()
->getPage()
->pressButton('Continue');
$this
->submitForm([
'payment[amount][number]' => '100',
], 'Add payment');
$this
->assertSession()
->addressEquals($this->paymentUri);
$this
->assertSession()
->pageTextContains('Pending');
\Drupal::entityTypeManager()
->getStorage('commerce_payment')
->resetCache([
1,
]);
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = Payment::load(1);
$this
->assertEquals($this->order
->id(), $payment
->getOrderId());
$this
->assertEquals('100.00', $payment
->getAmount()
->getNumber());
$this
->assertEquals('Pending', $payment
->getState()
->getLabel());
$this
->drupalGet($this->paymentUri . '/add');
$this
->assertSession()
->pageTextContains('Cash on delivery');
$this
->getSession()
->getPage()
->pressButton('Continue');
$this
->submitForm([
'payment[amount][number]' => '100',
'payment[received]' => TRUE,
], 'Add payment');
$this
->assertSession()
->addressEquals($this->paymentUri);
$this
->assertSession()
->elementContains('css', 'table tbody tr:nth-child(2) td:nth-child(2)', 'Completed');
\Drupal::entityTypeManager()
->getStorage('commerce_payment')
->resetCache([
2,
]);
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = Payment::load(2);
$this
->assertEquals($this->order
->id(), $payment
->getOrderId());
$this
->assertEquals('100.00', $payment
->getAmount()
->getNumber());
$this
->assertEquals('Completed', $payment
->getState()
->getLabel());
$this
->assertNotEmpty($payment
->getCompletedTime());
}