Tests Split class pass.
authorMaxime Bourget <bmx007@gmail.com>
Fri, 7 Jun 2013 21:52:43 +0000 (22:52 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Fri, 7 Jun 2013 21:52:43 +0000 (22:52 +0100)
includes/splitter.inc
tests/splitTest.php [new file with mode: 0644]

index 8ff4640e2e26ae249ecf17f13143aba394e72b6e..a9f47b938f596c23bf22c31054b3ead64df8b1e8 100644 (file)
@@ -1,12 +1,13 @@
 <?php
 require_once($path_to_root.'/'.'includes/date_functions.inc');
 class Split {
-       public $stard_date;
+       public $start_date;
        public $end_date;
 
-       function __constructor($start_date, $period) {
-                       $this->start_date = $this->end_date = $start_date;
-                       $this->extend($period);
+       function __construct($start_date, $period=null) {
+                       $this->start_date = $start_date;
+                       $this->end_date = $start_date;
+                       if($period) $this->extend($period);
        }
 
        function extend($days) {
diff --git a/tests/splitTest.php b/tests/splitTest.php
new file mode 100644 (file)
index 0000000..693521a
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+global $path_to_root;
+$path_to_root = '../../';
+require_once('includes/splitter.inc');
+
+/* Stubbing undefined function */
+global $dateformats, $dateseps;
+       $dateformats    = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD","MmmDDYYYY", "DDMmmYYYY", "YYYYMmmDD");
+       $dateseps               = array("/", ".", "-", " ");
+function user_date_format() {
+       return 2; // YYYMMDD
+}
+
+function user_date_sep() {
+       return 0;
+}
+
+class splitTest extends PHPUnit_Framework_TestCase {
+       public function testConstructor() {
+               $date = '2013/01/05';
+               $split = new Split($date);
+       
+               $this->assertEquals($split->start_date, $date);
+               $this->assertEquals($split->end_date, $date);
+               
+               return $split;
+       }
+
+       /**
+        *  @depends testConstructor
+        */
+       public function testExtend($split) {
+               $split->extend(10);
+               $this->assertEquals($split->end_date, '2013/01/15');
+       }
+}
+?>