View source
<?php
namespace Drupal\Tests\uc_payment\Functional;
use Drupal\Tests\uc_store\Functional\UbercartBrowserTestBase;
class OrderPaymentsFormTest extends UbercartBrowserTestBase {
protected static $modules = [
'uc_payment',
'uc_payment_pack',
];
protected static $adminPermissions = [
'view payments',
'manual payments',
'delete payments',
];
protected $precision = 2;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
$config = \Drupal::config('uc_store.settings')
->get('currency');
$this->precision = $config['precision'];
}
public function testOrderPayments() {
$method = $this
->createPaymentMethod('check');
$this
->addToCart($this->product);
$order = $this
->checkout();
uc_payment_enter($order
->id(), 'check', 1.0);
$this
->drupalLogin($this->adminUser);
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/payments');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($order
->getTotal()) . '</span>', 'Order total is correct');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($order
->getTotal() - 1.0) . '</span>', 'Current balance is correct');
$first_payment = round($order
->getTotal() / 4.0, $this->precision);
$edit = [
'amount' => $first_payment,
'method' => 'check',
'comment' => 'Test <b>markup</b> in comments.',
];
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/payments');
$this
->submitForm($edit, 'Record payment');
$assert
->pageTextContains('Payment entered.');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($first_payment) . '</span>', 'Payment appears on page.');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($order
->getTotal() - 1.0 - $first_payment) . '</span>', 'Current balance is correct');
$assert
->responseContains('Test <b>markup</b> in comments.', 'Markup is preserved in payment receipt comments.');
$second_payment = round($order
->getTotal() / 2.0, $this->precision);
$edit = [
'amount' => $second_payment,
'method' => 'check',
'comment' => 'Test <em>markup</em> in comments.',
];
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/payments');
$this
->submitForm($edit, 'Record payment');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($second_payment) . '</span>', 'Payment appears on page.');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($order
->getTotal() - 1.0 - $first_payment - $second_payment) . '</span>', 'Order total is correct');
$assert
->linkExists('Delete');
$this
->clickLink('Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/payments/1/delete');
$assert
->pageTextContains('Are you sure you want to delete this payment?');
$this
->clickLink('Cancel');
$assert
->linkByHrefExists('admin/store/orders/' . $order
->id() . '/payments');
$this
->clickLink('Delete', 1);
$this
->submitForm([], 'Delete');
$assert
->addressEquals('admin/store/orders/' . $order
->id() . '/payments');
$assert
->pageTextContains('Payment deleted.');
$assert
->responseContains('<span class="uc-price">' . uc_currency_format($order
->getTotal() - 1.0 - $second_payment) . '</span>', 'Current balance is correct');
$this
->drupalGet('admin/store/orders/' . $order
->id() . '/log');
$assert
->pageTextContains('Check payment for ' . uc_currency_format($first_payment) . ' entered.');
$assert
->pageTextContains('Check payment for ' . uc_currency_format($second_payment) . ' entered.');
$assert
->pageTextContains('Check payment for ' . uc_currency_format($first_payment) . ' deleted.');
}
}