FOSSology  4.5.1
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  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
12 namespace Fossology\Tests;
13 
14 use PHPUnit\Framework\TestCase;
15 
16 require_once dirname(__FILE__) . '/../common-menu.php';
17 require_once dirname(__FILE__) . '/../common-parm.php';
18 
23 class CommonMenuTest extends TestCase
24 {
28  public function testMenuPage()
29  {
30  $page = 10;
31  $totalPage = 15;
32  $uri = "http://fossology.org/repo/";
33  $expected = "<a class='page-link' href='http://fossology.org/repo/&page=9'>Prev</a>";
34  $result = MenuPage($page, $totalPage, $uri);
35  // Assert that the result contains the expected output
36  $this->assertStringContainsString("<a class='page-link' href='#'>11</a>", $result);
37  $this->assertStringContainsString($expected, $result);
38  }
39 
43  public function testMenuEndlessPage()
44  {
45  $page = 10;
46  $uri = "http://fossology.org/repo/";
47  $expected = "<a class='page-link' href='http://fossology.org/repo/&page=9'>Prev</a>";
48  $result = MenuEndlessPage($page, 1, $uri);
49  // Assert that the result contains the expected output
50  $this->assertStringContainsString("<a class='page-link' href='#'>11</a>", $result);
51  $this->assertStringContainsString($expected, $result);
52  }
53 
57  public function testMenuCmp()
58  {
59  $menua = new \menu();
60  $menub = new \menu();
61  $menua->Name = 'menua';
62  $menub->Name = 'menua';
63 
64  // Assert that menu_cmp returns 0 for identical menus
65  $this->assertEquals(0, menu_cmp($menua, $menub));
66 
67  $menua->Order = 1;
68  $menub->Order = 2;
69  // Assert that menu_cmp returns 1 when menua has a higher order than menub
70  $this->assertEquals(1, menu_cmp($menua, $menub));
71  }
72 
76  public function testMenuFunctions()
77  {
78  global $MenuList;
79 
80  $path = "TestMenu::Test1::Test2";
81  $lastOrder = 0;
82  $uri = "TestURI";
83  $title = "TestTitle";
84  $target = "TestTarget";
85  $html = "TestHTML";
86  $countMenuListBefore = count($MenuList);
87 
88  menu_insert($path, $lastOrder, $uri, $title, $target, $html);
89 
90  // Assert that menu_insert correctly inserts the menu item
91  $this->assertEquals($path, $MenuList[$countMenuListBefore]->SubMenu[0]->SubMenu[0]->FullName);
92 
93  $depth = 2;
94  $result = menu_find("Test1", $depth);
95 
96  // Assert that menu_to_1html() generates correct output
97  $result = menu_to_1html($MenuList);
98  $pattern = "/TestMenu/";
99  $this->assertRegExp($pattern, $result);
100 
101  $parm = "";
102  $result = menu_to_1list($MenuList, $parm, "", "");
103  // Assert that menu_to_1list() generates correct output
104  $this->assertRegExp($pattern, $result);
105  }
106 
110  protected function tearDown(): void
111  {
112  // Additional teardown code, if needed
113  }
114 }
Unit test for common-menu.php.
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.