You are here

public function UbercartStockTestCase::testStockThresholdMail in Ubercart 7.3

Same name and namespace in other branches
  1. 6.2 uc_stock/uc_stock.test \UbercartStockTestCase::testStockThresholdMail()

File

uc_stock/tests/uc_stock.test, line 73
Ubercart stock related tests.

Class

UbercartStockTestCase
@file Ubercart stock related tests.

Code

public function testStockThresholdMail() {
  $edit = array(
    'uc_stock_threshold_notification' => 1,
  );
  $this
    ->drupalPost('admin/store/settings/stock', $edit, 'Save configuration');
  $qty = rand(10, 100);
  $edit = array(
    'stock[0][active]' => 1,
    'stock[0][stock]' => $qty + 1,
    'stock[0][threshold]' => $qty,
  );
  $this
    ->drupalPost('node/' . $this->product->nid . '/edit/stock', $edit, 'Save changes');
  $this
    ->drupalPost('node/' . $this->product->nid, array(), 'Add to cart');
  $this
    ->checkout();
  $mail = $this
    ->drupalGetMails(array(
    'id' => 'uc_stock_threshold',
  ));
  $mail = array_pop($mail);
  $this
    ->assertTrue(strpos($mail['subject'], 'Stock threshold limit reached') !== FALSE, 'Threshold mail subject is correct.');
  $this
    ->assertTrue(strpos($mail['body'], $this->product->title) !== FALSE, 'Mail body contains product title.');
  $this
    ->assertTrue(strpos($mail['body'], $this->product->model) !== FALSE, 'Mail body contains SKU.');
  $this
    ->assertTrue(strpos($mail['body'], 'has reached ' . $qty) !== FALSE, 'Mail body contains quantity.');
}