From: Maxime Bourget Date: Sat, 25 May 2013 15:40:21 +0000 (+0100) Subject: parse line test setup correctly. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=f8faa1fb238286f843b6e9331cdf8dafe6c0f7d3;p=textcart.git parse line test setup correctly. --- diff --git a/includes/textcart_manager.inc b/includes/textcart_manager.inc index 81678f7..2acbc4f 100644 --- a/includes/textcart_manager.inc +++ b/includes/textcart_manager.inc @@ -323,6 +323,7 @@ class TextCartManager { 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
"; @@ -349,7 +350,7 @@ class TextCartManager { $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); @@ -379,7 +380,7 @@ class TextCartManager { 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) { diff --git a/test/textcartManagerTest.php b/test/textcartManagerTest.php new file mode 100644 index 0000000..b31b497 --- /dev/null +++ b/test/textcartManagerTest.php @@ -0,0 +1,41 @@ +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 + ) + ); + } + +} diff --git a/test/textcart_manager.php b/test/textcart_manager.php deleted file mode 100644 index 608da26..0000000 --- a/test/textcart_manager.php +++ /dev/null @@ -1,10 +0,0 @@ -