23 require_once (
'TestEnvironment.php');
24 require_once (
'commonTestFuncs.php');
46 protected $User = NULL;
47 private $Password = NULL;
50 public function getBrowser() {
51 return ($this->mybrowser);
53 public function getCookie() {
54 return ($this->cookie);
56 public function getPassword() {
57 return ($this->Password);
59 public function getUser() {
62 public function setBrowser($browser) {
63 return ($this->mybrowser = $browser);
65 public function setmyCookie($cookie) {
66 return ($this->cookie = $cookie);
68 public function setPassword($password) {
69 return ($this->Password = $password);
71 public function setUser($user) {
72 return ($this->User = $user);
100 if(is_object($this->mybrowser)) {
101 return($this->mybrowser);
104 $browser =
new SimpleBrowser();
105 if(is_object($browser)) {
106 $this->setBrowser($browser);
109 $this->fail(
"FAIL! Login() internal failure did not get a browser object\n");
112 return($this->mybrowser);
129 if ($parent ==
'root') { $parent =
null; }
132 $name =
'Testing-' . $pid;
134 $page = $this->mybrowser->get($URL);
135 $this->createFolder($parent, $name,
null);
151 if(empty($folderName)) {
154 else if (empty($page)) {
157 else if (empty($selectName)) {
166 if(($folderName ==
'root') || ($folderName == 1)) {
170 if(empty($FolderId)) {
189 if(empty($uploadName)) {
192 else if (empty($page)) {
195 else if (empty($selectName)) {
199 if(empty($UploadId)) {
214 public function Login($User=NULL, $Password=NULL)
222 $this->setUser($User);
223 $this->setPassword($Password);
227 $this->setUser($USER);
228 $this->setPassword($PASSWORD);
232 $page = $this->mybrowser->get($URL);
233 $this->assertTrue($page,
"Login FAILED! did not fetch a web page, can't login\n'");
234 $cookie = $this->_repoDBlogin($this->mybrowser);
235 $this->setmyCookie($cookie);
236 $host = getHost($URL);
237 $this->mybrowser->setCookie(
'Login', $cookie, $host);
239 $url = $this->mybrowser->getUrl();
240 $page = $this->mybrowser->getContent($url);
258 $this->setUser($User);
265 $url = $this->mybrowser->getUrl();
266 $loggedIn = $this->mybrowser->get($URL);
273 $page = $this->mybrowser->get(
"$URL?mod=auth");
274 $page = $this->mybrowser->clickLink(
'logout');
275 $host = getHost($URL);
276 $clearCookie = $this->mybrowser->setCookie(
'Login',
'', $host);
277 $page = $this->mybrowser->get(
"$URL?mod=Default");
281 if($this->myassertText($page,
"/This login uses HTTP/") !== TRUE) {
283 $this->fail(
"FAIL! Did not find string 'This login uses HTTP', Is user logged out?\n");
285 $this->setUser(NULL);
286 $this->setPassword(NULL);
292 private function _repoDBlogin($browser = NULL) {
294 if (is_null($browser))
306 $host = getHost($URL);
307 $this->assertTrue(is_object($this->mybrowser));
308 $this->mybrowser->useCookies();
309 $cookieValue = $this->mybrowser->getCookieValue($host,
'/',
'Login');
310 $this->mybrowser->setCookie(
'Login', $cookieValue, $host);
311 $page = $this->mybrowser->get(
"$URL?mod=auth&nopopup=1");
312 $this->assertTrue($page);
315 if(!strlen($this->User)) {
316 $this->setUser($USER);
321 $this->assertTrue($this->mybrowser->setField(
'username', $this->User),
322 "Fatal! could not set username field in login form for $this->User\n");
323 $this->assertTrue($this->mybrowser->setField(
'password', $this->Password),
324 "Fatal! could not set password field in login form for $this->User\n");
325 $this->assertTrue($this->mybrowser->isSubmit(
'Login'));
326 $page = $this->mybrowser->clickSubmit(
'Login');
327 $this->assertTrue($page,
"FATAL! did not get a valid page back from Login\n");
329 $page = $this->mybrowser->get(
"$URL?mod=Default");
332 $this->assertTrue($this->myassertText($page,
"/User:<\/small>\s$this->User/"),
333 "Did not find User:<\/small> $this->User\nThe User may not be logged in\n");
334 $this->mybrowser->setCookie(
'Login', $cookieValue, $host);
335 $page = $this->mybrowser->getContent();
336 $NumMatches = preg_match(
'/User Logged Out/', $page, $matches);
337 $this->assertFalse($NumMatches,
"User Logged out!, Login Failed! %s");
338 return ($cookieValue);
341 public function myassertText($page, $pattern) {
342 $NumMatches = preg_match($pattern, $page, $matches);
368 if(empty($selectName)) {
371 $hpage =
new DOMDocument();
372 @$hpage->loadHTML($page);
374 $selectList = $hpage->getElementsByTagName(
'select');
375 $optionList = $hpage->getElementsByTagName(
'option');
380 for($i=0; $i < $selectList->length; $i++) {
381 $ChildList = $selectList->item($i)->childNodes;
382 foreach($ChildList as $child) {
383 $optionValue = $child->getAttribute(
'value');
384 $orig = $child->nodeValue;
389 $he = htmlentities($orig);
390 $htmlGone = preg_replace(
'/&.*?;/',
'',$he);
391 $cleanText =
trim($htmlGone);
392 if(!empty($optionText)) {
393 $noDotOptText = escapeDots($optionText);
394 $match = preg_match(
"/^$noDotOptText$/", $cleanText, $matches);
398 $Selects[$selectList->item($i)->getAttribute(
'name')][$matches[0]] = $optionValue;
407 $Selects[$selectList->item($i)->getAttribute(
'name')][$cleanText] = $optionValue;
408 $foo = $selectList->item($i)->getAttribute(
'onload');
417 if (empty($Selects)) {
422 if (!is_null($optionText)) {
423 if(array_key_exists($optionText,$Selects[$selectName])){
424 return($Selects[$selectName][$optionText]);
431 if(array_key_exists($selectName,$Selects)){
432 return($Selects[$selectName]);
464 $last = exec(
'fossjobs -u',$uploadList, $rtn);
465 foreach ($uploadList as $upload) {
470 list($upId, $file) = explode(
' ', $upload);
475 $uploadId = rtrim($upId,
':');
476 $Uploads[$uploadId] = $file;
480 $LastUploads[$file] = $uploadId;
482 $lastUp = &$LastUploads;
483 $sorted = arsort($lastUp);
491 return($LastUploads);
511 'buckets' =>
'Check_agent_bucket',
512 'copyright' =>
'Check_agent_copyright',
513 'mimetype' =>
'Check_agent_mimetype',
514 'nomos' =>
'Check_agent_nomos',
515 'package' =>
'Check_agent_pkgagent',
518 if (is_null($agents)) {
522 if (0 === strcasecmp($agents,
'all')) {
523 foreach ($agentList as $agent => $name) {
525 print
"SA: setting agents for 'all', agent name is:$name\n";
527 $this->assertTrue($this->mybrowser->setField($name, 1));
535 $numberList = explode(
',', $agents);
536 $numAgents = count($numberList);
538 if ($numAgents = 0) {
542 foreach ($numberList as $number) {
545 $checklist[] = $agentList[
'buckets'];
548 $checklist[] = $agentList[
'copyright'];
551 $checklist[] = $agentList[
'mimetype'];
554 $checklist[] = $agentList[
'nomos'];
557 $checklist[] = $agentList[
'package'];
560 $checklist[] = $agentList[
'specagent'];
563 $checklist[] = $agentList[
'license'];
568 if ($this->
debug == 1) {
569 print
"the agent list is:\n";
572 foreach ($checklist as $agent) {
574 print
"DEBUG: $agent\n";
576 $this->assertTrue($this->mybrowser->setField($agent, 1));
599 if(empty($selectName)) {
602 $hpage =
new DOMDocument();
603 @$hpage->loadHTML($page);
605 $selectList = $hpage->getElementsByTagName(
'select');
612 for($i=0; $i < $selectList->length; $i++) {
613 $sname = $selectList->item($i)->getAttribute(
'name');
614 if($sname == $selectName) {
616 $onload = $selectList->item($i)->getAttribute(
'onload');
617 $onchange = $selectList->item($i)->getAttribute(
'onchange');
618 $id = $selectList->item($i)->getAttribute(
'id');
619 $select[$sname] = array (
'onload' => $onload,
620 'onchange' => $onchange,
643 protected function setSelectAttr($page, $selectName, $attribute, $value=NULL){
648 if(empty($selectName)) {
651 if(empty($attribute)) {
654 $hpage =
new DOMDocument();
655 @$hpage->loadHTML($page);
657 $selectList = $hpage->getElementsByTagName(
'select');
663 for($i=0; $i < $selectList->length; $i++) {
664 $sname = $selectList->item($i)->getAttribute(
'name');
665 if($sname == $selectName) {
666 $oldValue= $selectList->item($i)->getAttribute($attribute);
669 $node = $selectList->item($i)->setAttribute($attribute,$value);
674 $setValue= $selectList->item($i)->getAttribute($attribute);
675 if($setValue != $value) {
695 return(substr($page,-1536));
getUploadId($uploadName, $page, $selectName)
setSelectAttr($page, $selectName, $attribute, $value=NULL)
createTestFolder($name, $parent='root')
getFolderId($folderName, $page, $selectName)
parseSelectStmnt($page, $selectName, $optionText=NULL)
Login($User=NULL, $Password=NULL)
getSelectAttr($page, $selectName)
char * trim(char *ptext)
Trimming whitespace.
list_t type structure used to keep various lists. (e.g. there are multiple lists).