[Weberp-svn] SF.net SVN: weberp:[7198] trunk
Brought to you by:
sotandeka,
tim_schofield
From: <tim...@us...> - 2011-07-28 16:54:56
|
Revision: 7198 http://weberp.svn.sourceforge.net/weberp/?rev=7198&view=rev Author: tim_schofield Date: 2011-07-28 16:54:49 +0000 (Thu, 28 Jul 2011) Log Message: ----------- Improvements to testing suite Modified Paths: -------------- trunk/build/tests/SupplierTest.php trunk/build/tests/classes/URLDetails.class.php trunk/build/tests/includes/SelectModule.php trunk/build/tests/includes/login.php trunk/includes/header.inc Modified: trunk/build/tests/SupplierTest.php =================================================================== --- trunk/build/tests/SupplierTest.php 2011-07-27 21:10:53 UTC (rev 7197) +++ trunk/build/tests/SupplierTest.php 2011-07-28 16:54:49 UTC (rev 7198) @@ -2,7 +2,9 @@ <?php include('includes/config.php'); + include('includes/login.php'); +include('includes/SelectModule.php'); include('includes/validators/XhtmlValidator.php'); include('classes/URLDetails.class.php'); @@ -10,9 +12,11 @@ //Set up the session ID //open connection $ch = curl_init(); +$TestSessionID = sha1(uniqid(mt_rand(), true)); -$IndexPage=webERPLogIn($ch, $RootPath, $CompanyName, $UserName, $Password); - +$IndexPage=webERPLogIn($ch, $TestSessionID, $RootPath, $ServerPath, $CompanyName, $UserName, $Password); +$APPage=FindModule($ch, $RootPath, $ServerPath, $TestSessionID, $IndexPage, 'AP'); +//echo $APPage; curl_close($ch); /* Modified: trunk/build/tests/classes/URLDetails.class.php =================================================================== --- trunk/build/tests/classes/URLDetails.class.php 2011-07-27 21:10:53 UTC (rev 7197) +++ trunk/build/tests/classes/URLDetails.class.php 2011-07-28 16:54:49 UTC (rev 7198) @@ -9,6 +9,8 @@ function __construct($SessionID) { $this->SessionID = $SessionID; + $this->xml = new DOMDocument(); + $this->PostArray=array(); if (!file_exists('/tmp/'.$this->SessionID)) mkdir('/tmp/'.$this->SessionID); } @@ -61,143 +63,133 @@ public function Load($name) { } - private function GetTextDetails($xml) { + private function GetTextDetails() { $Texts=array(); - $result=$xml->xpath('//input'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - if ($key=='type' and $value=='text') { - foreach ($result[$i]->attributes() as $key=>$value) { - $Texts['text'][$j][$key]=(string)$value[0]; - } - $j++; + $result=$this->xml->getElementsByTagName('input'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + if ($result->item($i)->getAttribute('type')=='text') { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; +// echo $name.' '.$result->item($i)->attributes->getNamedItem($name)->nodeValue . "\n"; + $Texts['text'][$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; } + $k++; } } return $Texts; } - private function GetSubmitDetails($xml) { + private function GetSubmitDetails() { $Submits=array(); - $result=$xml->xpath('//input'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - if ($key=='type' and $value=='submit') { - foreach ($result[$i]->attributes() as $key=>$value) { - $Submits['submit'][$j][$key]=(string)$value[0]; - } - $j++; + $result=$this->xml->getElementsByTagName('input'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + if ($result->item($i)->getAttribute('type')=='submit') { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; + $Submits['submit'][$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; } + $k++; } } return $Submits; } - private function GetRadioDetails($xml) { + private function GetRadioDetails() { $Radios=array(); - $result=$xml->xpath('//input'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - if ($key=='type' and $value=='radio') { - foreach ($result[$i]->attributes() as $key=>$value) { - $Radios['radio'][$j][$key]=(string)$value[0]; - } - $j++; + $result=$this->xml->getElementsByTagName('input'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + if ($result->item($i)->getAttribute('type')=='radio') { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; + $Radios['radio'][$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; } + $k++; } } return $Radios; } - private function GetCheckBoxDetails($xml) { + private function GetCheckBoxDetails() { $CheckBoxs=array(); - $result=$xml->xpath('//input'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - if ($key=='type' and $value=='checkbox') { - foreach ($result[$i]->attributes() as $key=>$value) { - $CheckBoxs['checkbox'][$j][$key]=(string)$value[0]; - } - $j++; + $result=$this->xml->getElementsByTagName('input'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + if ($result->item($i)->getAttribute('type')=='checkbox') { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; + $CheckBoxs['checkbox'][$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; } + $k++; } } return $CheckBoxs; } - private function GetHiddenDetails($xml) { + private function GetHiddenDetails() { $Hiddens=array(); - $result=$xml->xpath('//input'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - if ($key=='type' and $value=='hidden') { - foreach ($result[$i]->attributes() as $key=>$value) { - $Hiddens['hidden'][$j][$key]=(string)$value[0]; - } - $j++; + $result=$this->xml->getElementsByTagName('input'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + if ($result->item($i)->getAttribute('type')=='hidden') { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; + $Hiddens['hidden'][$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; } + $k++; } } return $Hiddens; } - private function GetHREFDetails($xml) { - $Links=array(); - print_r($xml); - $result=$xml->xpath('//title'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - echo $key.' '.$value."\n"; - foreach ($result[$i]->attributes() as $key=>$value) { - $Links['a'][$j][$key]=(string)$value[0]; - } - } - } - return $Links; - } - - private function GetPasswordDetails($xml) { + private function GetPasswordDetails() { $Passwords=array(); - $result=$xml->xpath('//input'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - if ($key=='type' and $value=='password') { - foreach ($result[$i]->attributes() as $key=>$value) { - $Passwords['password'][$j][$key]=(string)$value[0]; - } - $j++; + $result=$this->xml->getElementsByTagName('input'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + if ($result->item($i)->getAttribute('type')=='password') { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; + $Passwords['password'][$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; } + $k++; } } return $Passwords; } - private function GetSelectDetails($xml) { + private function GetSelectDetails() { $Selects=array(); - $result=$xml->xpath('//select'); - $j = 0; - for ($i=0; $i<sizeOf($result); $i++) { - foreach ($result[$i]->attributes() as $key=>$value) { - $result1=$value->xpath('//option'); - $name=(string)$value; - for ($k=0; $k<sizeOf($result1); $k++) { - foreach ($result1[$j]->attributes() as $key=>$value) { - $Selects['select'][$name]['options'][$j][$key]=(string)$value; + $result=$this->xml->getElementsByTagName('select'); + for ($i=0; $i<$result->length; $i++) { + $SelectName=$result->item($i)->getAttribute('name'); + $result1=$result->item($i)->getElementsByTagName('option'); + for ($j=0; $j<$result1->length; $j++) { + for ($k=0; $k<$result1->item($j)->attributes->length; $k++) { + $name = $result1->item($j)->attributes->item($k)->name; + $Selects['select'][$SelectName]['options'][$j][$name]=(string)$result1->item($j)->attributes->getNamedItem($name)->nodeValue; } - $j++; - } } } return $Selects; } + private function GetHREFDetails() { + $Links=array(); + $result=$this->xml->getElementsByTagName('a'); + $k=0; + for ($i=0; $i<$result->length; $i++) { + for ($j=0; $j<$result->item($i)->attributes->length; $j++) { + $name = $result->item($i)->attributes->item($j)->name; + $Links[$k][$name]=(string)$result->item($i)->attributes->getNamedItem($name)->nodeValue; + } + $k++; + } + return $Links; + } + public function GetFormDetails() { $this->FormDetails['Texts']=$this->GetTextDetails($this->xml); $this->FormDetails['Passwords']=$this->GetPasswordDetails($this->xml); @@ -212,10 +204,20 @@ return $result; } - private function ValidateLink($html) { + private function ValidateLinks($ServerPath, $ch) { + for ($i=0; $i<sizeOf($this->Links); $i++) { + curl_setopt($ch,CURLOPT_URL,$ServerPath.$this->Links[$i]['href']); + curl_setopt($ch,CURLOPT_RETURNTRANSFER,True); + curl_setopt($ch,CURLOPT_COOKIEJAR,'/tmp/'.$this->SessionID.'/curl.txt'); + $result = curl_exec($ch); + $response = curl_getinfo( $ch ); + if ($response['http_code']!=200) { + error_log($i.' '.$this->Links[$i]['href'].' '.$response['http_code']."\n", 3, '/home/tim/weberp'.$this->SessionID.'.log'); + } + } } - public function FetchPage($RootPath, $ch) { + public function FetchPage($RootPath, $ServerPath, $ch) { //url-ify the data for the POST $fields_string=''; foreach($this->GetPostArray() as $key=>$value) { @@ -233,11 +235,16 @@ //execute post $result = curl_exec($ch); - $this->xml = simplexml_load_string($result); + $this->xml->loadHTML($result); $answer = $this->ValidateHTML($result); - $this->GetHREFDetails($this->xml); + + $this->Links=$this->GetHREFDetails(); + $this->ValidateLinks($ServerPath, $ch); + $this->GetFormDetails(); + return $result; + } } Modified: trunk/build/tests/includes/SelectModule.php =================================================================== --- trunk/build/tests/includes/SelectModule.php 2011-07-27 21:10:53 UTC (rev 7197) +++ trunk/build/tests/includes/SelectModule.php 2011-07-28 16:54:49 UTC (rev 7198) @@ -1,8 +1,12 @@ <?php -$ModuleID=mb_substr(mb_strstr($result, $ModuleName, true),-4,2); -$url=$RootPath.'index.php?Application='.$ModuleID; +function FindModule($ch, $RootPath, $ServerPath, $TestSessionID, $IndexPage, $Module) { + $SelectedModuleScreen = new URLDetails($TestSessionID); + $SelectedModuleScreen->SetURL('index.php?Application='.$Module); -include('GetURL.php'); + $ModulePage=$SelectedModuleScreen->FetchPage($RootPath, $ServerPath, $ch); + return $ModulePage; +} + ?> \ No newline at end of file Modified: trunk/build/tests/includes/login.php =================================================================== --- trunk/build/tests/includes/login.php 2011-07-27 21:10:53 UTC (rev 7197) +++ trunk/build/tests/includes/login.php 2011-07-28 16:54:49 UTC (rev 7198) @@ -1,13 +1,12 @@ <?php -function webERPLogIn($ch, $RootPath, $Company, $UserName, $Password) { - $TestSessionID = sha1(uniqid(mt_rand(), true)); +function webERPLogIn($ch, $TestSessionID, $RootPath, $ServerPath, $Company, $UserName, $Password) { $LoginScreenDetails = new URLDetails($TestSessionID); $LoginScreenDetails->SetURL('index.php'); $LoginScreenDetails->SetPostArray(array()); - $LoginScreenDetails->FetchPage($RootPath, $ch); + $LoginScreenDetails->FetchPage($RootPath, $ServerPath, $ch); for ($i=0; $i<sizeOf($LoginScreenDetails->FormDetails['Selects']['select']['CompanyNameField']['options']); $i++) { if ($LoginScreenDetails->FormDetails['Selects']['select']['CompanyNameField']['options'][$i]['label']==$Company) { @@ -44,13 +43,17 @@ } } + $LoginScreenDetails->__destruct(); + $IndexScreenDetails = new URLDetails($TestSessionID); $IndexScreenDetails->SetURL('index.php'); $IndexScreenDetails->SetPostArray($PostArray); - $IndexScreenDetails->FetchPage($RootPath, $ch); + $IndexPage=$IndexScreenDetails->FetchPage($RootPath, $ServerPath, $ch); - return $IndexScreenDetails; + $IndexScreenDetails->__destruct(); + + return $IndexPage; } ?> \ No newline at end of file Modified: trunk/includes/header.inc =================================================================== --- trunk/includes/header.inc 2011-07-27 21:10:53 UTC (rev 7197) +++ trunk/includes/header.inc 2011-07-28 16:54:49 UTC (rev 7198) @@ -6,7 +6,7 @@ // $rootpath // $title - should be defined in the page this file is included with - $StrictXHTML=True; + $StrictXHTML=False; if (!headers_sent()){ if ($StrictXHTML) { @@ -41,8 +41,8 @@ echo '<tr>'; echo '<td align="left" style="width:100%;" class="quick_menu_left">'; // Use icons for company and user data, saves screen realestate, use ALT tag in case theme icon not avail. - echo '<img src="'.$rootpath.'/css/'.$theme.'/images/company.png" title="' . _('Company') . '" ALT="' . _('Company') . '"></img>'; - echo ' ' . stripslashes($_SESSION['CompanyRecord']['coyname']) . ' <a href="' . $rootpath . '/UserSettings.php"><img src="'.$rootpath.'/css/'.$theme.'/images/user.png" TITLE="User" ALT="' . _('User') . '"> </img>' . stripslashes($_SESSION['UsersRealName']) . '</a>'; + echo '<img src="'.$rootpath.'/css/'.$theme.'/images/company.png" title="' . _('Company') . '" ALT="' . _('Company') . '" />'; + echo ' ' . stripslashes($_SESSION['CompanyRecord']['coyname']) . ' <a href="' . $rootpath . '/UserSettings.php"><img src="'.$rootpath.'/css/'.$theme.'/images/user.png" TITLE="User" ALT="' . _('User') . '" /> ' . stripslashes($_SESSION['UsersRealName']) . '</a>'; // Make the title text a class, can be set to display:none is some themes echo '<br /><font class="header_title"> ' . $title . '</font></td>'; echo '<td class="quick_menu_tabs">'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |