From 55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Thu, 10 Nov 2005 12:47:19 +0000
Subject: Initial import of prado framework
---
tests/UnitTests/framework/Collections/utList.php | 321 ++++++++++++++++
tests/UnitTests/framework/Collections/utMap.php | 245 ++++++++++++
tests/UnitTests/framework/Data/CacheTestCase.php | 98 +++++
tests/UnitTests/framework/Data/utMemCache.php | 66 ++++
tests/UnitTests/framework/Data/utSqliteCache.php | 59 +++
tests/UnitTests/framework/Data/utXmlDocument.php | 68 ++++
tests/UnitTests/framework/Data/xml/data1.xml | 45 +++
tests/UnitTests/framework/Data/xml/data1.xml.out | 41 ++
tests/UnitTests/framework/Data/xml/data2.xml | 41 ++
tests/UnitTests/framework/Data/xml/data2.xml.out | 40 ++
tests/UnitTests/framework/Data/xml/data3.xml | 46 +++
tests/UnitTests/framework/Data/xml/data3.xml.out | 45 +++
.../framework/TestSystem/protected/application.xml | 21 ++
.../framework/TestSystem/protected/data/test.db | Bin 0 -> 5120 bytes
.../TestSystem/protected/pages/config.xml | 12 +
tests/UnitTests/framework/Web/UI/utControl.php | 420 +++++++++++++++++++++
tests/UnitTests/framework/common.php | 26 ++
tests/UnitTests/framework/index.php | 100 +++++
tests/UnitTests/framework/utApplication.php | 25 ++
tests/UnitTests/framework/utComponent.php | 224 +++++++++++
tests/UnitTests/framework/utPradoBase.php | 111 ++++++
21 files changed, 2054 insertions(+)
create mode 100644 tests/UnitTests/framework/Collections/utList.php
create mode 100644 tests/UnitTests/framework/Collections/utMap.php
create mode 100644 tests/UnitTests/framework/Data/CacheTestCase.php
create mode 100644 tests/UnitTests/framework/Data/utMemCache.php
create mode 100644 tests/UnitTests/framework/Data/utSqliteCache.php
create mode 100644 tests/UnitTests/framework/Data/utXmlDocument.php
create mode 100644 tests/UnitTests/framework/Data/xml/data1.xml
create mode 100644 tests/UnitTests/framework/Data/xml/data1.xml.out
create mode 100644 tests/UnitTests/framework/Data/xml/data2.xml
create mode 100644 tests/UnitTests/framework/Data/xml/data2.xml.out
create mode 100644 tests/UnitTests/framework/Data/xml/data3.xml
create mode 100644 tests/UnitTests/framework/Data/xml/data3.xml.out
create mode 100644 tests/UnitTests/framework/TestSystem/protected/application.xml
create mode 100644 tests/UnitTests/framework/TestSystem/protected/data/test.db
create mode 100644 tests/UnitTests/framework/TestSystem/protected/pages/config.xml
create mode 100644 tests/UnitTests/framework/Web/UI/utControl.php
create mode 100644 tests/UnitTests/framework/common.php
create mode 100644 tests/UnitTests/framework/index.php
create mode 100644 tests/UnitTests/framework/utApplication.php
create mode 100644 tests/UnitTests/framework/utComponent.php
create mode 100644 tests/UnitTests/framework/utPradoBase.php
(limited to 'tests/UnitTests/framework')
diff --git a/tests/UnitTests/framework/Collections/utList.php b/tests/UnitTests/framework/Collections/utList.php
new file mode 100644
index 00000000..faebae4c
--- /dev/null
+++ b/tests/UnitTests/framework/Collections/utList.php
@@ -0,0 +1,321 @@
+_itemAdded=true;
+ }
+
+ protected function removedItem($item)
+ {
+ $this->_itemRemoved=true;
+ }
+
+ protected function canAddItem($item)
+ {
+ return $this->_canAddItem;
+ }
+
+ protected function canRemoveItem($item)
+ {
+ return $this->_canRemoveItem;
+ }
+
+ public function setCanAddItem($value)
+ {
+ $this->_canAddItem=$value;
+ }
+
+ public function setCanRemoveItem($value)
+ {
+ $this->_canRemoveItem=$value;
+ }
+
+ public function isItemAdded()
+ {
+ return $this->_itemAdded;
+ }
+
+ public function isItemRemoved()
+ {
+ return $this->_itemRemoved;
+ }
+}
+
+class utList extends UnitTestCase
+{
+ protected $list;
+ protected $item1,$item2,$item3;
+
+ public function setUp()
+ {
+ $this->list=new TList;
+ $this->item1=new ListItem;
+ $this->item2=new ListItem;
+ $this->item3=new ListItem;
+ $this->list->add($this->item1);
+ $this->list->add($this->item2);
+ }
+
+ public function tearDown()
+ {
+ $this->list=null;
+ $this->item1=null;
+ $this->item2=null;
+ $this->item3=null;
+ }
+
+ public function testConstruct()
+ {
+ $a=array(1,2,3);
+ $list=new TList($a);
+ $this->assertEqual(3,$list->getCount());
+ $list2=new TList($this->list);
+ $this->assertEqual(2,$list2->getCount());
+ }
+ public function testGetCount()
+ {
+ $this->assertEqual(2,$this->list->getCount());
+ $this->assertEqual(2,$this->list->Count);
+ }
+
+ public function testAdd()
+ {
+ $this->list->add(null);
+ $this->list->add($this->item3);
+ $this->assertEqual(4,$this->list->getCount());
+ $this->assertEqual(3,$this->list->indexOf($this->item3));
+ }
+
+
+ public function testAddAt()
+ {
+ $this->list->addAt(0,$this->item3);
+ $this->assertEqual(3,$this->list->getCount());
+ $this->assertEqual(2,$this->list->indexOf($this->item2));
+ $this->assertEqual(0,$this->list->indexOf($this->item3));
+ $this->assertEqual(1,$this->list->indexOf($this->item1));
+ try
+ {
+ $this->list->addAt(4,$this->item3);
+ $this->fail('exception not raised when adding item at an out-of-range index');
+ }
+ catch(TIndexOutOfRangeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testRemove()
+ {
+ $this->list->remove($this->item1);
+ $this->assertEqual(1,$this->list->getCount());
+ $this->assertEqual(-1,$this->list->indexOf($this->item1));
+ $this->assertEqual(0,$this->list->indexOf($this->item2));
+ try
+ {
+ $this->list->remove($this->item1);
+ $this->fail('exception not raised when removing nonexisting item');
+ }
+ catch(Exception $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testRemoveAt()
+ {
+ $this->list->add($this->item3);
+ $this->list->removeAt(1);
+ $this->assertEqual(-1,$this->list->indexOf($this->item2));
+ $this->assertEqual(1,$this->list->indexOf($this->item3));
+ $this->assertEqual(0,$this->list->indexOf($this->item1));
+ try
+ {
+ $this->list->removeAt(2);
+ $this->fail('exception not raised when removing item with invalid index');
+ }
+ catch(TIndexOutOfRangeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testClear()
+ {
+ $this->list->clear();
+ $this->assertEqual(0,$this->list->getCount());
+ $this->assertEqual(-1,$this->list->indexOf($this->item1));
+ $this->assertEqual(-1,$this->list->indexOf($this->item2));
+ }
+
+ public function testContains()
+ {
+ $this->assertTrue($this->list->contains($this->item1));
+ $this->assertTrue($this->list->contains($this->item2));
+ $this->assertFalse($this->list->contains($this->item3));
+ }
+
+ public function testIndexOf()
+ {
+ $this->assertEqual(0,$this->list->indexOf($this->item1));
+ $this->assertEqual(1,$this->list->indexOf($this->item2));
+ $this->assertEqual(-1,$this->list->indexOf($this->item3));
+ }
+
+ public function testCopyFrom()
+ {
+ $array=array($this->item3,$this->item1);
+ $this->list->copyFrom($array);
+ $this->assertTrue(count($array)==2 && $this->list[0]===$this->item3 && $this->list[1]===$this->item1);
+ try
+ {
+ $this->list->copyFrom($this);
+ $this->fail('exception not raised when copying from non-traversable object');
+ }
+ catch(TInvalidDataTypeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testMergeWith()
+ {
+ $array=array($this->item3,$this->item1);
+ $this->list->mergeWith($array);
+ $this->assertTrue($this->list->getCount()==4 && $this->list[0]===$this->item1 && $this->list[3]===$this->item1);
+ try
+ {
+ $this->list->mergeWith($this);
+ $this->fail('exception not raised when copying from non-traversable object');
+ }
+ catch(TInvalidDataTypeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testToArray()
+ {
+ $array=$this->list->toArray();
+ $this->assertTrue(count($array)==2 && $array[0]===$this->item1 && $array[1]===$this->item2);
+ }
+
+ public function testArrayRead()
+ {
+ $this->assertTrue($this->list[0]===$this->item1);
+ $this->assertTrue($this->list[1]===$this->item2);
+ try
+ {
+ $a=$this->list[2];
+ $this->fail('exception not raised when accessing item with out-of-range index');
+ }
+ catch(TIndexOutOfRangeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testArrayWrite()
+ {
+ $this->list[]=$this->item3;
+ $this->assertTrue($this->list[2]===$this->item3 && $this->list->getCount()===3);
+ $this->list[0]=$this->item3;
+ $this->assertTrue($this->list[0]===$this->item3 && $this->list->getCount()===3 && $this->list->indexOf($this->item1)===-1);
+ unset($this->list[1]);
+ $this->assertTrue($this->list->getCount()===2 && $this->list->indexOf($this->item2)===-1);
+ try
+ {
+ $this->list[5]=$this->item3;
+ $this->fail('exception not raised when setting item at an out-of-range index');
+ }
+ catch(TIndexOutOfRangeException $e)
+ {
+ $this->pass();
+ }
+ try
+ {
+ unset($this->list[5]);
+ $this->fail('exception not raised when unsetting item at an out-of-range index');
+ }
+ catch(TIndexOutOfRangeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testGetIterator()
+ {
+ $n=0;
+ $found=0;
+ foreach($this->list as $index=>$item)
+ {
+ foreach($this->list as $a=>$b); // test of iterator
+ $n++;
+ if($index===0 && $item===$this->item1)
+ $found++;
+ if($index===1 && $item===$this->item2)
+ $found++;
+ }
+ $this->assertTrue($n==2 && $found==2);
+ }
+
+ public function testArrayMisc()
+ {
+ $this->assertEqual(1,count($this->list));
+ $this->assertTrue(isset($this->list[1]));
+ $this->assertFalse(isset($this->list[2]));
+ }
+
+ public function testDerivedClasses()
+ {
+ $newList=new NewList;
+ $this->assertFalse($newList->isItemAdded());
+ $newList->add($this->item1);
+ $this->assertTrue($newList->isItemAdded());
+ $newList->add($this->item2);
+
+ $newList->setCanAddItem(false);
+ try
+ {
+ $newList->add($this->item3);
+ $this->fail('no exception raised when adding an item that is disallowed');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->assertEqual(2,$newList->getCount());
+ $this->pass();
+ }
+
+ $this->assertFalse($newList->isItemRemoved());
+ $newList->remove($this->item1);
+ $this->assertTrue($newList->isItemRemoved());
+
+ $newList->setCanRemoveItem(false);
+ try
+ {
+ $newList->remove($this->item2);
+ $this->fail('no exception raised when removing an item that is disallowed');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->assertEqual(1,$newList->getCount());
+ $this->pass();
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/UnitTests/framework/Collections/utMap.php b/tests/UnitTests/framework/Collections/utMap.php
new file mode 100644
index 00000000..1f7a20ad
--- /dev/null
+++ b/tests/UnitTests/framework/Collections/utMap.php
@@ -0,0 +1,245 @@
+_itemAdded=true;
+ }
+
+ protected function removedItem($key,$value)
+ {
+ $this->_itemRemoved=true;
+ }
+
+ protected function canAddItem($key,$value)
+ {
+ return $this->_canAddItem;
+ }
+
+ protected function canRemoveItem($key,$value)
+ {
+ return $this->_canRemoveItem;
+ }
+
+ public function setCanAddItem($value)
+ {
+ $this->_canAddItem=$value;
+ }
+
+ public function setCanRemoveItem($value)
+ {
+ $this->_canRemoveItem=$value;
+ }
+
+ public function isItemAdded()
+ {
+ return $this->_itemAdded;
+ }
+
+ public function isItemRemoved()
+ {
+ return $this->_itemRemoved;
+ }
+}
+
+class utMap extends UnitTestCase
+{
+ protected $map;
+ protected $item1,$item2,$item3;
+
+ public function setUp()
+ {
+ $this->map=new TMap;
+ $this->item1=new MapItem;
+ $this->item2=new MapItem;
+ $this->item3=new MapItem;
+ $this->map->add('key1',$this->item1);
+ $this->map->add('key2',$this->item2);
+ }
+
+ public function tearDown()
+ {
+ $this->map=null;
+ $this->item1=null;
+ $this->item2=null;
+ $this->item3=null;
+ }
+
+ public function testConstruct()
+ {
+ $a=array(1,2,'key3'=>3);
+ $map=new TMap($a);
+ $this->assertEqual(3,$map->getCount());
+ $map2=new TMap($this->map);
+ $this->assertEqual(2,$map2->getCount());
+ }
+
+ public function testGetCount()
+ {
+ $this->assertEqual(2,$this->map->getCount());
+ }
+
+ public function testGetKeys()
+ {
+ $keys=$this->map->getKeys();
+ $this->assertTrue(count($keys)===2 && $keys[0]==='key1' && $keys[1]==='key2');
+ }
+
+ public function testAdd()
+ {
+ $this->map->add('key3',$this->item3);
+ $this->assertTrue($this->map->getCount()==3 && $this->map->contains('key3'));
+ }
+
+ public function testRemove()
+ {
+ $this->map->remove('key1');
+ $this->assertTrue($this->map->getCount()==1 && !$this->map->contains('key1'));
+ $this->assertTrue($this->map->remove('unknown key')===null);
+ }
+
+ public function testClear()
+ {
+ $this->map->clear();
+ $this->assertTrue($this->map->getCount()==0 && !$this->map->contains('key1') && !$this->map->contains('key2'));
+ }
+
+ public function testContains()
+ {
+ $this->assertTrue($this->map->contains('key1'));
+ $this->assertTrue($this->map->contains('key2'));
+ $this->assertFalse($this->map->contains('key3'));
+ }
+
+ public function testCopyFrom()
+ {
+ $array=array('key3'=>$this->item3,'key4'=>$this->item1);
+ $this->map->copyFrom($array);
+ $this->assertTrue($this->map->getCount()==2 && $this->map['key3']===$this->item3 && $this->map['key4']===$this->item1);
+ try
+ {
+ $this->map->copyFrom($this);
+ $this->fail('no exception raised when copying a non-traversable object');
+ }
+ catch(TInvalidDataTypeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testMergeWith()
+ {
+ $array=array('key2'=>$this->item1,'key3'=>$this->item3);
+ $this->map->mergeWith($array);
+ $this->assertTrue($this->map->getCount()==3 && $this->map['key2']===$this->item1 && $this->map['key3']===$this->item3);
+ try
+ {
+ $this->map->mergeWith($this);
+ $this->fail('no exception raised when copying a non-traversable object');
+ }
+ catch(TInvalidDataTypeException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testArrayRead()
+ {
+ $this->assertTrue($this->map['key1']===$this->item1);
+ $this->assertTrue($this->map['key2']===$this->item2);
+ $this->assertEqual(null,$this->map['key3']);
+ }
+
+ public function testArrayWrite()
+ {
+ $this->map['key3']=$this->item3;
+ $this->assertTrue($this->map['key3']===$this->item3 && $this->map->getCount()===3);
+ $this->map['key1']=$this->item3;
+ $this->assertTrue($this->map['key1']===$this->item3 && $this->map->getCount()===3);
+ unset($this->map['key2']);
+ $this->assertTrue($this->map->getCount()===2 && !$this->map->contains('key2'));
+ try
+ {
+ unset($this->map['unknown key']);
+ $this->pass();
+ }
+ catch(Exception $e)
+ {
+ $this->fail('exception raised when unsetting element with unknown key');
+ }
+ }
+
+ public function testArrayForeach()
+ {
+ $n=0;
+ $found=0;
+ foreach($this->map as $index=>$item)
+ {
+ $n++;
+ if($index==='key1' && $item===$this->item1)
+ $found++;
+ if($index==='key2' && $item===$this->item2)
+ $found++;
+ }
+ $this->assertTrue($n==2 && $found==2);
+ }
+
+ public function testArrayMisc()
+ {
+ $this->assertEqual(1,count($this->map));
+ $this->assertTrue(isset($this->map['key1']));
+ $this->assertFalse(isset($this->map['unknown key']));
+ }
+
+ public function testDerivedClasses()
+ {
+ $newMap=new NewMap;
+ $this->assertFalse($newMap->isItemAdded());
+ $newMap->add('key','value');
+ $this->assertTrue($newMap->isItemAdded());
+ $newMap->add('key2','value2');
+
+ $newMap->setCanAddItem(false);
+ try
+ {
+ $newMap->add('new key','new value');
+ $this->fail('no exception raised when adding an item that is disallowed');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->assertEqual(2,$newMap->getCount());
+ $this->pass();
+ }
+
+ $this->assertFalse($newMap->isItemRemoved());
+ $newMap->remove('key');
+ $this->assertTrue($newMap->isItemRemoved());
+
+ $newMap->setCanRemoveItem(false);
+ try
+ {
+ $newMap->remove('key2');
+ $this->fail('no exception raised when removing an item that is disallowed');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->assertEqual(1,$newMap->getCount());
+ $this->pass();
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/CacheTestCase.php b/tests/UnitTests/framework/Data/CacheTestCase.php
new file mode 100644
index 00000000..68a7b067
--- /dev/null
+++ b/tests/UnitTests/framework/Data/CacheTestCase.php
@@ -0,0 +1,98 @@
+_cache;
+ }
+
+ public function setCache($cache)
+ {
+ $this->_cache=$cache;
+ }
+
+ public function basicOperations()
+ {
+ $object=new TComponent;
+ $number=12345;
+ $string='12345\'"';
+ $array=array('123'=>123,'abc'=>'def');
+
+ // test set (first time)
+ $this->assertFalse($this->_cache->get('object'));
+ $this->assertTrue($this->_cache->set('object',$object));
+ $this->assertTrue($this->_cache->get('object') instanceof TComponent);
+ $this->assertFalse($this->_cache->get('number'));
+ $this->assertTrue($this->_cache->set('number',$number));
+ $this->assertTrue($this->_cache->get('number')===$number);
+ $this->assertFalse($this->_cache->get('string'));
+ $this->assertTrue($this->_cache->set('string',$string));
+ $this->assertTrue($this->_cache->get('string')===$string);
+ $this->assertFalse($this->_cache->get('array'));
+ $this->assertTrue($this->_cache->set('array',$array));
+ $this->assertTrue($this->_cache->get('array')===$array);
+
+ // test set (second time)
+ $this->assertTrue($this->_cache->set('object',$array));
+ $this->assertTrue($this->_cache->get('object')===$array);
+
+ // test delete
+ $this->assertTrue($this->_cache->delete('object'));
+ $this->assertFalse($this->_cache->get('object'));
+ $this->assertTrue($this->_cache->delete('number'));
+ $this->assertFalse($this->_cache->get('number'));
+ $this->assertTrue($this->_cache->delete('string'));
+ $this->assertFalse($this->_cache->get('string'));
+ $this->assertTrue($this->_cache->delete('array'));
+ $this->assertFalse($this->_cache->get('array'));
+
+ // test add (first time)
+ $this->assertFalse($this->_cache->get('object'));
+ $this->assertTrue($this->_cache->add('object',$object));
+ $this->assertTrue($this->_cache->get('object') instanceof TComponent);
+ $this->assertFalse($this->_cache->get('number'));
+ $this->assertTrue($this->_cache->add('number',$number));
+ $this->assertTrue($this->_cache->get('number')===$number);
+ $this->assertFalse($this->_cache->get('string'));
+ $this->assertTrue($this->_cache->add('string',$string));
+ $this->assertTrue($this->_cache->get('string')===$string);
+ $this->assertFalse($this->_cache->get('array'));
+ $this->assertTrue($this->_cache->add('array',$array));
+ $this->assertTrue($this->_cache->get('array')===$array);
+
+ // test add (second time)
+ $this->assertFalse($this->_cache->add('object',$array));
+ $this->assertTrue($this->_cache->get('object') instanceof TComponent);
+
+ // test replace
+ $this->assertTrue($this->_cache->replace('object',$array));
+ $this->assertTrue($this->_cache->get('object')===$array);
+ $this->assertFalse($this->_cache->replace('object2',$array));
+ $this->assertFalse($this->_cache->get('object2'));
+
+ // test flush
+ $this->assertTrue($this->_cache->set('number',$number));
+ $this->assertTrue($this->_cache->get('number')===$number);
+ $this->assertTrue($this->_cache->flush());
+ $this->assertFalse($this->_cache->get('number'));
+
+ // test expiring
+ // set a value with 5sec valid time
+ $this->_cache->set('expiring',123,3);
+ $this->assertTrue($this->_cache->get('expiring')===123);
+ $this->_cache->set('nonexpiring',456);
+ $this->assertTrue($this->_cache->get('nonexpiring')===456);
+
+ // wait 6sec to see if the value still exists
+ sleep(4);
+ $this->assertFalse($this->_cache->get('expiring'));
+ $this->assertTrue($this->_cache->get('nonexpiring')===456);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/utMemCache.php b/tests/UnitTests/framework/Data/utMemCache.php
new file mode 100644
index 00000000..26981f63
--- /dev/null
+++ b/tests/UnitTests/framework/Data/utMemCache.php
@@ -0,0 +1,66 @@
+fail('TMemCache is not tested. PHP extension "memcache" is required by TMemCache.');
+ return;
+ }
+ $cache=new TMemCache;
+
+ $this->assertTrue($cache->getHost()==='localhost');
+ $cache->setHost('localhost2');
+ $this->assertTrue($cache->getHost()==='localhost2');
+
+ $this->assertTrue($cache->getPort()===11211);
+ $cache->setPort(1000);
+ $this->assertTrue($cache->getPort()===1000);
+
+ $cache->init(null,null);
+ try
+ {
+ $cache->setHost('newhost');
+ $this->fail('exception not raised when setting Server after init');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ try
+ {
+ $cache->setPort(10000);
+ $this->fail('exception not raised when setting Port after init');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testBasicOperations()
+ {
+ if(!extension_loaded('memcache'))
+ {
+ $this->fail('TMemCache is not tested. PHP extension "memcache" is required by TMemCache.');
+ return;
+ }
+ $cache=new TMemCache;
+ $cache->init(null,null);
+ $this->setCache($cache);
+ $this->basicOperations();
+ $this->setCache(null);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/utSqliteCache.php b/tests/UnitTests/framework/Data/utSqliteCache.php
new file mode 100644
index 00000000..726a5c08
--- /dev/null
+++ b/tests/UnitTests/framework/Data/utSqliteCache.php
@@ -0,0 +1,59 @@
+dbFile='utSqliteCache.test';
+ }
+
+ public function tearDown()
+ {
+ $file=Prado::getPathOfNamespace('utSqliteCache.test',TSqliteCache::DB_FILE_EXT);
+ if(is_file($file))
+ unlink($file);
+ else
+ $this->fail("Unable to clean up db file: '".$file."'.");
+ }
+
+ public function testInit()
+ {
+ $cache=new TSqliteCache;
+
+ $this->assertTrue($cache->getDbFile()===null);
+ $cache->setDbFile($this->dbFile);
+ $this->assertTrue($cache->getDbFile()===$this->dbFile);
+
+ $cache->init(null,null);
+ try
+ {
+ $cache->setDbFile('newfile.db');
+ $this->fail('exception not raised when setting DbFile after init');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testBasicOperations()
+ {
+ $cache=new TSqliteCache;
+ $cache->setDbFile($this->dbFile);
+ $cache->init(null,null);
+ $this->setCache($cache);
+ $this->basicOperations();
+ $this->setCache(null);
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/utXmlDocument.php b/tests/UnitTests/framework/Data/utXmlDocument.php
new file mode 100644
index 00000000..f66a4f2d
--- /dev/null
+++ b/tests/UnitTests/framework/Data/utXmlDocument.php
@@ -0,0 +1,68 @@
+loadFromFile($dir.'/data1.xml');
+ $doc->saveToFile($dir.'/data1.xml.tmp');
+ $this->assertTrue($this->compareFiles($dir.'/data1.xml.tmp',$dir.'/data1.xml.out'));
+ @unlink($dir.'/data1.xml.tmp');
+
+ // an XML file with Chinese characters
+ $doc->loadFromFile($dir.'/data2.xml');
+ $doc->saveToFile($dir.'/data2.xml.tmp');
+ $this->assertTrue($this->compareFiles($dir.'/data2.xml.tmp',$dir.'/data2.xml.out'));
+ @unlink($dir.'/data2.xml.tmp');
+
+ // a typical Prado Application configuration file
+ $doc=new TXmlDocument;
+ $doc->loadFromFile($dir.'/data3.xml');
+ $doc->saveToFile($dir.'/data3.xml.tmp');
+ $this->assertTrue($this->compareFiles($dir.'/data3.xml.tmp',$dir.'/data3.xml.out'));
+ @unlink($dir.'/data3.xml.tmp');
+ }
+
+ protected function compareFiles($file1,$file2)
+ {
+ return file_get_contents($file1)===file_get_contents($file2);
+ }
+
+ public function testAccessDomTree()
+ {
+ $dir=dirname(__FILE__).'/xml';
+ $doc=new TXmlDocument;
+ $doc->loadFromFile($dir.'/data1.xml');
+ $this->assertTrue($doc->getVersion()==='1.0');
+ $this->assertTrue($doc->getEncoding()==='utf-8');
+ $this->assertTrue($doc->getElements()->getCount()===2);
+ $this->assertTrue($doc->getElements()->itemAt(0)->getTagName()==='title');
+ $this->assertTrue($doc->getElements()->itemAt(0)->getValue()==='My lists');
+ $this->assertTrue($doc->getElements()->itemAt(1)->getTagName()==='chapter');
+ $this->assertTrue($doc->getElements()->itemAt(1)->getAttribute('id')==='books');
+ }
+
+ public function testUpdateDomTree()
+ {
+ }
+
+ public function testComposeDomTree()
+ {
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/xml/data1.xml b/tests/UnitTests/framework/Data/xml/data1.xml
new file mode 100644
index 00000000..d865680a
--- /dev/null
+++ b/tests/UnitTests/framework/Data/xml/data1.xml
@@ -0,0 +1,45 @@
+
+
+
\n";
+ foreach($this->subFolders as $folder)
+ $str.=$folder->getHtml($level+1);
+ foreach($this->testFiles as $name=>$url)
+ $str.=str_repeat(' ',($level+1)*4)."$name
\n";
+ return $str;
+ }
+}
+
+
+function addTests($test,$path,$recursive)
+{
+ $dir=opendir($path);
+ while(($entry=readdir($dir))!==false)
+ {
+ if(is_file($path.'/'.$entry) && strncmp($entry,'ut',2)===0)
+ $test->addTestFile($path.'/'.$entry);
+ else if($entry!=='.' && $entry!=='..' && is_dir($path.'/'.$entry) && $recursive)
+ addTests($test,$path.'/'.$entry,$recursive);
+ }
+ closedir($dir);
+}
+
+
+$rootPath=realpath(dirname(__FILE__));
+$rootUri=dirname($_SERVER['PHP_SELF']);
+
+if(isset($_GET['target']))
+{
+ $target=$_GET['target'];
+ $recursive=true;
+ $fullpath=realpath("$rootPath/$target");
+ if($fullpath===false || strpos($fullpath,$rootPath)!==0)
+ die('invalid test target');
+
+ require_once($rootPath.'/common.php');
+
+ if(is_dir($fullpath))
+ {
+ $test=new GroupTest(basename($rootPath)."/$target");
+ addTests($test,$fullpath,$recursive);
+ $test->run(new HtmlReporterWithCoverage(__FILE__,$rootPath));
+ }
+ else
+ {
+ $testClass=basename($fullpath,'.php');
+ require_once($fullpath);
+ $test=new $testClass(basename($rootPath)."/$target");
+ $test->run(new HtmlReporter());
+ }
+}
+else
+{
+ echo "
+