You are here

public function StockTest::testStockThresholdMail in Ubercart 8.4

Tests sending out mail when stock drops below threshold.

File

uc_stock/tests/src/Functional/StockTest.php, line 114

Class

StockTest
Tests the stock control functionality.

Namespace

Drupal\Tests\uc_stock\Functional

Code

public function testStockThresholdMail() {
  $prefix = 'stock[' . $this->product->model->value . ']';
  $edit = [
    'uc_stock_threshold_notification' => 1,
  ];
  $this
    ->drupalGet('admin/store/config/stock');
  $this
    ->submitForm($edit, 'Save configuration');
  $qty = rand(10, 100);
  $edit = [
    $prefix . '[active]' => 1,
    $prefix . '[stock]' => $qty + 1,
    $prefix . '[threshold]' => $qty,
  ];
  $this
    ->drupalGet('node/' . $this->product
    ->id() . '/edit/stock');
  $this
    ->submitForm($edit, 'Save changes');
  $this
    ->addToCart($this->product);
  $this
    ->checkout();
  $mail = $this
    ->getMails([
    'id' => 'uc_stock_threshold',
  ]);
  $mail = array_pop($mail);
  $this
    ->assertEquals(uc_store_email(), $mail['to'], 'Threshold mail recipient is correct.');
  $this
    ->assertNotSame(FALSE, strpos($mail['subject'], 'Stock threshold limit reached'), 'Threshold mail subject is correct.');
  $this
    ->assertNotSame(FALSE, strpos($mail['body'], $this->product
    ->label()), 'Mail body contains product title.');
  $this
    ->assertNotSame(FALSE, strpos($mail['body'], $this->product->model->value), 'Mail body contains SKU.');
  $this
    ->assertNotSame(FALSE, strpos($mail['body'], 'has reached ' . $qty), 'Mail body contains quantity.');
}