OrderInvoiceTest.php in Ubercart 8.4
File
uc_order/tests/src/Functional/OrderInvoiceTest.php
View source
<?php
namespace Drupal\Tests\uc_order\Functional;
use Drupal\Core\Url;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\uc_country\Entity\Country;
use Drupal\uc_order\Entity\Order;
class OrderInvoiceTest extends BrowserTestBase {
use AssertMailTrait;
protected $profile = 'testing';
protected $strictConfigSchema = FALSE;
protected $adminUser;
protected $customer;
protected $order;
protected static $modules = [
'uc_cart',
'views',
];
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access user profiles',
'view customers',
'view all orders',
]);
$this->customer = $this
->drupalCreateUser();
$country = Country::load('US');
$this->order = Order::create([
'uid' => $this->customer
->id(),
'billing_country' => $country
->id(),
'billing_zone' => 'AK',
]);
$this->order
->save();
\Drupal::configFactory()
->getEditable('system.mail')
->set('interface.uc_order', 'test_html_mail_collector')
->save();
}
public function testViewOrderInvoice() {
$this
->drupalLogin($this->adminUser);
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/orders/' . $this->order
->id() . '/invoice');
$assert
->statusCodeEquals(200);
$assert
->linkByHrefExists('user/' . $this->customer
->id() . '/orders/' . $this->order
->id());
$assert
->pageTextContains($this->order
->getEmail());
$assert
->pageTextContains($this->order
->getAddress('billing')
->getZone());
}
public function testPrintOrderInvoice() {
$this
->drupalLogin($this->adminUser);
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/orders/' . $this->order
->id() . '/invoice/print');
$assert
->statusCodeEquals(200);
$assert
->buttonExists('Print invoice');
$assert
->buttonExists('Back');
$assert
->linkByHrefExists('user/' . $this->customer
->id() . '/orders/' . $this->order
->id());
$assert
->pageTextContains($this->order
->getEmail());
$assert
->pageTextContains($this->order
->getAddress('billing')
->getZone());
}
public function testMailOrderInvoice() {
$this
->drupalLogin($this->adminUser);
$assert = $this
->assertSession();
$this
->drupalGet('admin/store/orders/' . $this->order
->id() . '/invoice/mail');
$assert
->statusCodeEquals(200);
$assert
->fieldValueEquals('email', $this->order
->getEmail());
$assert
->buttonExists('Mail invoice')
->press();
$this
->assertMailString('subject', 'Your Order Invoice', 1, 'Order invoice was sent via email');
$this
->assertMailString('body', '<b>Billing Address:</b><br />', 1, 'Markup found in invoice mail.');
$uri = theme_get_setting('logo.url');
$expected = Url::fromUserInput($uri, [
'absolute' => TRUE,
])
->toString();
$this
->assertMailString('body', $expected, 1, 'Logo image has absolute URL.');
}
}