View source
<?php
namespace Drupal\Tests\uc_payment_pack\Functional;
use Drupal\Tests\uc_store\Traits\AddressTestTrait;
use Drupal\uc_order\Entity\Order;
class CheckTest extends PaymentPackTestBase {
use AddressTestTrait;
public function testCheck() {
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/config/payment/add/check');
$assert
->pageTextContains('Check');
$assert
->fieldValueEquals('settings[policy]', 'Personal and business checks will be held for up to 10 business days to ensure payment clears before an order is shipped.');
$edit = [
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
'settings[policy]' => $this
->randomString(),
];
$address = $this
->createAddress();
$address
->setLastName('');
$this
->submitForm([
'settings[address][country]' => $address
->getCountry(),
], 'Save');
if (!empty($address
->getZone())) {
$edit += [
'settings[address][zone]' => $address
->getZone(),
];
}
$edit += [
'settings[name]' => $address
->getFirstName(),
'settings[address][company]' => $address
->getCompany(),
'settings[address][street1]' => $address
->getStreet1(),
'settings[address][street2]' => $address
->getStreet2(),
'settings[address][city]' => $address
->getCity(),
'settings[address][postal_code]' => $address
->getPostalCode(),
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('cart/checkout');
$assert
->fieldValueEquals('panes[payment][payment_method]', $edit['id']);
$assert
->pageTextContains('Checks should be made out to:');
$assert
->responseContains((string) $address);
$assert
->assertEscaped($edit['settings[policy]'], 'Check payment policy found at checkout.');
$this
->submitForm([], 'Review order');
$assert
->pageTextContains('Check');
$assert
->pageTextContains('Mail to');
$assert
->responseContains((string) $address);
$this
->submitForm([], 'Submit order');
$order = Order::load(1);
$this
->assertEquals($edit['id'], $order
->getPaymentMethodId(), 'Order has check payment method.');
$this
->drupalGet('user/' . $order
->getOwnerId() . '/orders/' . $order
->id());
$assert
->pageTextContains('Method: Check');
$this
->drupalGet('admin/store/orders/' . $order
->id());
$assert
->pageTextContains('Method: Check');
$assert
->linkExists('Receive Check');
$this
->clickLink('Receive Check');
$assert
->fieldValueEquals('amount', number_format($order
->getTotal(), 2, '.', ''));
$receive_date = strtotime('now +' . mt_rand(1, 365) . ' days');
$formatted = \Drupal::service('date.formatter')
->format($receive_date, 'uc_store');
$edit = [
'comment' => $this
->randomString(),
'clear_date[date]' => date('Y-m-d', $receive_date),
];
$this
->submitForm($edit, 'Receive check');
$assert
->linkNotExists('Receive Check');
$assert
->pageTextContains('Clear Date: ' . $formatted);
$this
->drupalGet('user/' . $order
->getOwnerId() . '/orders/' . $order
->id());
$assert
->pageTextContains('Check received');
$assert
->pageTextContains('Expected clear date:');
$assert
->pageTextContains($formatted, 'Check clear date found.');
}
}