View source
<?php
namespace Drupal\Tests\payment\Functional\Controller;
use Drupal\payment\Payment;
use Drupal\Tests\BrowserTestBase;
class PaymentStatusWebTest extends BrowserTestBase {
public static $modules = array(
'payment',
'block',
);
protected $defaultTheme = 'stark';
public $paymentStatusStorage;
protected function setUp() : void {
parent::setUp();
$this->paymentStatusStorage = \Drupal::entityTypeManager()
->getStorage('payment_status');
$this
->drupalPlaceBlock('local_actions_block');
}
public function testList() {
$payment_status_id = strtolower($this
->randomMachineName());
$status = $this->paymentStatusStorage
->create([]);
$status
->setId($payment_status_id)
->setLabel($this
->randomMachineName())
->save();
$path = 'admin/config/services/payment/status';
$this
->drupalGet($path);
$this
->assertResponse(403);
$this
->drupalLogin($this
->drupalCreateUser(array(
'payment.payment_status.administer',
)));
$this
->drupalGet($path);
$this
->assertResponse(200);
$this
->assertLinkByHref('admin/config/services/payment/status/add');
$manager = Payment::statusManager();
foreach ($manager
->getDefinitions() as $definition) {
$this
->assertText($definition['label']);
if ($definition['description']) {
$this
->assertText($definition['description']);
}
}
$this
->assertLinkByHref('admin/config/services/payment/status/edit/' . $payment_status_id);
$this
->assertLinkByHref('admin/config/services/payment/status/delete/' . $payment_status_id);
}
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);
$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'));
$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);
}
$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'));
$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);
}
$this
->drupalPostForm($path, array(
'label' => $label,
'id' => $payment_status_id,
), t('Save'));
$this
->assertFieldByXPath('//input[@id="edit-id" and contains(@class, "error")]');
}
public function testDelete() {
$payment_status_id = strtolower($this
->randomMachineName());
$status = $this->paymentStatusStorage
->create([]);
$status
->setId($payment_status_id)
->save();
$path = 'admin/config/services/payment/status/delete/' . $payment_status_id;
$this
->drupalGet($path);
$this
->assertResponse(403);
$this
->drupalLogin($this
->drupalCreateUser(array(
'payment.payment_status.administer',
)));
$this
->drupalGet($path);
$this
->assertResponse(200);
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertNull($this->paymentStatusStorage
->loadUnchanged($payment_status_id));
}
}