Adding line test.
authorMaxime Bourget <bmx007@gmail.com>
Sat, 25 May 2013 15:50:54 +0000 (16:50 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Sat, 25 May 2013 16:05:33 +0000 (17:05 +0100)
test/textcartManagerTest.php

index b31b497fd5aa53209d0fd32f9548dc70ff3fae1e..e2766c44d78d06e085f36d404536ef4606bbc5a7 100644 (file)
@@ -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