display_error("Can't find line details with ".join(", ",array($stock_code, $quantity, $price, $discount, $description)));
return null;
}
+
function parse_line($line) {
global $mode_map;
#echo "parsing : $line<br/>";
$mode = $this->mode_map[$matches[1]];
$stock_code = $matches[2];
$fields_str = $matches[3];
- $description = trim($matches[4], '" ');
+ $description = trim(@$matches[4], '" ');
# Hack to allow spaces between attribute qualifier
$fields_str = preg_replace('/([+$^])\s*/', '\1' , $fields_str);
display_error("price already set for line '$line'");
return;
};
- $price = $matches[1] . $matches[2];// ack to get first match or the second one
+ $price = $matches[1] . @$matches[2];// ack to get first match or the second one
}
elseif (preg_match('/^(\d+(?:.\d+)?'.PARAM_REG.')%$/', $field, $matches)) {
if($discount) {
--- /dev/null
+<?php
+
+$path_to_root = '../../';
+require_once 'includes/textcart_manager.inc';
+
+
+class TextcartManagerTest extends PHPUnit_Framework_TestCase {
+ protected $cart;
+ protected $mgr;
+
+ protected function setUp() {
+ $this->cart = array("mock");
+ $this->mgr = new TextCartManager();
+ }
+
+
+ public function parseExamples() {
+ return array(
+ array("A 10 5.0 3% | hello", NORMAL_LINE, "A", '10', '5.0', 0.03, "hello")
+ ,array("A", "A", 1, 0.0, 0, "")
+ );
+ }
+/**
+ * * @dataProvider parseExamples
+ * */
+ public function testAdd($line, $mode, $stock_code, $quantity, $price, $discount=null, $description=null, $date=null)
+ {
+ $data = $this->mgr->parse_line($line);
+ $this->assertEquals($data, array(
+ "mode" => $mode
+ ,"stock_code" => $stock_code
+ ,"quantity" => $quantity
+ ,"price" => $price
+ ,"discount" => $discount
+ ,"description" => $description
+ ,"date" => $date
+ )
+ );
+ }
+
+}