OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
147
tests/Unit/app/Domain/Menu/Repositories/MenuRepositoryTest.php
Normal file
147
tests/Unit/app/Domain/Menu/Repositories/MenuRepositoryTest.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace Unit\app\Domain\Menu\Repositories;
|
||||
|
||||
use Leantime\Core\Configuration\Environment;
|
||||
use Leantime\Core\Language;
|
||||
use Leantime\Domain\Menu\Repositories\Menu;
|
||||
use Leantime\Domain\Setting\Repositories\Setting;
|
||||
use Leantime\Domain\Tickets\Services\Tickets;
|
||||
use Unit\TestCase;
|
||||
|
||||
class MenuRepositoryTest extends TestCase
|
||||
{
|
||||
use \Codeception\Test\Feature\Stub;
|
||||
|
||||
/**
|
||||
* The test object
|
||||
*
|
||||
* @var Menu
|
||||
*/
|
||||
protected $menu;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
|
||||
parent::setUp();
|
||||
|
||||
if (! defined('BASE_URL')) {
|
||||
define('BASE_URL', 'http://localhost');
|
||||
}
|
||||
|
||||
// Mock classes
|
||||
$settingsRepo = $this->make(Setting::class);
|
||||
$language = $this->make(Language::class);
|
||||
$config = $this->make(Environment::class);
|
||||
$ticketService = $this->make(Tickets::class, [
|
||||
'getLastTicketViewUrl' => function () {
|
||||
return '';
|
||||
},
|
||||
'getLastTimelineViewUrl' => function () {
|
||||
return '';
|
||||
},
|
||||
]);
|
||||
|
||||
// Load class to be tested
|
||||
$this->menu = new Menu(
|
||||
settingsRepo: $settingsRepo,
|
||||
language: $language,
|
||||
config: $config,
|
||||
ticketsService: $ticketService
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$this->menu = null;
|
||||
}
|
||||
|
||||
// Write tests below
|
||||
|
||||
/**
|
||||
* Test GetMenuTypes method
|
||||
*/
|
||||
public function test_get_menu_types()
|
||||
{
|
||||
$result = $this->menu->getMenuTypes();
|
||||
|
||||
// Assert that the result is an array
|
||||
$this->assertIsArray($result);
|
||||
|
||||
// Assert that menu types have the expected keys
|
||||
$this->assertContains(Menu::DEFAULT_MENU, array_keys($result));
|
||||
|
||||
// Further assertions can be done depending on use case and requirements
|
||||
}
|
||||
|
||||
public function test_get_default_menu_structure()
|
||||
{
|
||||
$expected = $this->menu::DEFAULT_MENU;
|
||||
$defaultStructure = $this->menu->getMenuStructure();
|
||||
|
||||
// Menu structure checks if roles are set in a menu item and will disable a menu item if not allowed to see
|
||||
// User executing the test is not logged in, has no session so it being disabled is correct
|
||||
$this->menu->menuStructures[$expected][40]['submenu'][80]['type'] = 'disabled';
|
||||
$this->menu->menuStructures[$expected][30]['submenu'][30]['href'] = '/ideas/showBoards';
|
||||
|
||||
$this->assertEquals($this->menu->menuStructures[$expected], $defaultStructure, 'Default menu structure does not match the expected structure');
|
||||
}
|
||||
|
||||
public function test_get_full_menu_structure()
|
||||
{
|
||||
$expected = 'full_menu';
|
||||
$fullMenuStructure = $this->menu->getMenuStructure('full_menu');
|
||||
$this->menu->menuStructures[$expected][80]['submenu'][83]['type'] = 'disabled';
|
||||
|
||||
$this->assertEquals($this->menu->menuStructures[$expected], $fullMenuStructure, 'Full menu structure does not match the expected structure');
|
||||
}
|
||||
|
||||
public function test_get_invalid_menu_structure()
|
||||
{
|
||||
$expected = [];
|
||||
$invalidMenuStructure = $this->menu->getMenuStructure('invalid');
|
||||
$this->assertEquals($expected, $invalidMenuStructure, 'Invalid menu structure does not match the expected structure');
|
||||
}
|
||||
|
||||
public function test_get_filtered_menu_structure()
|
||||
{
|
||||
|
||||
\Leantime\Core\Events\EventDispatcher::add_filter_listener('leantime.domain.menu.repositories.menu.getMenuStructure.menuStructures.company', function ($menu) {
|
||||
|
||||
if (isset($menu[15]) && isset($menu[15]['submenu'])) {
|
||||
unset($menu[15]['submenu'][20]);
|
||||
}
|
||||
|
||||
return $menu;
|
||||
|
||||
}, 10);
|
||||
|
||||
$fullMenuStructure = $this->menu->getMenuStructure('company');
|
||||
$this->assertIsArray($fullMenuStructure[15]['submenu']);
|
||||
|
||||
$this->assertFalse(isset($fullMenuStructure[15]['submenu'][20]), 'menu item was not removed');
|
||||
|
||||
}
|
||||
|
||||
public function test_inject_new_project_menu_type()
|
||||
{
|
||||
|
||||
\Leantime\Core\Events\EventDispatcher::add_filter_listener('leantime.domain.menu.repositories.menu.getMenuStructure.menuStructures', function ($menuStructure) {
|
||||
|
||||
$testStructure = [
|
||||
10 => ['item' => 'myNewMenu', 'type' => 'item'],
|
||||
];
|
||||
|
||||
$menuStructure['testType'] = $testStructure;
|
||||
|
||||
return $menuStructure;
|
||||
|
||||
}, 10);
|
||||
|
||||
$fullMenuStructure = $this->menu->getMenuStructure('testType');
|
||||
$this->assertIsArray($fullMenuStructure);
|
||||
$this->assertEquals('myNewMenu', $fullMenuStructure[10]['item']);
|
||||
|
||||
}
|
||||
}
|
||||
92
tests/Unit/app/Domain/Menu/Services/MenuServiceTest.php
Normal file
92
tests/Unit/app/Domain/Menu/Services/MenuServiceTest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Unit\app\Domain\Menu\Services;
|
||||
|
||||
use Leantime\Domain\Menu\Repositories\Menu as MenuRepository;
|
||||
use Leantime\Domain\Menu\Services\Menu;
|
||||
use Leantime\Domain\Projects\Services\Projects as ProjectService;
|
||||
use Leantime\Domain\Setting\Services\Setting;
|
||||
use Leantime\Domain\Users\Services\Users;
|
||||
use Unit\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for the pure project-selector helper logic extracted from the
|
||||
* Menu ProjectSelector HxController into the Menu service.
|
||||
*/
|
||||
class MenuServiceTest extends TestCase
|
||||
{
|
||||
use \Codeception\Test\Feature\Stub;
|
||||
|
||||
/**
|
||||
* Builds a Menu service with stubbed collaborators. The helpers under test
|
||||
* (settings link + redirect url) do not touch any collaborator, so the
|
||||
* dependencies just need to exist.
|
||||
*/
|
||||
private function makeService(): Menu
|
||||
{
|
||||
return new Menu(
|
||||
$this->make(ProjectService::class),
|
||||
$this->make(Users::class),
|
||||
$this->make(Setting::class),
|
||||
$this->make(MenuRepository::class),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_settings_link_is_populated_for_project_menu(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$link = $service->getProjectSelectorSettingsLink('project');
|
||||
|
||||
$this->assertSame('projects', $link['module']);
|
||||
$this->assertSame('showProject', $link['action']);
|
||||
$this->assertArrayHasKey('label', $link);
|
||||
$this->assertArrayHasKey('settingsIcon', $link);
|
||||
$this->assertArrayHasKey('settingsTooltip', $link);
|
||||
}
|
||||
|
||||
public function test_settings_link_is_populated_for_default_menu(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$link = $service->getProjectSelectorSettingsLink('default');
|
||||
|
||||
$this->assertSame('projects', $link['module']);
|
||||
$this->assertSame('showProject', $link['action']);
|
||||
}
|
||||
|
||||
public function test_settings_link_is_empty_for_other_menu_types(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$link = $service->getProjectSelectorSettingsLink('personal');
|
||||
|
||||
$this->assertSame([
|
||||
'label' => '',
|
||||
'module' => '',
|
||||
'action' => '',
|
||||
'settingsIcon' => '',
|
||||
'settingsTooltip' => '',
|
||||
], $link);
|
||||
}
|
||||
|
||||
public function test_redirect_url_rewrites_show_project_to_dashboard(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$this->assertSame(
|
||||
'/dashboard/show',
|
||||
$service->getProjectSelectorRedirectUrl('/projects/showProject/5')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_redirect_url_is_unchanged_for_other_uris(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$this->assertSame(
|
||||
'/tickets/showKanban',
|
||||
$service->getProjectSelectorRedirectUrl('/tickets/showKanban')
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user