FOSSology  4.4.0
Open Source License Compliance by Open Source Software
bsam-verifyFossDirsOnly.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
16 require_once('../../../tests/fossologyTestCase.php');
17 require_once('../../../tests/commonTestFuncs.php');
18 require_once('../../../tests/TestEnvironment.php');
19 require_once('../../../tests/testClasses/parseBrowseMenu.php');
20 require_once('../../../tests/testClasses/parseMiniMenu.php');
21 require_once('../../../tests/testClasses/parseFolderPath.php');
22 require_once('../../../tests/testClasses/parseLicenseTbl.php');
23 require_once('../../../tests/testClasses/parseLicenseTblDirs.php');
24 
25 global $URL;
26 
32 {
33  public $mybrowser;
34  public $host;
35 
36  function setUp()
37  {
38  /*
39  * This test requires that the fossology test archive has been
40  * loaded under the name fossDirsOnly.tar.bz2
41  */
42  global $URL;
43  global $name;
44  global $safeName;
45 
46  print "starting verifyFossDirsOnly-SetUp\n";
47  $name = 'fossDirsOnly.tar.bz2';
48  $safeName = escapeDots($name);
49  $this->host = getHost($URL);
50  $this->Login();
51 
52  /* check for existense of archive */
53  $page = $this->mybrowser->get($URL);
54  $page = $this->mybrowser->clickLink('Browse');
55  $this->assertTrue($this->myassertText($page, '/Browse/'),
56  "verifyDirsOnly FAILED! Could not find Browse menu\n");
57  $result = $this->myassertText($page, "/$safeName/");
58  if(!($result)) {
59  $this->fail("Failure, cannot find archive $name, Stopping test\n");
60  exit(1);
61  }
62  }
63 
64  function testVerifyFossology()
65  {
66  global $URL;
67  global $name;
68  global $safeName;
69 
70  print "starting verifyFossDirsOnly test\n";
71  $page = $this->mybrowser->clickLink('Browse');
72  $this->assertTrue($this->myassertText($page, '/Browse/'),
73  "verifyFossDirsOnly FAILED! Could not find Browse menu\n");
74  //print "************ Page after upload link *************\n$page\n";
75  $this->assertTrue($this->myassertText($page, "/$safeName/"),
76  "verifyFossDirsOnly FAILED! did not find $name\n");
77  $this->assertTrue($this->myassertText($page, "/>View</"),
78  "verifyFossDirsOnly FAILED! >View< not found\n");
79  $this->assertTrue($this->myassertText($page, "/>Meta</"),
80  "verifyFossDirsOnly FAILED! >Meta< not found\n");
81  $this->assertTrue($this->myassertText($page, "/>Download</"),
82  "verifyFossDirsOnly FAILED! >Download< not found\n");
83 
84  /* Select archive */
85  $page = $this->mybrowser->clickLink($name);
86  //print "************ Page after select foss archive *************\n$page\n";
87  $this->assertTrue($this->myassertText($page, "/empty\//"),
88  "verifyFossDirsOnly FAILED! 'empty/' not found\n");
89  $this->assertTrue($this->myassertText($page, "/1 item/"),
90  "verifyFossDirsOnly FAILED! '1 item' not found\n");
91 
92  /* Select empty link */
93  $page = $this->mybrowser->clickLink('empty/');
94 
95  /* need to check that there are 9 items */
96  $this->assertTrue($this->myassertText($page, "/9 items/"),
97  "verifyFossDirsOnly FAILED! '9 items' not found\n");
98  $this->assertTrue($this->myassertText($page, "/agents/"),
99  "verifyFossDirsOnly FAILED! did not find 'agents' directory\n");
100  $this->assertTrue($this->myassertText($page, "/scheduler/"),
101  "verifyFossDirsOnly FAILED! did not find scheduler directory\n");
102 
103  /* Select the License link to View License Historgram */
104  $browse = new parseBrowseMenu($page);
105  $mini = new parseMiniMenu($page);
106  $miniMenu = $mini->parseMiniMenu();
107  $url = makeUrl($this->host, $miniMenu['License']);
108  if($url === NULL) { $this->fail("verifyFossDirsOnly Failed, host is not set"); }
109 
110  $page = $this->mybrowser->get($url);
111  //print "page after get of $url is:\n$page\n";
112  $this->assertTrue($this->myassertText($page, '/License Browser/'),
113  "verifyFossDirsOnly FAILED! License Browser Title not found\n");
114  $this->assertTrue($this->myassertText($page, '/Total licenses: 0/'),
115  "verifyFossDirsOnly FAILED! Total Licenses does not equal 0\n");
116 
117  $dList = new parseLicenseTblDirs($page);
118  $dirList = $dList->parseLicenseTblDirs();
119  //print "dirList is:\n"; print_r($dirList) . "\n";
120  /*
121  * the directiory agents has 13 subdirectories all other directories
122  * are empty. we are going to loop through them, but for now just
123  * test a few of them out....
124  */
125  $url = makeUrl($this->host, $dirList['scheduler/']);
126  $page = $this->mybrowser->get($url);
127  //print "page after scheduler is:\n$page\n";
128  $fList = new parseFolderPath($page, $url);
129  $dirCnt = $fList->countFiles();
130  // should only get one folder path)
131  $this->assertEqual((int)$dirCnt, 1,
132  "verifyFossDirsOnly FAILED! did not get 1 folder path back, got $dirCnt instead\n");
133  // every entry but the last must have a non-null value (we assume parse
134  // routine worked)
135  $fpaths = $fList->parseFolderPath();
136  $this->assertTrue($this->check4Links($fpaths),
137  "verifyFossDirsOnly FAILED! something wrong with folder path\n" .
138  "See this url:\n$url\n");
139  }
152  function check4Links($folderPath)
153  {
154  $flistSize = count($folderPath[0]);
155  foreach($folderPath as $flist)
156  {
157  $i = 0;
158  foreach($flist as $folder => $link)
159  {
160  $i++;
161  // is it the last entry?
162  if ($i == $flistSize)
163  {
164  $this->assertTrue(is_null($link),
165  "verifyFossDirsOnly FAILED! Last entry is not null\n$folder $link\n");
166  continue;
167  }
168  $this->assertFalse(is_null($link),
169  "verifyFossDirsOnly FAILED! Found a folder with no link\n$folder $link\n");
170  }
171  }
172  return(TRUE);
173  }
174 }
Login($User=NULL, $Password=NULL)