You are here

protected function InvoiceConfirmationMailTest::setUp in Commerce Invoice 8.2

Overrides InvoiceKernelTestBase::setUp

File

tests/src/Kernel/Mail/InvoiceConfirmationMailTest.php, line 47

Class

InvoiceConfirmationMailTest
Tests the sending of invoice confirmation emails.

Namespace

Drupal\Tests\commerce_invoice\Kernel\Mail

Code

protected function setUp() : void {
  parent::setUp();
  $user = $this
    ->createUser([
    'mail' => 'customer@example.com',
    'preferred_langcode' => 'en',
  ]);
  $profile = Profile::create([
    'type' => 'customer',
    'address' => [
      'country_code' => 'US',
      'postal_code' => '53177',
      'locality' => 'Milwaukee',
      'address_line1' => 'Pabst Blue Ribbon Dr',
      'administrative_area' => 'WI',
      'given_name' => 'Frederick',
      'family_name' => 'Pabst',
    ],
    'uid' => $user
      ->id(),
  ]);
  $profile
    ->save();
  $this->profile = $this
    ->reloadEntity($profile);
  $order_item = OrderItem::create([
    'type' => 'test',
    'quantity' => 1,
    'title' => $this
      ->randomString(),
    'unit_price' => new Price('12.00', 'USD'),
  ]);
  $order_item
    ->save();
  $order = Order::create([
    'type' => 'default',
    'mail' => $user
      ->getEmail(),
    'state' => 'completed',
    'store_id' => $this->store,
    'billing_profile' => $this->profile,
    'uid' => $user
      ->id(),
    'order_items' => [
      $order_item,
    ],
  ]);
  $order
    ->save();
  $invoice = Invoice::create([
    'type' => 'default',
    'mail' => $user
      ->getEmail(),
    'invoice_number' => '10',
    'orders' => [
      $order,
    ],
    'store_id' => $this->store
      ->id(),
    'billing_profile' => $this->profile,
    'state' => 'paid',
    'uid' => $user
      ->id(),
  ]);
  $invoice
    ->save();
  $this->invoice = $this
    ->reloadEntity($invoice);
  $this->invoiceConfirmationMail = $this->container
    ->get('commerce_invoice.invoice_confirmation_mail');
}