Codeception\Module\WPDb::haveMenuItemInDatabase PHP Method

haveMenuItemInDatabase() public method

Adds a menu element to a menu for the current theme.
public haveMenuItemInDatabase ( string $menuSlug, string $title, integer | null $menuOrder = null, array $meta = [] ) : integer
$menuSlug string The menu slug the item should be added to.
$title string The menu item title.
$menuOrder integer | null An optional menu order, `1` based.
$meta array An associative array that will be prefixed with `_menu_item_` for the item post meta.
return integer The menu item post `ID`
    public function haveMenuItemInDatabase($menuSlug, $title, $menuOrder = null, array $meta = [])
    {
        if (!is_string($menuSlug)) {
            throw new \InvalidArgumentException('Menu slug must be a string.');
        }
        if (empty($this->stylesheet)) {
            throw new \RuntimeException('Stylesheet must be set to add menus, use `useTheme` first.');
        }
        if (!array_key_exists($menuSlug, $this->menus[$this->stylesheet])) {
            throw new \RuntimeException("Menu {$menuSlug} is not a registered menu for the current theme.");
        }
        $menuOrder = $menuOrder ?: count($this->menuItems[$this->stylesheet][$menuSlug]) + 1;
        $menuItemId = $this->havePostInDatabase(['post_title' => $title, 'menu_order' => $menuOrder, 'post_type' => 'nav_menu_item']);
        $defaults = ['type' => 'custom', 'object' => 'custom', 'url' => 'http://example.com'];
        $meta = array_merge($defaults, $meta);
        array_walk($meta, function ($value, $key) use($menuItemId) {
            $this->havePostmetaInDatabase($menuItemId, '_menu_item_' . $key, $value);
        });
        $this->haveTermRelationshipInDatabase($menuItemId, $this->menus[$this->stylesheet][$menuSlug][1]);
        $this->menuItems[$this->stylesheet][$menuSlug][] = $menuItemId;
        return $menuItemId;
    }
WPDb