From b7614a9c62f9e6597ea83bdc6901693efb74e68a Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Mon, 21 Apr 2014 12:09:30 +0200 Subject: Fixed #516 , added test case (cherry picked from commit c66097eac2c2691bf0047829275962ec0bf2b41f) --- .../issues/protected/pages/Issue516.page | 50 +++++++++ .../issues/protected/pages/Issue516.php | 115 +++++++++++++++++++++ .../issues/tests/Issue516TestCase.php | 37 +++++++ 3 files changed, 202 insertions(+) create mode 100644 tests/FunctionalTests/issues/protected/pages/Issue516.page create mode 100644 tests/FunctionalTests/issues/protected/pages/Issue516.php create mode 100644 tests/FunctionalTests/issues/tests/Issue516TestCase.php (limited to 'tests/FunctionalTests/issues') diff --git a/tests/FunctionalTests/issues/protected/pages/Issue516.page b/tests/FunctionalTests/issues/protected/pages/Issue516.page new file mode 100644 index 00000000..c922c6e1 --- /dev/null +++ b/tests/FunctionalTests/issues/protected/pages/Issue516.page @@ -0,0 +1,50 @@ + + +

Issue 516 Test

+ + + + + + + + + + + + + + +
+ diff --git a/tests/FunctionalTests/issues/protected/pages/Issue516.php b/tests/FunctionalTests/issues/protected/pages/Issue516.php new file mode 100644 index 00000000..bd3e7a72 --- /dev/null +++ b/tests/FunctionalTests/issues/protected/pages/Issue516.php @@ -0,0 +1,115 @@ +_data===null) + $this->loadData(); + return $this->_data; + } + + protected function loadData() + { + // We use viewstate keep track of data. + // In real applications, data should come from database using an SQL SELECT statement. + // In the following tabular data, field 'ISBN' is the primary key. + // All update and delete operations should come with an 'id' value in order to go through. + if(($this->_data=$this->getViewState('Data',null))===null) + { + $this->_data=array( + array( + 'ISBN'=>'0596007124', + 'title'=>'', + ), + array( + 'ISBN'=>'0201633612', + 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', + ), + array( + 'ISBN'=>'0321247140', + 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', + ), + array( + 'ISBN'=>'0201485672', + 'title'=>'Refactoring: Improving the Design of Existing Code', + ), + array( + 'ISBN'=>'0321213351', + 'title'=>'Refactoring to Patterns', + ), + array( + 'ISBN'=>'0735619670', + 'title'=>'Code Complete', + ), + array( + 'ISBN'=>'0321278658 ', + 'title'=>'Extreme Programming Explained : Embrace Change', + ), + ); + $this->saveData(); + } + } + + protected function saveData() + { + $this->setViewState('Data',$this->_data); + } + + protected function updateBook($isbn,$title) + { + // In real applications, data should be saved to database using an SQL UPDATE statement + if($this->_data===null) + $this->loadData(); + $updateRow=null; + foreach($this->_data as $index=>$row) + if($row['ISBN']===$isbn) + $updateRow=&$this->_data[$index]; + if($updateRow!==null) + { + $updateRow['title']=$title; + $this->saveData(); + } + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack && !$this->IsCallBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } + + public function editItem($sender,$param) + { + $this->DataGrid->EditItemIndex=$param->Item->ItemIndex; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $this->updateBook( + $this->DataGrid->DataKeys[$item->ItemIndex], // ISBN + $item->BookTitleColumn->TextBox->Text // title + ); + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function cancelItem($sender,$param) + { + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + +} diff --git a/tests/FunctionalTests/issues/tests/Issue516TestCase.php b/tests/FunctionalTests/issues/tests/Issue516TestCase.php new file mode 100644 index 00000000..363e9f84 --- /dev/null +++ b/tests/FunctionalTests/issues/tests/Issue516TestCase.php @@ -0,0 +1,37 @@ +url('issues/index.php?page=Issue516'); + $this->assertContains('Issue 516 Test', $this->source()); + $base='ctl0_Content_'; + $row1='DataGrid_ctl1_'; + $row2='DataGrid_ctl2_'; + + // click "edit" and check for textbox + $this->byID("{$base}{$row1}ctl3")->click(); + $this->pause(800); + $this->assertElementPresent("{$base}{$row1}TextBox"); + // click "save" and check for validator + $this->byID("{$base}{$row1}ctl3")->click(); + $this->pause(800); + $this->assertEquals('Please provide a title.', $this->getElement("{$base}{$row1}ctl1")->text()); + // click "cancel" and ensure validator has disappeared + $this->byID("{$base}{$row1}ctl4")->click(); + $this->pause(800); + $this->assertElementNotPresent("{$base}{$row1}ctl1"); + + // click "edit" and check for textbox on the second row + $this->byID("{$base}{$row2}ctl3")->click(); + $this->pause(800); + $this->assertTrue($this->getElement("{$base}{$row2}TextBox")!==null); + // click "save" and ensure bvalidation has been successfull + $this->byID("{$base}{$row2}ctl3")->click(); + $this->pause(800); + $this->assertElementNotPresent("{$base}{$row2}ctl1"); + $this->assertElementNotPresent("{$base}{$row2}TextBox"); + $this->assertEquals('Edit', $this->getElement("{$base}{$row2}ctl3")->text()); + } +} -- cgit v1.2.3