PaymentTest.php in Payment 8.2
File
tests/src/Functional/Controller/PaymentTest.php
View source
<?php
namespace Drupal\Tests\payment\Functional\Controller;
use Drupal\payment\Payment;
use Drupal\payment\Tests\Generate;
use Drupal\Tests\BrowserTestBase;
class PaymentTest extends BrowserTestBase {
public static $modules = array(
'payment',
'payment_test',
'block',
'views',
);
protected $defaultTheme = 'stark';
public function testPaymentUi() {
$this
->drupalPlaceBlock('local_tasks_block');
$payment_method = Payment::methodManager()
->createInstance('payment_test');
$count_payments = 50 * 2 + 1;
foreach (range(0, $count_payments) as $i) {
$payment = Generate::createPayment(2, $payment_method);
$payment
->save();
$payment = \Drupal\payment\Entity\Payment::load($payment
->id());
}
$this
->drupalLogin($this
->drupalCreateUser(array(
'access administration pages',
)));
$this
->drupalGet('admin/content');
$this
->assertResponse('200');
$this
->assertNoLinkByHref('admin/content/payment');
$this
->drupalGet('admin/content/payment');
$this
->assertResponse('403');
$this
->drupalLogin($this
->drupalCreateUser(array(
'access administration pages',
'payment.payment.view.any',
)));
$this
->drupalGet('admin/content');
$this
->clickLink(t('Payments'));
$this
->assertResponse('200');
$this
->assertTitle(t('Payments | Drupal'));
$this
->assertText(t('Last updated'));
$this
->assertText(t('Payment method'));
$this
->assertText(t('Enter a comma separated list of user names.'));
$this
->assertText(t('EUR 24.20'));
$this
->assertText($payment_method
->getPluginLabel());
$count_pages = ceil($count_payments / 50);
if ($count_pages) {
foreach (range(1, $count_pages - 1) as $page) {
$this
->assertLinkByHref('&page=' . $page);
}
$this
->assertNoLinkByHref('&page=' . ($page + 1));
}
$this
->assertLinkByHref('payment/1');
$this
->drupalLogout();
$path = 'payment/' . $payment
->id();
$this
->drupalGet($path);
$this
->assertResponse('403');
$this
->drupalLogin($this
->drupalCreateUser(array(
'payment.payment.view.any',
)));
$this
->drupalGet($path);
$this
->assertResponse('200');
$this
->assertText(t('Payment method'));
$this
->assertText(t('Status'));
$path = 'payment/' . $payment
->id() . '/delete';
$this
->drupalGet($path);
$this
->assertResponse('403');
$this
->drupalLogin($this
->drupalCreateUser(array(
'payment.payment.delete.any',
'payment.payment.view.any',
)));
$this
->drupalGet($path);
$this
->assertResponse('200');
$this
->clickLink(t('Cancel'));
$this
->assertUrl('payment/' . $payment
->id());
$this
->drupalGet($path);
$this
->drupalPostForm(NULL, [], t('Delete'));
$this
->assertResponse('200');
$this
->assertFalse((bool) \Drupal::entityTypeManager()
->getStorage('payment')
->loadUnchanged($payment
->id()));
}
}