From: Maxime Bourget Date: Sat, 25 May 2013 15:50:54 +0000 (+0100) Subject: Adding line test. X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=0f92636068ce21f8756d0bb9bbca4cbb78c703fb;p=textcart.git Adding line test. --- diff --git a/test/textcartManagerTest.php b/test/textcartManagerTest.php index b31b497..e2766c4 100644 --- a/test/textcartManagerTest.php +++ b/test/textcartManagerTest.php @@ -4,6 +4,10 @@ $path_to_root = '../../'; require_once 'includes/textcart_manager.inc'; + +function display_error($msg) { + +} class TextcartManagerTest extends PHPUnit_Framework_TestCase { protected $cart; protected $mgr; @@ -14,17 +18,50 @@ class TextcartManagerTest extends PHPUnit_Framework_TestCase { } - public function parseExamples() { + public function parseNormalExamples() { 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, "") + /*** parse quantity ***/ + array("A", "A", null, null, 0) + ,array("A 1 ", "A", '1', null, 0) + ,array("A 17 ", "A", '17', null, 0) + ,array("A +1.7 ", "A", '1.7', null, 0) + ,array("A 1.7 ", "A", null, '1.7', 0) + ,array("A $17 ", "A", null, '17', 0) + ,array("A 2 7.0 ", "A", '2', '7.0', 0) + ,array("A 7.0 2 ", "A", '2', '7.0', 0) + ,array("A $(7.0) 2 ", "A", '2', '7.0', 0) + ,array("A 7.0 +(2 ) ", "A", '2', '7.0', 0) + ,array("A 7.0 +(2.5 ) ", "A", '2.5', '7.0', 0) + ); + } +/** + * @group normal + * @dataProvider parseNormalExamples + */ + public function testNormal($line, $stock_code, $quantity, $price, $discount=null, $description=null) + { + $this->assertParse($line, NORMAL_LINE, $stock_code, $quantity, $price, $discount, $description, null); + } + + public function parseDatedExamples() { + return array( + /*** Everything is passed ***/ + array("A 10 5.0 3% ^2013/03/01' | hello", "A", '10', '5.0', 0.03, "hello", '2013/03/01') + ,array("A 3% 10 5.0 ^2013/03/01' | hello", "A", '10', '5.0', 0.03, "hello", '2013/03/01') ); } /** - * * @dataProvider parseExamples - * */ - public function testAdd($line, $mode, $stock_code, $quantity, $price, $discount=null, $description=null, $date=null) + * @group dated + * @dataProvider parseDatedExamples + */ + public function testDated($line, $stock_code, $quantity, $price, $discount=null, $description=null, $date=null) + { + $this->assertParse($line, NORMAL_LINE, $stock_code, $quantity, $price, $discount, $description, $date); + } + + public function assertParse($line, $mode, $stock_code, $quantity, $price, $discount=null, $description=null, $date=null) { + $data = $this->mgr->parse_line($line); $data = $this->mgr->parse_line($line); $this->assertEquals($data, array( "mode" => $mode