FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_common_menu.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
13 use PHPUnit\Runner\Version as PHPUnitVersion;
14 
15 require_once(dirname(__FILE__) . '/../common-menu.php');
16 require_once(dirname(__FILE__) . '/../common-parm.php');
17 
21 class test_common_menu extends \PHPUnit\Framework\TestCase
22 {
23  /* initialization */
24  protected function setUp() : void
25  {
26  }
27 
31  function test_MenuPage()
32  {
33  print "Starting unit test for common-menu.php\n";
34  print "test function MenuPage()\n";
35 
36  $Page = 10;
37  $TotalPage = 15;
38  $Uri = "http://fossology.org/repo/";
39  $expected = "<a class='page-link' href='http:\/\/fossology.org\/repo\/&page=9'>Prev<\/a>";
40  $result = MenuPage($Page, $TotalPage, $Uri);
41  if (intval(explode('.', PHPUnitVersion::id())[0]) >= 9) {
42  $this->assertMatchesRegularExpression("/<a class='page-link' href='#'>11<\/a>/", $result);
43  $this->assertMatchesRegularExpression("/$expected/", $result);
44  } else {
45  $this->assertRegExp("/<a class='page-link' href='#'>11<\/a>/", $result);
46  $this->assertRegExp("/$expected/", $result);
47  }
48  }
49 
54  {
55  print "test function MenuEndlessPage()\n";
56 
57  $Page = 10;
58  $Uri = "http://fossology.org/repo/";
59  $expected = "<a class='page-link' href='http:\/\/fossology.org\/repo\/&page=9'>Prev<\/a>";
60  $result = MenuEndlessPage($Page, 1, $Uri);
61  if (intval(explode('.', PHPUnitVersion::id())[0]) >= 9) {
62  $this->assertMatchesRegularExpression("/<a class='page-link' href='#'>11<\/a>/", $result);
63  $this->assertMatchesRegularExpression("/$expected/", $result);
64  } else {
65  $this->assertRegExp("/<a class='page-link' href='#'>11<\/a>/", $result);
66  $this->assertRegExp("/$expected/", $result);
67  }
68  }
69 
73  function test_menu_cmp()
74  {
75  print "test function menu_cmp()\n";
76 
77  $menua = new menu;
78  $menub = new menu;
79  $menua->Name = 'menua';
80  $menub->Name = 'menua';
81  $result = menu_cmp($menua, $menub);
82  $this->assertEquals(0,$result);
83  $menua->Order = 1;
84  $menub->Order = 2;
85  $result = menu_cmp($menua, $menub);
86  $this->assertEquals(1,$result);
87  }
92  {
93  print "test function menu_insert()\n";
94 
95  global $MenuList;
96 
97  $Path = "TestMenu::Test1::Test2";
98  $LastOrder = 0;
99  $URI = "TestURI";
100  $Title = "TestTitle";
101  $Target = "TestTarget";
102  $HTML = "TestHTML";
103  $countMenuListBefore = count($MenuList);
104  $result = menu_insert($Path, $LastOrder, $URI, $Title, $Target, $HTML);
105  $this->assertEquals($Path,
106  $MenuList[$countMenuListBefore]->SubMenu[0]->SubMenu[0]->FullName);
107 
108  print "test function menu_find)\n";
109  $depth = 2;
110  $result = menu_find("Test1", $depth);
111 
112  print "test function menu_to_1html)\n";
113  $result = menu_to_1html($MenuList);
114  $pattern = "/TestMenu/";
115  if (intval(explode('.', PHPUnitVersion::id())[0]) >= 9) {
116  $this->assertMatchesRegularExpression($pattern, $result);
117  } else {
118  $this->assertRegExp($pattern, $result);
119  }
120 
121  print "test function menu_to_1list)\n";
122  $Parm = "";
123  $result = menu_to_1list($MenuList, $Parm, "", "");
124  if (intval(explode('.', PHPUnitVersion::id())[0]) >= 9) {
125  $this->assertMatchesRegularExpression($pattern, $result);
126  } else {
127  $this->assertRegExp($pattern, $result);
128  }
129  print "Ending unit test for common-menu.php\n";
130  }
131 
135  protected function tearDown() : void
136  {
137  }
138 }
Code for creating a menu list (2D linked list) from a set of plugins.
Definition: common-menu.php:20
test_MenuEndlessPage()
test for MenuEndlessPage()
test_MenuPage()
test for MenuPage()
test_menu_cmp()
test for menu_cmp()
tearDown()
clean the env
test_menu_functions()
test for menu_functions()
MenuEndlessPage($Page, $Next=1, $Uri='')
Create a "First Prev 1 2 ... Next" page links for paged output.
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.
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.
MenuPage($Page, $TotalPage, $Uri='')
Create a "First Prev 1 2 ... Next Last" page links for paged output.
Definition: common-menu.php:60
$MenuList
Global menu list array.
Definition: common-menu.php:48
menu_cmp($a, $b)
Compare two menu items for sorting.
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.
menu_to_1html($Menu, $ShowRefresh=1, $ShowTraceback=0, $ShowAll=1)
Take a menu and render it as one HTML line.