FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_common_menu.php
Go to the documentation of this file.
1 <?php
2 /*
3  Copyright (C) 2011 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 
24 require_once(dirname(__FILE__) . '/../common-menu.php');
25 require_once(dirname(__FILE__) . '/../common-parm.php');
26 
30 class test_common_menu extends \PHPUnit\Framework\TestCase
31 {
32  /* initialization */
33  protected function setUp()
34  {
35  }
36 
40  function test_MenuPage()
41  {
42  print "Starting unit test for common-menu.php\n";
43  print "test function MenuPage()\n";
44 
45  $Page = 10;
46  $TotalPage = 15;
47  $Uri = "http://fossology.org/repo/";
48  $expected = "<a href='http:\/\/fossology.org\/repo\/&page=9'>\[Prev\]<\/a>";
49  $result = MenuPage($Page, $TotalPage, $Uri);
50  $this->assertRegExp("/<b>11<\/b>/", $result);
51  $this->assertRegExp("/$expected/", $result);
52  }
53 
58  {
59  print "test function MenuEndlessPage()\n";
60 
61  $Page = 10;
62  $Uri = "http://fossology.org/repo/";
63  $expected = "<a href='http:\/\/fossology.org\/repo\/&page=9'>\[Prev\]<\/a>";
64  $result = MenuEndlessPage($Page, 1, $Uri);
65  $this->assertRegExp("/<b>11<\/b>/", $result);
66  $this->assertRegExp("/$expected/", $result);
67  }
68 
72  function test_menu_cmp()
73  {
74  print "test function menu_cmp()\n";
75 
76  $menua = new menu;
77  $menub = new menu;
78  $menua->Name = 'menua';
79  $menub->Name = 'menua';
80  $result = menu_cmp($menua, $menub);
81  $this->assertEquals(0,$result);
82  $menua->Order = 1;
83  $menub->Order = 2;
84  $result = menu_cmp($menua, $menub);
85  $this->assertEquals(1,$result);
86  }
91  {
92  print "test function menu_insert()\n";
93 
94  global $MenuList;
95 
96  $Path = "TestMenu::Test1::Test2";
97  $LastOrder = 0;
98  $URI = "TestURI";
99  $Title = "TestTitle";
100  $Target = "TestTarget";
101  $HTML = "TestHTML";
102  $countMenuListBefore = count($MenuList);
103  $result = menu_insert($Path, $LastOrder, $URI, $Title, $Target, $HTML);
104  $this->assertEquals($Path,$MenuList[$countMenuListBefore]->FullName);
105 
106  print "test function menu_find)\n";
107  $depth = 2;
108  $result = menu_find("Test1", $depth);
109 
110  print "test function menu_to_1html)\n";
111  $result = menu_to_1html($MenuList);
112  $this->assertRegExp("/TestMenu/", $result);
113 
114  print "test function menu_to_1list)\n";
115  $Parm = "";
116  $result = menu_to_1list($MenuList, $Parm, "", "");
117  $this->assertRegExp("/TestMenu/", $result);
118  print "Ending unit test for common-menu.php\n";
119  }
120 
124  protected function tearDown()
125  {
126  }
127 }
tearDown()
clean the env
menu_find($Name, &$MaxDepth, $Menu=NULL)
Given a top-level menu name, find the list of sub-menus below it and max depth of menu...
MenuPage($Page, $TotalPage, $Uri= '')
Create a "First Prev 1 2 ... Next Last" page links for paged output.
Definition: common-menu.php:71
menu_to_1list($Menu, &$Parm, $Pre="", $Post="", $ShowAll=1, $upload_id="")
Take a menu and render it as one HTML line with items in a "[name]" list.
MenuEndlessPage($Page, $Next=1, $Uri= '')
Create a "First Prev 1 2 ... Next" page links for paged output.
menu_to_1html($Menu, $ShowRefresh=1, $ShowTraceback=0, $ShowAll=1)
Take a menu and render it as one HTML line.
$MenuList
Global menu list array.
Definition: common-menu.php:59
menu_insert($Path, $LastOrder=0, $URI=NULL, $Title=NULL, $Target=NULL, $HTML=NULL)
Given a Path, order level for the last item, and optional plugin name, insert the menu item...
Code for creating a menu list (2D linked list) from a set of plugins.
Definition: common-menu.php:30
test_menu_functions()
test for menu_functions()
test_MenuEndlessPage()
test for MenuEndlessPage()
test_menu_cmp()
test for menu_cmp()
test_MenuPage()
test for MenuPage()
menu_cmp(&$a, &$b)
Compare two menu items for sorting.