$this->get_default_price($cart, $stock_code));
//$price = round2($price, $attributes['price'], user_price_dec());
$discount = $attributes["discount"];
- $discount = expand_template($template_line['discount'], $attributes['discount'], 0);
+ $discount = expand_template($template_line['discount'], $attributes['discount'],
+ $this->get_default_discount($cart, $stock_code));
}
else {
$price = 0;
$date = expand_template($template_line['date'], $attributes['date'],
$this->get_default_date($cart, $stock_code));
}
- $description = expand_template($template_line['description'], $attributes['description'], get_kit_description($stock_code));
+ else {
+ $date = null;
+ }
+
+ $description = expand_template($template_line['description'], $attributes['description'], $this->get_kit_description($cart, $stock_code));
}
else {
$stock_code = $attributes["stock_code"];
$quantity = $attributes["quantity"];
$price = $attributes["price"];
$discount = $attributes["discount"];
+ $date = $attributes["date"];
$description = $attributes["description"];
}
#echo "</ul>";
// Checking that product exists, to not process dodgy one
- $kit = get_item_kit($stock_code);
- $number = db_num_rows($kit);
- if ($number == 0) {
+ if(!$this->check_item_exists($stock_code)) {
display_error("Product '$stock_code' doesn't exist");
display_error("Line '$line' skipped");
}
- db_free_result($kit);
if(!$mode) { $mode = $default_mode; }
switch ($mode) {
return add_days(Today(), 10);
}
+ function get_kit_description($cart, $stock_code) {
+ return get_kit_description($stock_code);
+ }
+
function unmodifiable_quantity($cart, $line_no) {
return 0;
}
function quantity($cart, $line_no) {
return $cart->line_items[$line_no]->quantity;
}
+
+ function check_item_exists($stock_code) {
+ $kit = get_item_kit($stock_code);
+ $number = db_num_rows($kit);
+ db_free_result($kit);
+ return $number != 0;
+ }
}
class SalesTextCartManager extends TextCartManager {
--- /dev/null
+<?php
+require_once('test/helper.php');
+
+class ProcessTest extends PHPUnit_Framework_TestCase {
+ protected $cart;
+ protected $mgr;
+
+ protected function setUp() {
+ $this->cart = $this->getMock("Cart");
+ $this->mgr = $this->getMock("TextCartManager", array(
+ 'get_default_price'
+ ,'get_default_discount'
+ ,'get_kit_description'
+ ,'check_item_exists'
+ ,'add_to_order'
+ ));
+ }
+
+
+ public function processNormalExamples() {
+ return array(
+ array("A", "A", 1, 5.2, 0.02)
+ ,array("A 3", "A", 3, 5.2, 0.02)
+ ,array("A $3", "A", 1, 3, 0.02)
+ ,array(":# $3\nA", "A", 1, 3, 0.02)
+ ,array(":# $3\nA $7", "A", 1, 7, 0.02)
+ ,array(":# $(10*#+@)\nA $7", "A", 1, 75.2, 0.02)
+ ,array(":# 5%\nA", "A", 1, 5.2, 0.05)
+ ,array("A 0%", "A", 1, 5.2, 0)
+ ,array("A 10%", "A", 1, 5.2, 0.1)
+ );
+ }
+
+ /**
+ * @dataProvider processNormalExamples
+ */
+ function testNormalExamples($textcart, $stock_code, $quantity, $price, $discount=null, $description=null) {
+ // Stubbing mgr
+ $this->mgr->expects($this->any())
+ ->method('get_default_price')
+ ->will($this->returnValue(5.2));
+ $this->mgr->expects($this->any())
+ ->method('get_default_discount')
+ ->will($this->returnValue(.02));
+
+ // setting up expectation
+ $this->mgr->expects($this->once())
+ ->method('add_to_order')
+ ->with($this->equalTo($this->cart)
+ ,$this->equalTo($stock_code)
+ ,$this->equalTo($quantity)
+ ,$this->equalTo($price)
+ ,$this->equalTo($discount)
+ ,$this->equalTo($description));
+
+
+ $this->mgr->process_textcart($this->cart, $textcart, INSERT_MODE);
+ }
+
+}