From 15161da7755a8d74853ccae0966afa22d9830b07 Mon Sep 17 00:00:00 2001 From: "Christophe.Boulain" <> Date: Sat, 8 Nov 2008 17:41:48 +0000 Subject: Issue#36: Refactored TRatingList/TActiveRatingList, and added some docs. --- .gitattributes | 20 +- HISTORY | 1 + .../source/prado/activeratings/blocks.css | 42 --- .../source/prado/activeratings/default.css | 43 --- .../source/prado/activeratings/ratings.js | 178 ----------- .../Javascripts/source/prado/ratings/ratings.js | 207 ++++++++++-- .../Web/UI/ActiveControls/TActiveRatingList.php | 343 +++----------------- framework/Web/UI/WebControls/TRatingList.php | 347 ++++++++++++++------- .../pages/ActiveRatingListAllowInputTest.page | 14 + .../pages/ActiveRatingListAllowInputTest.php | 27 ++ .../pages/ActiveRatingListAutoPostBackTest.page | 16 + .../pages/ActiveRatingListAutoPostBackTest.php | 27 ++ .../pages/ActiveRatingListCheckBoxesTest.page | 12 + .../pages/ActiveRatingListCheckBoxesTest.php | 23 ++ .../pages/ActiveRatingListEnabledTest.page | 17 + .../pages/ActiveRatingListEnabledTest.php | 37 +++ .../pages/ActiveRatingListHoverCaptionTest.page | 14 + .../pages/ActiveRatingListHoverCaptionTest.php | 27 ++ .../pages/ActiveRatingListRatingTest.page | 17 + .../protected/pages/ActiveRatingListRatingTest.php | 32 ++ .../pages/ActiveRatingListReadOnlyTest.page | 17 + .../pages/ActiveRatingListReadOnlyTest.php | 38 +++ .../pages/ActiveRatingListSelectedIndexTest.page | 17 + .../pages/ActiveRatingListSelectedIndexTest.php | 32 ++ .../protected/pages/RatingList.page | 13 +- .../ActiveRatingListTestCase.php | 253 +++++++++++++++ 26 files changed, 1100 insertions(+), 714 deletions(-) delete mode 100644 framework/Web/Javascripts/source/prado/activeratings/blocks.css delete mode 100644 framework/Web/Javascripts/source/prado/activeratings/default.css delete mode 100644 framework/Web/Javascripts/source/prado/activeratings/ratings.js create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.php create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.page create mode 100644 tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.php create mode 100644 tests/FunctionalTests/active-controlstests/ActiveRatingListTestCase.php diff --git a/.gitattributes b/.gitattributes index b1b5e6df..762440c3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2532,19 +2532,16 @@ framework/Web/Javascripts/source/prado/activefileupload/ActiveFileUploadComplete framework/Web/Javascripts/source/prado/activefileupload/ActiveFileUploadError.png -text svneol=unset#image/png framework/Web/Javascripts/source/prado/activefileupload/ActiveFileUploadIndicator.gif -text framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js -text -framework/Web/Javascripts/source/prado/activeratings/blocks.css -text framework/Web/Javascripts/source/prado/activeratings/blocks.png -text framework/Web/Javascripts/source/prado/activeratings/blocks_blank.gif -text framework/Web/Javascripts/source/prado/activeratings/blocks_combined.gif -text framework/Web/Javascripts/source/prado/activeratings/blocks_half.gif -text framework/Web/Javascripts/source/prado/activeratings/blocks_selected.gif -text -framework/Web/Javascripts/source/prado/activeratings/default.css -text framework/Web/Javascripts/source/prado/activeratings/default.png -text framework/Web/Javascripts/source/prado/activeratings/default_blank.gif -text framework/Web/Javascripts/source/prado/activeratings/default_combined.gif -text framework/Web/Javascripts/source/prado/activeratings/default_half.gif -text framework/Web/Javascripts/source/prado/activeratings/default_selected.gif -text -framework/Web/Javascripts/source/prado/activeratings/ratings.js -text framework/Web/Javascripts/source/prado/colorpicker/background.png -text framework/Web/Javascripts/source/prado/colorpicker/button.gif -text framework/Web/Javascripts/source/prado/colorpicker/colorpicker.js -text @@ -2782,6 +2779,22 @@ tests/FunctionalTests/active-controls/protected/pages/ActiveRadioButtonListTest. tests/FunctionalTests/active-controls/protected/pages/ActiveRadioButtonListTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveRadioButtonTest.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveRadioButtonTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.php -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.page -text +tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.php -text tests/FunctionalTests/active-controls/protected/pages/ActiveRedirectionTest.page -text tests/FunctionalTests/active-controls/protected/pages/ActiveRedirectionTest.php -text tests/FunctionalTests/active-controls/protected/pages/Callback.page -text @@ -2871,6 +2884,7 @@ tests/FunctionalTests/active-controls/tests/PostLoadingTestCase.php -text tests/FunctionalTests/active-controls/tests/ReplaceContentTestCase.php -text tests/FunctionalTests/active-controls/tests/TextBoxGroupValidationTestCase.php -text tests/FunctionalTests/active-controls/tests/ValueTriggerCallbackTestCase.php -text +tests/FunctionalTests/active-controlstests/ActiveRatingListTestCase.php -text tests/FunctionalTests/features.php -text tests/FunctionalTests/features/index.php -text tests/FunctionalTests/features/protected/application.xml -text diff --git a/HISTORY b/HISTORY index 7b460ddc..64241176 100644 --- a/HISTORY +++ b/HISTORY @@ -2,6 +2,7 @@ Version 3.1.4 To be released ============================== BUG: Issue#59 - TPropertyAccess::has() returns false even if the property of an object was found (Carl) NEW: Issue#29 - Ability to specify position of popup TDatePicker (Carl) +ENH: Issue#36 - Refactored TRatingList/TActiveRatingList, and added some docs (Bradley) ENH: Issue#52 - Upgraded to TinyMCE 3.2.1 Version 3.1.3 November 1, 2008 diff --git a/framework/Web/Javascripts/source/prado/activeratings/blocks.css b/framework/Web/Javascripts/source/prado/activeratings/blocks.css deleted file mode 100644 index bb846094..00000000 --- a/framework/Web/Javascripts/source/prado/activeratings/blocks.css +++ /dev/null @@ -1,42 +0,0 @@ -.TActiveRatingList_blocks -{ - border-collapse: collapse; -} -.TActiveRatingList_blocks input, .TActiveRatingList_blocks label -{ - display: none; -} - -.TActiveRatingList_blocks td -{ - width: 18px; - height: 9px; - padding: 1px; -} - -.TActiveRatingList_blocks td.rating -{ - background-image: url(blocks_combined.gif); - background-repeat: no-repeat; - cursor: pointer; - background-position: 1px 0px; -} -.TActiveRatingList_blocks td.rating_selected -{ - background-position: 1px -100px; -} - -.TActiveRatingList_blocks td.rating_half -{ - background-position: 1px -200px; -} - -.TActiveRatingList_blocks td.rating_hover -{ - background-position: 1px -300px; -} - -.TActiveRatingList_blocks td.rating_disabled -{ - cursor: default !important; -} diff --git a/framework/Web/Javascripts/source/prado/activeratings/default.css b/framework/Web/Javascripts/source/prado/activeratings/default.css deleted file mode 100644 index ba90eb27..00000000 --- a/framework/Web/Javascripts/source/prado/activeratings/default.css +++ /dev/null @@ -1,43 +0,0 @@ -.TActiveRatingList_default -{ - border-collapse: collapse; -} -.TActiveRatingList_default input, .TActiveRatingList_default label -{ - display: none; -} - -.TActiveRatingList_default td -{ - width: 18px; - height: 18px; - padding: 0; -} - -.TActiveRatingList_default td.rating -{ - background-image: url(default_combined.gif); - background-repeat: no-repeat; - cursor: pointer; - background-position: 0px 0px; -} - -.TActiveRatingList_default td.rating_selected -{ - background-position: 0px -100px; -} - -.TActiveRatingList_default td.rating_half -{ - background-position: 0px -200px; -} - -.TActiveRatingList_default td.rating_hover -{ - background-position: 0px -300px; -} - -.TActiveRatingList_default td.rating_disabled -{ - cursor: default !important; -} \ No newline at end of file diff --git a/framework/Web/Javascripts/source/prado/activeratings/ratings.js b/framework/Web/Javascripts/source/prado/activeratings/ratings.js deleted file mode 100644 index 4eeddbd8..00000000 --- a/framework/Web/Javascripts/source/prado/activeratings/ratings.js +++ /dev/null @@ -1,178 +0,0 @@ -Prado.WebUI.TActiveRatingList = Base.extend( -{ - selectedIndex : -1, - rating: -1, - enabled : true, - readOnly : false, - - constructor : function(options) - { - var cap = $(options.CaptionID); - this.options = Object.extend( - { - caption : cap ? cap.innerHTML : '' - }, options || {}); - - Prado.WebUI.TActiveRatingList.register(this); - this._init(); - this.selectedIndex = options.SelectedIndex; - this.rating = options.Rating; - if(options.Rating <= 0 && options.SelectedIndex >= 0) - this.rating = options.SelectedIndex+1; - this.showRating(this.rating); - }, - - _init: function(options) - { - Element.addClassName($(this.options.ListID),this.options.Style); - this.radios = new Array(); - var index=0; - for(var i = 0; i halfMax ? base+1 : base; - for(var i = 0; i halfMax ? base+1 : base; - var hasHalf = remainder >= halfMin && remainder <= halfMax; - for(var i = 0; i index ? 'removeClassName' : 'addClassName'; - Element[action](node, "rating_selected"); - if(i==index+1 && hasHalf) - Element.addClassName(node, "rating_half"); - else - Element.removeClassName(node, "rating_half"); - Element.removeClassName(node,"rating_hover"); - } - }, - - getIndexCaption : function(index) - { - return index > -1 ? this.radios[index].value : this.options.caption; - }, - - showCaption : function(value) - { - var caption = $(this.options.CaptionID); - if(caption) caption.innerHTML = value; - $(this.options.ListID).title = value; - }, - - setCaption : function(value) - { - this.options.caption = value; - this.showCaption(value); - }, - - setEnabled : function(value) - { - this.enabled = value; - for(var i = 0; i= 0) + this.rating = options.SelectedIndex+1; + this.setReadOnly(this.readOnly); + }, + + _init: function(options) + { + Element.addClassName($(this.options.ListID),this.options.Style); + this.radios = new Array(); + this._mouseOvers = new Array(); + this._mouseOuts = new Array(); + this._clicks = new Array(); + var index=0; + for(var i = 0; i halfMax ? base+1 : base; + for(var i = 0; i halfMax ? base+1 : base; + var hasHalf = remainder >= halfMin && remainder <= halfMax; + for(var i = 0; i index ? 'removeClassName' : 'addClassName'; + Element[action](node, "rating_selected"); + if(i==index+1 && hasHalf) + Element.addClassName(node, "rating_half"); + else + Element.removeClassName(node, "rating_half"); + Element.removeClassName(node,"rating_hover"); + } + }, + + getIndexCaption : function(index) + { + return index > -1 ? this.radios[index].value : this.options.caption; + }, + + showCaption : function(value) + { + var caption = $(this.options.CaptionID); + if(caption) caption.innerHTML = value; + $(this.options.ListID).title = value; }, - setRating: function(index) + setCaption : function(value) { - for(var i = 0; i<=index; i++) - this.radios[i].parentNode.parentNode.className = "rating_selected"; - this.setCaption(index); + this.options.caption = value; + this.showCaption(value); }, - setCaption : function(index) + setReadOnly : function(value) { - this.caption.innerHTML = index > -1 ? - this.radios[index].value : this.options.caption; + this.readOnly = value; + for(var i = 0; i + * @author Bradley Booms * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ * @package System.Web.UI.ActiveControls @@ -13,107 +14,85 @@ /** * TActiveRatingList Class * - * Displays clickable images that represent a TActiveRadioButtonList + * Displays clickable images that represent a TRadioButtonList * * @author Wei Zhuo + * @author Bradley Booms * @version $Id$ * @package System.Web.UI.ActiveControls * @since 3.1 */ -class TActiveRatingList extends TActiveRadioButtonList +class TActiveRatingList extends TRatingList implements IActiveControl, ICallbackEventHandler { - const SCRIPT_PATH = 'prado/activeratings'; - - /** - * @var array list of published rating images. - */ - private $_ratingImages = array(); - /** - * Sets the default repeat direction to horizontal. + * Creates a new callback control, sets the adapter to + * TActiveListControlAdapter. If you override this class, be sure to set the + * adapter appropriately by, for example, by calling this constructor. */ public function __construct() { + $this->setAdapter(new TActiveListControlAdapter($this)); + $this->setAutoPostBack(true); parent::__construct(); - $this->setRepeatDirection(TRepeatDirection::Horizontal); - } - - /** - * @return boolean whether the items in the column can be edited. Defaults to false. - */ - public function getReadOnly() - { - return $this->getViewState('ReadOnly',false); } /** - * @param boolean whether the items in the column can be edited + * @return TBaseActiveCallbackControl standard callback control options. */ - public function setReadOnly($value) + public function getActiveControl() { - $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); + return $this->getAdapter()->getBaseActiveControl(); } /** - * The repeat layout must be Table. - * @param string repeat layout type - * @throws TInvaliddataValueException when repeat layout is not Table. + * @return TCallbackClientSide client side request options. */ - public function setRepeatLayout($value) + public function getClientSide() { - if($value!==TRepeatLayout::Table) - throw new TInvalidDataValueException('ratinglist_table_layout_only'); - else - parent::setRepeatLayout($value); + return $this->getAdapter()->getBaseActiveControl()->getClientSide(); } /** - * @return float rating value. + * Raises the callback event. This method is required by {@link + * ICallbackEventHandler} interface. + * This method is mainly used by framework and control developers. + * @param TCallbackEventParameter the event parameter */ - public function getRating() + public function raiseCallbackEvent($param) { - return $this->getViewState('Rating',0.0); + $this->onCallback($param); } /** - * @param float rating value, also sets the selected Index + * This method is invoked when a callback is requested. The method raises + * 'OnCallback' event to fire up the event handlers. If you override this + * method, be sure to call the parent implementation so that the event + * handler can be invoked. + * @param TCallbackEventParameter event parameter to be passed to the event handlers */ - public function setRating($value) + public function onCallback($param) { - $rating = TPropertyValue::ensureFloat($value); - $this->setViewState('Rating', $rating); - $canUpdate = $this->getActiveControl()->getEnableUpdate(); - $this->getActiveControl()->setEnableUpdate(false); - parent::setSelectedIndex($this->getRatingIndex($rating)); - $this->getActiveControl()->setEnableUpdate($canUpdate); - if($this->getActiveControl()->canUpdateClientSide()) - $this->callClientFunction('setRating',$rating); + $this->raiseEvent('OnCallback', $this, $param); } /** - * @param float rating value - * @return int rating as integer + * @param boolean whether the items in the column can be edited */ - protected function getRatingIndex($rating) + public function setReadOnly($value) { - $interval = $this->getHalfRatingInterval(); - $base = intval($rating)-1; - $remainder = $rating-$base-1; - return $remainder > $interval[1] ? $base+1 : $base; + parent::setReadOnly($value); + $value = $this->getReadOnly(); + $this->callClientFunction('setReadOnly',$value); } /** - * @param int change the rating selection index + * @param float rating value, also sets the selected Index */ - public function setSelectedIndex($value) + public function setRating($value) { - $value = TPropertyValue::ensureInteger($value); - $canUpdate = $this->getActiveControl()->getEnableUpdate(); - $this->getActiveControl()->setEnableUpdate(false); - parent::setSelectedIndex($value); - $this->getActiveControl()->setEnableUpdate($canUpdate); - if($this->getActiveControl()->canUpdateClientSide()) - $this->callClientFunction('setRating',$value+1); + parent::setRating($value); + $value = $this->getRating(); + $this->callClientFunction('setRating',$value); } /** @@ -123,250 +102,22 @@ class TActiveRatingList extends TActiveRadioButtonList */ protected function callClientFunction($func,$value) { - $client = $this->getPage()->getCallbackClient(); - $code = $this->getClientClassName().'.'.$func; - $client->callClientFunction($code,array($this,$value)); - } - - /** - * @return string control or html element ID for displaying a caption. - */ - public function getCaptionID() - { - return $this->getViewState('CaptionID', ''); - } - - /** - * @param string control or html element ID for displaying a caption. - */ - public function setCaptionID($value) - { - $this->setViewState('CaptionID', $value, ''); - } - - protected function getCaptionControl() - { - if(($id=$this->getCaptionID())!=='') - { - if($control=$this->getParent()->findControl($id)) - return $control; - } - throw new TInvalidDataValueException( - 'ratinglist_invalid_caption_id',$id,$this->getID()); - } - - public function setCaption($value) - { - $this->getCaptionControl()->setText($value); - if($this->getActiveControl()->canUpdateClientSide()) - $this->callClientFunction('setCaption',$value); - } - - public function getCaption() - { - return $this->getCaptionControl()->getText(); - } - - /** - * @param boolean true to enable the rating to be changed. - */ - public function setEnabled($value) - { - $value = TPropertyValue::ensureBoolean($value); - parent::setEnabled($value); if($this->getActiveControl()->canUpdateClientSide()) - $this->callClientFunction('setEnabled',$value); - } - - /** - * @param string set the rating style, default is "default" - */ - public function setRatingStyle($value) - { - $this->setViewState('RatingStyle', $value, 'default'); - } - - /** - * @return TActiveRatingListStyle current rating style - */ - public function getRatingStyle() - { - return $this->getViewState('RatingStyle', 'default'); - } - - /** - * Sets the interval such that those rating values within the interval - * will be considered as a half star rating. - * @param array rating display half value interval, default is array(0.3, 0.7); - */ - public function setHalfRatingInterval($value) - { - $this->setViewState('HalfRating', - TPropertyValue::ensureArray($value), array(0.3, 0.7)); - } - - /** - * @return array rating display half value interval, default is array(0.3, 0.7); - */ - public function getHalfRatingInterval() - { - return $this->getViewState('HalfRating', array(0.3, 0.7)); - } - - /** - * @return string rating style css class name. - */ - protected function getRatingStyleCssClass() - { - return 'TActiveRatingList_'.$this->getRatingStyle(); - } - - /** - * @return array list of post back options. - */ - protected function getPostBackOptions() - { - $options = parent::getPostBackOptions(); - $options['Style'] = $this->getRatingStyleCssClass(); - $options['CaptionID'] = $this->getCaptionControlID(); - $options['SelectedIndex'] = $this->getSelectedIndex(); - $options['Rating'] = $this->getRating(); - $options['HalfRating'] = $this->getHalfRatingInterval(); - return $options; - } - - /** - * Registers the javascript code for initializing the active control - * only if {@link setReadOnly ReadOnly} property is false. - */ - protected function renderClientControlScript($writer) - { - if($this->getReadOnly()===false) - parent::renderClientControlScript($writer); - } - - /** - * @return string find the client ID of the caption control. - */ - protected function getCaptionControlID() - { - if(($id=$this->getCaptionID())!=='') { - if($control=$this->getParent()->findControl($id)) - { - if($control->getVisible(true)) - return $control->getClientID(); - } - else - return $id; + $client = $this->getPage()->getCallbackClient(); + $code = parent::getClientClassName().'.'.$func; + $client->callClientFunction($code,array($this,$value)); } - return ''; } /** - * @param string asset file in the self::SCRIPT_PATH directory. - * @return string asset file url. + * @param string caption text */ - protected function getAssetUrl($file='') - { - $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); - return $base.'/'.self::SCRIPT_PATH.'/'.$file; - } - - /** - * @param string rating style name - * @return string URL of the css style file - */ - protected function publishRatingListStyle($style) - { - $cs = $this->getPage()->getClientScript(); - $url = $this->getAssetUrl($style.'.css'); - if(!$cs->isStyleSheetFileRegistered($url)) - $cs->registerStyleSheetFile($url, $url); - return $url; - } - - /** - * @param string rating style name - * @param string rating image file extension, default is '.gif' - * @return array URL of publish the rating images - */ - protected function publishRatingListImages($style, $fileExt='.gif') - { - $types = array('blank', 'selected', 'half', 'combined'); - $files = array(); - foreach($types as $type) - $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}"); - return $files; - } - - /** - * Add rating style class name to the class attribute - * when {@link setReadOnly ReadOnly} property is true and when the - * {@link setCssClass CssClass} property is empty. - * @param THtmlWriter renderer - */ - public function render($writer) - { - if($this->getReadOnly()) - $writer->addAttribute('class', $this->getRatingStyleCssClass()); - else - { - $writer->addAttribute('id',$this->getClientID()); - $this->getActiveControl()->registerCallbackClientScript( - $this->getClientClassName(), $this->getPostBackOptions()); - } - parent::render($writer); - } - - /** - * Publish the the rating style css file and rating image files. - */ - public function onPreRender($param) - { - parent::onPreRender($param); - - $this->publishRatingListStyle($this->getRatingStyle()); - $this->_ratingImages = $this->publishRatingListImages($this->getRatingStyle()); - } - - /** - * Renders the rating images if {@link setReadOnly ReadOnly} is true - * otherwise render the radio buttons. - */ - public function renderItem($writer,$repeatInfo,$itemType,$index) - { - if($this->getReadOnly()) - $this->renderStaticRating($writer, $repeatInfo, $itemType, $index); - else - parent::renderItem($writer, $repeatInfo, $itemType, $index); - } - - /** - * Renders the static rating images. - */ - protected function renderStaticRating($writer, $repeatInfo, $itemType, $index) - { - $image = new TImage; - $image->setImageUrl($this->_ratingImages[$this->getRatingImageType($index)]); - $image->setAlternateText($this->getRating()); - $image->render($writer); - } - - /** - * @param integer rating image index - * @return string the rating image corresponding to current index to be rendered. - */ - protected function getRatingImageType($index) + public function setCaption($value) { - $rating = floatval($this->getRating()); - $int = intval($rating); - $limit = $this->getHalfRatingInterval(); - if($index < $int || ($rating < $index+1 && $rating > $index+$limit[1])) - return 'selected'; - if($rating >= $index+$limit[0] && $rating <= $index+$limit[1]) - return 'half'; - return 'blank'; + parent::setCaption($value); + // if it's an active control, this should not be needed. + $this->callClientFunction('setCaption',$value); } /** diff --git a/framework/Web/UI/WebControls/TRatingList.php b/framework/Web/UI/WebControls/TRatingList.php index 85e7f66c..aba44fb0 100644 --- a/framework/Web/UI/WebControls/TRatingList.php +++ b/framework/Web/UI/WebControls/TRatingList.php @@ -4,7 +4,7 @@ * * @author Wei Zhuo * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ * @package System.Web.UI.WebControls @@ -21,191 +21,320 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList'); * This class is EXPERIMENTAL. * * @author Wei Zhuo + * @author Bradley Booms * @version $Id$ * @package System.Web.UI.WebControls * @since 3.0 */ class TRatingList extends TRadioButtonList { + /** + * Script path relative to the TClientScriptManager::SCRIPT_PATH + */ const SCRIPT_PATH='prado/ratings'; + /** + * @var array list of published rating images. + */ private $_ratingImages = array(); + /** + * Sets the default repeat direction to horizontal. + */ public function __construct() { parent::__construct(); - $this->getRepeatInfo()->setRepeatDirection('Horizontal'); + $this->setRepeatDirection(TRepeatDirection::Horizontal); } + /** + * @return boolean whether the items in the column can be edited. Defaults to false. + */ + public function getReadOnly() + { + return $this->getViewState('ReadOnly',false); + } + + /** + * @param boolean whether the items in the column can be edited + */ + public function setReadOnly($value) + { + $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); + } + + /** + * Wrapper for {@link setReadOnly ReadOnly} property. + * @return boolean whether the rating list can be edited. Defaults to true. + */ public function getAllowInput() { - return $this->getViewState('AllowInput', true); + return !$this->getReadOnly(); } + /** + * Wrapper for {@link setReadOnly ReadOnly} property. + * @param boolean whether the rating list can be edited + */ public function setAllowInput($value) { - $this->setViewState('AllowInput', TPropertyValue::ensureBoolean($value), true); + $this->setReadOnly(!TPropertyValue::ensureBoolean($value)); } - public function getRating() + /** + * Wrapper for {@link setReadOnly ReadOnly} property. + * @param boolean whether the rating list can be edited + */ + public function setEnabled($value) { - if($this->getAllowInput()) - return $this->getSelectedIndex(); - else - return $this->getViewState('Rating',0); + $this->setReadOnly(!TPropertyValue::ensureBoolean($value)); } - public function setRating($value) + /** + * The repeat layout must be Table. + * @param string repeat layout type + * @throws TInvaliddataValueException when repeat layout is not Table. + */ + public function setRepeatLayout($value) { - if($this->getAllowInput()) - $this->setSelectedIndex($value); + if($value!==TRepeatLayout::Table) + throw new TInvalidDataValueException('ratinglist_table_layout_only'); else - $this->setViewState('Rating', TPropertyValue::ensureFloat($value),0); + parent::setRepeatLayout($value); } /** - * @param string set the rating style + * @return float rating value. */ - public function setRatingStyle($value) + public function getRating() { - $this->setViewState('RatingStyle', $value, 'default'); + $rating = $this->getViewState('Rating', null); + if ($rating === null) + return $this->getSelectedIndex()+1; + else + return $rating; } /** - * @return TRatingListStyle current rating style + * @param float rating value, also sets the selected Index */ - public function getRatingStyle() + public function setRating($value) { - return $this->getViewState('RatingStyle', 'default'); + $value = TPropertyValue::ensureFloat($value); + $this->setViewState('Rating', $value, null); + $index = $this->getRatingIndex($value); + parent::setSelectedIndex($index); + } + + public function setSelectedIndex($value) + { + $this->setRating($value+1); + parent::setSelectedIndex($value); } /** - * @return string caption text. Default is "Rate It:". + * @param float rating value + * @return int rating as integer */ - public function getCaption() + protected function getRatingIndex($rating) { - return $this->getViewState('Caption', 'Rate It:'); + $interval = $this->getHalfRatingInterval(); + $base = intval($rating)-1; + $remainder = $rating-$base-1; + return $remainder > $interval[1] ? $base+1 : $base; } /** - * @param string caption text + * @param int change the rating selection index */ - public function setCaption($value) + public function onSelectedIndexChanged($param) { - $this->setViewState('Caption', $value, 'Rate It:'); + $value = $this->getRating(); + $value = TPropertyValue::ensureInteger($value); + $this->setRating($value); + parent::onSelectedIndexChanged($param); } + /** + * @return string control or html element ID for displaying a caption. + */ + public function getCaptionID() + { + return $this->getViewState('CaptionID', ''); + } - public function setHalfRatingLimit($value) + /** + * @param string control or html element ID for displaying a caption. + */ + public function setCaptionID($value) { - $this->setViewState('HalfRating', - TPropertyValue::ensureArray($value), array(0.3, 0.7)); + $this->setViewState('CaptionID', $value, ''); } - public function getHalfRatingLimit() + protected function getCaptionControl() { - return $this->getViewState('HalfRating', array(0.3, 0.7)); + if(($id=$this->getCaptionID())!=='') + { + if($control=$this->getParent()->findControl($id)) + return $control; + } + throw new TInvalidDataValueException( + 'ratinglist_invalid_caption_id',$id,$this->getID()); } /** - * @param string asset file in the self::SCRIPT_PATH directory. - * @return string asset file url. + * @return string caption text. Default is "Rate It:". */ - protected function getAssetUrl($file='') + public function getCaption() { - $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); - return $base.'/'.self::SCRIPT_PATH.'/'.$file; + return $this->getCaptionControl()->getText(); } - public function getRatingClientOptions() - { - $options['cssClass'] = 'TRatingList_'.$this->getRatingStyle(); - $options['ID'] = $this->getClientID(); - $options['caption'] = $this->getCaption(); - $options['field'] = $this->getUniqueID(); - $options['selectedIndex'] = $this->getSelectedIndex(); + /** + * @return TRatingListStyle current rating style + */ + public function setCaption($value) + { + $this->getCaptionControl()->setText($value); + } + + /** + * @param string set the rating style, default is "default" + */ + public function setRatingStyle($value) + { + $this->setViewState('RatingStyle', $value, 'default'); + } + + /** + * @return TRatingListStyle current rating style + */ + public function getRatingStyle() + { + return $this->getViewState('RatingStyle', 'default'); + } + + /** + * @return string rating style css class name. + */ + protected function getRatingStyleCssClass() + { + return 'TRatingList_'.$this->getRatingStyle(); + } + + /** + * Sets the interval such that those rating values within the interval + * will be considered as a half star rating. + * @param array rating display half value interval, default is array(0.3, 0.7); + */ + public function setHalfRatingInterval($value) + { + $this->setViewState('HalfRating', + TPropertyValue::ensureArray($value), array(0.3, 0.7)); + } + + /** + * @return array rating display half value interval, default is array(0.3, 0.7); + */ + public function getHalfRatingInterval() + { + return $this->getViewState('HalfRating', array(0.3, 0.7)); + } + + /** + * @return array list of post back options. + */ + protected function getPostBackOptions() + { + $options = parent::getPostBackOptions(); + $options['AutoPostBack'] = $this->getAutoPostBack(); + $options['ReadOnly'] = $this->getReadOnly(); + $options['Style'] = $this->getRatingStyleCssClass(); + $options['CaptionID'] = $this->getCaptionControlID(); + $options['SelectedIndex'] = $this->getSelectedIndex(); + $options['Rating'] = $this->getRating(); + $options['HalfRating'] = $this->getHalfRatingInterval(); return $options; - } + } - protected function publishRatingListStyle($style) - { + /** + * @return string find the client ID of the caption control. + */ + protected function getCaptionControlID() + { + if(($id=$this->getCaptionID())!=='') + { + if($control=$this->getParent()->findControl($id)) + { + if($control->getVisible(true)) + return $control->getClientID(); + } + else + return $id; + } + return ''; + } + + /** + * Publish the the rating style css file and rating image files. + */ + public function onPreRender($param) + { + parent::onPreRender($param); + $this->publishStyle($this->getRatingStyle()); + $this->_ratingImages = $this->publishImages($this->getRatingStyle()); + } + + /** + * @param string rating style name + * @return string URL of the css style file + */ + protected function publishStyle($style) + { $cs = $this->getPage()->getClientScript(); $url = $this->getAssetUrl($style.'.css'); if(!$cs->isStyleSheetFileRegistered($url)) $cs->registerStyleSheetFile($url, $url); return $url; - } + } - protected function publishRatingListImages($style, $fileExt='.gif') - { - $images = array('blank', 'hover', 'selected', 'half'); + /** + * @param string rating style name + * @param string rating image file extension, default is '.gif' + * @return array URL of publish the rating images + */ + protected function publishImages($style, $fileExt='.gif') + { + $types = array('blank', 'selected', 'half', 'combined'); $files = array(); - foreach($images as $type) + foreach($types as $type) $files[$type] = $this->getAssetUrl("{$style}_{$type}{$fileExt}"); return $files; - } + } /** - * @param THtmlWriter writer + * @param string asset file in the self::SCRIPT_PATH directory. + * @return string asset file url. */ - public function onPreRender($param) - { - parent::onPreRender($param); - - $this->publishRatingListStyle($this->getRatingStyle()); - $this->_ratingImages = $this->publishRatingListImages($this->getRatingStyle()); - - if($this->getAllowInput()) - $this->registerRatingListClientScript(); - else - { - $this->getRepeatInfo()->setCaption($this->getCaption()); - $this->setAttribute('title', $this->getRating()); - } - } - - protected function registerRatingListClientScript() - { - $id = $this->getClientID(); - $scripts = $this->getPage()->getClientScript(); - $scripts->registerPradoScript('prado'); - $options = TJavaScript::encode($this->getRatingClientOptions()); - $code = "new Prado.WebUI.TRatingList($options);"; - $scripts->registerEndScript("prado:$id", $code); - } - - public function renderItem($writer,$repeatInfo,$itemType,$index) - { - if($this->getAllowInput()) - parent::renderItem($writer, $repeatInfo, $itemType, $index); - else - $this->renderRatingListItem($writer, $repeatInfo, $itemType, $index); - } - - protected function renderRatingListItem($writer, $repeatInfo, $itemType, $index) - { - $image = new TImage; - $image->setImageUrl($this->_ratingImages[$this->getRatingImageType($index)]); - $image->setAlternateText($this->getRating()); - $image->render($writer); - } - - protected function getRatingImageType($index) - { - $rating = floatval($this->getRating()); - $int = intval($rating); - $limit = $this->getHalfRatingLimit(); - if($index < $int || ($rating < $index + 1 && $rating > $index +$limit[1])) - return 'selected'; - if($rating >= $index+$limit[0] && $rating <= $index+$limit[1]) - return 'half'; - return 'blank'; - } + protected function getAssetUrl($file='') + { + $base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl(); + return $base.'/'.self::SCRIPT_PATH.'/'.$file; + } - public function generateItemStyle($itemType,$index) - { - return new TStyle; - } + /** + * Add rating style class name to the class attribute + * when {@link setReadOnly ReadOnly} property is true and when the + * {@link setCssClass CssClass} property is empty. + * @param THtmlWriter renderer + */ + public function render($writer) + { + $writer->addAttribute('id',$this->getClientID()); + $this->getPage()->getClientScript()->registerPostBackControl( + $this->getClientClassName(), $this->getPostBackOptions()); + parent::render($writer); + } /** * Gets the name of the javascript class responsible for performing postback for this control. diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.page new file mode 100644 index 00000000..35fcadc7 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.page @@ -0,0 +1,14 @@ + + +

TActiveRatingList AllowInput Test Case

+ + + + + + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.php new file mode 100644 index 00000000..c825f3f8 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAllowInputTest.php @@ -0,0 +1,27 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListAllowInputTest extends TPage{ + public function ratingChanged($sender, $param){ + $this->Status->setText($sender->getRating().' : '.$sender->getSelectedValue()); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.page new file mode 100644 index 00000000..84ce4ef3 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.page @@ -0,0 +1,16 @@ + + +

TActiveRatingList AutoPostBack Test Case

+ + + + + + + + + +
+ +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.php new file mode 100644 index 00000000..4b087b76 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListAutoPostBackTest.php @@ -0,0 +1,27 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListAutoPostBackTest extends TPage{ + public function ratingChanged($sender, $param){ + $this->Status->setText($sender->getRating().' : '.$sender->getSelectedValue()); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.page new file mode 100644 index 00000000..36f4404d --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.page @@ -0,0 +1,12 @@ + + +

TActiveRatingList Check Boxes Test Case

+ + + + + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.php new file mode 100644 index 00000000..5c6dfa70 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListCheckBoxesTest.php @@ -0,0 +1,23 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListCheckBoxesTest extends TPage{ } +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.page new file mode 100644 index 00000000..5f732e0d --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.page @@ -0,0 +1,17 @@ + + +

TActiveRatingList Enabled Test Case

+ + + + + + + + + +
+ + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.php new file mode 100644 index 00000000..0cac7418 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListEnabledTest.php @@ -0,0 +1,37 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListEnabledTest extends TPage{ + public function ratingChanged($sender, $param){ + $this->Status->setText($sender->getRating().' : '.$sender->getSelectedValue()); + } + + public function enable($sender, $param){ + $this->RatingList->setEnabled(true); + $this->Status->setText('Enabled=true'); + } + + public function disable($sender, $param){ + $this->RatingList->setEnabled(false); + $this->Status->setText('Enabled=false'); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.page new file mode 100644 index 00000000..01e47a34 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.page @@ -0,0 +1,14 @@ + + +

TActiveRatingList Hover Caption Test Case

+ + + + + + + + + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.php new file mode 100644 index 00000000..06d82d39 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListHoverCaptionTest.php @@ -0,0 +1,27 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListHoverCaptionTest extends TPage{ + public function ratingChanged($sender, $param){ + $sender->setCaption($sender->getRating().' : '.$sender->getSelectedValue()); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.page new file mode 100644 index 00000000..942a5b45 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.page @@ -0,0 +1,17 @@ + + +

TActiveRatingList Rating Test Case

+ + + + + + + + + +
+ +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.php new file mode 100644 index 00000000..fe5c8404 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListRatingTest.php @@ -0,0 +1,32 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListRatingTest extends TPage{ + public function ratingChanged($sender, $param){ + $this->Status->setText('Rating: '.$sender->getRating()); + } + + public function setRating($sender, $param){ + $this->RatingList->setRating(3); + $this->ratingChanged($this->RatingList, null); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.page new file mode 100644 index 00000000..dad3fd6e --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.page @@ -0,0 +1,17 @@ + + +

TActiveRatingList ReadOnly Test Case

+ + + + + + + + + +
+ + +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.php new file mode 100644 index 00000000..070fd13f --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListReadOnlyTest.php @@ -0,0 +1,38 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListReadOnlyTest extends TPage{ + public function ratingChanged($sender, $param){ + $this->Status->setText($sender->getRating().' : '.$sender->getSelectedValue()); + } + + public function readOnly($sender, $param){ + $this->RatingList->setReadOnly(true); + $this->Status->setText('ReadOnly=true'); + } + + public function writable($sender, $param){ + $this->RatingList->setReadOnly(false); + $this->Status->setText('ReadOnly=false'); + } + +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.page b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.page new file mode 100644 index 00000000..6fb52822 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.page @@ -0,0 +1,17 @@ + + +

TActiveRatingList SelectedIndex Test Case

+ + + + + + + + + +
+ +
\ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.php b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.php new file mode 100644 index 00000000..4dbc6949 --- /dev/null +++ b/tests/FunctionalTests/active-controls/protected/pages/ActiveRatingListSelectedIndexTest.php @@ -0,0 +1,32 @@ + + * @version Creation Date: Oct 13, 2008 + */ + +/** + * TRatingListTest.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 13, 2008 + * + * Modifications: + */ +class ActiveRatingListSelectedIndexTest extends TPage{ + public function ratingChanged($sender, $param){ + $this->Status->setText('SelectedIndex: '.$sender->getSelectedIndex()); + } + + public function setSelectedIndex($sender, $param){ + $this->RatingList->setSelectedIndex(5); + $this->ratingChanged($this->RatingList, null); + } +} +?> \ No newline at end of file diff --git a/tests/FunctionalTests/active-controls/protected/pages/RatingList.page b/tests/FunctionalTests/active-controls/protected/pages/RatingList.page index f9be4aee..ba9c2e5d 100644 --- a/tests/FunctionalTests/active-controls/protected/pages/RatingList.page +++ b/tests/FunctionalTests/active-controls/protected/pages/RatingList.page @@ -3,22 +3,11 @@ diff --git a/tests/FunctionalTests/active-controlstests/ActiveRatingListTestCase.php b/tests/FunctionalTests/active-controlstests/ActiveRatingListTestCase.php new file mode 100644 index 00000000..c6dc50c2 --- /dev/null +++ b/tests/FunctionalTests/active-controlstests/ActiveRatingListTestCase.php @@ -0,0 +1,253 @@ + + * @version Creation Date: Oct 22, 2008 + */ + +/** + * ActiveRatingListTestCase.php class + * + * + * + * Properties + * - + * + * @author Bradley Booms + * @version Modified Date: Oct 22, 2008 + * + * Modifications: + */ +class ActiveRatingListTestCase extends SeleniumTestCase +{ + function testCheckBoxes() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListCheckBoxesTest"); + $this->verifyTextPresent("TActiveRatingList Check Boxes Test Case"); + $this->assertCheckBoxes("RatingList", array(2), 6); + + // Change the list and make sure the radio buttons get updated properly. + $this->clickTD("RatingList_c4"); + $this->pause(800); + $this->assertCheckBoxes("RatingList", array(4), 6); + + $this->clickTD("RatingList_c2"); + $this->pause(800); + $this->assertCheckBoxes("RatingList", array(2), 6); + } + + function testRating() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListRatingTest"); + $this->verifyTextPresent("TActiveRatingList Rating Test Case"); + + // Check the list, make sure it starts out with 5 stars. + $this->assertText("Status", "Rating: 5"); + + // Click on 1 star and make sure the Rating property updates. + $this->clickTD("RatingList_c0"); + $this->pause(800); + $this->assertText("Status", "Rating: 1"); + + // Then set Rating to three on the server side and make sure it's correct. + $this->click("SetRating"); + $this->pause(800); + $this->assertText("Status", "Rating: 3"); + } + + function testSelectedIndex() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListSelectedIndexTest"); + $this->verifyTextPresent("TActiveRatingList SelectedIndex Test Case"); + $this->assertText("Status", " SelectedIndex: 1"); + + // Click on 5 stars and make sure the SelectedIndex property updates. + $this->clickTD("RatingList_c4"); + $this->pause(800); + $this->assertText("Status", " SelectedIndex: 4"); + + // Then set SelectedIndex to 5 on the server side and make sure it's correct. + $this->click("SetSelectedIndex"); + $this->pause(800); + $this->assertText("Status", " SelectedIndex: 5"); + } + + function testAutoPostBack() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListAutoPostBackTest"); + $this->verifyTextPresent("TActiveRatingList AutoPostBack Test Case"); + $this->assertText("Status", "AutoPostback=false"); + + // Make sure that it doesn't auto post when clicked. + $this->clickTD("RatingList_c3"); + $this->pause(800); + $this->assertText("Status", "AutoPostback=false"); + + // Then submit with an active button and make sure it updates. + $this->click("Submit"); + $this->pause(800); + $this->assertText("Status", "4 : Good"); + } + + function testAllowInput() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListAllowInputTest"); + $this->verifyTextPresent("TActiveRatingList AllowInput Test Case"); + $this->assertText("Status", "AllowInput=false"); + $this->assertCheckBoxes("RatingList", array(3), 6); + + // Make sure that clicking doesn't change anything. + $this->clickTD("RatingList_c5"); + $this->pause(800); + $this->assertText("Status", "AllowInput=false"); + $this->assertCheckBoxes("RatingList", array(3), 6); + } + + function testReadOnly() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListReadOnlyTest"); + $this->verifyTextPresent("TActiveRatingList ReadOnly Test Case"); + $this->assertText("Status", "ReadOnly=true"); + $this->assertCheckBoxes("RatingList", array(0), 6); + + $this->clickTD("RatingList_c4"); + $this->pause(800); + $this->assertText("Status", "ReadOnly=true"); + $this->assertCheckBoxes("RatingList", array(0), 6); + + // Then set ReadOnly to false, and make sure it works. + $this->click("Writable"); + $this->pause(800); + $this->assertText("Status", "ReadOnly=false"); + $this->assertCheckBoxes("RatingList", array(0), 6); + + + $this->clickTD("RatingList_c1"); + $this->pause(800); + $this->assertText("Status", "2 : Fair"); + $this->assertCheckBoxes("RatingList", array(1), 6); + + // Then set ReadOnly to true, and make sure it doesn't work anymore. + $this->click("ReadOnly"); + $this->pause(800); + $this->assertText("Status", "ReadOnly=true"); + $this->assertCheckBoxes("RatingList", array(1), 6); + + + $this->clickTD("RatingList_c2"); + $this->pause(800); + $this->assertText("Status", "ReadOnly=true"); + $this->assertCheckBoxes("RatingList", array(1), 6); + } + + function testEnabled() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListEnabledTest"); + $this->verifyTextPresent("TActiveRatingList Enabled Test Case"); + $this->assertText("Status", "Enabled=false"); + $this->assertCheckBoxes("RatingList", array(5), 6); + + $this->clickTD("RatingList_c4"); + $this->pause(800); + $this->assertText("Status", "Enabled=false"); + $this->assertCheckBoxes("RatingList", array(5), 6); + + // Then set Enable to true, and make sure it works. + $this->click("Enable"); + $this->pause(800); + $this->assertText("Status", "Enabled=true"); + $this->assertCheckBoxes("RatingList", array(5), 6); + + + $this->clickTD("RatingList_c3"); + $this->pause(800); + $this->assertText("Status", "4 : Good"); + $this->assertCheckBoxes("RatingList", array(3), 6); + + // Then set Enable to false, and make sure it doesn't work anymore. + $this->click("Disable"); + $this->pause(800); + $this->assertText("Status", "Enabled=false"); + $this->assertCheckBoxes("RatingList", array(3), 6); + + + $this->clickTD("RatingList_c5"); + $this->pause(800); + $this->assertText("Status", "Enabled=false"); + $this->assertCheckBoxes("RatingList", array(3), 6); + } + + function testHoverCaption() + { + // Verify we're on the right page. + $this->open("active-controls/index.php?page=ActiveRatingListHoverCaptionTest"); + $this->verifyTextPresent("TActiveRatingList Hover Caption Test Case"); + $this->assertText("Status", "CaptionID='Status'"); + $this->assertElementPresent("//input[@id='RatingList_c0']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c1']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c2']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c3']/../..[contains(@class, 'rating_half')]"); + $this->assertElementPresent("//input[@id='RatingList_c3']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c4']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c5']/../..[contains(@class, 'rating')]"); + + $this->mouseOver("//input[@id='RatingList_c4']/../../"); + $this->assertText("Status", "Excellent"); + $this->assertElementPresent("//input[@id='RatingList_c0']/../..[contains(@class, 'rating_hover')]"); + $this->assertElementPresent("//input[@id='RatingList_c1']/../..[contains(@class, 'rating_hover')]"); + $this->assertElementPresent("//input[@id='RatingList_c2']/../..[contains(@class, 'rating_hover')]"); + $this->assertElementPresent("//input[@id='RatingList_c3']/../..[contains(@class, 'rating_hover')]"); + $this->assertElementPresent("//input[@id='RatingList_c4']/../..[contains(@class, 'rating_hover')]"); + $this->assertElementNotPresent("//input[@id='RatingList_c5']/../..[contains(@class, 'rating_hover')]"); + $this->assertElementPresent("//input[@id='RatingList_c5']/../..[contains(@class, 'rating')]"); + + $this->mouseOut("//input[@id='RatingList_c4']/../../"); + $this->assertText("Status", "CaptionID='Status'"); + $this->assertElementPresent("//input[@id='RatingList_c0']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c1']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c2']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementNotPresent("//input[@id='RatingList_c3']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c3']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c4']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c5']/../..[contains(@class, 'rating')]"); + + + $this->mouseOver("//input[@id='RatingList_c1']/../../"); + $this->assertText("Status", "Fair"); + + $this->click("//input[@id='RatingList_c1']/../../"); + $this->pause(800); + $this->assertText("Status", "2 : Fair"); + $this->assertElementPresent("//input[@id='RatingList_c0']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c1']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementNotPresent("//input[@id='RatingList_c2']/../..[contains(@class, 'rating_selected')]"); + $this->assertElementPresent("//input[@id='RatingList_c2']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c3']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c4']/../..[contains(@class, 'rating')]"); + $this->assertElementPresent("//input[@id='RatingList_c5']/../..[contains(@class, 'rating')]"); + } + + function clickTD($clientID){ + $this->click("//input[@id='{$clientID}']/../.."); + } + + function assertCheckBoxes($clientID, $checks, $total = 5) + { + for($i = 0; $i < $total; $i++) + { + if(in_array($i, $checks)) + $this->assertChecked("{$clientID}_c{$i}"); + else + $this->assertNotChecked("{$clientID}_c{$i}"); + } + } +} +?> \ No newline at end of file -- cgit v1.2.3