src/Codeception/Module/WPDb.php
public function haveUserCapabilitiesInDatabase($userId, $role)
    {
        if (!is_array($role)) {
            $meta_key = $this->grabPrefixedTableNameFor() . 'capabilities';
            $meta_value = serialize([$role => 1]);

            return $this->haveUserMetaInDatabase($userId, $meta_key, $meta_value);
        }
        $ids = [];
        foreach ($role as $blogId => $_role) {
            $blogIdAndPrefix = $blogId == 0 ? '' : $blogId . '_';
            $meta_key = $this->grabPrefixedTableNameFor() . $blogIdAndPrefix . 'capabilities';
            $meta_value = serialize([$_role => 1]);
            $ids[] = array_merge($ids, $this->haveUserMetaInDatabase($userId, $meta_key, $meta_value));
        }

        return $ids;
    }
public function haveUserCapabilitiesInDatabase($userId, $role)
    {
        if (!is_array($role)) {
            $meta_key = $this->grabPrefixedTableNameFor() . 'capabilities';
            $meta_value = serialize([$role => 1]);

            return $this->haveUserMetaInDatabase($userId, $meta_key, $meta_value);
        }
        $ids = [];
        foreach ($role as $blogId => $_role) {
            $blogIdAndPrefix = $blogId == 0 ? '' : $blogId . '_';
            $meta_key = $this->grabPrefixedTableNameFor() . $blogIdAndPrefix . 'capabilities';
            $meta_value = serialize([$_role => 1]);
            $ids[] = array_merge($ids, $this->haveUserMetaInDatabase($userId, $meta_key, $meta_value));
        }

        return $ids;
    }
public function haveUserCapabilitiesInDatabase ( $ userId , $ role ) { if ( ! is_array ( $ role ) ) { $ meta_key = $ this -> grabPrefixedTableNameFor ( ) . 'capabilities' ; $ meta_value = serialize ( [ $ role => 1 ] ) ; return $ this -> haveUserMetaInDatabase ( $ userId , $ meta_key , $ meta_value ) ; } $ ids = [ ] ; foreach ( $ role as $ blogId => $ _role ) { $ blogIdAndPrefix = $ blogId == 0 ? '' : $ blogId . '_' ; $ meta_key = $ this -> grabPrefixedTableNameFor ( ) . $ blogIdAndPrefix . 'capabilities' ; $ meta_value = serialize ( [ $ _role => 1 ] ) ; $ ids [ ] = array_merge ( $ ids , $ this -> haveUserMetaInDatabase ( $ userId , $ meta_key , $ meta_value ) ) ; } return $ ids ; }
Sets a user capabilities in the database.

@example
```php
$blogId = $this->haveBlogInDatabase('test');
$editor = $I->haveUserInDatabase('luca', 'editor');
$capsIds = $I->haveUserCapabilitiesInDatabase($editor, [$blogId => 'editor']);
```

@param int          $userId The ID of the user to set the capabilities of.
@param string|array $role Either a role string (e.g. `administrator`) or an associative array of blog IDs/roles
for a multisite installation (e.g. `[1 => 'administrator`, 2 => 'subscriber']`).

@return array An array of inserted `meta_id`.
Sets a user capabilities in the database .