diff --git a/uc_stock/tests/uc_stock.test b/uc_stock/tests/uc_stock.test index 18d6357..f563a1a 100644 --- a/uc_stock/tests/uc_stock.test +++ b/uc_stock/tests/uc_stock.test @@ -69,4 +69,27 @@ class UbercartStockTestCase extends UbercartTestHelper { $this->assertEqual($stock - $qty, uc_stock_level($this->product->model)); } + + 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.'); + } } diff --git a/uc_stock/uc_stock.module b/uc_stock/uc_stock.module index 068c681..10c872f 100644 --- a/uc_stock/uc_stock.module +++ b/uc_stock/uc_stock.module @@ -134,7 +134,7 @@ function uc_stock_mail($key, &$message, $params) { */ function uc_stock_uc_message() { $messages['uc_stock_threshold_notification_subject'] = t('[store:name]: Stock threshold limit reached'); - $messages['uc_stock_threshold_notification_message'] = t("This message has been sent to let you know that the stock level for the model [uc_stock:model] has reached [uc_stock:level]. There may not be enough units in stock to fulfill order #[uc_order:link]."); + $messages['uc_stock_threshold_notification_message'] = t('This message has been sent to let you know that the stock level for "[node:title]" with SKU [uc_stock:model] has reached [uc_stock:level]. There may not be enough units in stock to fulfill order #[uc_order:link].'); return $messages; }