summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorctrlaltca <>2013-01-06 17:27:51 +0000
committerctrlaltca <>2013-01-06 17:27:51 +0000
commit55eb721567c84d0a30914f76615691990d005ac3 (patch)
tree14b283e6f7980e3c45f6109e90fd0fd0f280c8c0
parent1f6d9caf8397416747aa2105b2aac352cdf92fe3 (diff)
fixed old/broken unit tests; update documentation
-rw-r--r--HISTORY1
-rw-r--r--UPGRADE3
-rw-r--r--tests/unit/Collections/TPriorityMapTest.php2
-rw-r--r--tests/unit/Security/TSecurityManagerTest.php7
-rw-r--r--tests/unit/Util/TDateTimeStampTest.php53
-rw-r--r--tests/unit/Util/TSimpleDateFormatterTest.php2
-rw-r--r--tests/unit/Web/THttpRequestTest.php13
7 files changed, 39 insertions, 42 deletions
diff --git a/HISTORY b/HISTORY
index 32eb3fef..2c183ebb 100644
--- a/HISTORY
+++ b/HISTORY
@@ -20,6 +20,7 @@ EHN: Permit to change the default cipher in TSecurityManager::setEncryption(); c
EHN: Use php's hash_hmac() when available in TSecurityManager, and permit the use of all algorithms supported by php (ctrlaltca)
EHN: Use mbstring when available in TSecurityManager to better handle multibyte text (ctrlaltca)
EHN: Updated TinyMCE to 3.5.6 (ctrlaltca)
+CHG: Rewrite TDateTimeStamp as a wrapper to php's native DateTime and deprecate it (ctrlaltca)
Version 3.2.0 Jun 25, 2012
BUG: Fixed an inconsistency in TRegularExpressionValidator
diff --git a/UPGRADE b/UPGRADE
index 0212a540..2c041501 100644
--- a/UPGRADE
+++ b/UPGRADE
@@ -16,6 +16,9 @@ Upgrading from v3.2.0
algorithm supported by the local php installation.
- TSecurityManager's Encryption property has been deprecated (it was unusable). Instead, use the new
CryptAlgorithm property that permites the use of any algorithm supported by the local php installation.
+- TDateTimeStamp has been deprecated in favour of php's native DateTime classes. TDateTimeStamp has been
+ rewritten as a wrapper to DateTime, so porting and testing old code should be as easy as just looking at
+ the new implementation.
Upgrading from v3.1.10
---------------------
diff --git a/tests/unit/Collections/TPriorityMapTest.php b/tests/unit/Collections/TPriorityMapTest.php
index c7d56243..7c6ed498 100644
--- a/tests/unit/Collections/TPriorityMapTest.php
+++ b/tests/unit/Collections/TPriorityMapTest.php
@@ -352,7 +352,7 @@ class TPriorityMapTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, $priorities[1]);
$this->assertEquals(10, $priorities[2]);
$this->assertEquals(100, $priorities[3]);
- $this->assertEquals(null, $priorities[4]);
+ $this->assertEquals(false, isset($priorities[4]));
}
diff --git a/tests/unit/Security/TSecurityManagerTest.php b/tests/unit/Security/TSecurityManagerTest.php
index 2daf6ede..d265d127 100644
--- a/tests/unit/Security/TSecurityManagerTest.php
+++ b/tests/unit/Security/TSecurityManagerTest.php
@@ -73,10 +73,11 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase {
$sec=new TSecurityManager ();
$sec->init (null);
try {
- $sec->setEncryption ('DES');
+ $sec->setCryptAlgorithm('NotExisting');
+ $foo=$sec->encrypt('dummy');
self::fail ('Expected TNotSupportedException not thrown');
} catch (TNotSupportedException $e) {
- self::assertEquals('3DES', $sec->getEncryption());
+ self::assertEquals('NotExisting', $sec->getCryptAlgorithm());
}
}
@@ -96,6 +97,8 @@ class TSecurityManagerTest extends PHPUnit_Framework_TestCase {
return;
}
$decrypted = $sec->decrypt($encrypted);
+ // the decrypted string is padded with \0
+ $decrypted = strstr($decrypted, "\0", TRUE);
self::assertEquals($plainText,$decrypted);
diff --git a/tests/unit/Util/TDateTimeStampTest.php b/tests/unit/Util/TDateTimeStampTest.php
index e9a0a22f..60ccf640 100644
--- a/tests/unit/Util/TDateTimeStampTest.php
+++ b/tests/unit/Util/TDateTimeStampTest.php
@@ -4,12 +4,15 @@ require_once dirname(__FILE__).'/../phpunit.php';
Prado::using('System.Util.TDateTimeStamp');
+/**
+ * @package System.Util
+ */
class TDateTimeStampTest extends PHPUnit_Framework_TestCase {
public function testGetTimeStampAndFormat() {
$s = new TDateTimeStamp;
$t = $s->getTimeStamp(0,0,0);
- $this->assertEquals($s->formatDate('Y-m-d'), date('Y-m-d'));
+ $this->assertEquals($s->formatDate('Y-m-d',$t), date('Y-m-d'));
$t = $s->getTimeStamp(0,0,0,6,1,2102);
$this->assertEquals($s->formatDate('Y-m-d',$t), '2102-06-01');
@@ -18,33 +21,6 @@ class TDateTimeStampTest extends PHPUnit_Framework_TestCase {
$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);
@@ -53,13 +29,13 @@ class TDateTimeStampTest extends PHPUnit_Framework_TestCase {
$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));
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1965-03-01', 'Error in day overflow 3 '.$s->formatDate('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));
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-01', 'Error in day overflow 4 '.$s->formatDate('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));
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-02-01', 'Error in day overflow 5 '.$s->formatDate('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');
+ $this->assertEquals($s->formatDate('Y-m-d',$t), '1966-01-03', 'Error in math overflow 1');
}
public function test2DigitTo4DigitYearConversion() {
@@ -93,11 +69,11 @@ class TDateTimeStampTest extends PHPUnit_Framework_TestCase {
}
}
- public function testRandomDatesBetween100And4000() {
- $this->assertIsValidDate(100,1);
+ public function testRandomDatesBetween1000And4000() {
+ $this->assertIsValidDate(1000,1);
//echo "Testing year ";
for ($i=10; --$i >= 0;) {
- $y1 = 100+rand(0,1970-100);
+ $y1 = 1000+rand(0,1970-1000);
//echo $y1." ";
$m = rand(1,12);
$this->assertIsValidDate($y1,$m);
@@ -137,7 +113,12 @@ class TDateTimeStampTest extends PHPUnit_Framework_TestCase {
$newi = $s->getTimestamp($arr[3],$arr[4],$arr[5],$arr[0],$arr[1],$arr[2]);
if ($i != $newi) {
- $fails++;
+ // This actually can fail if $i is in the middle of a time change due to DST
+ $tz = new DateTimeZone(date_default_timezone_get());
+ $transitions = $tz->getTransitions($i-3600, $i+3600);
+ if(count($transitions) == 0)
+ $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";
}
diff --git a/tests/unit/Util/TSimpleDateFormatterTest.php b/tests/unit/Util/TSimpleDateFormatterTest.php
index 13ad25a9..bfda4712 100644
--- a/tests/unit/Util/TSimpleDateFormatterTest.php
+++ b/tests/unit/Util/TSimpleDateFormatterTest.php
@@ -45,7 +45,7 @@ class TSimpleDateFormatterTest extends PHPUnit_Framework_TestCase {
public function testMissingYearPattern() {
$formatter = new TSimpleDateFormatter("MM/dd");
- self::assertEquals("2008-10-22", date('Y-m-d', $formatter->parse("10/22")));
+ self::assertEquals(date("Y-10-22"), date('Y-m-d', $formatter->parse("10/22")));
}
public function testDayMonthYearOrdering() {
diff --git a/tests/unit/Web/THttpRequestTest.php b/tests/unit/Web/THttpRequestTest.php
index 6af8cd78..e8b86ac8 100644
--- a/tests/unit/Web/THttpRequestTest.php
+++ b/tests/unit/Web/THttpRequestTest.php
@@ -197,7 +197,9 @@ class THttpRequestTest extends PHPUnit_Framework_TestCase {
}
public function testGetBrowser() {
- /*$request = new THttpRequest();
+ /*
+ // requires browscap configuration in php.ini
+ $request = new THttpRequest();
$request->init(null);
// Reset UserAgent, because constructor of THttpRequest unset it if called from cli !
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3';
@@ -240,13 +242,20 @@ class THttpRequestTest extends PHPUnit_Framework_TestCase {
}
public function testGetUserLanguages() {
+ /*
+ // this actually doesn't work because:
+ // - THttpRequest::getUserLanguages() is a wrapper for PradoBase::getUserLanguages()
+ // - PradoBase is using a static variable to hold the user languages array
+ // - PradoBase exists before we set $_SERVER['HTTP_ACCEPT_LANGUAGE']
$request = new THttpRequest();
$request->init(null);
// Browser sent fr,en-us;q=0.8,fr-fr;q=0.5,en;q=0.3
// that means that browser want fr (1) first, next en-us (0.8), then fr-fr(0.5)n and last en (0.3)
// So, we expect method to return an array with these languages, and this order
- $acceptLanguages=array ('fr', 'en-us','fr-fr','en');
+ $acceptLanguages=array('fr', 'en-us','fr-fr','en');
self::assertEquals($acceptLanguages, $request->getUserLanguages());
+ */
+ throw new PHPUnit_Framework_IncompleteTestError();
}
public function testSetEnableCookieValidation() {