public function PaymentStatusWebTest::testAdd in Payment 8.2
Tests adding and editing a payment status.
File
- tests/
src/ Functional/ Controller/ PaymentStatusWebTest.php, line 79
Class
- PaymentStatusWebTest
- Payment status UI.
Namespace
Drupal\Tests\payment\Functional\ControllerCode
public function testAdd() {
$path = 'admin/config/services/payment/status/add';
$this
->drupalGet($path);
$this
->assertResponse(403);
$this
->drupalLogin($this
->drupalCreateUser(array(
'payment.payment_status.administer',
)));
$this
->drupalGet($path);
$this
->assertResponse(200);
// Test a valid submission.
$payment_status_id = strtolower($this
->randomMachineName());
$label = $this
->randomString();
$parent_id = 'payment_success';
$description = $this
->randomString();
$this
->drupalPostForm($path, array(
'label' => $label,
'id' => $payment_status_id,
'container[select][container][plugin_id]' => $parent_id,
'description' => $description,
), t('Save'));
/** @var \Drupal\payment\Entity\PaymentStatusInterface $status */
$status = $this->paymentStatusStorage
->loadUnchanged($payment_status_id);
if ($this
->assertTrue((bool) $status)) {
$this
->assertEqual($status
->id(), $payment_status_id);
$this
->assertEqual($status
->label(), $label);
$this
->assertEqual($status
->getParentId(), $parent_id);
$this
->assertEqual($status
->getDescription(), $description);
}
// Test editing a payment status.
$this
->drupalGet('admin/config/services/payment/status/edit/' . $payment_status_id);
$this
->assertLinkByHref('admin/config/services/payment/status/delete/' . $payment_status_id);
$label = $this
->randomString();
$parent_id = 'payment_success';
$description = $this
->randomString();
$this
->drupalPostForm(NULL, array(
'label' => $label,
'container[select][container][plugin_id]' => $parent_id,
'description' => $description,
), t('Save'));
/** @var \Drupal\payment\Entity\PaymentStatusInterface $status */
$status = $this->paymentStatusStorage
->loadUnchanged($payment_status_id);
if ($this
->assertTrue((bool) $status)) {
$this
->assertEqual($status
->id(), $payment_status_id);
$this
->assertEqual($status
->label(), $label);
$this
->assertEqual($status
->getParentId(), $parent_id);
$this
->assertEqual($status
->getDescription(), $description);
}
// Test an invalid submission.
$this
->drupalPostForm($path, array(
'label' => $label,
'id' => $payment_status_id,
), t('Save'));
$this
->assertFieldByXPath('//input[@id="edit-id" and contains(@class, "error")]');
}