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