Exemplo n.º 1
0
 /**
  * @test
  * it should allow setting the user role on a blog base
  */
 public function it_should_allow_setting_the_user_role_on_a_blog_base(FunctionalTester $I)
 {
     $blogIdsAndRoles = array_keys($this->rolesAndLevels);
     $I->haveUserInDatabase('Luca', $blogIdsAndRoles);
     $userId = $I->grabUserIdFromDatabase('Luca');
     foreach ($blogIdsAndRoles as $blogId => $msRole) {
         $msLevel = Roles::getLevelForRole($msRole);
         $blogIdAndPrefix = $blogId == 0 ? '' : $blogId . '_';
         $I->seeUserMetaInDatabase(['user_id' => $userId, 'meta_key' => $I->grabPrefixedTableNameFor($blogIdAndPrefix . 'capabilities'), 'meta_value' => serialize([$msRole => 1])]);
         $I->seeUserMetaInDatabase(['user_id' => $userId, 'meta_key' => $I->grabPrefixedTableNameFor($blogIdAndPrefix . 'user_level'), 'meta_value' => $msLevel]);
     }
 }
Exemplo n.º 2
0
 /**
  * Sets the user level in the database for a user.
  *
  * @param int $userId
  * @param string|array $role Either a role string (e.g. `administrator`) or an array of blog IDs/roles for a
  *                           multisite installation.
  *
  * @return array An array of inserted `meta_id`.
  */
 public function haveUserLevelsInDatabase($userId, $role)
 {
     if (!is_array($role)) {
         $meta_key = $this->grabPrefixedTableNameFor() . 'user_level';
         $meta_value = User\Roles::getLevelForRole($role);
         return $this->haveUserMetaInDatabase($userId, $meta_key, $meta_value);
     }
     $ids = [];
     foreach ($role as $blogId => $_role) {
         $blogIdAndPrefix = $blogId == 0 ? '' : $blogId . '_';
         $meta_key = $this->grabPrefixedTableNameFor() . $blogIdAndPrefix . 'user_level';
         $meta_value = User\Roles::getLevelForRole($_role);
         $ids[] = $this->haveUserMetaInDatabase($userId, $meta_key, $meta_value);
     }
     return $ids;
 }