PaymentStorageWebTest.php in Payment 8.2
File
tests/src/Functional/Entity/Payment/PaymentStorageWebTest.php
View source
<?php
namespace Drupal\Tests\payment\Functional\Entity\Payment;
use Drupal\payment\Entity\PaymentInterface;
use Drupal\payment\Payment;
use Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface;
use Drupal\payment\plugin\payment\status\PaymentStatusInterface;
use Drupal\payment\Plugin\Payment\Type\PaymentTypeInterface;
use Drupal\payment\Tests\Generate;
use Drupal\Tests\BrowserTestBase;
class PaymentStorageWebTest extends BrowserTestBase {
public static $modules = array(
'payment',
);
protected $defaultTheme = 'stark';
public function testCRUD() {
$database = \Drupal::database();
$user = $this
->drupalCreateUser();
$payment_type_configuration = array(
$this
->randomMachineName() => $this
->randomMachineName(),
);
$payment_method = Payment::methodManager()
->createInstance('payment_basic:no_payment_required');
$payment = Generate::createPayment($user
->id(), $payment_method);
$payment
->getPaymentType()
->setConfiguration($payment_type_configuration);
$this
->assertTrue($payment instanceof PaymentInterface);
$this
->assertTrue(is_numeric($payment
->getOwnerId()));
$this
->assertEqual(count($payment
->validate()), 0);
$this
->assertTrue($payment
->getPaymentType() instanceof PaymentTypeInterface);
$this
->assertNull($payment
->id());
$payment
->setPaymentStatus(Payment::statusManager()
->createInstance('payment_success'));
$payment
->save();
$this
->assertTrue(is_numeric($payment
->id()));
$this
->assertNotEmpty($payment
->uuid());
$this
->assertEquals($user
->id(), $payment
->getOwnerId());
$payment_data = $database
->select('payment', 'p')
->fields('p', array(
'current_payment_status_delta',
))
->condition('id', $payment
->id())
->execute()
->fetchAssoc();
$this
->assertEqual($payment_data['current_payment_status_delta'], 1);
$payment_loaded = \Drupal\payment\Entity\Payment::load($payment
->id());
$this
->assertEqual(count($payment_loaded
->getLineItems()), count($payment
->getLineItems()));
foreach ($payment_loaded
->getLineItems() as $line_item) {
$this
->assertTrue($line_item instanceof PaymentLineItemInterface);
}
$this
->assertEqual(count($payment_loaded
->getPaymentStatuses()), count($payment
->getPaymentStatuses()));
foreach ($payment_loaded
->getPaymentStatuses() as $status) {
$this
->assertTrue($status instanceof PaymentStatusInterface);
}
$this
->assertEqual($payment_loaded
->getPaymentMethod()
->getConfiguration(), $payment
->getPaymentMethod()
->getConfiguration());
$this
->assertEqual($payment_loaded
->getPaymentType()
->getConfiguration(), $payment
->getPaymentType()
->getConfiguration());
}
}