FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
verifyFossDirsOnly.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2008 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 
27 require_once('../../../tests/fossologyTestCase.php');
28 require_once('../../../tests/commonTestFuncs.php');
29 require_once('../../../tests/TestEnvironment.php');
30 require_once('../../../tests/testClasses/parseMiniMenu.php');
31 require_once('../../../tests/testClasses/parseFolderPath.php');
32 require_once('../../../tests/testClasses/parseLicenseTbl.php');
33 require_once('../../../tests/testClasses/dom-parseLicenseTable.php');
34 require_once('../../../tests/testClasses/parseLicenseTblDirs.php');
35 
36 global $URL;
37 
43 {
44  public $mybrowser;
45  public $host;
46 
47  function setUp()
48  {
49  /*
50  * This test requires that the fossology test archive has been
51  * loaded under the name fossDirsOnly.tar.bz2
52  */
53  global $URL;
54  global $name;
55  global $safeName;
56 
57  print "starting verifyFossDirsOnly-SetUp\n";
58  $name = 'fossDirsOnly.tar.bz2';
59  $safeName = escapeDots($name);
60  $this->host = getHost($URL);
61  $this->Login();
62 
63  /* check for existense of archive */
64  $page = $this->mybrowser->get($URL);
65  $page = $this->mybrowser->clickLink('Browse');
66  $this->assertTrue($this->myassertText($page, '/Browse/'),
67  "verifyDirsOnly FAILED! Could not find Browse menu\n");
68  $result = $this->myassertText($page, "/$safeName/");
69  if(!($result)) {
70  $this->fail("Failure, cannot find archive $name, Stopping test\n");
71  exit(1);
72  }
73  }
74 
75  function testVerifyFossology()
76  {
77  global $URL;
78  global $name;
79  global $safeName;
80 
81  $licenseSummary = array(
82  'Unique licenses' => 0,
83  'Licenses found' => 0,
84  'Files with no licenses' => 0,
85  'Files' => 0
86  );
87 
88  print "starting verifyFossDirsOnly test\n";
89  $page = $this->mybrowser->clickLink('Browse');
90  $this->assertTrue($this->myassertText($page, '/Browse/'),
91  "verifyFossDirsOnly FAILED! Could not find Browse menu\n");
92  //print "************ Page after upload link *************\n$page\n";
93  $this->assertTrue($this->myassertText($page, "/$safeName/"),
94  "verifyFossDirsOnly FAILED! did not find $name\n");
95  $this->assertTrue($this->myassertText($page, "/>View</"),
96  "verifyFossDirsOnly FAILED! >View< not found\n");
97  $this->assertTrue($this->myassertText($page, "/>Info</"),
98  "verifyFossDirsOnly FAILED! >Info< not found\n");
99  $this->assertTrue($this->myassertText($page, "/>Download</"),
100  "verifyFossDirsOnly FAILED! >Download< not found\n");
101 
102  /* Select archive */
103  $page = $this->mybrowser->clickLink($name);
104  //print "************ Page after select foss archive *************\n$page\n";
105  $this->assertTrue($this->myassertText($page, "/empty\//"),
106  "verifyFossDirsOnly FAILED! 'empty/' not found\n");
107  $this->assertTrue($this->myassertText($page, "/1 item/"),
108  "verifyFossDirsOnly FAILED! '1 item' not found\n");
109 
110  /* Select empty link */
111  $page = $this->mybrowser->clickLink('empty/');
112 
113  /* need to check that there are 9 items */
114  $this->assertTrue($this->myassertText($page, "/9 items/"),
115  "verifyFossDirsOnly FAILED! '9 items' not found\n");
116  $this->assertTrue($this->myassertText($page, "/agents/"),
117  "verifyFossDirsOnly FAILED! did not find 'agents' directory\n");
118  $this->assertTrue($this->myassertText($page, "/scheduler/"),
119  "verifyFossDirsOnly FAILED! did not find scheduler directory\n");
120 
121  /* Select the License link to View License Historgram */
122  $mini = new parseMiniMenu($page);
123  $miniMenu = $mini->parseMiniMenu();
124  $url = makeUrl($this->host, $miniMenu['Nomos License']);
125  if($url === NULL) { $this->fail("verifyFossDirsOnly Failed, host is not set"); }
126 
127  $page = $this->mybrowser->get($url);
128  //print "page after get of $url is:\n$page\n";
129  $this->assertTrue($this->myassertText($page, '/Nomos License Browser/'),
130  "verifyFossDirsOnly FAILED! Nomos License Browser Title not found\n");
131 
132  $licSummary = new domParseLicenseTbl($page, 'licsummary', 0);
133  $licSummary->parseLicenseTbl();
134 
135  foreach ($licSummary->hList as $summary) {
136  $key = $summary['textOrLink'];
137  $this->assertEqual($licenseSummary[$key], $summary['count'],
138  "verifyFossDirsOnly FAILED! $key does not equal $licenseSummary[$key],
139  got $summary[count]\n");
140  //print "summary is:\n";print_r($summary) . "\n";
141  }
142 
143  $dList = new parseLicenseTblDirs($page);
144  $dirList = $dList->parseLicenseTblDirs();
145  /*
146  * the directiory agents has 13 subdirectories all other directories
147  * are empty. we are going to loop through them, but for now just
148  * test a few of them out....
149  */
150  $url = makeUrl($this->host, $dirList['scheduler/']);
151  $page = $this->mybrowser->get($url);
152  //print "page after scheduler is:\n$page\n";
153  $folders = new parseFolderPath($page, $url);
154  $dirCnt = $folders->countFiles();
155  // should only get one folder path)
156  $this->assertEqual((int)$dirCnt, 1,
157  "verifyFossDirsOnly FAILED! did not get 1 folder path back, got $dirCnt instead\n");
158  // every entry but the last must have a non-null value (we assume parse
159  // routine worked)
160  $fpaths = $folders->parseFolderPath();
161  $this->assertTrue($this->check4Links($fpaths),
162  "verifyFossDirsOnly FAILED! something wrong with folder path\n" .
163  "See this url:\n$url\n");
164  }
177  function check4Links($folderPath)
178  {
179  $flistSize = count($folderPath[0]);
180  foreach($folderPath as $flist)
181  {
182  $i = 0;
183  foreach($flist as $folder => $link)
184  {
185  $i++;
186  // is it the last entry?
187  if ($i == $flistSize)
188  {
189  $this->assertTrue(is_null($link),
190  "verifyFossDirsOnly FAILED! Last entry is not null\n$folder $link\n");
191  continue;
192  }
193  $this->assertFalse(is_null($link),
194  "verifyFossDirsOnly FAILED! Found a folder with no link\n$folder $link\n");
195  }
196  }
197  return(TRUE);
198  }
199 }
200 ?>
Login($User=NULL, $Password=NULL)