sections)->toHaveCount(1); expect($menu->sections[0])->toBe($section); }); it('can be created from array', function () { $data = [ [ 'section' => 'System', 'items' => [ ['name' => 'Dashboard', 'url' => '/admin'], ['name' => 'Users', 'url' => '/admin/users'], ], 'icon' => 'server', ], [ 'section' => 'Content', 'items' => [ ['name' => 'Pages', 'url' => '/admin/pages'], ], ], ]; $menu = NavigationMenu::fromArray($data); expect($menu->sections)->toHaveCount(2); expect($menu->sections[0]->name)->toBe('System'); expect($menu->sections[0]->icon)->toBe('server'); expect($menu->sections[0]->items)->toHaveCount(2); expect($menu->sections[1]->name)->toBe('Content'); expect($menu->sections[1]->items)->toHaveCount(1); }); it('converts to array correctly', function () { $menu = new NavigationMenu([ new NavigationSection('System', [ new NavigationItem('Dashboard', '/admin', 'dashboard-icon'), ], 'server'), ]); $array = $menu->toArray(); expect($array)->toHaveCount(1); expect($array[0]['section'])->toBe('System'); expect($array[0]['icon'])->toBe('server'); expect($array[0]['items'])->toHaveCount(1); expect($array[0]['items'][0]['name'])->toBe('Dashboard'); expect($array[0]['items'][0]['url'])->toBe('/admin'); expect($array[0]['items'][0]['icon'])->toBe('dashboard-icon'); }); it('can add sections immutably', function () { $originalMenu = new NavigationMenu([]); $newSection = new NavigationSection('New Section', []); $newMenu = $originalMenu->addSection($newSection); expect($originalMenu->sections)->toHaveCount(0); expect($newMenu->sections)->toHaveCount(1); expect($newMenu->sections[0])->toBe($newSection); }); it('can find sections by name', function () { $systemSection = new NavigationSection('System', []); $contentSection = new NavigationSection('Content', []); $menu = new NavigationMenu([$systemSection, $contentSection]); $found = $menu->findSectionByName('System'); $notFound = $menu->findSectionByName('NonExistent'); expect($found)->toBe($systemSection); expect($notFound)->toBeNull(); }); it('handles empty menu correctly', function () { $menu = new NavigationMenu([]); expect($menu->sections)->toHaveCount(0); expect($menu->findSectionByName('Any'))->toBeNull(); $array = $menu->toArray(); expect($array)->toHaveCount(0); }); });