Codeception\Module\WPDb::haveMenuInDatabase PHP Method

haveMenuInDatabase() public method

Creates and adds a menu to a theme location in the database.
public haveMenuInDatabase ( string $slug, string $location, array $overrides = [] ) : array
$slug string The menu slug.
$location string The theme menu location the menu will be assigned to.
$overrides array An array of values to override the defaults.
return array An array containing the created menu `term_id` and `term_taxonomy_id`.
    public function haveMenuInDatabase($slug, $location, array $overrides = [])
    {
        if (!is_string($slug)) {
            throw new \InvalidArgumentException('Menu slug must be a string.');
        }
        if (!is_string($location)) {
            throw new \InvalidArgumentException('Menu location must be a string.');
        }
        if (empty($this->stylesheet)) {
            throw new \RuntimeException('Stylesheet must be set to add menus, use `useTheme` first.');
        }
        $title = empty($overrides['title']) ? ucwords($slug, ' -_') : $overrides['title'];
        $menuIds = $this->haveTermInDatabase($title, 'nav_menu', ['slug' => $slug]);
        $menuTermTaxonomyIds = reset($menuIds);
        // set theme options to use the `primary` location
        $this->haveOptionInDatabase('theme_mods_' . $this->stylesheet, ['nav_menu_locations' => [$location => $menuTermTaxonomyIds]]);
        $this->menus[$this->stylesheet][$slug] = $menuIds;
        $this->menuItems[$this->stylesheet][$slug] = [];
        return $menuIds;
    }
WPDb