FOSSology  4.4.0
Open Source License Compliance by Open Source Software
verifyFossDirsOnly.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008 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/parseMiniMenu.php');
20 require_once('../../../tests/testClasses/parseFolderPath.php');
21 require_once('../../../tests/testClasses/parseLicenseTbl.php');
22 require_once('../../../tests/testClasses/dom-parseLicenseTable.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  $licenseSummary = array(
71  'Unique licenses' => 0,
72  'Licenses found' => 0,
73  'Files with no licenses' => 0,
74  'Files' => 0
75  );
76 
77  print "starting verifyFossDirsOnly test\n";
78  $page = $this->mybrowser->clickLink('Browse');
79  $this->assertTrue($this->myassertText($page, '/Browse/'),
80  "verifyFossDirsOnly FAILED! Could not find Browse menu\n");
81  //print "************ Page after upload link *************\n$page\n";
82  $this->assertTrue($this->myassertText($page, "/$safeName/"),
83  "verifyFossDirsOnly FAILED! did not find $name\n");
84  $this->assertTrue($this->myassertText($page, "/>View</"),
85  "verifyFossDirsOnly FAILED! >View< not found\n");
86  $this->assertTrue($this->myassertText($page, "/>Info</"),
87  "verifyFossDirsOnly FAILED! >Info< not found\n");
88  $this->assertTrue($this->myassertText($page, "/>Download</"),
89  "verifyFossDirsOnly FAILED! >Download< not found\n");
90 
91  /* Select archive */
92  $page = $this->mybrowser->clickLink($name);
93  //print "************ Page after select foss archive *************\n$page\n";
94  $this->assertTrue($this->myassertText($page, "/empty\//"),
95  "verifyFossDirsOnly FAILED! 'empty/' not found\n");
96  $this->assertTrue($this->myassertText($page, "/1 item/"),
97  "verifyFossDirsOnly FAILED! '1 item' not found\n");
98 
99  /* Select empty link */
100  $page = $this->mybrowser->clickLink('empty/');
101 
102  /* need to check that there are 9 items */
103  $this->assertTrue($this->myassertText($page, "/9 items/"),
104  "verifyFossDirsOnly FAILED! '9 items' not found\n");
105  $this->assertTrue($this->myassertText($page, "/agents/"),
106  "verifyFossDirsOnly FAILED! did not find 'agents' directory\n");
107  $this->assertTrue($this->myassertText($page, "/scheduler/"),
108  "verifyFossDirsOnly FAILED! did not find scheduler directory\n");
109 
110  /* Select the License link to View License Historgram */
111  $mini = new parseMiniMenu($page);
112  $miniMenu = $mini->parseMiniMenu();
113  $url = makeUrl($this->host, $miniMenu['Nomos License']);
114  if($url === NULL) { $this->fail("verifyFossDirsOnly Failed, host is not set"); }
115 
116  $page = $this->mybrowser->get($url);
117  //print "page after get of $url is:\n$page\n";
118  $this->assertTrue($this->myassertText($page, '/Nomos License Browser/'),
119  "verifyFossDirsOnly FAILED! Nomos License Browser Title not found\n");
120 
121  $licSummary = new domParseLicenseTbl($page, 'licsummary', 0);
122  $licSummary->parseLicenseTbl();
123 
124  foreach ($licSummary->hList as $summary) {
125  $key = $summary['textOrLink'];
126  $this->assertEqual($licenseSummary[$key], $summary['count'],
127  "verifyFossDirsOnly FAILED! $key does not equal $licenseSummary[$key],
128  got $summary[count]\n");
129  //print "summary is:\n";print_r($summary) . "\n";
130  }
131 
132  $dList = new parseLicenseTblDirs($page);
133  $dirList = $dList->parseLicenseTblDirs();
134  /*
135  * the directiory agents has 13 subdirectories all other directories
136  * are empty. we are going to loop through them, but for now just
137  * test a few of them out....
138  */
139  $url = makeUrl($this->host, $dirList['scheduler/']);
140  $page = $this->mybrowser->get($url);
141  //print "page after scheduler is:\n$page\n";
142  $folders = new parseFolderPath($page, $url);
143  $dirCnt = $folders->countFiles();
144  // should only get one folder path)
145  $this->assertEqual((int)$dirCnt, 1,
146  "verifyFossDirsOnly FAILED! did not get 1 folder path back, got $dirCnt instead\n");
147  // every entry but the last must have a non-null value (we assume parse
148  // routine worked)
149  $fpaths = $folders->parseFolderPath();
150  $this->assertTrue($this->check4Links($fpaths),
151  "verifyFossDirsOnly FAILED! something wrong with folder path\n" .
152  "See this url:\n$url\n");
153  }
166  function check4Links($folderPath)
167  {
168  $flistSize = count($folderPath[0]);
169  foreach($folderPath as $flist)
170  {
171  $i = 0;
172  foreach($flist as $folder => $link)
173  {
174  $i++;
175  // is it the last entry?
176  if ($i == $flistSize)
177  {
178  $this->assertTrue(is_null($link),
179  "verifyFossDirsOnly FAILED! Last entry is not null\n$folder $link\n");
180  continue;
181  }
182  $this->assertFalse(is_null($link),
183  "verifyFossDirsOnly FAILED! Found a folder with no link\n$folder $link\n");
184  }
185  }
186  return(TRUE);
187  }
188 }
Login($User=NULL, $Password=NULL)