FOSSology  4.4.0
Open Source License Compliance by Open Source Software
templateTest.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 
20 /* every test must use these includes, adjust the paths based on where the
21  * tests are in the source tree.
22  */
23 require_once ('../../../../tests/fossologyTestCase.php');
24 require_once ('../../../../tests/TestEnvironment.php');
25 
26 /* Globals for test use, most tests need $URL, only login needs the others */
27 global $URL;
28 global $USER;
29 global $PASSWORD;
30 
31 /* The class name should end in Test */
32 
33 /* NOTE: You MUST remove the abstract or the test will not get run */
34 abstract class someTest extends fossologyTestCase
35 {
36  public $mybrowser; // must have
37  public $someOtherVariable;
38 
39  /*
40  * Every Test needs to login so we use the setUp method for that.
41  * setUp is called before any other method by default.
42  *
43  * If other actions like creating a folder or something are needed,
44  * put them in the setUp method after login.
45  *
46  */
47  function setUp()
48  {
49  global $URL;
50  $this->Login();
51  }
52 
53  /*
54  * usually the test will only have one method. For a test to be
55  * run the method name must start with 'test'.
56  *
57  * Every Test should print a start message, this is useful to help
58  * determine where a test failed. Most assert's can take an optional
59  * string to be printed on failure of the assertion. This is a good
60  * practice to help someone running the tests figure out what went
61  * wrong.
62  *
63  * Every test should login to the site, so that it can be run
64  * standalone. Use the Login method (defined in fossologyTest).
65  *
66  * The login method will get a browser object and store that in the
67  * instance variable/class property $mybrowser. The login method also
68  * sets the cookie so the test doesn't get logged out.
69  */
70  function testsome()
71  {
72  global $URL;
73 
74  print "starting testSome\n";
75 
76  /* at this point the test is ready to naviate to the url it wants to
77  * test and starts testing.
78  *
79  * For example, the lines below navigate to the browse screen and
80  * look for a title called Folder Navigation and the standard root
81  * folder (Software Repository.)
82  *
83  * Just for fun it checks to see if /tmp exists. :)
84  */
85  $page = $this->mybrowser->clickLink('Browse');
86  $this->assertTrue(assertText('/Folder Navigation/'),
87  "FAIL! There is no Folder Navigation Title\n");
88  $this->assertTrue(assertText('/>S.*?y<//'),
89  "FAIL! There is no Root Folder!\n");
90  $this->assertTrue(is_dir('/tmp'),
91  "FAIL! There is no /tmp\n");
92  }
93 
94  /* use the tearDown method to clean up after a test. This method like
95  * setUp will run after every test.
96  */
97  function tearDown()
98  {
99  return(TRUE);
100  }
101 }
Login($User=NULL, $Password=NULL)