From ddc25b8fee819757f6468383e6c0183610feb949 Mon Sep 17 00:00:00 2001 From: knut <> Date: Thu, 26 Jan 2006 21:42:08 +0000 Subject: Prototype on new test system with Phing and PHPUnit2 to generate both Unit Test reports and corresponding Code Coverage reports --- .gitattributes | 9 + build.xml | 108 ++++++ etc/style/coverage-frames.xsl | 636 ++++++++++++++++++++++++++++++++ etc/style/log.xsl | 216 +++++++++++ etc/style/phpunit2-frames.xsl | 677 +++++++++++++++++++++++++++++++++++ etc/style/phpunit2-noframes.xsl | 436 ++++++++++++++++++++++ etc/style/str.replace.function.xsl | 105 ++++++ tests/unit/Collections/TListTest.php | 271 ++++++++++++++ tests/unit/TComponentTest.php | 178 +++++++++ tests/unit/phpunit2.php | 9 + 10 files changed, 2645 insertions(+) create mode 100644 build.xml create mode 100644 etc/style/coverage-frames.xsl create mode 100644 etc/style/log.xsl create mode 100644 etc/style/phpunit2-frames.xsl create mode 100644 etc/style/phpunit2-noframes.xsl create mode 100644 etc/style/str.replace.function.xsl create mode 100644 tests/unit/Collections/TListTest.php create mode 100644 tests/unit/TComponentTest.php create mode 100644 tests/unit/phpunit2.php diff --git a/.gitattributes b/.gitattributes index 645acbff..ae17cc37 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ /COPYRIGHT -text /HISTORY -text /UPGRADE -text +/build.xml -text demos/composer/index.php -text demos/composer/index2.php -text demos/composer/protected/pages/ClassDefinition.php -text @@ -144,6 +145,11 @@ demos/quickstart/themes/Simple/style.css -text docs/application.xml -text docs/conceptual-structure.vsd -text docs/request-sequence.vsd -text +etc/style/coverage-frames.xsl -text +etc/style/log.xsl -text +etc/style/phpunit2-frames.xsl -text +etc/style/phpunit2-noframes.xsl -text +etc/style/str.replace.function.xsl -text framework/.htaccess -text framework/3rdParty/SafeHtml/HTMLSax3.php -text framework/3rdParty/SafeHtml/HTMLSax3/Decorators.php -text @@ -892,6 +898,9 @@ tests/UnitTests/simpletest/url.php -text tests/UnitTests/simpletest/user_agent.php -text tests/UnitTests/simpletest/web_tester.php -text tests/UnitTests/simpletest/xml.php -text +tests/unit/Collections/TListTest.php -text +tests/unit/TComponentTest.php -text +tests/unit/phpunit2.php -text tools/.htaccess -text tools/jsbuilder/build.php -text tools/jsbuilder/custom_rhino.jar -text diff --git a/build.xml b/build.xml new file mode 100644 index 00000000..0f239e71 --- /dev/null +++ b/build.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Generating API documentation + + + + + + Preparing directory structure + + + + + + Preparing Code Coverage Database + + + + + + + + + + + + + + + + + + + + Running Unit Tests + + + + + + + + + + Creating Unit Test Report + + + Creating Code Coverage Report + + + + + + + TBD + + + + + Cleaning up the mess + + + + + + + \ No newline at end of file diff --git a/etc/style/coverage-frames.xsl b/etc/style/coverage-frames.xsl new file mode 100644 index 00000000..edfcf298 --- /dev/null +++ b/etc/style/coverage-frames.xsl @@ -0,0 +1,636 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Coverage Results. + + + + + + + + + <h2>Frame Alert</h2> + <p> + This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + </p> + + + + + + + + .bannercell { + border: 0px; + padding: 0px; + } + body { + margin-left: 10; + margin-right: 10; + background-color:#FFFFFF; + font-family: verdana,arial,sanserif; + color:#000000; + } + a { + color: #003399; + } + a:hover { + color: #888888; + } + .a td { + background: #efefef; + } + .b td { + background: #fff; + } + th, td { + text-align: left; + vertical-align: top; + } + th { + font-weight:bold; + background: #ccc; + color: black; + } + table, th, td { + font-size: 12px; + border: none + } + table.log tr td, tr th { + } + h2 { + font-weight:bold; + font-size: 12px; + margin-bottom: 5; + } + h3 { + font-size:100%; + font-weight: 12px; + background: #DFDFDF + color: white; + text-decoration: none; + padding: 5px; + margin-right: 2px; + margin-left: 2px; + margin-bottom: 0; + } + .small { + font-size: 9px; + } +TD.empty { + FONT-SIZE: 2px; BACKGROUND: #c0c0c0; BORDER:#9c9c9c 1px solid; + color: #c0c0c0; +} +TD.fullcover { + FONT-SIZE: 2px; BACKGROUND: #00df00; BORDER:#9c9c9c 1px solid; + color: #00df00; +} +TD.covered { + FONT-SIZE: 2px; BACKGROUND: #00df00; BORDER-LEFT:#9c9c9c 1px solid;BORDER-TOP:#9c9c9c 1px solid;BORDER-BOTTOM:#9c9c9c 1px solid; + color: #00df00; +} +TD.uncovered { + FONT-SIZE: 2px; BACKGROUND: #df0000; BORDER:#9c9c9c 1px solid; + color: #df0000; +} +PRE.srcLine { + BACKGROUND: #ffffff; MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; +} +td.lineCount, td.coverageCount { + BACKGROUND: #F0F0F0; PADDING-RIGHT: 3px; + text-align: right; +} +td.lineCountHighlight { + background: #C8C8F0; PADDING-RIGHT: 3px; + text-align: right; +} +td.coverageCountHighlight { + background: #F0C8C8; PADDING-RIGHT: 3px; + text-align: right; +} +span.srcLineHighlight { + background: #F0C8C8; +} +span.srcLine { + background: #C8C8F0; +} +TD.srcLineClassStart { + WIDTH: 100%; BORDER-TOP:#dcdcdc 1px solid; FONT-WEIGHT: bold; +} +.srcLine , .srcLine ol, .srcLine ol li {margin: 0;} +.srcLine .de1, .srcLine .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;} +.srcLine .imp {font-weight: bold; color: red;} +.srcLine .kw1 {color: #b1b100;} +.srcLine .kw2 {color: #000000; font-weight: bold;} +.srcLine .kw3 {color: #000066;} +.srcLine .co1 {color: #808080; font-style: italic;} +.srcLine .co2 {color: #808080; font-style: italic;} +.srcLine .coMULTI {color: #808080; font-style: italic;} +.srcLine .es0 {color: #000099; font-weight: bold;} +.srcLine .br0 {color: #66cc66;} +.srcLine .st0 {color: #ff0000;} +.srcLine .nu0 {color: #cc66cc;} +.srcLine .me1 {color: #006600;} +.srcLine .me2 {color: #006600;} +.srcLine .re0 {color: #0000ff;} + + + + + + + + + +

All Classes

+ + + + + + + / + .html + + + + + +
+ + + + (-) + + + () + + +
+ + +
+ + + + + + + + +

Overview

+

All Packages

+ + + + + + + +
+ + + +
+ + +
+ + + + + + + + + + + + + + + + +
Packages: Classes: Methods: LOC:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Methods covered
Total coverage

PackagesMethods covered
+ + + +
+ + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+
+ +

Classes

+ + + + + + + +
+ + + + (-) + + + () + + +
+ + +
+ + + + + + + + + + + + + + + + + + +
Classes: Methods: LOC:
+
+ + + + + + + + + + + + + + + + + + + + +
PackageMethods covered

ClassesMethods covered
+ + + +
+ + + + + + + + + + + + + + + + + +
Methods: LOC:
+
+ + + + + + + + + + + + +
Source fileMethods covered
+ + +
+
+ + + + +
+ + + + + + + + + + + + +
+ + http://phing.info/ + +

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.
+
+
+ + + + + + +

Report generated at
+
+ + + + + + + + + + + + + + + + + + + + + - + + + + + +
 
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
   
+ +
+
+
+ + + + + + + + + + 0 + + + + + + + + srcLineClassStart + + + +
+
+
+ + +
+
+
+ +
+
+ + +
+ + + + + + ../ + + + + + + ../ + + + + + + + + stylesheet.css + + + + + + a + b + + + +
+ + diff --git a/etc/style/log.xsl b/etc/style/log.xsl new file mode 100644 index 00000000..a460b667 --- /dev/null +++ b/etc/style/log.xsl @@ -0,0 +1,216 @@ + + + + + + + + + + + Phing Build Log + + + + + + + + + +
+ + http://phing.info/ + + + Phing +
+ + + +

+ + + + + + + +

+
+ Phing +
+
+ + +
+ + + + + + failed + complete + + + + + + + + + + + + + +
Build FailedBuild CompleteTotal Time:
+ +
+ See the stacktrace. +
+
+ + + +
phing.file
phing.version
+ +

Build events

+ + + + + + + +
targettaskmessage
+

+ + + +

Error details

+ + +
+
+
+ +

+
+ + + + + + + a + b + + + [ ] + + + + + + +
diff --git a/etc/style/phpunit2-frames.xsl b/etc/style/phpunit2-frames.xsl new file mode 100644 index 00000000..7ccc4f33 --- /dev/null +++ b/etc/style/phpunit2-frames.xsl @@ -0,0 +1,677 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unit Test Results. + + + + + + + + + <h2>Frame Alert</h2> + <p> + This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + </p> + + + + + + + +body { + font-family: verdana,arial,helvetica; + color:#000000; + font-size: 12px; +} +table tr td, table tr th { + font-family: verdana,arial,helvetica; + font-size: 12px; +} +table.details tr th{ + font-family: verdana,arial,helvetica; + font-weight: bold; + text-align:left; + background:#a6caf0; +} +table.details tr td{ + background:#eeeee0; +} + +p { + line-height:1.5em; + margin-top:0.5em; margin-bottom:1.0em; + font-size: 12px; +} +h1 { + margin: 0px 0px 5px; + font-family: verdana,arial,helvetica; +} +h2 { + margin-top: 1em; margin-bottom: 0.5em; + font-family: verdana,arial,helvetica; +} +h3 { + margin-bottom: 0.5em; + font-family: verdana,arial,helvetica; +} +h4 { + margin-bottom: 0.5em; + font-family: verdana,arial,helvetica; +} +h5 { + margin-bottom: 0.5em; + font-family: verdana,arial,helvetica; +} +h6 { + margin-bottom: 0.5em; + font-family: verdana,arial,helvetica; +} +.Error { + font-weight:bold; color:red; +} +.Failure { + font-weight:bold; color:purple; +} +.small { + font-size: 9px; +} +a { + color: #003399; +} +a:hover { + color: #888888; +} + + + + + + + . + + + Unit Test Results: <xsl:value-of select="$class.name"/> + + + + + + +

Class

+ + + + + +
+ +

Tests

+ + + + + + + + + +
+ + + +
+ + + + + + + + Unit Test Classes: <xsl:value-of select="$name"/> + + + + + + + + + +
+

+ + <none> +

+
+ +

Classes

+ + + + + + + +
+ +
+ + +
+ + + + + + + All Unit Test Classes + + + + + +

Classes

+ + + + +
+ + +
+ + + + + +
+ + + / + .html + + + + + + + + + + + + + All Unit Test Packages + + + + + +

Home

+

Packages

+ + + + +
+ + +
+ + + + + + + <none> + + + + + + + + + + Unit Test Results: Summary + + + + + + open('allclasses-frame.html','classListFrame') + +

Summary

+ + + + + + + + + + + + + + + + + Error + Failure + Pass + + + + + + + + + +
TestsFailuresErrorsSuccess rateTime
+ + + + + + + +
+ + + + +
+ Note: failures are anticipated and checked for with assertions while errors are unanticipated. +
+ +

Packages

+ + + + + + + + + + + Error + Failure + Pass + + + + + + + + + +
+ + <none> + + + + +
+ + + +
+ + + + + + + + + + + + open('package-frame.html','classListFrame') + +

Package

+ + + + + +

Classes

+

+ + + + + +
+

+
+ + + +
+ + + + + + + ../ + + + + + + ../ + + + + + + + + stylesheet.css + + + + + +

Unit Test Results

+ + + + + +
Designed for use with PHPUnit2 and Phing.
+
+
+ + + + + + +

Report generated at
+
+ + + + + Name + Tests + Errors + Failures + Time(s) + + + + + + + Name + Status + Type + Time(s) + + + + + + + + + + Error + Failure + Pass + + + + + + + + + + + + + + + + + + Error + Failure + TableRowColor + + + + + + Failure + + + + Error + + + + Success + + + + + + + + + + + + + + + + + + + + + + + + + N/A + + + + + +

+ + + + + +
+ + + + + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + diff --git a/etc/style/phpunit2-noframes.xsl b/etc/style/phpunit2-noframes.xsl new file mode 100644 index 00000000..d2c772da --- /dev/null +++ b/etc/style/phpunit2-noframes.xsl @@ -0,0 +1,436 @@ + + + + + + + + + + + Unit Test Results + + + + + + + + +
+ + + +
+ + + +
+ + + + + + + +
+ + + + + + + + +

Packages

+ Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers. + + + + + + + + + + + + + + + + + Failure + Error + + + + + + + + + +
+ + + +
+
+ + + + + + + + + + + + +

Package

+ + + + + + +
+ Back to top +

+

+ + + + + + + + +

TestCase

+ + + + + + + + + + +
+

+ + Back to top + + + + +

Summary

+ + + + + + + + + + + + + + + + + Failure + Error + + + + + + + + + +
TestsFailuresErrorsSuccess rateTime
+ + + + + + + +
+ + + + +
+ Note: failures are anticipated and checked for with assertions while errors are unanticipated. +
+
+ + + +

Unit Test Results

+ + + + + +
Designed for use with PHPUnit2 and Phing.
+
+
+ + + + + + +

Report generated at
+
+ + + + Name + Tests + Errors + Failures + Time(s) + + + + + + + Name + Tests + Errors + Failures + Time(s) + + + + + + + Name + Status + Type + Time(s) + + + + + + + + + + + Failure + Error + + + + + + + + + + + + + + + + + + + + + Error + + + + + + Failure + + + + Error + + + + Success + + + + + + + + + + + + + + + + + + + + + + + + N/A + + + + + + +

+ + + +
+
+ + + + + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + +
+ diff --git a/etc/style/str.replace.function.xsl b/etc/style/str.replace.function.xsl new file mode 100644 index 00000000..5d74e86c --- /dev/null +++ b/etc/style/str.replace.function.xsl @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ERROR: function implementation of str:replace() relies on exsl:node-set(). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/unit/Collections/TListTest.php b/tests/unit/Collections/TListTest.php new file mode 100644 index 00000000..3dacb701 --- /dev/null +++ b/tests/unit/Collections/TListTest.php @@ -0,0 +1,271 @@ +_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; + } +} + +/** + * @package System.Collections + */ +class TListTest extends PHPUnit2_Framework_TestCase { + 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->assertEquals(3,$list->getCount()); + $list2=new TList($this->list); + $this->assertEquals(2,$list2->getCount()); + } + + public function testGetCount() { + $this->assertEquals(2,$this->list->getCount()); + $this->assertEquals(2,$this->list->Count); + } + + public function testAdd() { + $this->list->add(null); + $this->list->add($this->item3); + $this->assertEquals(4,$this->list->getCount()); + $this->assertEquals(3,$this->list->indexOf($this->item3)); + } + + public function testInsert() { + $this->list->insert(0,$this->item3); + $this->assertEquals(3,$this->list->getCount()); + $this->assertEquals(2,$this->list->indexOf($this->item2)); + $this->assertEquals(0,$this->list->indexOf($this->item3)); + $this->assertEquals(1,$this->list->indexOf($this->item1)); + try { + $this->list->insert(4,$this->item3); + $this->fail('exception not raised when adding item at an out-of-range index'); + } catch(TInvalidDataValueException $e) { + + } + } + + public function testRemove() { + $this->list->remove($this->item1); + $this->assertEquals(1,$this->list->getCount()); + $this->assertEquals(-1,$this->list->indexOf($this->item1)); + $this->assertEquals(0,$this->list->indexOf($this->item2)); + try { + $this->list->remove($this->item1); + $this->fail('exception not raised when removing nonexisting item'); + } catch(Exception $e) { + + } + } + + public function testRemoveAt() { + $this->list->add($this->item3); + $this->list->removeAt(1); + $this->assertEquals(-1,$this->list->indexOf($this->item2)); + $this->assertEquals(1,$this->list->indexOf($this->item3)); + $this->assertEquals(0,$this->list->indexOf($this->item1)); + try { + $this->list->removeAt(2); + $this->fail('exception not raised when removing item with invalid index'); + } catch(TInvalidDataValueException $e) { + + } + } + + public function testClear() { + $this->list->clear(); + $this->assertEquals(0,$this->list->getCount()); + $this->assertEquals(-1,$this->list->indexOf($this->item1)); + $this->assertEquals(-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->assertEquals(0,$this->list->indexOf($this->item1)); + $this->assertEquals(1,$this->list->indexOf($this->item2)); + $this->assertEquals(-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) { + + } + } + + 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) { + + } + } + + 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(TInvalidDataValueException $e) { + + } + } + + /*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(TInvalidDataValueException $e) { + + } + try { + unset($this->list[5]); + $this->fail('exception not raised when unsetting item at an out-of-range index'); + } catch(TInvalidDataValueException $e) { + + } + }*/ + + 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->assertEquals(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->assertEquals(2,$newList->getCount()); + } + + $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->assertEquals(1,$newList->getCount()); + } + } +} + + +?> \ No newline at end of file diff --git a/tests/unit/TComponentTest.php b/tests/unit/TComponentTest.php new file mode 100644 index 00000000..e62017a7 --- /dev/null +++ b/tests/unit/TComponentTest.php @@ -0,0 +1,178 @@ +_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('OnMyEvent',$this,$param); + } + + public function myEventHandler($sender,$param) { + $this->_eventHandled=true; + } + + public function isEventHandled() { + return $this->_eventHandled; + } +} + +/** + * @package System + */ +class TComponentTest extends PHPUnit2_Framework_TestCase { + + protected $component; + + public function setUp() { + $this->component = new NewComponent(); + } + + public function tearDown() { + $this->component = null; + } + + public function testHasProperty() { + $this->assertTrue($this->component->hasProperty('Text'), "Component hasn't property Text"); + $this->assertTrue($this->component->hasProperty('text'), "Component hasn't property text"); + $this->assertFalse($this->component->hasProperty('Caption'), "Component as property 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) { + } + } + + 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) { + } + } + + public function testGetSubProperty() { + $this->assertTrue('object text'===$this->component->getSubProperty('Object.Text')); + } + + public function testSetSubProperty() { + $this->component->setSubProperty('Object.Text','new object text'); + $this->assertEquals('new object text',$this->component->getSubProperty('Object.Text')); + } + + public function testHasEvent() { + $this->assertTrue($this->component->hasEvent('OnMyEvent')); + $this->assertTrue($this->component->hasEvent('onmyevent')); + $this->assertFalse($this->component->hasEvent('onYourEvent')); + } + + public function testHasEventHandler() { + $this->assertFalse($this->component->hasEventHandler('OnMyEvent')); + $this->component->attachEventHandler('OnMyEvent','foo'); + $this->assertTrue($this->component->hasEventHandler('OnMyEvent')); + } + + public function testGetEventHandlers() { + $list=$this->component->getEventHandlers('OnMyEvent'); + $this->assertTrue(($list instanceof TList) && ($list->getCount()===0)); + $this->component->attachEventHandler('OnMyEvent','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) { + } + } + + public function testAttachEventHandler() { + $this->component->attachEventHandler('OnMyEvent','foo'); + $this->assertTrue($this->component->getEventHandlers('OnMyEvent')->getCount()===1); + try { + $this->component->attachEventHandler('YourEvent','foo'); + $this->fail('exception not raised when attaching event handlers for undefined event'); + } catch(TInvalidOperationException $e) { + } + /*$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')->insert(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('OnMyEvent',array($this->component,'myEventHandler')); + $this->assertFalse($this->component->isEventHandled()); + $this->component->raiseEvent('OnMyEvent',$this,null); + $this->assertTrue($this->component->isEventHandled()); + $this->component->attachEventHandler('OnMyEvent',array($this->component,'Object.myEventHandler')); + $this->assertFalse($this->component->Object->isEventHandled()); + $this->component->raiseEvent('OnMyEvent',$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) { + } + } + + public function testEvaluateStatements() { + $statements='$a="test string"; echo $a;'; + $this->assertEquals('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) { + } + } +} + +?> \ No newline at end of file diff --git a/tests/unit/phpunit2.php b/tests/unit/phpunit2.php new file mode 100644 index 00000000..81e85057 --- /dev/null +++ b/tests/unit/phpunit2.php @@ -0,0 +1,9 @@ + \ No newline at end of file -- cgit v1.2.3