src/Codeception/Module/WPDb.php
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;
    }
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;
    }
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 ; }
Creates and adds a menu to a theme location in the database.

@example
```php
list($termId, $termTaxId) = $I->haveMenuInDatabase('test', 'sidebar');
```

@param string $slug      The menu slug.
@param string $location  The theme menu location the menu will be assigned to.
@param array  $overrides An array of values to override the defaults.

@return array An array containing the created menu `term_id` and `term_taxonomy_id`.
Creates and adds a menu to a theme location in the database .