summaryrefslogtreecommitdiff
path: root/tests/UnitTests/framework
diff options
context:
space:
mode:
authorxue <>2005-11-10 12:47:19 +0000
committerxue <>2005-11-10 12:47:19 +0000
commit55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 (patch)
treea0599d5e36fdbb3f1e169ae56bab7d529597e3eb /tests/UnitTests/framework
Initial import of prado framework
Diffstat (limited to 'tests/UnitTests/framework')
-rw-r--r--tests/UnitTests/framework/Collections/utList.php321
-rw-r--r--tests/UnitTests/framework/Collections/utMap.php245
-rw-r--r--tests/UnitTests/framework/Data/CacheTestCase.php98
-rw-r--r--tests/UnitTests/framework/Data/utMemCache.php66
-rw-r--r--tests/UnitTests/framework/Data/utSqliteCache.php59
-rw-r--r--tests/UnitTests/framework/Data/utXmlDocument.php68
-rw-r--r--tests/UnitTests/framework/Data/xml/data1.xml45
-rw-r--r--tests/UnitTests/framework/Data/xml/data1.xml.out41
-rw-r--r--tests/UnitTests/framework/Data/xml/data2.xml41
-rw-r--r--tests/UnitTests/framework/Data/xml/data2.xml.out40
-rw-r--r--tests/UnitTests/framework/Data/xml/data3.xml46
-rw-r--r--tests/UnitTests/framework/Data/xml/data3.xml.out45
-rw-r--r--tests/UnitTests/framework/TestSystem/protected/application.xml21
-rw-r--r--tests/UnitTests/framework/TestSystem/protected/data/test.dbbin0 -> 5120 bytes
-rw-r--r--tests/UnitTests/framework/TestSystem/protected/pages/config.xml12
-rw-r--r--tests/UnitTests/framework/Web/UI/utControl.php420
-rw-r--r--tests/UnitTests/framework/common.php26
-rw-r--r--tests/UnitTests/framework/index.php100
-rw-r--r--tests/UnitTests/framework/utApplication.php25
-rw-r--r--tests/UnitTests/framework/utComponent.php224
-rw-r--r--tests/UnitTests/framework/utPradoBase.php111
21 files changed, 2054 insertions, 0 deletions
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 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+
+class ListItem
+{
+ public $data='data';
+}
+
+class NewList extends TList
+{
+ private $_canAddItem=true;
+ private $_canRemoveItem=true;
+ private $_itemAdded=false;
+ private $_itemRemoved=false;
+
+ protected function addedItem($item)
+ {
+ $this->_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 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+
+class MapItem
+{
+ public $data='data';
+}
+
+class NewMap extends TMap
+{
+ private $_canAddItem=true;
+ private $_canRemoveItem=true;
+ private $_itemAdded=false;
+ private $_itemRemoved=false;
+
+ protected function addedItem($key,$value)
+ {
+ $this->_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 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+
+class CacheTestCase extends UnitTestCase
+{
+ private $_cache;
+
+ public function getCache()
+ {
+ return $this->_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 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+require_once(dirname(__FILE__).'/CacheTestCase.php');
+Prado::using('System.Data.TMemCache');
+
+class utMemCache extends UnitTestCase
+{
+ private $_prefix='';
+ private $_server='localhost';
+ private $_port=11211;
+
+ public function testInit()
+ {
+ if(!extension_loaded('memcache'))
+ {
+ $this->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 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+require_once(dirname(__FILE__).'/CacheTestCase.php');
+Prado::using('System.Data.TSqliteCache');
+
+class utSqliteCache extends CacheTestCase
+{
+ private $dbFile;
+
+ public function __construct()
+ {
+ parent::__construct();
+ if(Prado::getPathOfAlias('utSqliteCache')===null)
+ Prado::setPathOfAlias('utSqliteCache',dirname(__FILE__));
+ $this->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 @@
+<?php
+
+require_once(dirname(__FILE__).'/../common.php');
+
+class utXmlDocument extends UnitTestCase
+{
+ public function setUp()
+ {
+ }
+
+ public function tearDown()
+ {
+ }
+
+ public function testLoadAndSave()
+ {
+ $dir=dirname(__FILE__).'/xml';
+
+ // a regular XML file
+ $doc=new TXmlDocument;
+ $doc->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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+ "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
+]>
+<book id="listing">
+ <title>My lists</title>
+ <chapter id="books">
+ <title>My books</title>
+ <para>
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Title</entry>
+ <entry>Author</entry>
+ <entry>Language</entry>
+ <entry>ISBN</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>The Grapes of Wrath</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>0140186409</entry>
+ </row>
+ <row>
+ <entry>The Pearl</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>014017737X</entry>
+ </row>
+ <row>
+ <entry>Samarcande</entry>
+ <entry>Amine Maalouf</entry>
+ <entry>fr</entry>
+ <entry>2253051209</entry>
+ </row>
+ <!-- TODO: I have a lot of remaining books to add.. -->
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </chapter>
+</book>
diff --git a/tests/UnitTests/framework/Data/xml/data1.xml.out b/tests/UnitTests/framework/Data/xml/data1.xml.out
new file mode 100644
index 00000000..de491e4c
--- /dev/null
+++ b/tests/UnitTests/framework/Data/xml/data1.xml.out
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<book id="listing">
+ <title>My lists</title>
+ <chapter id="books">
+ <title>My books</title>
+ <para>
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Title</entry>
+ <entry>Author</entry>
+ <entry>Language</entry>
+ <entry>ISBN</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>The Grapes of Wrath</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>0140186409</entry>
+ </row>
+ <row>
+ <entry>The Pearl</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>014017737X</entry>
+ </row>
+ <row>
+ <entry>Samarcande</entry>
+ <entry>Amine Maalouf</entry>
+ <entry>fr</entry>
+ <entry>2253051209</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </chapter>
+</book> \ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/xml/data2.xml b/tests/UnitTests/framework/Data/xml/data2.xml
new file mode 100644
index 00000000..9231ef7b
--- /dev/null
+++ b/tests/UnitTests/framework/Data/xml/data2.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<book id="listing" title="我的书单">
+ <chapter id="books">
+ <title>我的书</title>
+ <para>
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>标题</entry>
+ <entry>作者</entry>
+ <entry>语言</entry>
+ <entry>ISBN</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>The Grapes of Wrath</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>0140186409</entry>
+ </row>
+ <row>
+ <entry>The Pearl</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>014017737X</entry>
+ </row>
+ <row>
+ <entry>Samarcande</entry>
+ <entry>Amine Maalouf</entry>
+ <entry>fr</entry>
+ <entry>2253051209</entry>
+ </row>
+ <!-- TODO: I have a lot of remaining books to add.. -->
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </chapter>
+</book>
diff --git a/tests/UnitTests/framework/Data/xml/data2.xml.out b/tests/UnitTests/framework/Data/xml/data2.xml.out
new file mode 100644
index 00000000..d688884c
--- /dev/null
+++ b/tests/UnitTests/framework/Data/xml/data2.xml.out
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<book id="listing" title="我的书单">
+ <chapter id="books">
+ <title>我的书</title>
+ <para>
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>标题</entry>
+ <entry>作者</entry>
+ <entry>语言</entry>
+ <entry>ISBN</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>The Grapes of Wrath</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>0140186409</entry>
+ </row>
+ <row>
+ <entry>The Pearl</entry>
+ <entry>John Steinbeck</entry>
+ <entry>en</entry>
+ <entry>014017737X</entry>
+ </row>
+ <row>
+ <entry>Samarcande</entry>
+ <entry>Amine Maalouf</entry>
+ <entry>fr</entry>
+ <entry>2253051209</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </chapter>
+</book> \ No newline at end of file
diff --git a/tests/UnitTests/framework/Data/xml/data3.xml b/tests/UnitTests/framework/Data/xml/data3.xml
new file mode 100644
index 00000000..9e66a7f0
--- /dev/null
+++ b/tests/UnitTests/framework/Data/xml/data3.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<application id="test">
+ <modules>
+ <module id="request" />
+ <module id="response" />
+ <module id="cache" type="System.Modules.TSqliteCache"
+ DbFile="protected/cache.db" />
+ <module id="error">
+ <case id="exception" handler="processException" />
+ <default handler="processHttpError" />
+ </module>
+ </modules>
+ <services default="page">
+ <service id="page" RootPath="protected/pages">
+ <modules>
+ <module id="template" type="System.Modules.TTemplateManager" />
+ <module id="session" type="System.Modules.TSession" />
+ </modules>
+ <pages default="home">
+ <page id="home" type="HomePage" />
+ <page id="about" type="AboutPage" />
+ </pages>
+ <location path="users">
+ <security>
+ <allow page="register,login" />
+ <deny page="profile" user="?" />
+ <allow page="admin" role="admin" />
+ <deny page="admin" />
+ </security>
+ <pages>
+ <page id="register" type="RegisterPage" />
+ <page id="login" type="LoginPage" />
+ <page id="admin" type="AdminPage" />
+ <page id="profile" type="ProfilePage" />
+ </pages>
+ </location>
+ <parameters>
+ </parameters>
+ </service>
+ <service id="asset" type="System.Services.TAssetService" />
+ </services>
+ <parameters>
+ <parameter id="AdminEmail">qiang.xue@gmail.com</parameter>
+ <parameter id="NetShow" type="Demo.NetShow" Host="localhost" />
+ </parameters>
+</application>
diff --git a/tests/UnitTests/framework/Data/xml/data3.xml.out b/tests/UnitTests/framework/Data/xml/data3.xml.out
new file mode 100644
index 00000000..a87d0558
--- /dev/null
+++ b/tests/UnitTests/framework/Data/xml/data3.xml.out
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<application id="test">
+ <modules>
+ <module id="request" />
+ <module id="response" />
+ <module id="cache" type="System.Modules.TSqliteCache" DbFile="protected/cache.db" />
+ <module id="error">
+ <case id="exception" handler="processException" />
+ <default handler="processHttpError" />
+ </module>
+ </modules>
+ <services default="page">
+ <service id="page" RootPath="protected/pages">
+ <modules>
+ <module id="template" type="System.Modules.TTemplateManager" />
+ <module id="session" type="System.Modules.TSession" />
+ </modules>
+ <pages default="home">
+ <page id="home" type="HomePage" />
+ <page id="about" type="AboutPage" />
+ </pages>
+ <location path="users">
+ <security>
+ <allow page="register,login" />
+ <deny page="profile" user="?" />
+ <allow page="admin" role="admin" />
+ <deny page="admin" />
+ </security>
+ <pages>
+ <page id="register" type="RegisterPage" />
+ <page id="login" type="LoginPage" />
+ <page id="admin" type="AdminPage" />
+ <page id="profile" type="ProfilePage" />
+ </pages>
+ </location>
+ <parameters>
+ </parameters>
+ </service>
+ <service id="asset" type="System.Services.TAssetService" />
+ </services>
+ <parameters>
+ <parameter id="AdminEmail">qiang.xue@gmail.com</parameter>
+ <parameter id="NetShow" type="Demo.NetShow" Host="localhost" />
+ </parameters>
+</application> \ No newline at end of file
diff --git a/tests/UnitTests/framework/TestSystem/protected/application.xml b/tests/UnitTests/framework/TestSystem/protected/application.xml
new file mode 100644
index 00000000..0ee5f172
--- /dev/null
+++ b/tests/UnitTests/framework/TestSystem/protected/application.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<configuration>
+ <paths>
+ <alias id="Test" path="pages" />
+ <using namespace="Test" />
+ </paths>
+ <modules>
+ <module id="request" />
+ <module id="cache" type="System.Data.TSqliteCache" DbFile="TestSystem/protected/data/test.db" />
+ </modules>
+ <services>
+ <service id="page" RootPath="TestSystem/protected/pages" />
+ </services>
+ <parameters>
+ <parameter id="param1">value 1</parameter>
+ <parameter id="param2"></parameter>
+ <parameter id="param3" type="System.TComponent" />
+ <parameter id="param4" type="TComponent" />
+ </parameters>
+</configuration> \ No newline at end of file
diff --git a/tests/UnitTests/framework/TestSystem/protected/data/test.db b/tests/UnitTests/framework/TestSystem/protected/data/test.db
new file mode 100644
index 00000000..9bc20c39
--- /dev/null
+++ b/tests/UnitTests/framework/TestSystem/protected/data/test.db
Binary files differ
diff --git a/tests/UnitTests/framework/TestSystem/protected/pages/config.xml b/tests/UnitTests/framework/TestSystem/protected/pages/config.xml
new file mode 100644
index 00000000..6a49df82
--- /dev/null
+++ b/tests/UnitTests/framework/TestSystem/protected/pages/config.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<configuration>
+ <pages>
+ </pages>
+ <parameters>
+ <parameter id="param1">value 1</parameter>
+ <parameter id="param2"></parameter>
+ <parameter id="param3" type="System.TComponent" />
+ <parameter id="param4" type="TComponent" />
+ </parameters>
+</configuration> \ No newline at end of file
diff --git a/tests/UnitTests/framework/Web/UI/utControl.php b/tests/UnitTests/framework/Web/UI/utControl.php
new file mode 100644
index 00000000..8498f7c0
--- /dev/null
+++ b/tests/UnitTests/framework/Web/UI/utControl.php
@@ -0,0 +1,420 @@
+<?php
+
+require_once(dirname(__FILE__).'/common.php');
+require_once(PRADO_DIR.'/Collections/TList.php');
+require_once(PRADO_DIR.'/Collections/TMap.php');
+require_once(PRADO_DIR.'/Exceptions/TInvalidOperationException.php');
+require_once(PRADO_DIR.'/Exceptions/TInvalidDataValueException.php');
+require_once(PRADO_DIR.'/Exceptions/TInvalidExpressionException.php');
+require_once(PRADO_DIR.'/Web/UI/TControl.php');
+
+class TContext extends TComponent
+{
+ public static $_instance=null;
+ public function __construct()
+ {
+ if(self::$_instance)
+ throw new Exception('....');
+ self::$_instance=$this;
+ }
+
+ public static function getInstance()
+ {
+ return self::$_instance;
+ }
+}
+
+class ContainerControl extends TControl implements INamingContainer
+{
+}
+
+class PageControl extends TControl implements INamingContainer
+{
+ public $eventRaised=false;
+ private $_context;
+
+ function __construct($context)
+ {
+ $this->setPage($this);
+ $this->_context=$context;
+ }
+
+ public function getContext()
+ {
+ return $this->_context;
+ }
+
+ public function clicked($sender,$param)
+ {
+ $this->eventRaised=true;
+ }
+
+ public function getContainsTheme()
+ {
+ return false;
+ }
+
+ public function runTo($lifecycle)
+ {
+ switch($lifecycle)
+ {
+ case 'init':
+ $this->initRecursive(null);
+ break;
+ case 'load':
+ $this->initRecursive(null);
+ $this->loadRecursive();
+ break;
+ case 'prerender':
+ $this->initRecursive(null);
+ $this->loadRecursive();
+ $this->preRenderRecursive();
+ break;
+ }
+ }
+}
+
+class WebControl extends TControl
+{
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ public function setText($value)
+ {
+ return $this->setViewState('Text',$value,'');
+ }
+
+ public function getData()
+ {
+ return $this->getControlState('Data','');
+ }
+
+ public function setData($value)
+ {
+ $this->setControlState('Data',$value,'');
+ }
+
+ public function onClick($param)
+ {
+ $this->raiseEvent('OnClick',$this,$param);
+ }
+}
+
+class testControl extends UnitTestCase
+{
+ private $context;
+ private $button1;
+ private $button2;
+ private $page;
+ private $form;
+ private $panel;
+
+ public function setUp()
+ {
+ // we mock up a page consisting of a form which encloses a panel.
+ // in the panel there are two buttons, button1 and button2
+ // The panel is a naming container
+ $this->context=new TContext;
+ $this->page=new PageControl($this->context);
+ $this->form=new WebControl;
+ $this->panel=new ContainerControl;
+ $this->button1=new WebControl;
+ $this->button2=new WebControl;
+ $this->form->setTemplateControl($this->page);
+ $this->panel->setTemplateControl($this->page);
+ $this->button1->setTemplateControl($this->page);
+ $this->button2->setTemplateControl($this->page);
+ $this->page->getControls()->add($this->form);
+ $this->form->getControls()->add($this->panel);
+ $this->panel->getControls()->add($this->button1);
+ $this->panel->getControls()->add($this->button2);
+ $this->button1->setID('button1');
+ $this->page->declareObject('button1',$this->button1);
+ }
+
+ public function tearDown()
+ {
+ $this->page=null;
+ $this->form=null;
+ $this->panel=null;
+ $this->button1=null;
+ $this->button2=null;
+ $this->context=null;
+ TContext::$_instance=null;
+ }
+
+ public function testOverload()
+ {
+ $this->assertEqual($this->page->button1,$this->button1);
+ try
+ {
+ $button=$this->page->button2;
+ $this->fail('non exception raised when accessing non-declared control');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testParent()
+ {
+ $this->assertEqual(null,$this->page->getParent());
+ $this->assertEqual($this->page,$this->form->getParent());
+ }
+
+ public function testNamingContainer()
+ {
+ $this->assertEqual(null,$this->page->getNamingContainer());
+ $this->assertEqual($this->page,$this->panel->getNamingContainer());
+ $this->assertEqual($this->panel,$this->button1->getNamingContainer());
+ }
+
+ public function testPage()
+ {
+ $this->assertEqual($this->page,$this->page->getPage());
+ $this->assertEqual($this->page,$this->panel->getPage());
+ $this->assertEqual($this->page,$this->button1->getPage());
+ }
+
+ public function testTemplateControl()
+ {
+ $this->assertEqual(null,$this->page->getTemplateControl());
+ $this->assertEqual($this->page,$this->panel->getTemplateControl());
+ $this->assertEqual($this->page,$this->button1->getTemplateControl());
+ }
+
+ public function testContext()
+ {
+ $this->assertEqual($this->context,$this->button1->getContext());
+ }
+
+ public function testSkinID()
+ {
+ $this->assertEqual('',$this->button1->getSkinID());
+ $this->button1->setSkinID('buttonSkin');
+ $this->assertEqual('buttonSkin',$this->button1->getSkinID());
+ $this->page->runTo('init');
+ try
+ {
+ $this->button1->setSkinID('buttonSkin2');
+ $this->fail('no exception raised when SkinID is set after PreInit');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testID()
+ {
+ $this->assertEqual('button1',$this->button1->getID());
+ $this->assertEqual('',$this->button2->getID());
+ $this->assertEqual('ctl1',$this->button2->getID(false));
+ $this->button2->setID('button2');
+ $this->assertEqual('button2',$this->button2->getID());
+ try
+ {
+ $this->button2->setID('123');
+ $this->fail('exception not raised when control is set with an invalid ID');
+ }
+ catch(TInvalidDataValueException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testUniqueID()
+ {
+ $sep=TControl::ID_SEPARATOR;
+ $this->assertEqual('ctl0',$this->form->getUniqueID());
+ $this->assertEqual('ctl1',$this->panel->getUniqueID());
+ $this->assertEqual('ctl1'.$sep.'button1',$this->button1->getUniqueID());
+ $this->assertEqual('ctl1'.$sep.'ctl1',$this->button2->getUniqueID());
+ $this->button2->setID('button2');
+ $this->assertEqual('ctl1'.$sep.'button2',$this->button2->getUniqueID());
+ $this->panel->setID('panel');
+ $this->assertEqual('panel'.$sep.'button2',$this->button2->getUniqueID());
+ }
+
+ public function testEnableTheming()
+ {
+ $this->assertEqual(true,$this->button1->getEnableTheming());
+ $this->page->setEnableTheming(false);
+ $this->assertEqual(false,$this->button1->getEnableTheming());
+ $this->page->setEnableTheming(true);
+ $this->assertEqual(true,$this->button1->getEnableTheming());
+ $this->button1->setEnableTheming(false);
+ $this->assertEqual(false,$this->button1->getEnableTheming());
+
+ $this->page->runTo('init');
+ try
+ {
+ $this->button1->setEnableTheming(true);
+ $this->fail('no exception raised when EnableTheming is set after PreInit');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testHasControls()
+ {
+ $this->assertEqual(true,$this->page->getHasControls());
+ $this->assertEqual(false,$this->button1->getHasControls());
+ }
+
+ public function testControls()
+ {
+ $this->assertEqual(1,$this->page->getControls()->getCount());
+ $control=new WebControl;
+ $this->panel->getControls()->add($control);
+ $this->assertEqual(3,$this->panel->getControls()->getCount());
+ $this->panel->getControls()->remove($this->button1);
+ $this->assertEqual(2,$this->panel->getControls()->getCount());
+ }
+
+ public function testVisible()
+ {
+ $this->assertEqual(true,$this->button1->getVisible());
+ $this->page->setVisible(false);
+ $this->assertEqual(false,$this->button1->getVisible());
+ $this->page->setVisible(true);
+ $this->assertEqual(true,$this->button1->getVisible());
+ $this->button1->setVisible(false);
+ $this->assertEqual(false,$this->button1->getVisible());
+ }
+
+ public function testEnabled()
+ {
+ $this->assertEqual(true,$this->button1->getEnabled());
+ $this->page->setEnabled(false);
+ $this->assertEqual(true,$this->button1->getEnabled());
+ $this->assertEqual(false,$this->button1->getEnabled(true));
+ $this->page->setEnabled(true);
+ $this->assertEqual(true,$this->button1->getEnabled(true));
+ $this->button1->setEnabled(false);
+ $this->assertEqual(false,$this->button1->getEnabled(true));
+ $this->assertEqual(false,$this->button1->getEnabled());
+ }
+
+ public function testHasAttributes()
+ {
+ $this->assertEqual(false,$this->button1->getHasAttributes());
+ $this->button1->getAttributes()->add('name','value');
+ $this->assertEqual(true,$this->button1->getHasAttributes());
+ $this->button1->getAttributes()->clear();
+ $this->assertEqual(false,$this->button1->getHasAttributes());
+ }
+
+ public function testAttributes()
+ {
+ $this->assertEqual(0,$this->button1->getAttributes()->getCount());
+ $this->button1->getAttributes()->add('name1','value1');
+ $this->button1->getAttributes()->add('name2','value2');
+ $this->assertEqual(2,$this->button1->getAttributes()->getCount());
+ $this->button1->getAttributes()->remove('name1');
+ $this->assertEqual(1,$this->button1->getAttributes()->getCount());
+ }
+
+ public function testEnableViewState()
+ {
+ $this->assertEqual(true,$this->button1->getEnableViewState());
+ $this->button1->setEnableViewState(false);
+ $this->assertEqual(false,$this->button1->getEnableViewState());
+
+ }
+
+ public function testViewState()
+ {
+ $this->assertEqual('',$this->button1->getText());
+ $this->button1->setText('abc');
+ $this->assertEqual('abc',$this->button1->getText());
+ }
+
+ public function testControlState()
+ {
+ $this->assertEqual('',$this->button1->getData());
+ $this->button1->setData('abc');
+ $this->assertEqual('abc',$this->button1->getData());
+ }
+
+ public function testEventScheme()
+ {
+ $this->assertEqual(true,$this->button1->hasEvent('OnClick'));
+ $this->assertEqual(false,$this->button1->hasEvent('Click'));
+ $this->button1->attachEventHandler('OnClick','Page.clicked');
+ $this->assertEqual(false,$this->page->eventRaised);
+ $this->button1->raiseEvent('OnClick',$this,null);
+ $this->assertEqual(true,$this->page->eventRaised);
+ $this->button1->getEventHandlers('OnClick')->clear();
+ try
+ {
+ $this->button1->attachEventHandler('Click','clicked');
+ $this->fail('no exception raised when undefined event is raised');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ $this->assertEqual(0,$this->button1->getEventHandlers('OnClick')->getCount());
+ $this->button1->attachEventHandler('OnClick','Pages.clicked');
+ try
+ {
+ $this->button1->raiseEvent('OnClick',$this,null);
+ $this->fail('no exception raised when undefined event handler is invoked');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testDataBindingScheme()
+ {
+ $this->button1->bindProperty('Text','"abc"."def"');
+ $this->button1->dataBind();
+ $this->assertEqual('abcdef',$this->button1->getText());
+ $this->button2->bindProperty('Text','"abc"."def"');
+ $this->button2->unbindProperty('Text');
+ $this->button2->dataBind();
+ $this->assertEqual('',$this->button2->getText());
+ $this->button1->bindProperty('Texts','"abc"."def"');
+ try
+ {
+ $this->button1->dataBind();
+ $this->fail('no exception raised for invalid databinding');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testFindControl()
+ {
+ $this->assertEqual($this->button1,$this->panel->findControl('button1'));
+ $this->assertEqual(null,$this->panel->findControl('button2'));
+ $this->assertEqual($this->button1,$this->page->findControl($this->panel->getID(false).TControl::ID_SEPARATOR.'button1'));
+ $this->button1->setID('button3');
+ $this->assertEqual($this->button1,$this->panel->findControl('button3'));
+ }
+
+ public function testAddRemoveControl()
+ {
+
+ }
+}
+
+
+if(!defined('RUN_ALL_TESTS'))
+{
+ $className=basename(__FILE__,'.php');
+ $test = new $className;
+ $test->run(new HtmlReporter());
+}
+
+?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/common.php b/tests/UnitTests/framework/common.php
new file mode 100644
index 00000000..dc268e28
--- /dev/null
+++ b/tests/UnitTests/framework/common.php
@@ -0,0 +1,26 @@
+<?php
+
+if(!defined('FRAMEWORK_DIR'))
+ define('FRAMEWORK_DIR',realpath(dirname(__FILE__).'/../../../framework'));
+if(!defined('SIMPLETEST_DIR'))
+ define('SIMPLETEST_DIR',realpath(dirname(__FILE__).'/../simpletest'));
+
+require_once(SIMPLETEST_DIR.'/unit_tester.php');
+require_once(SIMPLETEST_DIR.'/reporter.php');
+require_once(SIMPLETEST_DIR.'/HtmlReporterWithCoverage.php');
+
+require_once(FRAMEWORK_DIR.'/core.php');
+
+class Prado extends PradoBase
+{
+}
+
+function __autoload($className)
+{
+ require_once($className);
+}
+
+error_reporting(E_ALL);
+restore_error_handler();
+
+?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/index.php b/tests/UnitTests/framework/index.php
new file mode 100644
index 00000000..802e979e
--- /dev/null
+++ b/tests/UnitTests/framework/index.php
@@ -0,0 +1,100 @@
+<?php
+
+class TestFolder
+{
+ public $name='';
+ public $url='';
+ public $subFolders=array();
+ public $testFiles=array();
+
+ public function __construct($path,$rootPath,$rootUri)
+ {
+ $this->url="$rootUri?target=".strtr(substr($path,strlen($rootPath)+1),"\\",'/');
+ $this->name=basename($path);
+ $dir=opendir($path);
+ while(($entry=readdir($dir))!==false)
+ {
+ $fullpath="$path/$entry";
+ if($entry!=='.' && $entry!=='..' && is_dir($fullpath))
+ {
+ $folder=new TestFolder($fullpath,$rootPath,$rootUri);
+ if(!empty($folder->subFolders) || !empty($folder->testFiles))
+ $this->subFolders[]=$folder;
+ }
+ else if(is_file($fullpath) && strncmp($entry,'ut',2)===0)
+ {
+ $this->testFiles[$entry]="$rootUri?target=".strtr(substr($fullpath,strlen($rootPath)+1),"\\",'/');
+ }
+ }
+ closedir($dir);
+ }
+
+ public function getHtml($level=0)
+ {
+ $str=str_repeat('&nbsp;',$level*4)."[ <a href=\"{$this->url}\">{$this->name}</a> ]<br/>\n";
+ foreach($this->subFolders as $folder)
+ $str.=$folder->getHtml($level+1);
+ foreach($this->testFiles as $name=>$url)
+ $str.=str_repeat('&nbsp;',($level+1)*4)."<a href=\"$url\">$name</a><br/>\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 "<html>
+<head>
+<title>utList</title>
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
+</head>
+<body>
+<h1>Prado Framework Unit Tests</h1>
+";
+ $root=new TestFolder($rootPath,$rootPath,$rootUri);
+ echo $root->getHtml();
+ echo "</body>\n</html>";
+}
+
+?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/utApplication.php b/tests/UnitTests/framework/utApplication.php
new file mode 100644
index 00000000..603f9fc3
--- /dev/null
+++ b/tests/UnitTests/framework/utApplication.php
@@ -0,0 +1,25 @@
+<?php
+
+require_once(dirname(__FILE__).'/common.php');
+require_once(FRAMEWORK_DIR.'/TApplication.php');
+
+class utApplication extends UnitTestCase
+{
+ public function testCreateApplication()
+ {
+ $dir=getcwd();
+ chdir(dirname(__FILE__));
+ $application=new TApplication(dirname(__FILE__).'/TestSystem/protected/application.xml');
+ try
+ {
+ new TApplication(dirname(__FILE__).'/TestSystem/protected/application.xml');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ chdir($dir);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/utComponent.php b/tests/UnitTests/framework/utComponent.php
new file mode 100644
index 00000000..2683652a
--- /dev/null
+++ b/tests/UnitTests/framework/utComponent.php
@@ -0,0 +1,224 @@
+<?php
+
+require_once(dirname(__FILE__).'/common.php');
+
+class NewComponent extends TComponent
+{
+ private $_object=null;
+ private $_text='default';
+ private $_eventHandled=false;
+
+ public function getText()
+ {
+ return $this->_text;
+ }
+
+ public function setText($value)
+ {
+ $this->_text=$value;
+ }
+
+ public function getObject()
+ {
+ if(!$this->_object)
+ {
+ $this->_object=new NewComponent;
+ $this->_object->_text='object text';
+ }
+ return $this->_object;
+ }
+
+ public function onMyEvent($param)
+ {
+ $this->raiseEvent('MyEvent',$this,$param);
+ }
+
+ public function myEventHandler($sender,$param)
+ {
+ $this->_eventHandled=true;
+ }
+
+ public function isEventHandled()
+ {
+ return $this->_eventHandled;
+ }
+}
+
+class utComponent extends UnitTestCase
+{
+ protected $component;
+
+ public function setUp()
+ {
+ $this->component=new NewComponent;
+ }
+
+ public function tearDown()
+ {
+ $this->component=null;
+ }
+
+ public function testHasProperty()
+ {
+ $this->assertTrue($this->component->hasProperty('Text'));
+ $this->assertTrue($this->component->hasProperty('text'));
+ $this->assertFalse($this->component->hasProperty('Caption'));
+ }
+
+ public function testCanGetProperty()
+ {
+ $this->assertTrue($this->component->canGetProperty('Text'));
+ $this->assertTrue($this->component->canGetProperty('text'));
+ $this->assertFalse($this->component->canGetProperty('Caption'));
+ }
+
+ public function testCanSetProperty()
+ {
+ $this->assertTrue($this->component->canSetProperty('Text'));
+ $this->assertTrue($this->component->canSetProperty('text'));
+ $this->assertFalse($this->component->canSetProperty('Caption'));
+ }
+
+ public function testGetProperty()
+ {
+ $this->assertTrue('default'===$this->component->Text);
+ try
+ {
+ $value2=$this->component->Caption;
+ $this->fail('exception not raised when getting undefined property');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testSetProperty()
+ {
+ $value='new value';
+ $this->component->Text=$value;
+ $text=$this->component->Text;
+ $this->assertTrue($value===$this->component->Text);
+ try
+ {
+ $this->component->NewMember=$value;
+ $this->fail('exception not raised when setting undefined property');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testGetPropertyByPath()
+ {
+ $this->assertTrue('object text'===$this->component->getPropertyByPath('Object.Text'));
+ }
+
+ public function testSetPropertyByPath()
+ {
+ $this->component->setPropertyByPath('Object.Text','new object text');
+ $this->assertEqual('new object text',$this->component->getPropertyByPath('Object.Text'));
+ }
+
+ public function testHasEvent()
+ {
+ $this->assertTrue($this->component->hasEvent('MyEvent'));
+ $this->assertTrue($this->component->hasEvent('myevent'));
+ $this->assertFalse($this->component->hasEvent('YourEvent'));
+ }
+
+ public function testHasEventHandler()
+ {
+ $this->assertFalse($this->component->hasEventHandler('MyEvent'));
+ $this->component->attachEventHandler('MyEvent','foo');
+ $this->assertTrue($this->component->hasEventHandler('MyEvent'));
+ }
+
+ public function testGetEventHandlers()
+ {
+ $list=$this->component->getEventHandlers('MyEvent');
+ $this->assertTrue(($list instanceof TList) && ($list->getCount()===0));
+ $this->component->attachEventHandler('MyEvent','foo');
+ $this->assertTrue(($list instanceof TList) && ($list->getCount()===1));
+ try
+ {
+ $list=$this->component->getEventHandlers('YourEvent');
+ $this->fail('exception not raised when getting event handlers for undefined event');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testAttachEventHandler()
+ {
+ $this->component->attachEventHandler('MyEvent','foo');
+ $this->assertTrue($this->component->getEventHandlers('MyEvent')->getCount()===1);
+ try
+ {
+ $this->component->attachEventHandler('YourEvent','foo');
+ $this->fail('exception not raised when attaching event handlers for undefined event');
+ }
+ catch(TInvalidOperationException $e)
+ {
+ $this->pass();
+ }
+ $this->component->MyEvent[]='foo2';
+ $this->assertTrue($this->component->getEventHandlers('MyEvent')->getCount()===2);
+ $this->component->getEventHandlers('MyEvent')->add('foo3');
+ $this->assertTrue($this->component->getEventHandlers('MyEvent')->getCount()===3);
+ $this->component->MyEvent[0]='foo4';
+ $this->assertTrue($this->component->getEventHandlers('MyEvent')->getCount()===3);
+ $this->component->getEventHandlers('MyEvent')->addAt(0,'foo5');
+ $this->assertTrue($this->component->MyEvent->Count===4 && $this->component->MyEvent[0]==='foo5');
+ $this->component->MyEvent='foo6';
+ $this->assertTrue($this->component->MyEvent->Count===5 && $this->component->MyEvent[4]==='foo6');
+ }
+
+ public function testRaiseEvent()
+ {
+ $this->component->attachEventHandler('MyEvent',array($this->component,'myEventHandler'));
+ $this->assertFalse($this->component->isEventHandled());
+ $this->component->raiseEvent('MyEvent',$this,null);
+ $this->assertTrue($this->component->isEventHandled());
+ $this->component->attachEventHandler('MyEvent',array($this->component,'Object.myEventHandler'));
+ $this->assertFalse($this->component->Object->isEventHandled());
+ $this->component->raiseEvent('MyEvent',$this,null);
+ $this->assertTrue($this->component->Object->isEventHandled());
+ }
+
+ public function testEvaluateExpression()
+ {
+ $expression="1+2";
+ $this->assertTrue(3===$this->component->evaluateExpression($expression));
+ try
+ {
+ $button=$this->component->evaluateExpression('$this->button');
+ $this->fail('exception not raised when evaluating an invalid exception');
+ }
+ catch(Exception $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testEvaluateStatements()
+ {
+ $statements='$a="test string"; echo $a;';
+ $this->assertEqual('test string',$this->component->evaluateStatements($statements));
+ try
+ {
+ $statements='$a=new NewComponent; echo $a->button;';
+ $button=$this->component->evaluateStatements($statements);
+ $this->fail('exception not raised when evaluating an invalid statement');
+ }
+ catch(Exception $e)
+ {
+ $this->pass();
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/UnitTests/framework/utPradoBase.php b/tests/UnitTests/framework/utPradoBase.php
new file mode 100644
index 00000000..f7861c57
--- /dev/null
+++ b/tests/UnitTests/framework/utPradoBase.php
@@ -0,0 +1,111 @@
+<?php
+
+require_once(dirname(__FILE__).'/common.php');
+
+class testNode
+{
+ public $data='';
+ public $parent=null;
+ public $child=null;
+ public function __construct($data)
+ {
+ $this->data=$data;
+ }
+}
+
+class utPradoBase extends UnitTestCase
+{
+ public function testFrameworkPath()
+ {
+ $this->assertTrue(FRAMEWORK_DIR===Prado::getFrameworkPath());
+ }
+
+ public function testSerialization()
+ {
+ $object=new TComponent;
+ $number=12345.123;
+ $string='12345\'"';
+ $array=array('123'=>123,'abc'=>'def');
+ $this->assertFalse($object===Prado::unserialize(Prado::serialize($object)));
+ $this->assertTrue(Prado::unserialize(Prado::serialize($object)) instanceof TComponent);
+ $this->assertTrue($number===Prado::unserialize(Prado::serialize($number)));
+ $this->assertTrue($string===Prado::unserialize(Prado::serialize($string)));
+ $this->assertTrue($array===Prado::unserialize(Prado::serialize($array)));
+
+ // test complex object reference structure grandparent <-> parent <-> child
+ $grandp=new testNode('grandp');
+ $parent=new testNode('parent');
+ $child=new testNode('child');
+ $grandp->child=$parent;
+ $parent->child=$child;
+ $child->parent=$parent;
+ $parent->parent=$grandp;
+
+ $newGrandp=Prado::unserialize(Prado::serialize($grandp));
+ $this->assertTrue($newGrandp!==$grandp);
+ $this->assertTrue($newGrandp instanceof testNode);
+ $this->assertTrue($newGrandp->parent===null);
+ $this->assertTrue($newGrandp->data==='grandp');
+
+ $newParent=$newGrandp->child;
+ $this->assertTrue($newParent!==$parent);
+ $this->assertTrue($newParent instanceof testNode);
+ $this->assertTrue($newParent->parent===$newGrandp);
+ $this->assertTrue($newParent->data==='parent');
+
+ $newChild=$newParent->child;
+ $this->assertTrue($newChild!==$child);
+ $this->assertTrue($newChild instanceof testNode);
+ $this->assertTrue($newChild->parent===$newParent);
+ $this->assertTrue($newChild->child===null);
+ $this->assertTrue($newChild->data==='child');
+ }
+
+ public function testCreateComponent()
+ {
+ $this->assertTrue(Prado::createComponent('TComponent') instanceof TComponent);
+ $this->assertTrue(Prado::createComponent('System.TComponent') instanceof TComponent);
+ try
+ {
+ Prado::createComponent('System2.TComponent');
+ $this->fail('exception not raised when creating a nonexistent component');
+ }
+ catch(TInvalidDataValueException $e)
+ {
+ $this->pass();
+ }
+ }
+
+ public function testNamespace()
+ {
+ $this->assertTrue(FRAMEWORK_DIR===Prado::getPathOfAlias('System'));
+ $this->assertTrue(Prado::getPathOfAlias('System2')===null);
+ $testSystem=dirname(__FILE__).'/TestSystem';
+
+ Prado::setPathOfAlias('TestSystem',$testSystem);
+ $this->assertTrue(realpath($testSystem)===Prado::getPathOfAlias('TestSystem'));
+
+ $this->assertTrue(Prado::getPathOfNamespace('TestSystem.*')===realpath($testSystem));
+ $this->assertTrue(Prado::getPathOfNamespace('TestSystem.protected.*')===realpath($testSystem).'/protected');
+ $this->assertTrue(Prado::getPathOfNamespace('TestSystem')===null);
+
+ // test repeatedly using the same namespaces
+ Prado::using('System.*');
+ Prado::using('System.*');
+ Prado::using('System.TComponent');
+ Prado::using('System.TComponent');
+
+ try
+ {
+ Prado::using('System');
+ $this->fail('no exception raised when using an invalid namespace for a directory');
+ }
+ catch(TInvalidDataValueException $e)
+ {
+ $this->pass();
+ }
+ // TODO: using new namespaces to see if classes can be automatically loaded or found
+ }
+}
+
+?> \ No newline at end of file