FOSSology  4.4.0
Open Source License Compliance by Open Source Software
verifyRedHatTest.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 
19 $where = dirname(__FILE__);
20 if(preg_match('!/home/jenkins.*?tests.*!', $where, $matches))
21 {
22  //echo "running from jenkins....fossology/tests\n";
23  require_once ('fossologyTestCase.php');
24  //require_once ('../TestEnvironment.php');
25  require_once('testClasses/parseMiniMenu.php');
26  require_once('testClasses/dom-parseLicenseTable.php');
27  require_once('testClasses/parseFolderPath.php');
28  require_once('commonTestFuncs.php');
29 }
30 else
31 {
32  //echo "using requires for running outside of jenkins\n";
33  require_once ('../fossologyTestCase.php');
34  //require_once ('../TestEnvironment.php');
35  require_once('../testClasses/parseMiniMenu.php');
36  require_once('../testClasses/dom-parseLicenseTable.php');
37  require_once('../testClasses/parseFolderPath.php');
38  require_once('../commonTestFuncs.php');
39 }
40 
41 /* Globals for test use, most tests need $URL, only login needs the others */
42 global $URL;
43 
45 {
46  public $mybrowser; // must have
47  protected $host;
48 
49  /*
50  * Every Test needs to login so we use the setUp method for that.
51  * setUp is called before any other method by default.
52  *
53  */
54  function setUp()
55  {
56  global $URL;
57  $this->Login();
58  $this->host = getHost($URL);
59  }
60 
61  function testRHEL()
62  {
63  global $URL;
64 
65  $licBaseLine = array(
66  'No_license_found' => 6878,
67  'Apache_v2.0' => 858,
68  'ATT' => 812,
69  'GPL_v2+' => 289,
70  'CMU' => 247,
71  'FSF' => 176,
72  'BSD-style' => 154,
73  'LGPL' => 131,
74  'GPL_v3+' => 76,
75  'Apache-possibility' => 62,
76  'See-doc(OTHER)' => 28,
77  'Debian-SPI-style' => 34,
78  'GNU-Manpages' => 34,
79  'LGPL_v2.1+' => 29,
80  'MPL_v1.1' => 29,
81  'Trademark-ref' => 25,
82  'IETF' => 28,
83  'UnclassifiedLicense' => 28,
84  'GPL-exception' => 24,
85  'BSD' => 20,
86  'Apache' => 17,
87  'GPL' => 73,
88  'GPL_v2' => 13,
89  'GPL_v2.1+' => 1,
90  'Indemnity' => 2,
91  'GPL-possibility' => 1,
92  'Public-domain' => 20,
93  'Non-commercial!' => 6,
94  'RSA-Security' => 7,
95  'ATT-possibility' => 6,
96  'LGPL_v2+' => 6,
97  'OSL_v1.0' => 6,
98  'CPL_v1.0' => 5,
99  'GFDL_v1.1+' => 5,
100  'GPL_v3' => 5,
101  'Intel' => 5,
102  'LGPL_v3+' => 4,
103  'Public-domain-ref' => 4,
104  'Perl-possibility' => 4,
105  'APSL_v1.1' => 3,
106  'IOS' => 3,
107  'MIT-style' => 3,
108  'NOT-public-domain' => 10,
109  'Apache_v1.1' => 3,
110  'CMU-possibility' => 2,
111  'GFDL_v1.1' => 3,
112  'GFDL_v1.2+' => 3,
113  'MIT' => 2,
114  'MPL' => 2,
115  'Open-Publication_v1.0' => 2,
116  'Zope-PL_v2.0' => 2,
117  'AGFA(RESTRICTED)' => 1,
118  'APSL' => 1,
119  'APSL_v1.2' => 1,
120  'ATT-Source_v1.2d' => 1,
121  'BSD-possibility' => 1,
122  'CCA' => 1,
123  'Dyade' => 1,
124  'HP-possibility' => 1,
125  'ISC' => 1,
126  'GPL-Bison-exception' => 1,
127  'LGPL-possibility' => 1,
128  'LGPL_v2' => 1,
129  'MacroMedia-RPSL' => 1,
130  'Microsoft-possibility' => 1,
131  'NPL_v1.1' => 1,
132  'RedHat-EULA' => 1,
133  'RedHat(Non-commercial)' => 1,
134  'Same-license-as' => 1,
135  'See-file(COPYING)' => 1,
136  'Sun' => 1,
137  'Sun-BCLA' => 1,
138  'Sun-possibility' => 1,
139  'Sun(RESTRICTED)' => 1,
140  'TeX-exception' => 1,
141  'U-Wash(Free-Fork)' => 1,
142  'X11' => 1,
143  'zlib/libpng' => 1,
144  );
145 
146  $licenseSummary = array(
147  'Unique licenses' => 71,
148  'Licenses found' => 3328,
149  'Files with no licenses' => 6878,
150  'Files' => 12595
151  );
152 
153 
154  print "starting testRHEL\n";
155 
156  $name = 'RedHat.tar.gz';
157  $safeName = escapeDots($name);
158  //print "safeName is:$safeName\n";
159  $page = $this->mybrowser->clickLink('Browse');
160  $page = $this->mybrowser->clickLink('Testing');
161  $this->assertTrue($this->myassertText($page, "/$safeName/"),
162  "verifyRedHat FAILED! did not find $safeName\n");
163 
164  /* Select archive */
165  //print "CKZDB: page before call parseBMenu:\n$page\n";
166 
167  $page = $this->mybrowser->clickLink($name);
168  $this->assertTrue($this->myassertText($page, "/1 item/"),
169  "verifyRedHat FAILED! 1 item not found\n");
170  $page = $this->mybrowser->clickLink('RedHat.tar');
171  //print "page after clicklink RedHat.tar:\n$page\n";
172  $page = $this->mybrowser->clickLink('RedHat/');
173  //print "page after clicklink RedHat:\n$page\n";
174  $this->assertTrue($this->myassertText($page, "/65 items/"),
175  "verifyRedHat FAILED! '65 items' not found\n");
176  $mini = new parseMiniMenu($page);
177  $miniMenu = $mini->parseMiniMenu();
178  //print "miniMenu is:\n";print_r($miniMenu) . "\n";
179  $url = makeUrl($this->host, $miniMenu['License Browser']);
180  if($url === NULL) { $this->fail("verifyRedHat Failed, host/url is not set"); }
181 
182  $page = $this->mybrowser->get($url);
183  //print "page after get of $url is:\n$page\n";
184  $this->assertTrue($this->myassertText($page, '/License Browser/'),
185  "verifyRedHat FAILED! License Browser Title not found\n");
186 
187  // check that license summarys are correct
188  $licSummary = new domParseLicenseTbl($page, 'licsummary', 0);
189  $licSummary->parseLicenseTbl();
190 
191  print "verifying summaries....\n";
192  foreach ($licSummary->hList as $summary)
193  {
194  //print "summary is:\n";print_r($summary) . "\n";
195  $key = $summary['textOrLink'];
196  //print "SUM: key is:$key\n";
197  $this->assertEqual($licenseSummary[$key], $summary['count'],
198  "verifyRedHat FAILED! $key does not equal $licenseSummary[$key],
199  Expected: {$licenseSummary[$key]},
200  Got: $summary[count]\n");
201  //print "summary is:\n";print_r($summary) . "\n";
202  }
203 
204  // get the license names and 'Show' links
205  $licHistogram = new domParseLicenseTbl($page, 'lichistogram',1);
206  $licHistogram->parseLicenseTbl();
207 
208  if($licHistogram->noRows === TRUE)
209  {
210  $this->fail("FATAL! no table rows to process, there should be many for"
211  . " this test, Stopping the test");
212  return;
213  }
214 
215  // verify every row against the standard by comparing the counts.
216  /*
217  * @todo check the show links, but to do that, need to gather another
218  * standard array to match agains? or just use the count from the
219  * baseline?
220  */
221 
222  //print "table is:\n";print_r($licHistogram->hList) . "\n";
223  foreach($licHistogram->hList as $licFound)
224  {
225  $key = $licFound['textOrLink'];
226  //print "HDB: key is:$key\n";
227  //print "licFound is:\n";print_r($licFound) . "\n";
228  if(array_key_exists($key,$licBaseLine))
229  {
230  //print "licFound[textOrLink] is:{$licFound['textOrLink']}\n";
231  $this->assertEqual($licBaseLine[$key], $licFound['count'],
232  "verifyRedHat FAILED! the baseline count {$licBaseLine[$key]} does" .
233  " not equal {$licFound['count']} for license $key,\n" .
234  "Expected: {$licBaseLine[$key]},\n" .
235  " Got: {$licFound['count']}\n");
236  }
237  else
238  {
239  $this->fail("verifyRedHat FAILED! A License was found that is " .
240  "not in the standard:\n$key\n");
241  }
242  }
243  }
244 }
Login($User=NULL, $Password=NULL)