From 996bb8664856b302c96e19c6899010ea72ababe6 Mon Sep 17 00:00:00 2001
From: knut <>
Date: Mon, 4 Jun 2007 23:33:06 +0000
Subject: added more unit test stubs
---
tests/unit/AllTests.php | 6 +
tests/unit/Caching/AllTests.php | 27 ++++
tests/unit/Caching/TCacheTest.php | 51 ++++++++
tests/unit/Collections/AllTests.php | 2 +
tests/unit/Collections/TPagedDataSourceTest.php | 71 +++++++++++
tests/unit/Security/AllTests.php | 35 +++++
tests/unit/Security/TAuthManagerTest.php | 67 ++++++++++
tests/unit/Security/TAuthorizationRuleTest.php | 51 ++++++++
tests/unit/Security/TSecurityManagerTest.php | 59 +++++++++
tests/unit/Security/TUserManagerTest.php | 55 ++++++++
tests/unit/Security/TUserTest.php | 59 +++++++++
tests/unit/Util/AllTests.php | 29 +++++
tests/unit/Util/DateTimeStampTestCase.php | 162 ------------------------
tests/unit/Util/TDateTimeStampTest.php | 149 ++++++++++++++++++++++
tests/unit/Util/TLoggerTest.php | 27 ++++
15 files changed, 688 insertions(+), 162 deletions(-)
create mode 100644 tests/unit/Caching/AllTests.php
create mode 100644 tests/unit/Caching/TCacheTest.php
create mode 100644 tests/unit/Collections/TPagedDataSourceTest.php
create mode 100644 tests/unit/Security/AllTests.php
create mode 100644 tests/unit/Security/TAuthManagerTest.php
create mode 100644 tests/unit/Security/TAuthorizationRuleTest.php
create mode 100644 tests/unit/Security/TSecurityManagerTest.php
create mode 100644 tests/unit/Security/TUserManagerTest.php
create mode 100644 tests/unit/Security/TUserTest.php
create mode 100644 tests/unit/Util/AllTests.php
delete mode 100644 tests/unit/Util/DateTimeStampTestCase.php
create mode 100644 tests/unit/Util/TDateTimeStampTest.php
create mode 100644 tests/unit/Util/TLoggerTest.php
(limited to 'tests')
diff --git a/tests/unit/AllTests.php b/tests/unit/AllTests.php
index e097247b..6917ac71 100644
--- a/tests/unit/AllTests.php
+++ b/tests/unit/AllTests.php
@@ -11,6 +11,9 @@ require_once 'Collections/AllTests.php';
require_once 'I18N/core/AllTests.php';
require_once 'Web/AllTests.php';
require_once 'Web/UI/WebControls/AllTests.php';
+require_once 'Security/AllTests.php';
+require_once 'Caching/AllTests.php';
+require_once 'Util/AllTests.php';
require_once 'TComponentTest.php';
@@ -28,6 +31,9 @@ class AllTests {
$suite->addTest(I18N_core_AllTests::suite());
$suite->addTest(Web_AllTests::suite());
$suite->addTest(Web_UI_WebControls_AllTests::suite());
+ $suite->addTest(Security_AllTests::suite());
+ $suite->addTest(Caching_AllTests::suite());
+ $suite->addTest(Util_AllTests::suite());
$suite->addTestSuite('TComponentTest');
diff --git a/tests/unit/Caching/AllTests.php b/tests/unit/Caching/AllTests.php
new file mode 100644
index 00000000..072a6182
--- /dev/null
+++ b/tests/unit/Caching/AllTests.php
@@ -0,0 +1,27 @@
+addTestSuite('TCacheTest');
+
+ return $suite;
+ }
+}
+
+if(PHPUnit_MAIN_METHOD == 'Caching_AllTests::main') {
+ Caching_AllTests::main();
+}
+?>
diff --git a/tests/unit/Caching/TCacheTest.php b/tests/unit/Caching/TCacheTest.php
new file mode 100644
index 00000000..76df7903
--- /dev/null
+++ b/tests/unit/Caching/TCacheTest.php
@@ -0,0 +1,51 @@
+
diff --git a/tests/unit/Collections/AllTests.php b/tests/unit/Collections/AllTests.php
index a8a4e7f8..efa7eb21 100644
--- a/tests/unit/Collections/AllTests.php
+++ b/tests/unit/Collections/AllTests.php
@@ -11,6 +11,7 @@ require_once 'TQueueTest.php';
require_once 'TStackTest.php';
require_once 'TAttributeCollectionTest.php';
require_once 'TPagedListTest.php';
+require_once 'TPagedDataSourceTest.php';
class Collections_AllTests {
public static function main() {
@@ -26,6 +27,7 @@ class Collections_AllTests {
$suite->addTestSuite('TStackTest');
$suite->addTestSuite('TAttributeCollectionTest');
$suite->addTestSuite('TPagedListTest');
+ $suite->addTestSuite('TPagedDataSourceTest');
return $suite;
}
diff --git a/tests/unit/Collections/TPagedDataSourceTest.php b/tests/unit/Collections/TPagedDataSourceTest.php
new file mode 100644
index 00000000..f016c275
--- /dev/null
+++ b/tests/unit/Collections/TPagedDataSourceTest.php
@@ -0,0 +1,71 @@
+
diff --git a/tests/unit/Security/AllTests.php b/tests/unit/Security/AllTests.php
new file mode 100644
index 00000000..7de0996f
--- /dev/null
+++ b/tests/unit/Security/AllTests.php
@@ -0,0 +1,35 @@
+addTestSuite('TAuthManagerTest');
+ $suite->addTestSuite('TAuthorizationRuleTest');
+ $suite->addTestSuite('TSecurityManagerTest');
+ $suite->addTestSuite('TUserManagerTest');
+ $suite->addTestSuite('TUserTest');
+
+ return $suite;
+ }
+}
+
+if(PHPUnit_MAIN_METHOD == 'Security_AllTests::main') {
+ Security_AllTests::main();
+}
+?>
diff --git a/tests/unit/Security/TAuthManagerTest.php b/tests/unit/Security/TAuthManagerTest.php
new file mode 100644
index 00000000..6e3c05a9
--- /dev/null
+++ b/tests/unit/Security/TAuthManagerTest.php
@@ -0,0 +1,67 @@
+
diff --git a/tests/unit/Security/TAuthorizationRuleTest.php b/tests/unit/Security/TAuthorizationRuleTest.php
new file mode 100644
index 00000000..e20542dc
--- /dev/null
+++ b/tests/unit/Security/TAuthorizationRuleTest.php
@@ -0,0 +1,51 @@
+
diff --git a/tests/unit/Security/TSecurityManagerTest.php b/tests/unit/Security/TSecurityManagerTest.php
new file mode 100644
index 00000000..76029bde
--- /dev/null
+++ b/tests/unit/Security/TSecurityManagerTest.php
@@ -0,0 +1,59 @@
+
diff --git a/tests/unit/Security/TUserManagerTest.php b/tests/unit/Security/TUserManagerTest.php
new file mode 100644
index 00000000..8937ba22
--- /dev/null
+++ b/tests/unit/Security/TUserManagerTest.php
@@ -0,0 +1,55 @@
+
diff --git a/tests/unit/Security/TUserTest.php b/tests/unit/Security/TUserTest.php
new file mode 100644
index 00000000..67ac6eb4
--- /dev/null
+++ b/tests/unit/Security/TUserTest.php
@@ -0,0 +1,59 @@
+
diff --git a/tests/unit/Util/AllTests.php b/tests/unit/Util/AllTests.php
new file mode 100644
index 00000000..4a9ce809
--- /dev/null
+++ b/tests/unit/Util/AllTests.php
@@ -0,0 +1,29 @@
+addTestSuite('TDateTimeStampTest');
+ $suite->addTestSuite('TLoggerTest');
+
+ return $suite;
+ }
+}
+
+if(PHPUnit_MAIN_METHOD == 'Util_AllTests::main') {
+ Util_AllTests::main();
+}
+?>
diff --git a/tests/unit/Util/DateTimeStampTestCase.php b/tests/unit/Util/DateTimeStampTestCase.php
deleted file mode 100644
index de1413f7..00000000
--- a/tests/unit/Util/DateTimeStampTestCase.php
+++ /dev/null
@@ -1,162 +0,0 @@
-getTimeStamp(0,0,0);
- $this->assertEquals($s->formatDate('Y-m-d'), date('Y-m-d'));
-
- $t = $s->getTimeStamp(0,0,0,6,1,2102);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-06-01');
-
- $t = $s->getTimeStamp(0,0,0,2,1,2102);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-02-01');
- }
-
- function testGregorianToJulianConversion()
- {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0,10,11,1492);
-
- //http://www.holidayorigins.com/html/columbus_day.html - Friday check
- $this->assertEquals($s->formatDate('D Y-m-d',$t), 'Fri 1492-10-11');
-
- $t = $s->getTimeStamp(0,0,0,2,29,1500);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1500-02-29');
-
- $t = $s->getTimeStamp(0,0,0,2,29,1700);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1700-03-01');
-
- }
-
- function testGregorianCorrection()
- {
- $s = new TDateTimeStamp;
- $diff = $s->getTimeStamp(0,0,0,10,15,1582) - $s->getTimeStamp(0,0,0,10,4,1582);
-
- //This test case fails on my windows machine!
- //$this->assertEquals($diff, 3600*24,
- // "Error in gregorian correction = ".($diff/3600/24)." days");
-
- $this->assertEquals($s->getDayOfWeek(1582,10,15), 5.0);
- $this->assertEquals($s->getDayOfWeek(1582,10,4), 4.0);
- }
-
- function testOverFlow()
- {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0,3,33,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-04-02', 'Error in day overflow 1');
-
- $t = $s->getTimeStamp(0,0,0,4,33,1971);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1971-05-03', 'Error in day overflow 2');
- $t = $s->getTimeStamp(0,0,0,1,60,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-03-01', 'Error in day overflow 3 '.$s->getDate('Y-m-d',$t));
- $t = $s->getTimeStamp(0,0,0,12,32,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-01', 'Error in day overflow 4 '.$s->getDate('Y-m-d',$t));
- $t = $s->getTimeStamp(0,0,0,12,63,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-02-01', 'Error in day overflow 5 '.$s->getDate('Y-m-d',$t));
- $t = $s->getTimeStamp(0,0,0,13,3,1965);
- $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-03', 'Error in mth overflow 1');
- }
-
- function test2DigitTo4DigitYearConversion()
- {
- $s = new TDateTimeStamp;
- $this->assertEquals($s->get4DigitYear(00), 2000, "Err 2-digit 2000");
- $this->assertEquals($s->get4DigitYear(10), 2010, "Err 2-digit 2010");
- $this->assertEquals($s->get4DigitYear(20), 2020, "Err 2-digit 2020");
- $this->assertEquals($s->get4DigitYear(30), 2030, "Err 2-digit 2030");
- $this->assertEquals($s->get4DigitYear(40), 1940, "Err 2-digit 1940");
- $this->assertEquals($s->get4DigitYear(50), 1950, "Err 2-digit 1950");
- $this->assertEquals($s->get4DigitYear(90), 1990, "Err 2-digit 1990");
- }
-
- function testStringFormating()
- {
- $s = new TDateTimeStamp;
- $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003';
- $s1 = date($fmt,0);
- $s2 = $s->formatDate($fmt,0);
- $this->assertEquals($s1, $s2);//, " date() 0 failed \n $s1 \n $s2");
-
- for ($i=100; --$i > 0; )
- {
- $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000);
- $s1 = date($fmt,$ts);
- $s2 = $s->formatDate($fmt,$ts);
- //print "$s1
$s2
";
- $this->assertEquals($s1,$s2);
-
- $a1 = getdate($ts);
- $a2 = $s->getDate($ts,false);
- $this->assertEquals($a1,$a2);
- }
- }
-
- function testRandomDatesBetween100And4000()
- {
- $this->assertIsValidDate(100,1);
- //echo "Testing year ";
- for ($i=100; --$i >= 0;)
- {
- $y1 = 100+rand(0,1970-100);
- //echo $y1." ";
- $m = rand(1,12);
- $this->assertIsValidDate($y1,$m);
-
- $y1 = 3000-rand(0,3000-1970);
- //echo $y1." ";
- $this->assertIsValidDate($y1,$m);
- }
- }
-
- function assertIsValidDate($y1,$m,$d=13)
- {
- $s = new TDateTimeStamp;
- $t = $s->getTimeStamp(0,0,0,$m,$d,$y1);
- $rez = $s->formatDate('Y-n-j H:i:s',$t);
-
- $this->assertEquals("$y1-$m-$d 00:00:00", $rez);
- }
-
- function testRandomDates()
- {
- $start = 1960+rand(0,10);
- $yrs = 12;
- $i = 365.25*86400*($start-1970);
- $offset = 36000+rand(10000,60000);
- $max = 365*$yrs*86400;
- $lastyear = 0;
- $s = new TDateTimeStamp;
-
- // we generate a timestamp, convert it to a date, and convert it back to a timestamp
- // and check if the roundtrip broke the original timestamp value.
- //print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: ";
- $fails = 0;
- for ($max += $i; $i < $max; $i += $offset)
- {
- $ret = $s->formatDate('m,d,Y,H,i,s',$i);
- $arr = explode(',',$ret);
- if ($lastyear != $arr[2])
- $lastyear = $arr[2];
-
- $newi = $s->getTimestamp($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);
- if ($i != $newi)
- {
- $fails++;
- //$j = mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);
- //print "Error at $i, $j, getTimestamp() returned $newi ($ret)\n";
- }
- }
- $this->assertEquals($fails, 0);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/tests/unit/Util/TDateTimeStampTest.php b/tests/unit/Util/TDateTimeStampTest.php
new file mode 100644
index 00000000..5d296a83
--- /dev/null
+++ b/tests/unit/Util/TDateTimeStampTest.php
@@ -0,0 +1,149 @@
+getTimeStamp(0,0,0);
+ $this->assertEquals($s->formatDate('Y-m-d'), date('Y-m-d'));
+
+ $t = $s->getTimeStamp(0,0,0,6,1,2102);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-06-01');
+
+ $t = $s->getTimeStamp(0,0,0,2,1,2102);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '2102-02-01');
+ }
+
+ public function testGregorianToJulianConversion() {
+ $s = new TDateTimeStamp;
+ $t = $s->getTimeStamp(0,0,0,10,11,1492);
+
+ //http://www.holidayorigins.com/html/columbus_day.html - Friday check
+ $this->assertEquals($s->formatDate('D Y-m-d',$t), 'Fri 1492-10-11');
+
+ $t = $s->getTimeStamp(0,0,0,2,29,1500);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1500-02-29');
+
+ $t = $s->getTimeStamp(0,0,0,2,29,1700);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1700-03-01');
+
+ }
+
+ public function testGregorianCorrection() {
+ $s = new TDateTimeStamp;
+ $diff = $s->getTimeStamp(0,0,0,10,15,1582) - $s->getTimeStamp(0,0,0,10,4,1582);
+
+ //This test case fails on my windows machine!
+ //$this->assertEquals($diff, 3600*24,
+ // "Error in gregorian correction = ".($diff/3600/24)." days");
+
+ $this->assertEquals($s->getDayOfWeek(1582,10,15), 5.0);
+ $this->assertEquals($s->getDayOfWeek(1582,10,4), 4.0);
+ }
+
+ public function testOverFlow() {
+ $s = new TDateTimeStamp;
+ $t = $s->getTimeStamp(0,0,0,3,33,1965);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-04-02', 'Error in day overflow 1');
+
+ $t = $s->getTimeStamp(0,0,0,4,33,1971);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1971-05-03', 'Error in day overflow 2');
+ $t = $s->getTimeStamp(0,0,0,1,60,1965);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-03-01', 'Error in day overflow 3 '.$s->getDate('Y-m-d',$t));
+ $t = $s->getTimeStamp(0,0,0,12,32,1965);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-01', 'Error in day overflow 4 '.$s->getDate('Y-m-d',$t));
+ $t = $s->getTimeStamp(0,0,0,12,63,1965);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-02-01', 'Error in day overflow 5 '.$s->getDate('Y-m-d',$t));
+ $t = $s->getTimeStamp(0,0,0,13,3,1965);
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-03', 'Error in mth overflow 1');
+ }
+
+ public function test2DigitTo4DigitYearConversion() {
+ $s = new TDateTimeStamp;
+ $this->assertEquals($s->get4DigitYear(00), 2000, "Err 2-digit 2000");
+ $this->assertEquals($s->get4DigitYear(10), 2010, "Err 2-digit 2010");
+ $this->assertEquals($s->get4DigitYear(20), 2020, "Err 2-digit 2020");
+ $this->assertEquals($s->get4DigitYear(30), 2030, "Err 2-digit 2030");
+ $this->assertEquals($s->get4DigitYear(40), 1940, "Err 2-digit 1940");
+ $this->assertEquals($s->get4DigitYear(50), 1950, "Err 2-digit 1950");
+ $this->assertEquals($s->get4DigitYear(90), 1990, "Err 2-digit 1990");
+ }
+
+ public function testStringFormating() {
+ $s = new TDateTimeStamp;
+ $fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003';
+ $s1 = date($fmt,0);
+ $s2 = $s->formatDate($fmt,0);
+ $this->assertEquals($s1, $s2);//, " date() 0 failed \n $s1 \n $s2");
+
+ for ($i=10; --$i > 0; ) {
+ $ts = 3600.0*((rand()%60000)+(rand()%60000))+(rand()%60000);
+ $s1 = date($fmt,$ts);
+ $s2 = $s->formatDate($fmt,$ts);
+ //print "$s1
$s2
"; + $this->assertEquals($s1,$s2); + + $a1 = getdate($ts); + $a2 = $s->getDate($ts,false); + $this->assertEquals($a1,$a2); + } + } + + public function testRandomDatesBetween100And4000() { + $this->assertIsValidDate(100,1); + //echo "Testing year "; + for ($i=10; --$i >= 0;) { + $y1 = 100+rand(0,1970-100); + //echo $y1." "; + $m = rand(1,12); + $this->assertIsValidDate($y1,$m); + + $y1 = 3000-rand(0,3000-1970); + //echo $y1." "; + $this->assertIsValidDate($y1,$m); + } + } + + public function assertIsValidDate($y1,$m,$d=13) { + $s = new TDateTimeStamp; + $t = $s->getTimeStamp(0,0,0,$m,$d,$y1); + $rez = $s->formatDate('Y-n-j H:i:s',$t); + + $this->assertEquals("$y1-$m-$d 00:00:00", $rez); + } + + function testRandomDates() { + $start = 1960+rand(0,10); + $yrs = 12; + $i = 365.25*86400*($start-1970); + $offset = 36000+rand(10000,60000); + $max = 365*$yrs*86400; + $lastyear = 0; + $s = new TDateTimeStamp; + + // we generate a timestamp, convert it to a date, and convert it back to a timestamp + // and check if the roundtrip broke the original timestamp value. + //print "Testing $start to ".($start+$yrs).", or $max seconds, offset=$offset: "; + $fails = 0; + for ($max += $i; $i < $max; $i += $offset) { + $ret = $s->formatDate('m,d,Y,H,i,s',$i); + $arr = explode(',',$ret); + if ($lastyear != $arr[2]) + $lastyear = $arr[2]; + + $newi = $s->getTimestamp($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); + if ($i != $newi) { + $fails++; + //$j = mktime($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]); + //print "Error at $i, $j, getTimestamp() returned $newi ($ret)\n"; + } + } + $this->assertEquals($fails, 0); + } +} + +?> diff --git a/tests/unit/Util/TLoggerTest.php b/tests/unit/Util/TLoggerTest.php new file mode 100644 index 00000000..4da5aaa1 --- /dev/null +++ b/tests/unit/Util/TLoggerTest.php @@ -0,0 +1,27 @@ + -- cgit v1.2.3