34 require_once (
'TestEnvironment.php');
35 require_once (
'commonTestFuncs.php');
57 protected $User = NULL;
58 private $Password = NULL;
61 public function getBrowser() {
62 return ($this->mybrowser);
64 public function getCookie() {
65 return ($this->cookie);
67 public function getPassword() {
68 return ($this->Password);
70 public function getUser() {
73 public function setBrowser($browser) {
74 return ($this->mybrowser = $browser);
76 public function setmyCookie($cookie) {
77 return ($this->cookie = $cookie);
79 public function setPassword($password) {
80 return ($this->Password = $password);
82 public function setUser($user) {
83 return ($this->User = $user);
111 if(is_object($this->mybrowser)) {
112 return($this->mybrowser);
115 $browser =
new SimpleBrowser();
116 if(is_object($browser)) {
117 $this->setBrowser($browser);
120 $this->fail(
"FAIL! Login() internal failure did not get a browser object\n");
123 return($this->mybrowser);
140 if ($parent ==
'root') { $parent = null; }
143 $name =
'Testing-' . $pid;
145 $page = $this->mybrowser->get($URL);
146 $this->createFolder($parent, $name, null);
162 if(empty($folderName)) {
165 else if (empty($page)) {
168 else if (empty($selectName)) {
177 if(($folderName ==
'root') || ($folderName == 1)) {
181 if(empty($FolderId)) {
200 if(empty($uploadName)) {
203 else if (empty($page)) {
206 else if (empty($selectName)) {
210 if(empty($UploadId)) {
225 public function Login($User=NULL, $Password=NULL)
233 $this->setUser($User);
234 $this->setPassword($Password);
238 $this->setUser($USER);
239 $this->setPassword($PASSWORD);
243 $page = $this->mybrowser->get($URL);
244 $this->assertTrue($page,
"Login FAILED! did not fetch a web page, can't login\n'");
245 $cookie = $this->_repoDBlogin($this->mybrowser);
246 $this->setmyCookie($cookie);
247 $host = getHost($URL);
248 $this->mybrowser->setCookie(
'Login', $cookie, $host);
250 $url = $this->mybrowser->getUrl();
251 $page = $this->mybrowser->getContent($url);
269 $this->setUser($User);
276 $url = $this->mybrowser->getUrl();
277 $loggedIn = $this->mybrowser->get($URL);
284 $page = $this->mybrowser->get(
"$URL?mod=auth");
285 $page = $this->mybrowser->clickLink(
'logout');
286 $host = getHost($URL);
287 $clearCookie = $this->mybrowser->setCookie(
'Login',
'', $host);
288 $page = $this->mybrowser->get(
"$URL?mod=Default");
292 if($this->myassertText($page,
"/This login uses HTTP/") !== TRUE) {
294 $this->fail(
"FAIL! Did not find string 'This login uses HTTP', Is user logged out?\n");
296 $this->setUser(NULL);
297 $this->setPassword(NULL);
303 private function _repoDBlogin($browser = NULL) {
305 if (is_null($browser))
317 $host = getHost($URL);
318 $this->assertTrue(is_object($this->mybrowser));
319 $this->mybrowser->useCookies();
320 $cookieValue = $this->mybrowser->getCookieValue($host,
'/',
'Login');
321 $this->mybrowser->setCookie(
'Login', $cookieValue, $host);
322 $page = $this->mybrowser->get(
"$URL?mod=auth&nopopup=1");
323 $this->assertTrue($page);
326 if(!strlen($this->User)) {
327 $this->setUser($USER);
332 $this->assertTrue($this->mybrowser->setField(
'username', $this->User),
333 "Fatal! could not set username field in login form for $this->User\n");
334 $this->assertTrue($this->mybrowser->setField(
'password', $this->Password),
335 "Fatal! could not set password field in login form for $this->User\n");
336 $this->assertTrue($this->mybrowser->isSubmit(
'Login'));
337 $page = $this->mybrowser->clickSubmit(
'Login');
338 $this->assertTrue($page,
"FATAL! did not get a valid page back from Login\n");
340 $page = $this->mybrowser->get(
"$URL?mod=Default");
343 $this->assertTrue($this->myassertText($page,
"/User:<\/small>\s$this->User/"),
344 "Did not find User:<\/small> $this->User\nThe User may not be logged in\n");
345 $this->mybrowser->setCookie(
'Login', $cookieValue, $host);
346 $page = $this->mybrowser->getContent();
347 $NumMatches = preg_match(
'/User Logged Out/', $page, $matches);
348 $this->assertFalse($NumMatches,
"User Logged out!, Login Failed! %s");
349 return ($cookieValue);
352 public function myassertText($page, $pattern) {
353 $NumMatches = preg_match($pattern, $page, $matches);
379 if(empty($selectName)) {
382 $hpage =
new DOMDocument();
383 @$hpage->loadHTML($page);
385 $selectList = $hpage->getElementsByTagName(
'select');
386 $optionList = $hpage->getElementsByTagName(
'option');
391 for($i=0; $i < $selectList->length; $i++) {
392 $ChildList = $selectList->item($i)->childNodes;
393 foreach($ChildList as $child) {
394 $optionValue = $child->getAttribute(
'value');
395 $orig = $child->nodeValue;
400 $he = htmlentities($orig);
401 $htmlGone = preg_replace(
'/&.*?;/',
'',$he);
402 $cleanText =
trim($htmlGone);
403 if(!empty($optionText)) {
404 $noDotOptText = escapeDots($optionText);
405 $match = preg_match(
"/^$noDotOptText$/", $cleanText, $matches);
409 $Selects[$selectList->item($i)->getAttribute(
'name')][$matches[0]] = $optionValue;
418 $Selects[$selectList->item($i)->getAttribute(
'name')][$cleanText] = $optionValue;
419 $foo = $selectList->item($i)->getAttribute(
'onload');
428 if (empty($Selects)) {
433 if (!is_null($optionText)) {
434 if(array_key_exists($optionText,$Selects[$selectName])){
435 return($Selects[$selectName][$optionText]);
442 if(array_key_exists($selectName,$Selects)){
443 return($Selects[$selectName]);
475 $last = exec(
'fossjobs -u',$uploadList, $rtn);
476 foreach ($uploadList as $upload) {
481 list($upId, $file) = split(
' ', $upload);
486 $uploadId = rtrim($upId,
':');
487 $Uploads[$uploadId] = $file;
491 $LastUploads[$file] = $uploadId;
493 $lastUp = &$LastUploads;
494 $sorted = arsort($lastUp);
502 return($LastUploads);
522 'buckets' =>
'Check_agent_bucket',
523 'copyright' =>
'Check_agent_copyright',
524 'mimetype' =>
'Check_agent_mimetype',
525 'nomos' =>
'Check_agent_nomos',
526 'package' =>
'Check_agent_pkgagent',
529 if (is_null($agents)) {
533 if (0 === strcasecmp($agents,
'all')) {
534 foreach ($agentList as $agent => $name) {
536 print
"SA: setting agents for 'all', agent name is:$name\n";
538 $this->assertTrue($this->mybrowser->setField($name, 1));
546 $numberList = explode(
',', $agents);
547 $numAgents = count($numberList);
549 if ($numAgents = 0) {
553 foreach ($numberList as $number) {
556 $checklist[] = $agentList[
'buckets'];
559 $checklist[] = $agentList[
'copyright'];
562 $checklist[] = $agentList[
'mimetype'];
565 $checklist[] = $agentList[
'nomos'];
568 $checklist[] = $agentList[
'package'];
571 $checklist[] = $agentList[
'specagent'];
574 $checklist[] = $agentList[
'license'];
579 if ($this->
debug == 1) {
580 print
"the agent list is:\n";
583 foreach ($checklist as $agent) {
585 print
"DEBUG: $agent\n";
587 $this->assertTrue($this->mybrowser->setField($agent, 1));
610 if(empty($selectName)) {
613 $hpage =
new DOMDocument();
614 @$hpage->loadHTML($page);
616 $selectList = $hpage->getElementsByTagName(
'select');
623 for($i=0; $i < $selectList->length; $i++) {
624 $sname = $selectList->item($i)->getAttribute(
'name');
625 if($sname == $selectName) {
627 $onload = $selectList->item($i)->getAttribute(
'onload');
628 $onchange = $selectList->item($i)->getAttribute(
'onchange');
629 $id = $selectList->item($i)->getAttribute(
'id');
630 $select[$sname] = array (
'onload' => $onload,
631 'onchange' => $onchange,
654 protected function setSelectAttr($page, $selectName, $attribute, $value=NULL){
659 if(empty($selectName)) {
662 if(empty($attribute)) {
665 $hpage =
new DOMDocument();
666 @$hpage->loadHTML($page);
668 $selectList = $hpage->getElementsByTagName(
'select');
674 for($i=0; $i < $selectList->length; $i++) {
675 $sname = $selectList->item($i)->getAttribute(
'name');
676 if($sname == $selectName) {
677 $oldValue= $selectList->item($i)->getAttribute($attribute);
680 $node = $selectList->item($i)->setAttribute($attribute,$value);
685 $setValue= $selectList->item($i)->getAttribute($attribute);
686 if($setValue != $value) {
706 return(substr($page,-1536));
getUploadId($uploadName, $page, $selectName)
parseSelectStmnt($page, $selectName, $optionText=NULL)
getSelectAttr($page, $selectName)
getFolderId($folderName, $page, $selectName)
createTestFolder($name, $parent='root')
list_t type structure used to keep various lists. (e.g. there are multiple lists).
setSelectAttr($page, $selectName, $attribute, $value=NULL)
Login($User=NULL, $Password=NULL)
char * trim(char *ptext)
Trimming whitespace.