src/Codeception/Module/WPDb.php
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;
    }
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;
    }
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 ; }
Adds a menu element to a menu for the current theme.

@example
```php
$I->haveMenuInDatabase('test', 'sidebar');
$I->haveMenuItemInDatabase('test', 'Test one', 0);
$I->haveMenuItemInDatabase('test', 'Test two', 1);
```

@param string     $menuSlug  The menu slug the item should be added to.
@param string     $title     The menu item title.
@param int|null   $menuOrder An optional menu order, `1` based.
@param array|null $meta      An associative array that will be prefixed with `_menu_item_` for the item post
meta.

@return int The menu item post `ID`
Adds a menu element to a menu for the current theme .